Open Babel  3.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
OBChargeModel Class Referenceabstract

#include <openbabel/chargemodel.h>

Inheritance diagram for OBChargeModel:
OBPlugin

Public Types

typedef std::map< const char *, OBPlugin *, CharPtrLessPluginMapType
 
typedef PluginMapType::const_iterator PluginIterator
 

Public Member Functions

const char * TypeID ()
 
virtual bool ComputeCharges (OBMol &m)
 
virtual bool ComputeCharges (OBMol &m, const char *args)
 
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 OBPluginMakeInstance (const std::vector< std::string > &)
 
virtual void Init ()
 
const char * GetID () const
 
virtual PluginMapTypeGetMap () const =0
 

Static Public Member Functions

static OBPluginGetPlugin (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)
 
static void LoadAllPlugins ()
 

Protected Member Functions

void FillChargeVectors (OBMol &mol)
 
virtual double DipoleScalingFactor ()
 

Static Protected Member Functions

static PluginMapTypePluginMap ()
 
static PluginMapTypeGetTypeMap (const char *PluginID)
 
static OBPluginBaseFindType (PluginMapType &Map, const char *ID)
 

Protected Attributes

std::vector< double > m_partialCharges
 
std::vector< double > m_formalCharges
 
const char * _id
 

Static Protected Attributes

static int AllPluginsLoaded = 0
 

Detailed Description

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.

Member Function Documentation

◆ TypeID()

const char* TypeID ( )
inlinevirtual

Redefined by each plugin type: "formats", "fingerprints", etc.

Reimplemented from OBPlugin.

◆ ComputeCharges() [1/2]

virtual bool ComputeCharges ( OBMol m)
inlinevirtual
Returns
whether partial charges were successfully assigned to this molecule
Note
The method should fill m_partialCharges and m_formalCharges as well

◆ ComputeCharges() [2/2]

virtual bool ComputeCharges ( OBMol m,
const char *  args 
)
inlinevirtual

◆ GetFormalCharges()

const std::vector<double>& GetFormalCharges ( ) const
inline
Returns
a vector of the formal charges on each atom, indexed from 0 This method returns floating point formal charges since some charge models consider fractional charges (e.g., 0.5 for an oxygen in a carboxylate CO2- group).
Note
If ComputeCharges() has not been called, this will return an empty vector

◆ GetPartialCharges()

const std::vector<double>& GetPartialCharges ( ) const
inline
Returns
a vector of the partial charges on each atom, indexed from 0
Note
If ComputeCharges() has not been called, this will return an empty vector

◆ GetDipoleMoment()

vector3 GetDipoleMoment ( OBMol mol)
Returns
a vector of the dipole moment from this molecule

◆ FillChargeVectors()

void FillChargeVectors ( OBMol mol)
protected

Fill the internal partial and formal charge vectors (convenience function)

◆ DipoleScalingFactor()

virtual double DipoleScalingFactor ( )
inlineprotectedvirtual

Provide a scaling factor for the dipole moment – ideally calibrated from many molecules.

Member Data Documentation

◆ m_partialCharges

std::vector<double> m_partialCharges
protected

◆ m_formalCharges

std::vector<double> m_formalCharges
protected

The documentation for this class was generated from the following files: