# Chemical Molecule Drawing with rdkit

This post is just a quick introduction on how to use rdkit python bindings to draw chemical molecules.

I have a very special friend that downloads terrible jpegs/pngs from the internet to use in her lectures. Every time, I promise myself that I will make her better figures. Well, now it is time to fulfill that promise!

First, I had to familiarize myself with the Simplified Molecular Input Line Entry System or SMILES. In a nutshell SMILES is a string representation for molecules.

Also, I'm not a chemist, so I relied on PubChem to find the SMILES strings for the figures below.

I will use the Chem submodule from rdkit. rdkit.Chem has an option to override the IPython.display and show the molecules objects in the notebook. But I was unable to make it work in my environment. No biggie though, I just used the MolToMPL() method and displayed the plots as a matplotlib figures.

In [2]:
from rdkit import Chem
from rdkit.Chem import Draw

size = (120, 120)  # Smaller figures than the default.


First a simple figure with some ions.

In [3]:
m = Chem.MolFromSmiles('[Na+].[Cl-]')
fig = Draw.MolToMPL(m, size=size)


An organic-something ring (I think).

In [4]:
m = Chem.MolFromSmiles('c1ccccc1')
fig = Draw.MolToMPL(m, size=size)


One of the molecules that I'm sure she will need.

In [5]:
m = Chem.MolFromSmiles('C1=C2C(=CC(=C1Cl)Cl)OC3=CC(=C(C=C3O2)Cl)Cl')
fig = Draw.MolToMPL(m, size=size)


Every nerd's favorite molecule.

In [6]:
m = Chem.MolFromSmiles('Cn1cnc2c1c(=O)n(c(=O)n2C)C')
fig = Draw.MolToMPL(m, size=size)


And last, but not least, a Breaking Bad Good bye.

In [7]:
m = Chem.MolFromSmiles('C[C@@H](CC1=CC=CC=C1)NC')
fig = Draw.MolToMPL(m, size=size)


As you can see it is extremely easy to draw molecules using rdkit and the SMILES syntax.

The rdkit package is much more than just drawing molecules and I believe that a chemist might enjoy it even more that I did making these figures.

In [8]:
HTML(html)

Out[8]:

This post was written as an IPython notebook. It is available for download or as a static html.