4.4.2 Use of the conformer state

OEMCMolBases 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.

#include "oechem.h"
#include <iostream>

using namespace OEChem;
using namespace OESystem;
using namespace std;

float GetMaxX(const OEMolBase &mol)
{
  OEIter<OEAtomBase> atom;
  float xyz[3];
  float maxX = 0.0f;
  bool first = true;
  for(atom = mol.GetAtoms();atom;++atom)
  {
    mol.GetCoords(atom,xyz);
    if(first)
    {
      maxX = xyz[0];
      first = false;
    }
    else
      if(xyz[0] > maxX)
        maxX = xyz[0];
  }
  return maxX;
}

int main()
{
  OEIter<OEMCMolBase> mol;
  OEIter<OEConfBase> conf;
  oemolistream ims;

  for (mol=ims.GetMCMolBases(); mol; ++mol)
  {
    for(conf = mol->GetConfs(); conf; ++conf)
    {
      mol->SetActive(conf);
      cerr << "maxX = " << GetMaxX(*mol) << endl;
    }
  }

  return 0;
}

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 OEConfBases help 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.