I would like to use RDKit to highlight all benzene rings (regardless of substitution pattern - e.g. phenol, chlorobenene, benzoic acid type should all be highlighted) in any given molecule. I cannot come up with a general SMARTS pattern that simply matches 'benzene ring'. This seems like it should be a lot simpler than I found it to be :<
1 Answer
$\begingroup$
$\endgroup$
1
just "[c]1:[c]:[c]:[c]:[c]:[c]1" should do the job. lowercase c means aromatic carbon, i also include aromatic bonds ":" explicitly though even without it should work quite well for your purpose.
demonstration:
from rdkit import Chem
patt=Chem.MolFromSmarts("[c]1:[c]:[c]:[c]:[c]:[c]1")
chlorobenzene=Chem.MolFromSmiles("c1ccccc1Cl")
phenol=Chem.MolFromSmiles("c1ccccc1O")
benzoicacid=Chem.MolFromSmiles("c1ccccc1C(=O)O")
for m in [chlorobenzene,phenol,benzoicacid]:
print(m.HasSubstructMatch(patt))
spits out True
three times
-
$\begingroup$ Thanks so much wikke! $\endgroup$– user139752Commented Nov 23, 2023 at 21:50