seibuilder.packmol package

Wrapper for Packmol.

Thank you to Richard Gowers from MDAnalysis, see https://github.com/MDAnalysis/MDAPackmol

class PackmolStructure(atoms: Atoms, number: int, instructions: list | str, resname: str | None = None)[source]

Bases: object

Class to handle ASE Atoms object in packmol.

save_structure(index: int)[source]

Save this molecule for Packmol to use.

Parameters:

index (int) – the index of this template molecule within entire system.

to_packmol_inp(index: int) str[source]

Create portion of packmol.inp file from this molecule.

Parameters:

index (int) – the index of this template molecule within entire system.

Returns:

text to write to Packmol input for this molecule.

Return type:

str

packmol(structures: List[PackmolStructure], packmol_bin: str | None = None, n_lines: int = 10, cell: list | None = None, tolerance: float = 2.0, slurm: bool = False, maxit: int | None = None, nloop: int | None = None, seed: int | None = None, verbose: int = 2)[source]

Take molecules and settings and create a larger system.

Parameters:
  • structures (list) – list of PackmolStructure objects.

  • packmol_bin (str, optional) – path to the packmol binary if it is not stored in PATH, if None will use the command packmol. Defaults to None.

  • n_lines (int, optional) – number of starting lines to print. Defaults to 10.

  • cell (list, optional) – cell: 3x3 matrix or length 3 or 6 vector Unit cell. A 3x3 matrix (the three unit cell vectors) or just three numbers for an orthorhombic cell. Another option is 6 numbers, which describes unit cell with lengths of unit cell vectors and with angles between them (in degrees), in following order: [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)], see https://wiki.fysik.dtu.dk/ase/ase/cell.html?highlight=cell#module-ase.cell. Defaults to None.

  • tolerance (float, optional) – : Minimum distance between molecules. Defaults to 2.0.

  • slurm (bool, optional) – if True will submit a job with``SLURM`` workload manager,. Defaults to False.

  • maxit (int, optional) – This is the maximum number of iterations of the local optimizer (GENCAN) per loop. changing it may improve (or worse) the convergence. Defaults to 20.

  • nloop (int, optional) – Change the maximum number of optimization loops (if this option is used inside the structure section, it affects the number of optimization loops only of that specific structure). Defaults to None.

  • seed (int, optional) – Change random number generator seed. Defaults to None.

  • verbose (int, optional) – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2.

Returns:

final system with additiona info in the property array.

Return type:

ASE.Atoms

Submodules

Wrapper for Packmol.

Thank you to Richard Gowers from MDAnalysis, see https://github.com/MDAnalysis/MDAPackmol

exception PackmolError[source]

Bases: Exception

Pacmol error class.

class PackmolStructure(atoms: Atoms, number: int, instructions: list | str, resname: str | None = None)[source]

Bases: object

Class to handle ASE Atoms object in packmol.

save_structure(index: int)[source]

Save this molecule for Packmol to use.

Parameters:

index (int) – the index of this template molecule within entire system.

to_packmol_inp(index: int) str[source]

Create portion of packmol.inp file from this molecule.

Parameters:

index (int) – the index of this template molecule within entire system.

Returns:

text to write to Packmol input for this molecule.

Return type:

str

load_packmol_output(structures: List[PackmolStructure], verbose: int = 0)[source]

Load the packmol output.

Parameters:
  • structures (list) – list of PackmolStructure objects

  • (int – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2. Defaults to 0.

  • optional) – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2. Defaults to 0.

Returns:

final system with additiona info in the property Atoms.info.

Return type:

ASE.Atoms

make_packmol_input(structures: List[PackmolStructure], tolerance: float = 2.0, verbose: int = 1, maxit: int | None = 20, nloop: int | None = None, seed: int | None = None)[source]

Convert the call into a Packmol usable input file.

Parameters:
  • structures (list) – list of PackmolStructure objects

  • tolerance (float, optional) – Minimum distance between molecules. Defaults to 2.0.

  • verbose (int, optional) – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2.

  • maxit (int, optional) – This is the maximum number of iterations of the local optimizer (GENCAN) per loop. changing it may improve (or worse) the convergence. Defaults to 20.

  • nloop (int, optional) – Change the maximum number of optimization loops (if this option is used inside the structure section, it affects the number of optimization loops only of that specific structure). Defaults to None.

  • seed (int, optional) – Change random number generator seed. Defaults to None.

packmol(structures: List[PackmolStructure], packmol_bin: str | None = None, n_lines: int = 10, cell: list | None = None, tolerance: float = 2.0, slurm: bool = False, maxit: int | None = None, nloop: int | None = None, seed: int | None = None, verbose: int = 2)[source]

Take molecules and settings and create a larger system.

Parameters:
  • structures (list) – list of PackmolStructure objects.

  • packmol_bin (str, optional) – path to the packmol binary if it is not stored in PATH, if None will use the command packmol. Defaults to None.

  • n_lines (int, optional) – number of starting lines to print. Defaults to 10.

  • cell (list, optional) – cell: 3x3 matrix or length 3 or 6 vector Unit cell. A 3x3 matrix (the three unit cell vectors) or just three numbers for an orthorhombic cell. Another option is 6 numbers, which describes unit cell with lengths of unit cell vectors and with angles between them (in degrees), in following order: [len(a), len(b), len(c), angle(b,c), angle(a,c), angle(a,b)], see https://wiki.fysik.dtu.dk/ase/ase/cell.html?highlight=cell#module-ase.cell. Defaults to None.

  • tolerance (float, optional) – : Minimum distance between molecules. Defaults to 2.0.

  • slurm (bool, optional) – if True will submit a job with``SLURM`` workload manager,. Defaults to False.

  • maxit (int, optional) – This is the maximum number of iterations of the local optimizer (GENCAN) per loop. changing it may improve (or worse) the convergence. Defaults to 20.

  • nloop (int, optional) – Change the maximum number of optimization loops (if this option is used inside the structure section, it affects the number of optimization loops only of that specific structure). Defaults to None.

  • seed (int, optional) – Change random number generator seed. Defaults to None.

  • verbose (int, optional) – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2.

Returns:

final system with additiona info in the property array.

Return type:

ASE.Atoms

run_packmol(packmol_bin: str | None = None, n: int = 10, slurm: bool = False, verbose: int = 2)[source]

Run and follow that Packmol worked correctly.

Parameters:
  • packmol_bin (str, optional) – path to the packmol binary if it is not stored in PATH, if None will use the command packmol. Defaults to None.

  • n (int, optional) – number of starting lines to print. Defaults to 10.

  • slurm (bool, optional) – if True will submit a job with``SLURM`` workload manager,. Defaults to False.

  • verbose (int, optional) – loudness controller: - 0: print errors - 1: print errors and warnings - 2: print errors, warnings and info - 3: print errors, warnings, info and debugger messages. Defaults to 2.

Raises:

PackmolError – raise if packmol did not converged.