# source: https://www.rdkit.org/docs/Cookbook.html
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import Draw
IPythonConsole.ipython_useSVG=True
def mol_with_atom_index(mol):
for atom in mol.GetAtoms():
atom.SetAtomMapNum(atom.GetIdx())
return mol
# Test in a kinase inhibitor
mol = Chem.MolFromSmiles("C1CC2=C3C(=CC=C2)C(=CN3C1)[C@H]4[C@@H](C(=O)NC4=O)C5=CNC6=CC=CC=C65")
# Default
mol
For me, it works good enough (though in a Jupyter notebook I prefer the output as .png):
Then, running your example as a subsequent cell
# your example
m = Chem.MolFromSmiles('c1cc(C(=O)O)c(OC(=O)C)cc1')
substructure = Chem.MolFromSmarts('C(=O)O')
print(m.GetSubstructMatches(substructure))
m
both yields
((3, 4, 5), (8, 9, 7))
as well as the captured illustration below:
Note, it might be that RDKit packaged for your OS lags a little behind the one packaged by Miniconda (cf. tangents in this answer). On occasion, this may affect some of the functionality/syntax at your disposition.
# source: https://www.rdkit.org/docs/Cookbook.htmlfrom rdkit import Chemfrom rdkit.Chem.Draw import IPythonConsolefrom rdkit.Chem import DrawIPythonConsole.ipython_useSVG=Truedef mol_with_atom_index(mol): for atom in mol.GetAtoms(): atom.SetAtomMapNum(atom.GetIdx()) return mol# Test in a kinase inhibitormol = Chem.MolFromSmiles("C1CC2=C3C(=CC=C2)C(=CN3C1)[C@H]4[C@@H](C(=O)NC4=O)C5=CNC6=CC=CC=C65")# Defaultmol
For me, it works good enough (though in a Jupyter notebook I prefer the output as .png):
Then, running your example as a subsequent cell
# your examplem = Chem.MolFromSmiles('c1cc(C(=O)O)c(OC(=O)C)cc1')substructure = Chem.MolFromSmarts('C(=O)O')print(m.GetSubstructMatches(substructure))m
both yields
((3, 4, 5), (8, 9, 7))
as well as the captured illustration below:
Note, it might be that RDKit packaged for your OS lags a little behind the one packaged by Miniconda (cf. tangents in this answer). On occasion, this may affect some of the functionality/syntax at your disposition.
In your code for SVG you use GetSubstructMatch instead of GetSubstructMatches so only one match is found.
To get all matches you have to use GetSubstructMatches and then transform the matches in one single tuple for the highlights.
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem.Draw import rdMolDraw2D
from IPython.display import SVG
from itertools import chain
m = Chem.MolFromSmiles('c1cc(C(=O)O)c(OC(=O)C)cc1')
sub = m.GetSubstructMatches(Chem.MolFromSmarts('C(=O)O'))
print(sub)
((3, 4, 5), (8, 9, 7))
allsubs = tuple(chain.from_iterable(sub))
print(allsubs)
(3, 4, 5, 8, 9, 7)
In your code for SVG you use GetSubstructMatch instead of GetSubstructMatches so only one match is found.To get all matches you have to use GetSubstructMatches and then transform the matches in one single tuple for the highlights.
It may be useful to work RDKit's cookbook from top to bottom. I.e., to start with drawing a molecule
For me, it works good enough (though in a Jupyter notebook I prefer the output as
.png):Then, running your example as a subsequent cell
both yields
as well as the captured illustration below:
Note, it might be that RDKit packaged for your OS lags a little behind the one packaged by Miniconda (cf. tangents in this answer). On occasion, this may affect some of the functionality/syntax at your disposition.
It may be useful to work RDKit's cookbook from top to bottom. I.e., to start with drawing a molecule
For me, it works good enough (though in a Jupyter notebook I prefer the output as
.png):Then, running your example as a subsequent cell
both yields
as well as the captured illustration below:
Note, it might be that RDKit packaged for your OS lags a little behind the one packaged by Miniconda (cf. tangents in this answer). On occasion, this may affect some of the functionality/syntax at your disposition.
More
VOTE
In your code for SVG you use
GetSubstructMatchinstead ofGetSubstructMatchesso only one match is found. To get all matches you have to useGetSubstructMatchesand then transform the matches in one singletuplefor the highlights.Now use
allsubsand you get the your image.In your code for SVG you use
GetSubstructMatchinstead ofGetSubstructMatchesso only one match is found.To get all matches you have to useGetSubstructMatchesand then transform the matches in one singletuplefor the highlights.Now use
allsubsand you get the your image.More
VOTE