Debian Codegraph @

avogadro/calc/chargemanager.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CALC_CHARGEMANAGER_H
7 #define AVOGADRO_CALC_CHARGEMANAGER_H
8
9 #include "avogadrocalcexport.h"
10
11 #include <avogadro/core/array.h>
12 #include <avogadro/core/matrix.h>
13 #include <avogadro/core/vector.h>
14
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <vector>
19
20 namespace Avogadro {
21 namespace Core {
22 class Molecule;
23 }
24 namespace Calc {
25
26 class ChargeModel;
27
28 /**
29 * @class ChargeManager chargemanager.h
30 * <avogadro/calc/chargemanager.h>
31 * @brief Class to manage registration, searching and creation of partial charge
32 * models.
33 * @author Geoffrey R. Hutchison
34 *
35 * The charge manager is a singleton class that handles the runtime
36 * registration, search, creation and eventual destruction of electrostatics
37 * models. It can be used to gain a listing of available models, register new
38 * models, etc.
39 *
40 * All electrostatics can take place independent of this code, but for automated
41 * registration and look up, this is the preferred API. It is possible to use
42 * the convenience API without ever dealing directly with a model class.
43 */
44
45 class AVOGADROCALC_EXPORT ChargeManager
46 {
47 public:
48 /**
49 * Get the singleton instance of the charge manager. This instance should
50 * not be deleted.
51 */
52 static ChargeManager& instance();
53
54 /**
55 * @brief Register a new charge model with the manager.
56 * @param model An instance of the model to manage, the manager assumes
57 * ownership of the object passed in.
58 * @return True on success, false on failure.
59 */
60 static bool registerModel(ChargeModel* model);
61
62 /**
63 * @brief Unregister a charge model from the manager.
64 * @param identifier The identifier for the model to remove.
65 * @return True on success, false on failure.
66 */
67 static bool unregisterModel(const std::string& identifier);
68
69 /**
70 * Add the supplied @p model to the manager, registering its ID and other
71 * relevant data for later lookup. The manager assumes ownership of the
72 * supplied object.
73 * @return True on success, false on failure.
74 */
75 bool addModel(ChargeModel* model);
76
77 /**
78 * Remove the model with the identifier @a identifier from the manager.
79 * @return True on success, false on failure.
80 */
81 bool removeModel(const std::string& identifier);
82
83 /**
84 * Get a list of all loaded identifiers
85 */
86 std::set<std::string> identifiers() const;
87
88 /**
89 * @brief Get a list of models that work for this molecule.
90 *
91 * Includes partial charge types in the molecule itself (e.g., from a file)
92 * This is probably the method you want to get a list for a user
93 */
94 std::set<std::string> identifiersForMolecule(
95 const Core::Molecule& molecule) const;
96
97 /**
98 * @brief Get a recommended model for this molecule.
99 *
100 * This returns the identifier for a model that works,
101 * given the charge, unit cell, spin states, etc.
102 * @return The recommended model identifier
103 */
104 std::string recommendedModel(const Core::Molecule& molecule) const;
105
106 /**
107 * @return the user-visible name of the model with the identifier @a
108 * identifier
109 */
110 std::string nameForModel(const std::string& identifier) const;
111
112 /**
113 * This method will calculate atomic partial charges and save them,
114 * if the model is available (i.e., the molecule will change)
115 * Note that some models do not have well-defined atomic partial charges
116 * @return atomic partial charges for the molecule, or 0.0 if undefined
117 */
118 MatrixX partialCharges(const std::string& identifier,
119 Core::Molecule& mol) const;
120
121 /**
122 * Calculate the atomic partial charges and leave the molecule unchanged.
123 * Note that some models do not have well-defined atomic partial charges
124 * @return the dipole moment for the molecule, or 0.0 if undefined
125 */
126 MatrixX partialCharges(const std::string& identifier,
127 const Core::Molecule& mol) const;
128
129 /**
130 * @return the dipole moment for the molecule, or 0.0 if the model is not
131 * available
132 */
133 Vector3 dipoleMoment(const std::string& identifier,
134 const Core::Molecule& mol) const;
135
136 /**
137 * @return the potential at the point for the molecule, or 0.0 if the model is
138 * not available
139 */
140 double potential(const std::string& identifier, Core::Molecule& mol,
141 const Vector3& point) const;
142
143 /**
144 * @return the potentials at the point for the molecule, or an array of 0.0 if
145 * the model is not available
146 */
147 Core::Array<double> potentials(const std::string& identifier,
148 Core::Molecule& mol,
149 const Core::Array<Vector3>& points) const;
150
151 /**
152 * Get any errors that have been logged when loading models.
153 */
154 std::string error() const;
155
156 private:
157 using ChargeIdMap = std::map<std::string, size_t>;
158
159 ChargeManager();
160 ~ChargeManager();
161
162 ChargeManager(const ChargeManager&); // Not implemented.
163 ChargeManager& operator=(const ChargeManager&); // Not implemented.
164
165 /**
166 * @brief Append warnings/errors to the error message string.
167 * @param errorMessage The error message to append.
168 */
169 void appendError(const std::string& errorMessage);
170
171 std::vector<ChargeModel*> m_models;
172 mutable ChargeIdMap m_identifiers;
173 mutable std::map<std::string, std::string> m_identifierToName;
174
175 std::string m_error;
176 };
177
178 } // namespace Calc
179 } // namespace Avogadro
180
181 #endif // AVOGADRO_CALC_CHARGEMANAGER_H