Molecular Drawing code in RDKit

Using RDKit and Ipython notebook is useful for interactive coding.
User can check molecules directly in notebook
It can not only one molecule but also list of molecules. If user want to draw molecules as grid image, MolsToGridImage method is good choice.
Also the method highlight atoms.
Example is following.

from rdkit import Chem
from rdkit.Chem import rdBase
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
from rdkit import RDConfig
import os
sdf = Chem.SDMolSupplier(  os.path.join(RDConfig.RDDocsDir, 'Book/data/cdk2.sdf'))
mols = [  m for m in sdf ]
core = Chem.MolFromSmiles( 'c1ncc2nc[nH]c2n1' )
img = Draw.MolsToGridImage( mols, molsPerRow=3, highlightAtomLists=[ mol.GetSubstructMatch(core) for mol in mols], useSVG=True )
img

img returns following image.
gridimage

User can set Highlight atoms for each molecules. I think it’s very flexible for development.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s