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, below we'll use the SMILES ``c1ccccc1'' which describes the molecule benzene.
A molecule can be created from a SMILES string using the function
OEParseSmiles
1 #include "openeye.h"
2 #include "oechem.h"
3
4 using namespace OEChem;
5
6 int main()
7 {
8 OEGraphMol mol;
9
10 OEParseSmiles(mol,"c1ccccc1");
11 return 0;
12 }
The OEParseSmiles function returns a boolean value 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 uses C++'s
iostream library to report the error.
1 #include "openeye.h"
2 #include "oechem.h"
3 #include <iostream>
4
5 using namespace OEChem;
6 using namespace std;
7
8 int main()
9 {
10 OEGraphMol mol;
11
12 if (OEParseSmiles(mol,"c1ccccc1"))
13 {
14 // Do something with the molecule!
15 }
16 else cerr << "SMILES string was invalid!" << endl;
17 return 0;
18 }
The molecule returned by OEParseSmiles preserves the aromaticity present
in the input SMILES string. For example, if benzene is expressed as
``c1ccccc1,'' all atoms and bonds are marked as aromatic, but if it is expressed
as a Kekulé form, ``C1=CC=CC=C1,'' all atoms and bonds are kept aliphatic.
A common task after creating a molecule from SMILES is to normalize its
aromaticity with OEAssignAromaticFlags
1 #include "openeye.h"
2 #include "oechem.h"
3 #include <iostream>
4
5 using namespace OEChem;
6 using namespace std;
7
8 int main()
9 {
10 OEGraphMol mol;
11
12 if (OEParseSmiles(mol,"c1ccccc1"))
13 {
14 OEAssignAromaticFlags(mol);
15 // Do something with the molecule!
16 }
17 else cerr << "SMILES string was invalid!" << endl;
18 return 0;
19 }