OEChem also provides several functions that simplify the task of working with partial charges, independent of any partial charging scheme.
The OEClearPartialCharges
function may be used to result the partial
charge for all atoms in an OEMolBase to zero. By default, OEAtomBases
are created with zero partial charge, so this function is only really
required to zero the partial charges after values have been assigned.
The actual implementation is documented below:
void myOEClearPartialCharges(OEMolBase &mol) { OEIter<OEAtomBase> atom; for (atom=mol.GetAtoms(); atom; ++atom) atom->SetPartialCharge(0.0f); }
The OEFormalPartialCharges
function provides a convenient way to
set the partial charge on each OEAtomBase of an OEMolBase to it's formal
charge.
void myOEFormalPartialCharges(OEMolBase &mol) { OEIter<OEAtomBase> atom; float charge; for (atom=mol.GetAtoms(); atom; ++atom) { charge = atom->GetFormalCharge(); atom->SetPartialCharge(charge); } }
Finally, the OEHasPartialCharges
function examines an OEMolBase
to see whether any of it's OEAtomBases has a non-zero partial charge.
bool myOEHasPartialCharges( const OEMolBase &mol ) { OEIter<OEAtomBase> atom; for (atom=mol.GetAtoms(); atom; ++atom) if (atom->GetPartialCharge() != 0.0f) return true; return false; }