The most common method to create conformers in a molecule is by reading a
molecule from a file (see chapter "Reading and Writing Molecules").
However, when manipulating molecules it is often necessary to create
conformers on-the-fly. In OEChem, this is done with the
NewConf method of OEMCMolBases. There are five prominent overloads
of NewConf. All of the versions create conformers with the
capacity to store coordinates for the current number of atoms in the
molecule. NewAtom and NewBond adjust this capacity as
necessary. The default OEMCMolBase constructor puts the molecule in a
state with a single empty conformer (as does the OEMCMolBase::Clear
function). The DeleteConfs function of the OEMCMolBase removes
all of the conformers of the molecule.
#!/usr/bin/env python # ch10-5.py from openeye.oechem import * mol = OEMol() print "Default NumConfs = ", mol.NumConfs() mol.NewConf() print "After one additional, NumConfs = ", mol.NumConfs() mol.DeleteConfs() print "After deletion, NumConfs = ", mol.NumConfs()
The code about will produce the output:
Default NumConfs = 1 After one additional, NumConfs = 2 After deletion, NumConfs = 0
The versions of the NewConf method are:
NewConf() NewConf(OEFloatArray) NewConf(OEMolBase) NewConf(OEConfBase)
After the NewConf with no arguments has been called, the coordinates
of individual atoms can be set using the SetCoords
method which takes an atom, or all of the atoms can be set at once with
the SetCoords which takes only a OEFloatArray or only a
OEDoubleArray.
The NewConf overload which takes an argument OEFloatArray is
expecting a OEFloatArray of size 3*GetMaxAtomIdx() with the
Cartesian coordinates of each atom of the new conformer in
coords[atom->GetIdx()*3].
The NewConf which takes an OEMolBase is expecting the
molecule passed in to have the same graph as the OEMCMolBase which is the
parent of the new conformer. It is important to note that this version of
NewConf can take an OEGraphMol, OEMol, or OEMCMol. In the latter
two cases, the coordinates of the new conformer will come from the active
conformation of the molecule passed in.
Finally, there is an overload which takes a conformer. This function behaves the same as the overload which takes an OEMolBase.
#!/usr/bin/env python
# ch10-5.py
from openeye.oechem import *
def GetGoodMol(destination, source):
destination.DeleteConfs()
for conf in source.GetConfs():
if conf.GetEnergy() < -15.5:
newconf = destination.NewConf(conf)
newconf.SetTitle("Low Energy Conformer: %.3f" % newconf.GetEnergy())
oemolistream ifs("input.oeb")
oemolostream ofs("output.sdf")
goodmol = OEMol()
for mol in ifs.GetOEMols():
GetGoodMol(goodmol, mol)
OEWriteMolecule(ofs, goodmol)
The example above demonstrates copying conformers from one OEMol to another
using the NewConf and DeleteConfs functions. The main
routine reads all of the molecules from the file "input.oeb" and writes the
molecules with only their low-energy conformations to "output.sdf". The
function GetGoodMol generates a destination molecule that contains
only the low-energy conformations of the source molecule. The title of
each new conformer is set to reflect its energy.