OEConstCoords

template<class T>
class OEConstCoords : public detail::OECoordsBase<const T, const OEConfBase>

This class is used to provide convenient direct access to the memory storing coordinates for a OEConfBase through the OEConfBase::GetCoordsPtr methods. If the data type of T does not match the implementation of OEConfBase, this class makes a copy of the coordinates with OEConfBase::GetCoords instead.

Listing 1 demonstrates how OEConstCoords can be used to get direct access to the coordinates in an OEConfBase for a center-of-mass calculation. This can provide large efficiency gains due to the reduced need for temporary memory and copies like the OEConfBase::GetCoords method.

Listing 1:

    for (OEIter<const OEConfBase> conf = mol.GetConfs(); conf; ++conf)
    {
      OEConstCoords<float> crds(conf);

      vector<double> com(3, 0.0);
      for (OEIter<const OEAtomBase> atom = conf->GetAtoms(); atom; ++atom)
      {
        const auto idx = atom->GetIdx();
        com[0] += crds[idx * 3u];
        com[1] += crds[idx * 3u + 1];
        com[2] += crds[idx * 3u + 2];
      }

      com[0] /= conf->NumAtoms();
      com[1] /= conf->NumAtoms();
      com[2] /= conf->NumAtoms();

      cout << "Conformer " << conf->GetIdx() << " center of mass = (" <<
        com[0] << ", " << com[1] << ", " << com[2] << ")" << endl;
    }

See also

This class only provides const read-only access, use OEMutableCoords for write-access as well.

Constructors

OEConstCoords(const OEConfBase *conf)

Construct a read-only view of the coordinates in the conformer conf.

operator const T *

operator const T *() const

Allows implicitly casting this object into a const pointer of type T to the coordinates of the conformer used in the constructor.

GetPtr

const T *GetPtr() const

Returns a const pointer of type T to the coordinates of the conformer used in the constructor.