Depict a compound as an image

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 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 "CCC#CC[C@H](C)[C@@H](C#C[C@H]1[C@@H](C[C@@H]2[C@@H]1C/C(=C/COCC(=O)[O-])/C2)O)O" 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.

CDK/Java


CDK v1.5.12+ provides a new depict API simplifying image generation. An intermediate Depiction instance is generated that can then be written to raster (PNG,GIF,JPG) or vector (SVG,PDF) output.

CDK/Groovy


When saves as depict.groovy and run with the following command, it will automatically download all required libraries:

groovy depict.groovy

Cactvs/Tcl


prop setparam E_GIF width 200 height 250 bgcolor white \ atomcolor black format png header Caffeine \ filename caffeine.png ens get "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" E_GIF

Btw, it is no accident that the rings are horizontally aligned, and the six-membered ring on the left. That's what a chemist expects, and quality depictions need to take this into account!

The white space around the molecule is intentional. There is a parameter (here with default value 8, a useful setting for typical drugs, but large for this rather small structure) which controls how many standard bonds should fit in the rendering. Smaller molecules are centered, larger ones shrunk dynamically to just fit into the drawing area. This avoids the dreaded "pumping bonds" display style where the bond length varies from image to image.

Cactvs/Python
Prop.Setparam('E_GIF','width',200,'height',250,'bgcolor','white',  'atomcolor','black','format','png','header','Caffeine','filename','caffeine.png') Ens.Get('CN1C=NC2=C1C(=O)N(C(=O)N2C)C','E_GIF')

The output is pixel-identical to the Tcl result.