Molecule Properties

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.

Read/Write Molecule Properties

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 ClearCoords
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 and the list of identifiers (molecule names) are written to standard-out.

Listing 1: Printing molecule titles

#!/usr/bin/env python
from __future__ import print_function
from openeye.oechem import *
import sys

mol = OEGraphMol()
ifs = oemolistream(sys.argv[1])

while OEReadMolecule(ifs, mol):
    print (mol.GetTitle())

Atoms and Bonds

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 an Atom OEAtomBase GetAtom Predicates Functors
Access to a Bond OEBondBase GetBond Predicates Functors
Access to all Atoms OEIterBase<OEAtomBase> GetAtoms Atom and Bond Traversal
Access to all Bonds OEIterBase<OEBondBase> 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  

Atom and Bond Creation

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 an integer bond order as arguments and returns the new OEBondBase.

Listing 2: Creating new atoms and bonds

#!/usr/bin/env python
from openeye.oechem import *

mol = OEGraphMol()

o = mol.NewAtom(8)
h1 = mol.NewAtom(1)
h2 = mol.NewAtom(1)

b1 = mol.NewBond(o, h1, 1)
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

#!/usr/bin/env python
from openeye.oechem import *

mol = OEGraphMol()

o = mol.NewAtom(OEElemNo_O)
h1 = mol.NewAtom(OEElemNo_H)
h2 = mol.NewAtom(OEElemNo_H)

b1 = mol.NewBond(o, h1, 1)
b2 = mol.NewBond(o, h2, 1)


The atoms and bonds of a molecule are automatically deleted when their parent molecule is destroyed.