Molecule Properties

Molecules in OEChem TK 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 and Generic Data 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

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

using System;
using OpenEye.OEChem;

public class GetTitle 
{
    public static int Main(string[] args) 
    {
        OEGraphMol mol = new OEGraphMol();
        oemolistream ifs = new oemolistream(args[0]);

        while (OEChem.OEReadMolecule(ifs, mol))
        {
            Console.WriteLine(mol.GetTitle());
        }
        return 0;
    }
}

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

Predicate Functors

Access to a Bond

OEBondBase

GetBond

Predicate 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 TK 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

using System;
using 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 TK 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

using System;
using 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.

Attach Generic Data to Molecules

Generic data can be attached to any object that derives from the OEBase class. The following two snippets demonstrate how generic data (e.g. molecule weight) can be attached to a molecule:

uint tag = OEChem.OEGetTag("MolWeight");
mol.SetDoubleData(tag, OEChem.OECalculateMolecularWeight(mol));
mol.SetDoubleData("MolWeight", OEChem.OECalculateMolecularWeight(mol));

After annotation, the data can be accessed with the same integer or character string identifier:

tag = OEChem.OEGetTag("MolWeight");
Console.WriteLine(mol.GetDoubleData(tag));
Console.WriteLine(mol.GetDoubleData("MolWeight"));

The OEMolBase API provides the following methods, publicly inherited from OEBase, that allow the manipulation of generic data.

Methods to manipulate generic data

Method

Description

SetData

sets a generic data associating it with the given tag

AddData

adds a generic data associating it with the given tag

HasData

determines whether a molecule has any generic data with a given tag

GetData

returns the generic data associated with the given tag

DeleteData

deletes all generic data with the given tag

Clear

clears all stored generic data

Note

Generic data attached to a molecule or any of its atoms or bonds is automatically saved when the molecule is written into an .oeb file.

See also