pywindow.MolecularSystem¶
- class pywindow.MolecularSystem[source]¶
Bases:
objectContainer for the molecular system.
To load input and initialise
MolecularSystem, one of theMolecularSystemclassmethods (load_file(),load_rdkit_mol()orload_system()) should be used.MolecularSystemshould not be initialised by itself.Examples
Using file as an input:
pywindow.MolecularSystem.load_file("filepath")
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({...})
- molecules¶
A dictionary containing all the returned
Molecules after usingmake_modular().
Methods
Decipher force field atom ids.
Dump a
MolecularSystemto a file (PDB or XYZ).Dump a
MolecularSystemto a JSON dictionary.Create a
MolecularSystemfrom an input file.Create a
MolecularSystemfromrdkit.Chem.Mol.Create a
MolecularSystemfrom a pythondict.Find and return all
Molecules inMolecularSystem.Rebuild molecules in molecular system.
Swap a force field atom id for another user-defined value.
Return
MolecularSystemas aMoleculedirectly.- classmethod load_file(filepath)[source]¶
Create a
MolecularSystemfrom an input file.Recognized input file formats: XYZ, PDB and MOL (V3000).
- Parameters:
- Returns:
- Return type:
- classmethod load_rdkit_mol(mol)[source]¶
Create a
MolecularSystemfromrdkit.Chem.Mol.- Parameters:
mol (rdkit.Chem.Mol) – An RDKit molecule object.
- Returns:
- Return type:
- classmethod load_system(dict_, system_id='system')[source]¶
Create a
MolecularSystemfrom a pythondict.As the loaded
MolecularSystemis storred as adictin theMolecularSystem.systemit can also be loaded directly from adictinput. This feature is used bytrajectorythat extracts trajectory frames as dictionaries and returns them asMolecularSystemobjects through this classmethod.- Parameters:
- Returns:
- Return type:
- 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 createsMolecularSystem.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.systemdictionary 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
MolecularSystemto a file (PDB or XYZ).- Parameters:
filepath (Path | str | None) – The filepath for the dumped file. If
None, the file is dumped localy withsystem_idas filename. (defualt=None)modular (bool) – If False, dump the
MolecularSystemas inMolecularSystem.system, if True, dump theMolecularSystemas catenated :class:Molecule objects fromMolecularSystem.moleculesoverride (bool) – If True, any file in the filepath will be override. (default=False)
- Return type:
None
- dump_system_json(filepath=None, modular=False, override=False)[source]¶
Dump a
MolecularSystemto a JSON dictionary.The dumped JSON dictionary, with
MolecularSystem, can then be loaded through a JSON loader and then throughload_system()to retrieve aMolecularSystem.Kwargs are passed to
pywindow.io_tools.Output.dump2json().- Parameters:
filepath (Path | str | None) – The filepath for the dumped file. If
None, the file is dumped localy withsystem_idas filename. (defualt=None)modular (bool) – If False, dump the
MolecularSystemas inMolecularSystem.system, if True, dump theMolecularSystemas catenated :class:Molecule objects fromMolecularSystem.moleculesoverride (bool) – If True, any file in the filepath will be override. (default=False)
- Return type:
None
- make_modular(rebuild=False)[source]¶
Find and return all
Molecules inMolecularSystem.This function populates
MolecularSystem.moleculeswithMolecules.- 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 newMolecularSystem, if True, the currentMolecularSystemis modified.- Return type:
- 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.systemdictionary to perform the atom keys swapping operation on. (default=’atom_ids’)
- Returns:
NoneType- Return type:
None
- system_to_molecule()[source]¶
Return
MolecularSystemas aMoleculedirectly.Only to be used conditionally, when the
MolecularSystemis a discrete molecule and no input pre-processing is required.- Returns:
- Return type: