Draw molecule as SVG Part2.

New version of rdkit can draw molecule as SVG.
And newest version of it can change atom font size.
I’m waiting for this function for a long time. ;-)

Let’s Draw!
From ipython notebook…

from __future__ import print_function
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import rdDepictor
from IPython.display import SVG
mol = Chem.MolFromSmiles('CN1CCN(S(=O)(C2=CC=C(OCC)C(C3=NC4=C(N(C)N=C4CCC)C(N3)=O)=C2)=O)CC1')
rdDepictor.Compute2DCoords(mol)
mc = Chem.Mol(mol.ToBinary())
Chem.Kekulize(mc)
drawer = Draw.MolDraw2DSVG(400,400)
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText().replace("svg:","")
drawer.FontSize()

Out[39]:
0.5
SVG(svg)

Then I got following image.
mol1

Next change font size.(default size is 0.5.)

drawer = Draw.rdMolDraw2D.MolDraw2DSVG(400,400)
# set font size more larger
drawer.SetFontSize(0.8)
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText().replace("svg:","")
SVG(svg)

Then I got….
mol2

Cool!
Nice stuff.
I want to embed SVG image to markdown format.
Are there any good practice to do that ?

Advertisement

Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: