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.


PubChem 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.


Open Babel can convert all kinds of input into pictures with 2D structures.

  • 1
    $\begingroup$ While I appreciate the mention of Open Babel, there isn't a web api, which was the original request. If people do use obabel, I'd highly recommend using the SVG export option. $\endgroup$ – Geoff Hutchison Jul 30 '18 at 15:02

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/"structure identifier"/"representation"

For example, you can use:


enter image description here

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


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


Another option for a little programming is the Indigo Toolkit, which has Python, Java, .NET, and C libraries.

The following Python example takes the isomeric SMILES for Albuterol, which I obtained from PubChem, 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.


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)

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")

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

An example (taken from here) 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)                 

The result can be seen here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.