/src/openbabel/include/openbabel/chargemodel.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | chargemodel.h - Base class for partial charge models |
3 | | |
4 | | Copyright (C) 2010 by Geoffrey Hutchison |
5 | | Some portions Copyright (C) 2009 by Frank Peters |
6 | | |
7 | | This file is part of the Open Babel project. |
8 | | For more information, see <http://openbabel.org/> |
9 | | |
10 | | This program is free software; you can redistribute it and/or modify |
11 | | it under the terms of the GNU General Public License as published by |
12 | | the Free Software Foundation version 2 of the License. |
13 | | |
14 | | This program is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU General Public License for more details. |
18 | | ***********************************************************************/ |
19 | | |
20 | | #ifndef OB_CHARGEMODEL_H |
21 | | #define OB_CHARGEMODEL_H |
22 | | |
23 | | #include <openbabel/babelconfig.h> |
24 | | #include <openbabel/plugin.h> |
25 | | #include <openbabel/math/vector3.h> |
26 | | |
27 | | namespace OpenBabel |
28 | | { |
29 | | class OBMol; //Forward declaration; used only as pointer. |
30 | | |
31 | | // Documentation is down below |
32 | | class OBAPI OBChargeModel : public OBPlugin |
33 | | { |
34 | | MAKE_PLUGIN(OBChargeModel) |
35 | | |
36 | | public: |
37 | 8 | const char* TypeID() override { return "charges"; } |
38 | | |
39 | | /// \return whether partial charges were successfully assigned to this molecule |
40 | | /// \note The method should fill m_partialCharges and m_formalCharges as well |
41 | 0 | virtual bool ComputeCharges(OBMol &m ) { return false; }; |
42 | 0 | virtual bool ComputeCharges(OBMol &m, const char *args) { return ComputeCharges( m ); } |
43 | | |
44 | | /// \return a vector of the formal charges on each atom, indexed from 0 |
45 | | /// This method returns floating point formal charges since some |
46 | | /// charge models consider fractional charges (e.g., 0.5 for an |
47 | | /// oxygen in a carboxylate CO2- group). |
48 | | /// \note If ComputeCharges() has not been called, this will return an empty vector |
49 | | const std::vector<double> & GetFormalCharges() const |
50 | 0 | { return m_formalCharges; } |
51 | | |
52 | | /// \return a vector of the partial charges on each atom, indexed from 0 |
53 | | /// \note If ComputeCharges() has not been called, this will return an empty vector |
54 | | const std::vector<double> & GetPartialCharges() const |
55 | 0 | { return m_partialCharges; } |
56 | | |
57 | | /// \return a vector of the dipole moment from this molecule |
58 | | vector3 GetDipoleMoment(OBMol &); |
59 | | |
60 | | protected: |
61 | | std::vector<double> m_partialCharges; |
62 | | std::vector<double> m_formalCharges; |
63 | | |
64 | | /// Fill the internal partial and formal charge vectors (convenience function) |
65 | | void FillChargeVectors(OBMol &mol); |
66 | | |
67 | | /// Provide a scaling factor for the dipole moment -- ideally calibrated from many molecules |
68 | 0 | virtual double DipoleScalingFactor() { return 1.0; } |
69 | | }; |
70 | | |
71 | | /** \class OBChargeModel chargemodel.h <openbabel/chargemodel.h> |
72 | | \brief Atomic partial charge models |
73 | | \since version 2.3 |
74 | | |
75 | | Classes derived from OBChargeModel implement different atomic partial |
76 | | charge models. It is intended to allow assinging partial charges |
77 | | beyond the traditional Gasteiger-Marsili sigma charges previously used |
78 | | in Open Babel. A --partialcharge method is provided for the obabel |
79 | | command-line, allowing you to override the Gasteiger charge assignment |
80 | | and use other charge models. |
81 | | |
82 | | The advantage of plugin classes is that no existing code has to be modified |
83 | | when a new class is added. You can list those that are present by |
84 | | obabel -L charges |
85 | | or from a menu item in the GUI. |
86 | | |
87 | | Any OBChargeModel derived class works like other plugins and needs to |
88 | | to have a constructor, a function returning a short description, and a |
89 | | ComputeCharges() function which does the work. A single global |
90 | | instance of the class needs to be instantiated to define the ID, by |
91 | | which the class is subsequently accessed. |
92 | | |
93 | | Once ComputeCharges() has been called, the atoms of the molecule can |
94 | | be queried for partial or formal charges using |
95 | | OBAtom::GetPartialCharge() or in vector form from the model itself: |
96 | | |
97 | | \code |
98 | | OBMol inputMolecule; |
99 | | OBChargeModel *mmffCharges = OBChargeModel::FindType("mmff94"); |
100 | | const std::vector<double> partialCharges; |
101 | | if (mmffCharges && mmffCharges->ComputeCharges(inputMolecule)) { |
102 | | partialCharges = mmffCharges->GetPartialCharges(); |
103 | | } |
104 | | \endcode |
105 | | |
106 | | Note: Formal charges are also returned as floating point values, since |
107 | | some charge models consider delocalized charges (e.g., 0.5 for an O in |
108 | | a carboxylate CO2- group). |
109 | | |
110 | | \code |
111 | | OBChargeModel *gasteiger = OBChargeModel::FindType("gasteiger"); |
112 | | if (gasteiger) { |
113 | | cout << " gasteiger: " << dipoleMagnitude(gasteiger->GetDipoleMoment(mol)); |
114 | | } |
115 | | \endcode |
116 | | |
117 | | By default, Open Babel 2.3 includes Gasteiger and MMFF94 partial |
118 | | charges. If the Eigen matrix library is found when compiling, the QEq |
119 | | and QTPIE methods will be added. Future releases will likely add |
120 | | additional charge models, including the EEM method. |
121 | | |
122 | | */ |
123 | | |
124 | | }//namespace |
125 | | #endif |
126 | | |
127 | | //! \file chargemodel.h |
128 | | //! \brief Base class for molecular partial charge models |