Python rdkit.Chem.AllChem.MolFromSmarts() Examples
The following are 4
code examples of rdkit.Chem.AllChem.MolFromSmarts().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rdkit.Chem.AllChem
, or try the search function
.
Example #1
Source File: outputfingerprints.py From qsar-tools with Apache License 2.0 | 5 votes |
def loadsmarts(fname): ret = [] with open(fname) as f: for line in f: if line.startswith('#') or len(line.strip()) == 0: continue tokens = line.split() mol = Chem.MolFromSmarts(tokens[0]) ret.append(mol) return ret
Example #2
Source File: rdallconf.py From rdkit-scripts with MIT License | 5 votes |
def getDihedralMatches(mol): '''return list of atom indices of dihedrals''' #this is rdkit's "strict" pattern pattern = r"*~[!$(*#*)&!D1&!$(C(F)(F)F)&!$(C(Cl)(Cl)Cl)&!$(C(Br)(Br)Br)&!$(C([CH3])([CH3])[CH3])&!$([CD3](=[N,O,S])-!@[#7,O,S!D1])&!$([#7,O,S!D1]-!@[CD3]=[N,O,S])&!$([CD3](=[N+])-!@[#7!D1])&!$([#7!D1]-!@[CD3]=[N+])]-!@[!$(*#*)&!D1&!$(C(F)(F)F)&!$(C(Cl)(Cl)Cl)&!$(C(Br)(Br)Br)&!$(C([CH3])([CH3])[CH3])]~*" qmol = Chem.MolFromSmarts(pattern) matches = mol.GetSubstructMatches(qmol); #these are all sets of 4 atoms, uniquify by middle two uniqmatches = [] seen = set() for (a,b,c,d) in matches: if (b,c) not in seen: seen.add((b,c)) uniqmatches.append((a,b,c,d)) return uniqmatches
Example #3
Source File: template_extractor.py From GLN with MIT License | 4 votes |
def get_special_groups(mol): '''Given an RDKit molecule, this function returns a list of tuples, where each tuple contains the AtomIdx's for a special group of atoms which should be included in a fragment all together. This should only be done for the reactants, otherwise the products might end up with mapping mismatches We draw a distinction between atoms in groups that trigger that whole group to be included, and "unimportant" atoms in the groups that will not be included if another atom matches.''' # Define templates group_templates = [ (range(3), '[OH0,SH0]=C[O,Cl,I,Br,F]',), # carboxylic acid / halogen (range(3), '[OH0,SH0]=CN',), # amide/sulfamide (range(4), 'S(O)(O)[Cl]',), # sulfonyl chloride (range(3), 'B(O)O',), # boronic acid/ester ((0,), '[Si](C)(C)C'), # trialkyl silane ((0,), '[Si](OC)(OC)(OC)'), # trialkoxy silane, default to methyl (range(3), '[N;H0;$(N-[#6]);D2]-,=[N;D2]-,=[N;D1]',), # azide (range(8), 'O=C1N([Br,I,F,Cl])C(=O)CC1',), # NBS brominating agent (range(11), 'Cc1ccc(S(=O)(=O)O)cc1'), # Tosyl ((7,), 'CC(C)(C)OC(=O)[N]'), # N(boc) ((4,), '[CH3][CH0]([CH3])([CH3])O'), # (range(2), '[C,N]=[C,N]',), # alkene/imine (range(2), '[C,N]#[C,N]',), # alkyne/nitrile ((2,), 'C=C-[*]',), # adj to alkene ((2,), 'C#C-[*]',), # adj to alkyne ((2,), 'O=C-[*]',), # adj to carbonyl ((3,), 'O=C([CH3])-[*]'), # adj to methyl ketone ((3,), 'O=C([O,N])-[*]',), # adj to carboxylic acid/amide/ester (range(4), 'ClS(Cl)=O',), # thionyl chloride (range(2), '[Mg,Li,Zn,Sn][Br,Cl,I,F]',), # grinard/metal (non-disassociated) (range(3), 'S(O)(O)',), # SO2 group (range(2), 'N~N',), # diazo ((1,), '[!#6;R]@[#6;R]',), # adjacency to heteroatom in ring ((2,), '[a!c]:a:a',), # two-steps away from heteroatom in aromatic ring #((1,), 'c(-,=[*]):c([Cl,I,Br,F])',), # ortho to halogen on ring - too specific? #((1,), 'c(-,=[*]):c:c([Cl,I,Br,F])',), # meta to halogen on ring - too specific? ((0,), '[B,C](F)(F)F'), # CF3, BF3 should have the F3 included ] # Stereo-specific ones (where we will need to include neighbors) # Tetrahedral centers should already be okay... group_templates += [ ((1,2,), '[*]/[CH]=[CH]/[*]'), # trans with two hydrogens ((1,2,), '[*]/[CH]=[CH]\[*]'), # cis with two hydrogens ((1,2,), '[*]/[CH]=[CH0]([*])\[*]'), # trans with one hydrogens ((1,2,), '[*]/[D3;H1]=[!D1]'), # specified on one end, can be N or C ] # Build list groups = [] for (add_if_match, template) in group_templates: matches = mol.GetSubstructMatches(Chem.MolFromSmarts(template), useChirality=True) for match in matches: add_if = [] for pattern_idx, atom_idx in enumerate(match): if pattern_idx in add_if_match: add_if.append(atom_idx) groups.append((add_if, match)) return groups
Example #4
Source File: reaxys_generate_retro_templates_v9_chiral.py From ASKCOS with Mozilla Public License 2.0 | 4 votes |
def get_special_groups(mol): '''Given an RDKit molecule, this function returns a list of tuples, where each tuple contains the AtomIdx's for a special group of atoms which should be included in a fragment all together. This should only be done for the reactants, otherwise the products might end up with mapping mismatches We draw a distinction between atoms in groups that trigger that whole group to be included, and "unimportant" atoms in the groups that will not be included if another atom matches.''' # Define templates, based on Functional_Group_Hierarchy.txt from Greg Laandrum group_templates = [ (range(3), '[OH0,SH0]=C[O,Cl,I,Br,F]',), # carboxylic acid / halogen (range(3), '[OH0,SH0]=CN',), # amide/sulfamide (range(4), 'S(O)(O)[Cl]',), # sulfonyl chloride (range(3), 'B(O)O',), # boronic acid/ester ((0,), '[Si](C)(C)C'), # trialkyl silane ((0,), '[Si](OC)(OC)(OC)'), # trialkoxy silane, default to methyl (range(3), '[N;H0;$(N-[#6]);D2]-,=[N;D2]-,=[N;D1]',), # azide (range(8), 'O=C1N([Br,I,F,Cl])C(=O)CC1',), # NBS brominating agent (range(11), 'Cc1ccc(S(=O)(=O)O)cc1'), # Tosyl ((7,), 'CC(C)(C)OC(=O)[N]'), # N(boc) ((4,), '[CH3][CH0]([CH3])([CH3])O'), # (range(2), '[C,N]=[C,N]',), # alkene/imine (range(2), '[C,N]#[C,N]',), # alkyne/nitrile ((2,), 'C=C-[*]',), # adj to alkene ((2,), 'C#C-[*]',), # adj to alkyne ((2,), 'O=C-[*]',), # adj to carbonyl ((3,), 'O=C([CH3])-[*]'), # adj to methyl ketone ((3,), 'O=C([O,N])-[*]',), # adj to carboxylic acid/amide/ester (range(4), 'ClS(Cl)=O',), # thionyl chloride (range(2), '[Mg,Li,Zn,Sn][Br,Cl,I,F]',), # grinard/metal (non-disassociated) (range(3), 'S(O)(O)',), # SO2 group (range(2), 'N~N',), # diazo ((1,), '[!#6;R]@[#6;R]',), # adjacency to heteroatom in ring ((2,), '[a!c]:a:a',), # two-steps away from heteroatom in aromatic ring #((1,), 'c(-,=[*]):c([Cl,I,Br,F])',), # ortho to halogen on ring - too specific? #((1,), 'c(-,=[*]):c:c([Cl,I,Br,F])',), # meta to halogen on ring - too specific? ((0,), '[B,C](F)(F)F'), # CF3, BF3 should have the F3 included ] # Stereo-specific ones (where we will need to include neighbors) # Tetrahedral centers should already be okay... group_templates += [ ((1,2,), '[*]/[CH]=[CH]/[*]'), # trans with two hydrogens ((1,2,), '[*]/[CH]=[CH]\[*]'), # cis with two hydrogens ((1,2,), '[*]/[CH]=[CH0]([*])\[*]'), # trans with one hydrogens ((1,2,), '[*]/[D3;H1]=[!D1]'), # specified on one end, can be N or C ] # Build list groups = [] for (add_if_match, template) in group_templates: matches = mol.GetSubstructMatches(Chem.MolFromSmarts(template), useChirality=True) for match in matches: add_if = [] for pattern_idx, atom_idx in enumerate(match): if pattern_idx in add_if_match: add_if.append(atom_idx) groups.append((add_if, match)) return groups