mstk.forcefield.typer.SmartsTyper¶
- class mstk.forcefield.typer.SmartsTyper(file=None)¶
SmartsTyper assign atom types with local environment defined by SMARTS and a hierarchical rule.
A type definition file is required.
Examples
>>> TypeDefinition
>>> H_1 [#1] >>> C_4 [#6X4] >>> HC [H][CX4] >>> CT [CX4;H3] >>> CS [CX4;H2] >>> HT [H][CX4]c1ccccc1
>>> HierarchicalTree
>>> H_1 >>> HC >>> HT >>> C_4 >>> CT >>> CS
This is a sample type definition file for hydrocarbons with OPLS force field. Two sections are required: TypeDefinition and HierarchicalTree. TypeDefinition determines which type the atom can be by matching SMARTS. An atom can match several atom types defined in TypeDefinition section. e.g. Hydrogen atoms with one neighbour will match type H_1, and carbon atoms with four neighbour will match type C_4. Hydrogen atoms bonded with four neighboured carbon will also match type HC. If a four neighboured carbon is bonded to a benzene ring, then hydrogen atoms bonded to this carbon will also match type HT. Four neighboured carbon connected with two and three hydrogen atoms will also match CS and CT, respectively.
After all the possible atom types are matched, HierarchicalTree determines which type the atom will finally be by performing depth first search. The indentation (by 4 spaces) in the HierarchicalTree section represents the depth of atom types. Therefore, if a atom matches C_4, but not CT or CS, it will be typed as C_4 If a atom matches both C_4 and CT but not CS, it will be typed as CT. If a atom matches both C_4 and CS but not CT, it will be typed as CS. If a atom matches both C_4, CT and CS (which is impossible in this example), it will be typed as CT.
For molecule propane, based on the TypeDefinition, all the hydrogen atoms will match atom type H_1 and HC. All the carbon atoms will match atom type C_4, but the side carbon atoms will also match CT and the center carbon atom will also match CS. Then based on the HierarchicalTree, all the hydrogen atoms will be typed as HC. Side carbon atoms will be typed as CT, and center carbon atom will be typed as CS.
The hierarchical strategy make the atom type definition extendable.
- Parameters:
file (str or file-like object, optional) – Type definition file.
Notes
SMARTS is parsed by using RDKit package. Make sure it is installed.
In type definition file, empty lines are ignored, and comments should start with ##.
Methods
__init__([file])open(filename)Load a typer from a type definition file.
type(top_or_mol)Assign types for all atoms in a topology or molecule.