Atomic partial charge models.
- Since
- version 2.3
Classes derived from OBChargeModel implement different atomic partial charge models. It is intended to allow assinging partial charges beyond the traditional Gasteiger-Marsili sigma charges previously used in Open Babel. A –partialcharge method is provided for the obabel command-line, allowing you to override the Gasteiger charge assignment and use other charge models.
The advantage of plugin classes is that no existing code has to be modified when a new class is added. You can list those that are present by obabel -L charges or from a menu item in the GUI.
Any OBChargeModel derived class works like other plugins and needs to to have a constructor, a function returning a short description, and a ComputeCharges() function which does the work. A single global instance of the class needs to be instantiated to define the ID, by which the class is subsequently accessed.
Once ComputeCharges() has been called, the atoms of the molecule can be queried for partial or formal charges using OBAtom::GetPartialCharge() or in vector form from the model itself:
OBMol inputMolecule;
OBChargeModel *mmffCharges = OBChargeModel::FindType("mmff94");
const std::vector<double> partialCharges;
if (mmffCharges && mmffCharges->ComputeCharges(inputMolecule)) {
partialCharges = mmffCharges->GetPartialCharges();
}
Note: Formal charges are also returned as floating point values, since some charge models consider delocalized charges (e.g., 0.5 for an O in a carboxylate CO2- group).
OBChargeModel *gasteiger = OBChargeModel::FindType("gasteiger");
if (gasteiger) {
cout << " gasteiger: " << dipoleMagnitude(gasteiger->GetDipoleMoment(mol));
}
By default, Open Babel 2.3 includes Gasteiger and MMFF94 partial charges. If the Eigen matrix library is found when compiling, the QEq and QTPIE methods will be added. Future releases will likely add additional charge models, including the EEM method.