Free API to view 2D representation of Molecules
Solution 1
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 2
Open Babel can convert all kinds of input into pictures with 2D structures.
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:
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
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)
.withMolTitle()
.withTitleColor(Color.DARK_GRAY);
dptgen.depict(mol)
.writeTo("~/caffeine.png");
}
}
The result can be seen here
Related videos on Youtube
Admin
Updated on September 03, 2021Comments
-
Admin about 2 years
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.
-
Geoff Hutchison over 5 yearsWhile 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. -
Geoff Hutchison over 5 yearsAnd yes, you can also get the 3D structures.. e.g. cactus.nci.nih.gov/blog/?p=249