Chemistry Toolkit Rosetta Wiki
Advertisement

I don't know about you, but I have a hard time looking at anything other than trivial SMILES strings and SD files and understanding the contained molecular structure. Images help, a lot. Noel O'Boyle put together an incredible molecular depiction comparison, so go there if you want to get a sense for the visual styles from different toolkits.

The point here is to show the the details of how to take a structure without 2D coordinates, generate a layout, depict it, and save the results to a file.

Implementation

Depict the SMILES "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" as an image of size 200x250 pixels. The image should be in PNG format if possible, otherwise in GIF format. If possible, give it the title "Caffeine". It should display the structure on a white background.

The depiction should go through all the steps in generating a standard depiction for any input SMILES, and should not take advantage of the simplicity of the test structure.

OEChem/Python

Caffeine depiction with the OpenEye toolkits.

Output from OpenEye/Python

from openeye.oechem import *
from openeye.oedepict import *

smiles = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
mol = OEMol()
OEParseSmiles(mol, smiles)
mol.SetTitle("Caffeine")

OEAssignAromaticFlags(mol)
OESetDimensionFromCoords(mol)
OESuppressHydrogens(mol)
OEAddDepictionHydrogens(mol)
OEDepictCoordinates(mol)
OEMDLPerceiveBondStereo(mol)

view = OEDepictView(200, 250)
view.SetSuperAtoms(False)
view.SetAromaticCircles(False)
view.SetAromaticDashes(True)

# Make this a black and white depiction
view.SetColorOnBlack(False)
view.SetBackColor(255, 255, 255)
view.SetForeColor(0, 0, 0)

view.SetShowHydrogens(True)
view.SetDativeBonds(False)
#view.SetLogo(False)

img = OE8BitImage(view.XRange(), view.YRange())

view.SetMolecule(mol)
view.RenderImage(img, True, 0, 0)

# OpenEye does not have a PNG writer. See
#   http://www.dalkescientific.com/writings/diary/archive/2007/05/23/oe8bitimage_to_png.html
# for one way to export the image data to PIL, which can generate the PNG.
# For C++ programmers, see toolkits/examples/ogham/mol2png.cpp
ofs = oeofstream("caffeine.gif")
OEWriteGIF(ofs, img)
Advertisement