pywindow.MolecularSystem

class pywindow.MolecularSystem[source]

Bases: object

Container for the molecular system.

To load input and initialise MolecularSystem, one of the MolecularSystem classmethods (load_file(), load_rdkit_mol() or load_system()) should be used. MolecularSystem should not be initialised by itself.

Examples

  1. Using file as an input:

pywindow.MolecularSystem.load_file("filepath")
  1. Using RDKit molecule object as an input:

pywindow.MolecularSystem.load_rdkit_mol(rdkit.Chem.rdchem.Mol)

3. Using a dictionary (or another MoleculeSystem.system) as input:

pywindow.MolecularSystem.load_system({...})
system_id

str or int The input filename or user defined.

system

dict A dictionary containing all the information extracted from input.

molecules

A dictionary containing all the returned Molecule s after using make_modular().

Methods

decipher_atom_keys

Decipher force field atom ids.

dump_system

Dump a MolecularSystem to a file (PDB or XYZ).

dump_system_json

Dump a MolecularSystem to a JSON dictionary.

load_file

Create a MolecularSystem from an input file.

load_rdkit_mol

Create a MolecularSystem from rdkit.Chem.Mol.

load_system

Create a MolecularSystem from a python dict.

make_modular

Find and return all Molecule s in MolecularSystem.

rebuild_system

Rebuild molecules in molecular system.

swap_atom_keys

Swap a force field atom id for another user-defined value.

system_to_molecule

Return MolecularSystem as a Molecule directly.

classmethod load_file(filepath)[source]

Create a MolecularSystem from an input file.

Recognized input file formats: XYZ, PDB and MOL (V3000).

Parameters:

filepath (Path | str) – The input’s filepath.

Returns:

pywindow.MolecularSystem

Return type:

MolecularSystem

classmethod load_rdkit_mol(mol)[source]

Create a MolecularSystem from rdkit.Chem.Mol.

Parameters:

mol (rdkit.Chem.Mol) – An RDKit molecule object.

Returns:

pywindow.MolecularSystem

Return type:

MolecularSystem

classmethod load_system(dict_, system_id='system')[source]

Create a MolecularSystem from a python dict.

As the loaded MolecularSystem is storred as a dict in the MolecularSystem.system it can also be loaded directly from a dict input. This feature is used by trajectory that extracts trajectory frames as dictionaries and returns them as MolecularSystem objects through this classmethod.

Parameters:
  • dict – A python dictionary.

  • system_id (str | int) – Inherited or user defined system id. (default=’system’)

  • dict_ (dict)

Returns:

pywindow.MolecularSystem

Return type:

MolecularSystem

decipher_atom_keys(forcefield='DLF', dict_key='atom_ids')[source]

Decipher force field atom ids.

This takes all values in MolecularSystem.system['atom_ids'] that match force field type criteria and creates MolecularSystem.system['elements'] with the corresponding periodic table of elements equivalents.

If a forcefield is not supported by this method, the MolecularSystem.swap_atom_keys() can be used instead.

DLF stands for DL_F notation.

See: C. W. Yong, Descriptions and Implementations of DL_F Notation: A Natural Chemical Expression System of Atom Types for Molecular Simulations, J. Chem. Inf. Model., 2016, 56, 1405-1409.

Parameters:
  • forcefield (str) – The forcefield used to decipher atom ids. Allowed (not case sensitive): ‘OPLS’, ‘OPLS2005’, ‘OPLSAA’, ‘OPLS3’, ‘DLF’, ‘DL_F’. (default=’DLF’)

  • dict_key (str) – The MolecularSystem.system dictionary key to the array containing the force field atom ids. (default=’atom_ids’)

Returns:

NoneType

Return type:

None

dump_system(filepath=None, modular=False, override=False)[source]

Dump a MolecularSystem to a file (PDB or XYZ).

Parameters:
Return type:

None

dump_system_json(filepath=None, modular=False, override=False)[source]

Dump a MolecularSystem to a JSON dictionary.

The dumped JSON dictionary, with MolecularSystem, can then be loaded through a JSON loader and then through load_system() to retrieve a MolecularSystem.

Kwargs are passed to pywindow.io_tools.Output.dump2json().

Parameters:
Return type:

None

make_modular(rebuild=False)[source]

Find and return all Molecule s in MolecularSystem.

This function populates MolecularSystem.molecules with Molecule s.

Parameters:

rebuild (bool) – If True, run first the rebuild_system().

Returns:

NoneType

Return type:

None

rebuild_system(override=False)[source]

Rebuild molecules in molecular system.

Parameters:

override (bool) – bool, optional (default=False) If False the rebuild molecular system is returned as a new MolecularSystem, if True, the current MolecularSystem is modified.

Return type:

MolecularSystem

swap_atom_keys(swap_dict, dict_key='atom_ids')[source]

Swap a force field atom id for another user-defined value.

This modified all values in MolecularSystem.system['atom_ids'] that match criteria.

This function can be used to decipher a whole forcefield if an appropriate dictionary is passed to the function.

Example

In this example all atom ids ‘he’ will be exchanged to ‘H’.

pywindow.MolecularSystem.swap_atom_keys({'he': 'H'})
Parameters:
  • swap_dict (dict) – A dictionary containg force field atom ids (keys) to be swapped with corresponding values (keys’ arguments).

  • dict_key (str) – A key in MolecularSystem.system dictionary to perform the atom keys swapping operation on. (default=’atom_ids’)

Returns:

NoneType

Return type:

None

system_to_molecule()[source]

Return MolecularSystem as a Molecule directly.

Only to be used conditionally, when the MolecularSystem is a discrete molecule and no input pre-processing is required.

Returns:

pywindow.Molecule

Return type:

Molecule