Subsections

 
5.4 Properties of Multi-Conformer Molecules

Multi-conformer molecules in OEChem are represented by the abstract base class OEMCMolBases . OEMCMolBase derives from OEMolBase and thus contains all of the properties of molecules discussed in Section 4. In addition to storing the atoms and bonds of a molecule, an OEMCMolBase is able to store multiple conformations of a molecule. Conformations of a molecule share the same heavy-atom graph. Here, the word ``graph'' should be thought of in the graph theory sense, such that a molecule is modeled as vertices (atoms) and edges connecting pairs of vertices (bonds). Therefore, all conformers share a common connection table of the same atoms and bonds. Furthermore, because they share the same atoms and bonds, they also share any properties stored by the atoms and bonds (see Section 7 and Section 8). The sharing of a common connection table prevents tautomers from being modeled together with an OEMCMolBase. Coordinate information is stored by the molecule, not the shared atoms and bonds, which allows the conformers to share the same heavy-atom graph but have different spatial configurations. In OEChem, these conformers are represented by OEConfBase s, which are first-class objects.

OEMol s can be used as either a molecule with a particular one of its conformers represented as its current ``state,'' or as a container of conformers with access to many of them at once.

It should be noted that in C++ OEMCMolBase and OEConfBase are the following typedef's of template classes.

typedef OEMCMolBaseT<float,3> OEMCMolBase;
typedef OEConfBaseT<float,3> OEConfBase;

Listing:5.1

The templates allow OEChem to migrate to alternate conformer representations. For example, if greater coordinate precision is needed doubles could be used. However, floats are currently used as a space optimization.

5.4.1 GetConf and GetConfs

Conformers of OEMCMolBase s are accessed via the GetConf and GetConfs methods. GetConf returns the first conformer in the molecule for which the predicate function passed as the argument returns true (see Section 22 for more information on predicates). GetConfs returns an iterator over the conformers of the molecule.

5.4.2 Use of the conformer state

OEMCMolBase s have four functions which control the current state of the molecule with respect to conformers. SetActive takes an OEConfBase as an object and makes the OEMCMolBase act exactly like an OEMolBase with the ``Active'' conformer as the only conformer. The GetActive function returns a pointer to the currently ``Active'' conformation. There are many OEMolBase functions which access the single-conformer coordinates of a molecule. When these functions are called on an OEMCMolBase, the coordinates of the ``Active'' conformer are returned. Similarly, if the OEMCMolBase does not have a title or energy of its own, the title or energy of the active conformer will be returned. This is particularly convenient when passing the molecule to a function which has been written to use or manipulate the coordinates of an OEMolBase.

 1 #include "openeye.h"
 2 #include "oechem.h"
 3 #include <iostream>
 4
 5 using namespace OEChem;
 6 using namespace OESystem;
 7 using namespace std;
 8
 9 float GetMaxX(const OEMolBase &mol)
10 {
11   OEIter<OEAtomBase> atom;
12   float xyz[3];
13   float maxX = 0.0f;
14   bool first = true;
15   for(atom = mol.GetAtoms();atom;++atom)
16   {
17     mol.GetCoords(atom,xyz);
18     if(first)
19     {
20       maxX = xyz[0];
21       first = false;
22     }
23     else
24       if(xyz[0] > maxX)
25         maxX = xyz[0];
26   }
27   return maxX;
28 }
29
30 int main()
31 {
32   OEIter<OEMCMolBase> mol;
33   OEIter<OEConfBase> conf;
34   oemolistream ims;
35
36   for (mol=ims.GetMCMolBases(); mol; ++mol)
37   {
38     for(conf = mol->GetConfs(); conf; ++conf)
39     {
40       mol->SetActive(conf);
41       cerr << "maxX = " << GetMaxX(*mol) << endl;
42     }
43   }
44
45   return 0;
46 }

Listing:5.2 Setting the conformer state

While the SetActive and GetActive interface is sufficient for most uses, it is sometimes necessary to think of a more complex representation of the state of the molecule. The OEMCMolBase also has PushActive and PopActive functions which extend the control over the active conformation. All four of these functions work together to determine which conformation is the current active conformation. The active conformation is the top conformation in a stack of OEConfBase s held by the molecule. SetActive changes the top conformation on the stack, while GetActive returns the top conformation on the stack. PushActive puts a new conformation in the top position of the stack, pushing all other members of the stack down. PopActive removes the top conformer in the stack (allowing the next lower conformer to become the active conformer). The conformer stack is helpful for using the state of an OEMCMolBase within a function while restoring the molecule to its original state before returning it.

5.4.3 Use of the conformers as first-class objects

Alternatively, a programmer may wish to use the conformers as first class objects rather than via the state of the OEMCMolBase . This allows one to have multiple conformation objects at once and to treat the OEMCMolBase as a container of single-conformer molecules. The example below shows the use of the conformers as first class objects. Each conformer is represented by an OEConfBase which inherits from OEMolBase . Thus, each conformer can be treated as an independent molecule with respect to its coordinates as shown in the example code below.

 1 #include "openeye.h"
 2 #include "oechem.h"
 3 #include <iostream>
 4
 5 using namespace OEChem;
 6 using namespace OESystem;
 7 using namespace std;
 8
 9 float GetMaxX(const OEMolBase &mol)
10 {
11   OEIter<OEAtomBase> atom;
12   float xyz[3];
13   float maxX = 0.0f;
14   bool first = true;
15   for(atom = mol.GetAtoms();atom;++atom)
16   {
17     mol.GetCoords(atom,xyz);
18     if(first)
19     {
20       maxX = xyz[0];
21       first = false;
22     }
23     else
24       if(xyz[0] > maxX)
25         maxX = xyz[0];
26   }
27   return maxX;
28 }
29
30 int main(int, char ** argv)
31 {
32   OEIter<OEMCMolBase> mol;
33   OEIter<OEConfBase> conf;
34
35   oemolistream ims(argv[1]);
36
37   std::string maxconf;
38   float tmpx = 0.0f, maxX = 0.0f;
39
40   for (mol=ims.GetMCMolBases(); mol; ++mol)
41   {
42     for(conf = mol->GetConfs(); conf; ++conf)
43     {
44       tmpx = GetMaxX(*conf);
45       if(tmpx > maxX)
46       {
47         if(!maxconf.empty())
48         {
49           cerr << conf->GetTitle() << " has a larger value of x than " <<
50                   maxconf << endl;
51         }
52         maxconf = conf->GetTitle();
53         maxX = tmpx;
54       }
55     }
56   }
57
58   return 0;
59 }

Listing:5.3 Conformers as first class objects

In the listing above, the function GetMaxX returns the maximum x-coordinate of a molecule. The main routine loops over all of the conformers of each molecule and compares the maximum x-coordinate to a running maximum of the x-coordinate of every conformer. If there is a new maximum, the associated conformer is stored and the user is notified.