moleculekit.tools.detect module#
- moleculekit.tools.detect.connected_component_subgraphs(graph)#
- moleculekit.tools.detect.detectEquivalentAtoms(molecule)#
Detect topologically equivalent atoms.
- Parameters:
molecule (
Molecule
) – Molecule object- Returns:
equivalent_groups (list of tuples) – List of equivalent atom group. Each element is a tuple contain equivalent atom indices.
equivalent_atoms (list of tuples) – List of equivalent atom group for each atom. Each element is a tuple contain equivalent atom indices.
equivalent_group_by_atom (list) – List of equivalent group indices for each atom. The indices corresponds to equivalent_groups order.
Examples
>>> import os >>> from moleculekit.home import home >>> from moleculekit.molecule import Molecule >>> from moleculekit.tools.detect import detectEquivalentAtoms
Get benzamidine >>> molFile = os.path.join(home(‘test-detect’), ‘benzamidine.mol2’) >>> mol = Molecule(molFile)
Find the equivalent atoms of benzamidine >>> equivalent_groups, equivalent_atoms, equivalent_group_by_atom = detectEquivalentAtoms(mol) >>> equivalent_groups [(0,), (1, 5), (2, 4), (3,), (6,), (7, 11), (8, 10), (9,), (12, 13), (14, 15, 16, 17)] >>> equivalent_atoms [(0,), (1, 5), (2, 4), (3,), (2, 4), (1, 5), (6,), (7, 11), (8, 10), (9,), (8, 10), (7, 11), (12, 13), (12, 13), (14, 15, 16, 17), (14, 15, 16, 17), (14, 15, 16, 17), (14, 15, 16, 17)] >>> equivalent_group_by_atom [0, 1, 2, 3, 2, 1, 4, 5, 6, 7, 6, 5, 8, 8, 9, 9, 9, 9]
Get dicarbothioic acid >>> molFile = os.path.join(home(‘test-detect’), ‘dicarbothioic_acid.mol2’) >>> mol = Molecule(molFile)
Find the equivalent atoms of dicarbothioic acid >>> equivalent_groups, equivalent_atoms, equivalent_group_by_atom = detectEquivalentAtoms(mol) >>> equivalent_groups [(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,)] >>> equivalent_atoms [(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,)] >>> equivalent_group_by_atom [0, 1, 2, 3, 4, 5, 6, 7]
- moleculekit.tools.detect.detectParameterizableCores(graph, skip_methyl=True, skip_hydroxyl=False, skip_terminal_hs=False)#
Detect parametrizable dihedral angle cores (central atom pairs)
The cores are detected by looking for bridges (bonds which divide the molecule into two parts) in a molecular graph. Terminal cores are skipped.
- moleculekit.tools.detect.detectParameterizableDihedrals(molecule, exclude_atoms=(), return_all_dihedrals=False, skip_methyl=True, skip_hydroxyl=False, skip_terminal_hs=False)#
Detect parameterizable dihedral angles
- Parameters:
molecule (
Molecule
) – Molecule objectexclude_atoms (list) – Ignore dihedrals which consist purely of atoms in this list
return_all_dihedrals (bool) – Return all dihedral terms. When False it filters out and selects only the dihedral with the terminal with the highest centrality for each core.
skip_methyl (bool) – Setting to True will skip dihedrals whose terminal is a methyl group
skip_hydroxyl (bool) – Setting to True will skip dihedrals whose terminal is a hydroxyl group
skip_terminal_hs (bool) – Setting to True will skip dihedrals ending in hydrogens
- Returns:
dihedrals – List of equivalent dihedral angle groups. Each group is a list of equivalent dihedral angles. Each angle is defined as a tuple of four atom indices (0-based).
- Return type:
Examples
>>> import os >>> from moleculekit.home import home >>> from moleculekit.molecule import Molecule >>> from moleculekit.tools.detect import detectParameterizableDihedrals
Find the parameterizable dihedrals of glycol >>> molFile = os.path.join(home(‘test-detect’), ‘glycol.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(0, 1, 2, 3)], [(1, 2, 3, 9), (2, 1, 0, 4)]]
Find the parameterizable dihedrals of ethanolamine >>> molFile = os.path.join(home(‘test-detect’), ‘ethanolamine.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(0, 1, 2, 3)], [(1, 2, 3, 9), (1, 2, 3, 10)], [(2, 1, 0, 4)]]
Find the parameterizable dihedrals of benzamidine >>> molFile = os.path.join(home(‘test-detect’), ‘benzamidine.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(0, 6, 12, 16), (0, 6, 12, 17), (0, 6, 13, 14), (0, 6, 13, 15)], [(1, 0, 6, 12), (1, 0, 6, 13), (5, 0, 6, 12), (5, 0, 6, 13)]]
# Check if the atom swapping does not affect results
Find the parameterizable dihedrals of chlorethene >>> molFile = os.path.join(home(‘test-detect’), ‘chlorethene_1.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(2, 1, 0, 4), (2, 1, 0, 5)]]
Find the parameterizable dihedrals of chlorethene (with swapped atoms) >>> molFile = os.path.join(home(‘test-detect’), ‘chlorethene_2.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(3, 1, 0, 4), (3, 1, 0, 5)]]
# Check if triple bonds are skipped
Find the parameterizable dihedrals of 4-hexinenitrile >>> molFile = os.path.join(home(‘test-detect’), ‘4-hexinenitrile.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(2, 3, 4, 5)]]
# Check the scoring function
Find the parameterizable dihedrals of dicarbothioic acid >>> molFile = os.path.join(home(‘test-detect’), ‘dicarbothioic_acid.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(0, 1, 3, 5)], [(1, 3, 5, 7)], [(3, 1, 0, 6)]]
Find the parameterizable dihedrals of 2-hydroxypyridine >>> molFile = os.path.join(home(‘test-detect’), ‘2-hydroxypyridine.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(6, 1, 0, 7)]]
Find the parameterizable dihedrals of fluorchlorcyclopronol >>> molFile = os.path.join(home(‘test-detect’), ‘fluorchlorcyclopronol.mol2’) >>> mol = Molecule(molFile, guess=(‘bonds’, ‘angles’, ‘dihedrals’)) >>> detectParameterizableDihedrals(mol) [[(2, 4, 5, 9)]]
- moleculekit.tools.detect.rooted_tree_isomorphism(t1, root1, t2, root2, keyfunc)#
Return if two rooted trees are isomorphic
Given two rooted trees t1 and t2, with roots root1 and root2 respectively this routine will determine if they are isomorphic.
The idea is that for each node we build a hash of the node and its children which takes into account all the properties of the node which we want (here elements and formal charges). Thus isomorphic trees will have identical hashes.
We start from the bottom of the tree, going up. Everytime we find a new node+children combination we generate a new hash. If at any level hashes don’t match it means that one of the two trees has a different structure, this allows us to quit early while going up the tree.
The idea on how to iterate the tree is based on the same named networkx function, but the algorithm is completely original.
- Parameters:
t1 (NetworkX graph) – One of the trees being compared
root1 (int) – a node of t1 which is the root of the tree
t2 (undirected NetworkX graph) – The other tree being compared
root2 (int) – a node of t2 which is the root of the tree
keyfunc (function) – Function which generates the description key for each node. It should take as input the node and return a string