3.1 Creating a Molecule from SMILES

A common method of creating a molecule in OEChem is via the SMILES representation. SMILES notation is commonly used in chemical information systems, as it provides a convenient string representation of a molecule. An introduction to SMILES syntax is provided later in this manual. For examples we'll use the SMILES "c1ccccc1" which describes the benzene molecule.

A molecule can be created from a SMILES string using the function OEParseSmiles.

import openeye.oechem.*;

//create a new molecule
OEGraphMol mol = new OEGraphMol();

// convert the string into a molecule
oechem.OEParseSmiles(mol, "c1ccccc1");

The OEParseSmiles function actually returns true or false indicating whether the input string was a valid SMILES string. It is good programming practice to check the return value and report an error message if anything went wrong. The following example shows adding a check on the return status of OEParseSmiles and prints an error message to stdout.

import openeye.oechem.*;

//create a new molecule
OEGraphMol mol = new OEGraphMol();

// convert the string into a molecule
if (oechem.OEParseSmiles(mol, "c1ccccc1")) {
  // do something interesting with the molecule
}
else {
  System.err.println("Problem parsing the SMILES");
}