Free API to view 2D representation of Molecules

I'm looking for a free API that can accept a SMILE and produce the 2D structure of a molecule. I would like to include this in a web page.


I have collection of SMILES and would like to have the 2D structure available as part of a database. I tried generating images using RDKit but I can't add that these images to any data frame or tabular data structure. Any suggestions on how to display the 2D representation of and any SMILE queried on the web page will be appreciated.




[Open Babel](http://openbabel.org/wiki/Main_Page) can convert all kinds of input into pictures with 2D structures.


 6

[PubChem](https://pubchem.ncbi.nlm.nih.gov/edit2/index.html) offers a way to get the 2D structure of a molecule if you input the SMILES.


However, why settle for 2D, if you can get 3D structures just as easily?


As an added addition, you might as well check out `https://chemapps.stolaf.edu/jmol/jmol.php?model=[INSERT-SMILES-HERE]`. This tool will produce the 3D structure of any molecule you can get the SMILES of. Just write the SMILES after the equal to, and *voila*! You got yourself a nice interactive molecule viewer which you can rotate around to see how it looks.




---


**Disclaimer:** I am not affiliated with any of the sites posted above.


 4

If you want a free web service, as noted above you can use PubChem to convert from a SMILES string to a 2D representation. But that's only "limited" to the entries in PubChem...


A better option, IMHO, is the very easy to use [NIH Chemical Resolver](https://cactus.nci.nih.gov/chemical/structure)


<https://cactus.nci.nih.gov/chemical/structure/>"**structure identifier**"/"*representation*"


For example, you can use:


<https://cactus.nci.nih.gov/chemical/structure/aspirin/image>:


[![enter image description here](https://i.stack.imgur.com/1CR5h.gif)](https://i.stack.imgur.com/1CR5h.gif)


As indicated above, the "identifier" can be names, escaped SMILES strings, etc. 



> 
> Note: Triple bonds in SMILES strings represented by '#' have to be URL-escaped as '%23' (e.g. the SMILES string of ethyne has to be specified as 'C%23C' instead of 'C#C' if encoded as part of a URL
> 
> 
> 


 4

It's not an API, but JSME (Javascript Molecule Editor) can be used to convert MOL, SDF, or SMILES into a 2D structure.


 3

If you are willing to put a little programming effort into this you could have a look at the [Chemistry Development Kit (CDK)](https://cdk.github.io/) that is easily capable of converting a SMILES string into a 2D render of the molecule. 


An example (taken from [here](http://ctr.wikia.com/wiki/Depict_a_compound_as_an_image)) that will produce the depiction as a PNG image looks like this: 



```
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.*;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import java.awt.Color;

public class Main {
public static void main(String[] args) throws Exception {
    IChemObjectBuilder bldr   = SilentChemObjectBuilder.getInstance();
    SmilesParser       smipar = new SmilesParser(bldr);

    IAtomContainer mol = smipar.parseSmiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C");
    mol.setProperty(CDKConstants.TITLE, "caffeine");

    DepictionGenerator dptgen = new DepictionGenerator();
    // size in px (raster) or mm (vector)
    // annotations are red by default
    dptgen.withSize(200, 250)                 
          .withMolTitle()
          .withTitleColor(Color.DARK_GRAY);
    dptgen.depict(mol)
          .writeTo("~/caffeine.png");
}
}

```

The result can be seen [here](https://vignette.wikia.nocookie.net/ctr/images/5/56/Caffeine.png)


 2

Another option for a little programming is the [Indigo Toolkit](https://lifescience.opensource.epam.com/download/indigo/index.html), which has Python, Java, .NET, and C libraries. 


The following Python example takes the isomeric SMILES for Albuterol, which I obtained from [PubChem](https://pubchem.ncbi.nlm.nih.gov/), and renders 2D structures for three forms (one with unspecified stereochemistry and the two stereoisomers). The individual structures are labeled with their respective PubChem CIDs. 


[![Albuterol](https://i.stack.imgur.com/HyqB0.png)](https://i.stack.imgur.com/HyqB0.png)



```
from indigo import *
from indigo.renderer import *

indigo = Indigo()
renderer = IndigoRenderer(indigo)

mols = {   '2083': 'CC(C)(C)NCC(C1=CC(=C(C=C1)O)CO)O',
         '123600': 'CC(C)(C)NC[C@@H](C1=CC(=C(C=C1)O)CO)O',
         '182176': 'CC(C)(C)NC[C@H](C1=CC(=C(C=C1)O)CO)O' }

array = indigo.createArray()
for key in mols.keys():
    print(key, mols[key])
    mol = indigo.loadMolecule(mols[key])
    s = "CID=" + key
    mol.setProperty("grid-comment", s)
    array.arrayAdd(mol)

indigo.setOption("render-comment", "Albuterol")
indigo.setOption("render-comment-position", "top")
indigo.setOption("render-grid-margins", "40, 10")
indigo.setOption("render-grid-title-offset", "5")
indigo.setOption("render-grid-title-property", "grid-comment")
indigo.setOption("render-background-color", 1.0, 1.0, 1.0)
indigo.setOption("render-atom-color-property", "color")
indigo.setOption("render-coloring", True)
indigo.setOption("render-image-size", 1200, 300)

renderer.renderGridToFile(array, None, 3, "grid.png")

```

 2