Molecules in OEChem are represented by OEMolBases. In addition to keeping track of the atoms and bonds that constitute a molecule, the OEMolBase is also used to store global information about the molecule.
The OEMolBase API provides the following methods for storing common global information about the molecule.
| Property Name | Type | Get Method | Set Method | See Also |
|---|---|---|---|---|
| Coordinates | float array | GetCoords | SetCoords | |
| Dimension | unsigned int | GetDimension | SetDimension | |
| Energy | float | GetEnergy | SetEnergy | |
| Perception | bool | HasPerceived | SetPerceived | |
| Rxn | bool | IsRxn | SetRxn | Reactions |
| Title | string | GetTitle | SetTitle | Title |
The Title property is a string used to represent the name of the molecule. The default value is an empty string. This field may be used to store a registry number or other identifier, instead of a common name. The string is typically trimmed of white space by most file format readers.
The following code uses the GetTitle method to list the names of the molecules in a file. The input file is read from standard-in and the list of identifiers (molecule names) are written to standard-out.
Listing 1: Printing molecule titles
import openeye.oechem.*;
public class GetTitle {
public static void main(String argv[]) {
OEGraphMol mol = new OEGraphMol();
oemolistream ifs = new oemolistream();
while (oechem.OEReadMolecule(ifs, mol))
System.out.println(mol.GetTitle());
}
}
The OEMolBase API provides the following methods for accessing and altering the connection table of the molecule.
| Description | Return Type | Method | See Also |
|---|---|---|---|
| Number of Atoms | unsigned int | NumAtoms | |
| Number of Bonds | unsigned int | NumBonds | |
| Maximum Atom Index | unsigned int | GetMaxAtomIdx | Atom, Bond, and Conformer Indices |
| Maximum Bond Index | unsigned int | GetMaxBondIdx | Atom, Bond, and Conformer Indices |
| Access to a Atom | OEAtomBase | GetAtom | Predicate Functors |
| Access to a Bond | OEBondBase | GetBond | Predicate Functors |
| Access to all Atoms | OEIterBase | GetAtoms | Atom and Bond Traversal |
| Access to all Bonds | OEIterBase | GetBonds | Atom and Bond Traversal |
| Create a new Atom | OEAtomBase | NewAtom | Atom and Bond Creation |
| Create a new Bond | OEBondBase | NewBond | Atom and Bond Creation |
| Remove an Atom | bool | DeleteAtom | |
| Remove a Bond | bool | DeleteBond | |
| Rearrange Atoms | bool | OrderAtoms | |
| Rearrange Bonds | bool | OrderBonds |
OEChem contains functions that allow molecules to be constructed from atoms and bonds explicitly. Listing 2 demonstrates how to create the water molecule.
Atoms are created by calling the OEMolBase.NewAtom method, and bonds are created by calling the OEMolBase.NewBond method. NewAtom takes the atomic number of the atom to create and returns the new OEAtomBase. NewBond takes two OEAtomBases and a integer bond order as arguments and returns the new OEBondBase.
Listing 2: Creating new atoms and bonds
import openeye.oechem.*;
public class CreatingAtoms {
public static void main(String argv[]) {
OEGraphMol mol = new OEGraphMol();
OEAtomBase o = mol.NewAtom(8);
OEAtomBase h1 = mol.NewAtom(1);
OEAtomBase h2 = mol.NewAtom(1);
OEBondBase b1 = mol.NewBond(o,h1,1);
OEBondBase b2 = mol.NewBond(o,h2,1);
}
}
In Listing 2 the atomic numbers of oxygen, 8, and hydrogen, 1, are explicitly encoded in the program. To make code easier to read and less error prone, OEChem provides symbolic constants for the first 109 elements in the OEElemNo namespace. The OEElemNo namespace defines the atomic symbols with the appropriate atomic number.
Listing 3: Using OEElemNo namespace
import openeye.oechem.*;
public class CreatingAtoms2 {
public static void main(String argv[]) {
OEGraphMol mol = new OEGraphMol();
OEAtomBase o = mol.NewAtom(OEElemNo.O);
OEAtomBase h1 = mol.NewAtom(OEElemNo.H);
OEAtomBase h2 = mol.NewAtom(OEElemNo.H);
OEBondBase b1 = mol.NewBond(o,h1,1);
OEBondBase b2 = mol.NewBond(o,h2,1);
}
}
Note
The atoms and bonds of a molecule are automatically deleted when their parent molecule is destroyed.