Atomic partial charge models. More...
#include <openbabel/chargemodel.h>
Public Types | |
typedef std::map< const char *, OBPlugin *, CharPtrLess > | PluginMapType |
typedef PluginMapType::const_iterator | PluginIterator |
Public Member Functions | |
const char * | TypeID () |
virtual bool | ComputeCharges (OBMol &) |
const std::vector< double > & | GetFormalCharges () const |
const std::vector< double > & | GetPartialCharges () const |
vector3 | GetDipoleMoment (OBMol &) |
virtual const char * | Description () |
virtual bool | Display (std::string &txt, const char *param, const char *ID=NULL) |
virtual OBPlugin * | MakeInstance (const std::vector< std::string > &) |
virtual void | Init () |
const char * | GetID () const |
virtual PluginMapType & | GetMap () const =0 |
Static Public Member Functions | |
static OBPlugin * | GetPlugin (const char *Type, const char *ID) |
static bool | ListAsVector (const char *PluginID, const char *param, std::vector< std::string > &vlist) |
static void | List (const char *PluginID, const char *param=NULL, std::ostream *os=&std::cout) |
static std::string | ListAsString (const char *PluginID, const char *param=NULL) |
static std::string | FirstLine (const char *txt) |
static PluginIterator | Begin (const char *PluginID) |
static PluginIterator | End (const char *PluginID) |
Protected Member Functions | |
void | FillChargeVectors (OBMol &mol) |
virtual double | DipoleScalingFactor () |
Static Protected Member Functions | |
static PluginMapType & | PluginMap () |
static PluginMapType & | GetTypeMap (const char *PluginID) |
static OBPlugin * | BaseFindType (PluginMapType &Map, const char *ID) |
Protected Attributes | |
std::vector< double > | m_partialCharges |
std::vector< double > | m_formalCharges |
const char * | _id |
Atomic partial charge models.
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 babel 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 babel -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.
typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType [inherited] |
const char* TypeID | ( | ) | [inline, virtual] |
Redefined by each plugin type: "formats", "fingerprints", etc.
Reimplemented from OBPlugin.
virtual bool ComputeCharges | ( | OBMol & | ) | [inline, virtual] |
const std::vector<double>& GetFormalCharges | ( | ) | const [inline] |
const std::vector<double>& GetPartialCharges | ( | ) | const [inline] |
void FillChargeVectors | ( | OBMol & | mol ) | [protected] |
Fill the internal partial and formal charge vectors (convenience function)
virtual double DipoleScalingFactor | ( | ) | [inline, protected, virtual] |
Provide a scaling factor for the dipole moment -- ideally calibrated from many molecules.
std::vector<double> m_partialCharges [protected] |
std::vector<double> m_formalCharges [protected] |