suppl = Chem.SDMolSupplier('data/cdk2.sdf')
ms = [x for x in suppl if x is not None]
for m in ms: tmp=AllChem.Compute2DCoords(m)
from rdkit.Chem import Draw
Draw.MolToFile(ms[0],'images/cdk2_mol1.o.png')
Substructure searching
m = Chem.MolFromSmiles('C1=CC=CC=C1OC')
m.HasSubstructMatch(Chem.MolFromSmiles('COC')) # True
m.HasSubstructMatch(Chem.MolFromSmarts('COC')) # False
m.HasSubstructMatch(Chem.MolFromSmarts('COc')) # True #<- need an aromatic C
By default, stereochemistry is not used in substructure searches.
m = Chem.MolFromSmiles('CC[C@H](F)Cl')
m.HasSubstructMatch(Chem.MolFromSmiles('C[C@@H](F)Cl')) # True
m.HasSubstructMatch(Chem.MolFromSmiles('C[C@@H](F)Cl'),useChirality=True) # False
Atom map
qmol = Chem.MolFromSmarts( '[cH0:1][c:2]([cH0])!@[CX3!r:3]=[NX2!r:4]' )
ind_map = {}
for atom in qmol.GetAtoms() :
map_num = atom.GetAtomMapNum()
if map_num:
ind_map[map_num-1] = atom.GetIdx()
ind_map # {0: 0, 1: 1, 2: 3, 3: 4}
map_list = [ind_map[x] for x in sorted(ind_map)]
map_list # [0, 1, 3, 4]
# substructure match
mol = Chem.MolFromSmiles('Cc1cccc(C)c1C(C)=NC')
for match in mol.GetSubstructMatches( qmol ) :
mas = [match[x] for x in map_list]
print(mas) # [1, 7, 8, 10]