Chemistry - Free API to view 2D representation of Molecules

Solution 1:

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

Solution 2:

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.


Solution 3:

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:

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

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


Solution 4:

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


Solution 5:

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.

Albuterol

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

Tags: