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 |
|
|||
Dimension |
|
|||
Energy |
|
|||
Perception |
|
|||
Rxn |
|
|||
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
#include <openeye.h>
#include <oeplatform.h>
#include <oechem.h>
using namespace OEPlatform;
using namespace OEChem;
int main(int, char *argv[])
{
OEGraphMol mol;
oemolistream ifs(argv[1]);
while (OEReadMolecule(ifs, mol))
oeout << mol.GetTitle() << oeendl;
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 |
|
||
Number of Bonds |
|
||
Maximum Atom Index |
|
||
Maximum Bond Index |
|
||
Access to an Atom |
|||
Access to a Bond |
|||
Access to all Atoms |
|||
Access to all Bonds |
|||
Create a new Atom |
|||
Create a new Bond |
|||
Remove an Atom |
|
||
Remove a Bond |
|
||
Rearrange Atoms |
|
||
Rearrange Bonds |
|
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
#include <openeye.h>
#include <oechem.h>
using namespace OEChem;
int main()
{
OEGraphMol mol;
const auto elementNumO = 8u;
OEAtomBase *o = mol.NewAtom(elementNumO);
const auto elementNumH = 1u;
OEAtomBase *h1 = mol.NewAtom(elementNumH);
OEAtomBase *h2 = mol.NewAtom(elementNumH);
const auto order = 1u;
mol.NewBond(o, h1, order);
mol.NewBond(o, h2, order);
return 0;
}
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
#include <openeye.h>
#include <oechem.h>
using namespace OEChem;
int main()
{
OEGraphMol mol;
OEAtomBase *o = mol.NewAtom(OEElemNo::O);
OEAtomBase *h1 = mol.NewAtom(OEElemNo::H);
OEAtomBase *h2 = mol.NewAtom(OEElemNo::H);
const auto order = 1u;
mol.NewBond(o, h1, order);
mol.NewBond(o, h2, order);
return 0;
}
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:
const auto tag = OEGetTag("MolWeight");
mol.SetData(tag, OECalculateMolecularWeight(mol));
mol.SetData("MolWeight", OECalculateMolecularWeight(mol));
After annotation, the data can be accessed with the same integer or character string identifier:
cout << mol.GetData<double>(tag) << endl;
cout << mol.GetData<double>("MolWeight") << endl;
The OEMolBase API provides the following methods, publicly inherited from OEBase, that allow the manipulation of generic data.
Method |
Description |
---|---|
sets a generic data associating it with the given tag |
|
adds a generic data associating it with the given tag |
|
determines whether a molecule has any generic data with a given tag |
|
returns the generic data associated with the given tag |
|
deletes all generic data with the given tag |
|
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
Attaching other objects section
SD Tagged Data Manipulation section
PDB Tagged Data Manipulation section
For using tag data with multi-conformer molecules, see Dude, where’s my SD data?