Drawing molecules in iPython Notebook


In [1]:
from __future__ import print_function
import oddt

In [2]:
print(oddt.__version__)


0.4.1-15-gf7f6653

1. Download molecule from PDBbind


In [3]:
%%bash
wget -q -N www.pdbbind.org.cn/v2007/10gs/10gs_ligand.mol2

2. Variables controling images

There are two main variables for controling the drawing, namely image_size and image_backend located in a oddt.toolkit namespace. There are two backends available PNG (default) and SVG.


In [4]:
print('Default size: ', oddt.toolkit.image_size)
print('Default backend: ', oddt.toolkit.image_backend)


Default size:  (200, 200)
Default backend:  png

3. OpenBabel Drawing

OpenBabel is the default toolkit, although just for assurance will asign is as the toolkit of choice.


In [5]:
oddt.toolkit = oddt.toolkits.ob
mol = next(oddt.toolkit.readfile('mol2', '10gs_ligand.mol2'))
mol.removeh()

3.1 OB PNG (default)


In [6]:
mol


Out[6]:

3.2 OB SVG


In [7]:
oddt.toolkit.image_backend = 'svg'
mol


Out[7]:
10gs_ligand - Open Babel DepictionONHOOH+NH3SNHHOOO

4. RDKit molecules are drawn in the same way


In [8]:
oddt.toolkit = oddt.toolkits.rdk
mol = next(oddt.toolkit.readfile('mol2', '10gs_ligand.mol2'))
mol.removeh()

4.1 RDKit PNG


In [9]:
oddt.toolkit.image_backend = 'png'
mol


Out[9]:

4.2 RDKit SVG


In [10]:
oddt.toolkit.image_backend = 'svg'
mol


Out[10]:
NH3+O-OONHSONHO-O

In [ ]:

5. Changing a size of a molecule

A size can be arbitrally set to an int or two element tuple/list. It is a global setting appplied in all subsequent images.


In [11]:
oddt.toolkit.image_backend = 'png'
oddt.toolkit.image_size = 100

In [12]:
mol


Out[12]:

In [13]:
oddt.toolkit.image_size = (600, 400)

In [14]:
mol


Out[14]:

In [ ]: