RDKit rdMolDraw2D.PrepareAndDrawMolecule - Substructure Highlight

This section provides a tutorial example on how to highlight a substructure in a molecule with m.GetSubstructMatch(s) and rdMolDraw2D.PrepareAndDrawMolecule() methods in RDKit library.

If you want to highlight a substructure in a molecule, you can use:

Here is an example of from the "Getting Started with the RDKit in Python" guide at https://www.rdkit.org/docs/GettingStartedInPython.html.

from rdkit.Chem.Draw import rdMolDraw2D
smi = 'c1cc(F)ccc1Cl'
mol = Chem.MolFromSmiles(smi)
patt = Chem.MolFromSmarts('ClccccF')
hit_ats = list(mol.GetSubstructMatch(patt))
hit_bonds = []
for bond in patt.GetBonds():
   aid1 = hit_ats[bond.GetBeginAtomIdx()]
   aid2 = hit_ats[bond.GetEndAtomIdx()]
   hit_bonds.append(mol.GetBondBetweenAtoms(aid1,aid2).GetIdx())
d = rdMolDraw2D.MolDraw2DCairo(300, 300)
rdMolDraw2D.PrepareAndDrawMolecule(d, mol, highlightAtoms=hit_ats,
                                  highlightBonds=hit_bonds)
d.FinishDrawing()
p = d.GetDrawingText()

from IPython.display import Image
i = Image(p)
display(i)
RDKit rdMolDraw2D.PrepareAndDrawMolecule - Substructure Highlight
RDKit rdMolDraw2D.PrepareAndDrawMolecule - Substructure Highlight

Table of Contents

 About This Book

 SMILES (Simplified Molecular-Input Line-Entry System)

 Open Babel: The Open Source Chemistry Toolbox

 Using Open Babel Command: "obabel"

 Generating SVG Pictures with Open Babel

 Substructure Search with Open Babel

 Similarity Search with Open Babel

 Fingerprint Index for Fastsearch with Open Babel

 Stereochemistry with Open Babel

 Command Line Tools Provided by Open Babel

 RDKit: Open-Source Cheminformatics Software

 rdkit.Chem.rdchem - The Core Module

 rdkit.Chem.rdmolfiles - Molecular File Module

 rdkit.Chem.rdDepictor - Compute 2D Coordinates

 rdkit.Chem.Draw - Handle Molecule Images

Molecule Substructure Search with RDKit

 RDKit m.HasSubstructMatch(s) - Substructure Match

 RDKit GenerateDepictionMatching2DStructure(m, s) - Substructure Orientation

RDKit rdMolDraw2D.PrepareAndDrawMolecule - Substructure Highlight

 RDKit Substructure Search with SMARTS

 rdkit.Chem.rdFMCS - Maximum Common Substructure

 rdkit.Chem.rdSubstructLibrary - Substructure Library

 Substructure Library in Binary and SMILES Formats

 rdkit.Chem.rdmolops - Molecule Operations

 Daylight Fingerprint Generator in RDKit

 Morgan Fingerprint Generator in RDKit

 RDKit Performance on Substructure Search

 Introduction to Molecular Fingerprints

 OCSR (Optical Chemical Structure Recognition)

 AlphaFold - Protein Structure Prediction

 Resources and Tools

 Cheminformatics Related Terminologies

 References

 Full Version in PDF/EPUB