2.2 Reusing Molecules

OEChem also provides a mechanism for reusing a molecule. For example, when processing multiple molecules sequentially in a database, instead of requiring a new molecule to be allocated and destroyed for each entry, the OEMolBase::Clear method can be used to reset a molecule to its initial (empty) state.

The following program demonstrates calling the Clear method of our molecule. Note that the Clear in the example below is not required because a new molecule is already initialized by the implicit constructor. The code below demonstrates that an OEGraphMol behaves like an OEMolBase, allowing an OEGraphMol to be used with any of OEChem's OEMolBase methods or functions.

 1 #include "openeye.h"
 2 #include "oechem.h"
 3
 4 using namespace OEChem;
 5
 6 int main()
 7 {
 8   OEGraphMol mol;
 9   mol.Clear();
10   return 0;
11 }

Listing:2.3 Clearing a molecule