Home >
Community >
How to search substructures with explicit hydrogen in RDKit?
Upvote
28
Downvote
+ Cheminformatics
+ Chemistry
Posted by
Adam Moss
How to search substructures with explicit hydrogen in RDKit?
If you work in a Jupyter Notebook you can visualize your substructure patterns and the search results, so you can see how the patterns work.
from rdkit import Chem
from rdkit.Chem import Draw
smiles = ['CC1=CC=CC=C1','CC1=C([H])C([H])=C([H])C([H])=C1[H]',
'C1(C2=CC=CC=C2)=CC=CC=C1','C12=C(CC3=CC=CC=C3C2)C=CC=C1',
'C12=CC=CC=C1C=C3C(C=CC=C3)=C2','C12=C(C(C(C=C3)=CC=C4)=C4C=C2)C3=CC=C1']
params = Chem.SmilesParserParams()
params.removeHs=False # draw and work with explicit Hs
mols = [Chem.MolFromSmiles(s, params) for s in smiles]
Draw.MolsToGridImage(mols, molsPerRow=3)
This will give you the compounds and especially the one with the explicit Hs.
Now we get the patterns and especially the one with the explicit Hs.
ms = []
patt = []
allsubs = []
for m in range(len(mols)):
for p in range(len(patts)):
sub = mols[m].GetSubstructMatches(patts[p])
if len(sub) > 0:
ms.append(mols[m])
patt.append(leg[p])
allsubs.append(sub[0]) # substructures could be find multiple time - just take the first
Draw.MolsToGridImage(ms, molsPerRow=3, legends=patt, highlightAtomLists=allsubs)
Compounds 5 and 6 have no nonaromatic bonds, so there is nothing to find.
If you work in a Jupyter Notebook you can visualize your substructure patterns and the search results, so you can see how the patterns work.
from rdkit import Chemfrom rdkit.Chem import Drawsmiles = ['CC1=CC=CC=C1','CC1=C([H])C([H])=C([H])C([H])=C1[H]', 'C1(C2=CC=CC=C2)=CC=CC=C1','C12=C(CC3=CC=CC=C3C2)C=CC=C1', 'C12=CC=CC=C1C=C3C(C=CC=C3)=C2','C12=C(C(C(C=C3)=CC=C4)=C4C=C2)C3=CC=C1']params = Chem.SmilesParserParams()params.removeHs=False # draw and work with explicit Hsmols = [Chem.MolFromSmiles(s, params) for s in smiles]Draw.MolsToGridImage(mols, molsPerRow=3)
This will give you the compounds and especially the one with the explicit Hs.
Now we get the patterns and especially the one with the explicit Hs.
ms = []patt = []allsubs = []for m in range(len(mols)): for p in range(len(patts)): sub = mols[m].GetSubstructMatches(patts[p]) if len(sub) > 0: ms.append(mols[m]) patt.append(leg[p]) allsubs.append(sub[0]) # substructures could be find multiple time - just take the firstDraw.MolsToGridImage(ms, molsPerRow=3, legends=patt, highlightAtomLists=allsubs)
Compounds 5 and 6 have no nonaromatic bonds, so there is nothing to find.
@theozh It is not the extra carbon, it is just that 1 and 3 do not have explicit Hs. If I add explicit Hs to 3 it is found. I thought C[c;H,h]1[c;H,h][c;H,h][c;H,h][c;H,h][c;H,h]1 (see More
If you work in a Jupyter Notebook you can visualize your substructure patterns and the search results, so you can see how the patterns work.
This will give you the compounds and especially the one with the explicit Hs.
Now we get the patterns and especially the one with the explicit Hs.
Search and highlight the result.
Compounds 5 and 6 have no nonaromatic bonds, so there is nothing to find.
If you work in a Jupyter Notebook you can visualize your substructure patterns and the search results, so you can see how the patterns work.
This will give you the compounds and especially the one with the explicit Hs.
Now we get the patterns and especially the one with the explicit Hs.
Search and highlight the result.
Compounds 5 and 6 have no nonaromatic bonds, so there is nothing to find.
More
VOTE
VOTE
VOTE
VOTE
VOTE
VOTE