Debian Codegraph @

avogadro/calc/energymanager.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_ENERGYMANAGER_H
7 #define AVOGADRO_CALC_ENERGYMANAGER_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 EnergyCalculator;
27
28 /**
29 * @class EnergyManager chargemanager.h
30 * <avogadro/calc/energymanager.h>
31 * @brief Class to manage registration, searching and creation of force field
32 * (energy) calculators.
33 * @author Geoffrey R. Hutchison
34 *
35 * The energy manager is a singleton class that handles the runtime
36 * registration, search, creation and eventual destruction of calculators
37 * for geometry optimization and molecular dynamics.
38 * It can be used to gain a listing of available models, register new
39 * models, etc.
40 *
41 * All energy calculation can take place independent of this code, but for
42 * automated registration and look up, this is the preferred API.
43 */
44 class AVOGADROCALC_EXPORT EnergyManager
45 {
46 public:
47 /**
48 * Get the singleton instance of the energy manager. This instance should
49 * not be deleted.
50 */
51 static EnergyManager& instance();
52
53 /**
54 * @brief Register a new model with the manager.
55 * @param model An instance of the calculator to manage, the manager assumes
56 * ownership of the object passed in.
57 * @return True on success, false on failure.
58 */
59 static bool registerModel(EnergyCalculator* model);
60
61 /**
62 * @brief Unregister a charge model from the manager.
63 * @param identifier The identifier for the model to remove.
64 * @return True on success, false on failure.
65 */
66 static bool unregisterModel(const std::string& identifier);
67
68 /**
69 * Add the supplied @p model to the manager, registering its ID and other
70 * relevant data for later lookup. The manager assumes ownership of the
71 * supplied object.
72 * @return True on success, false on failure.
73 */
74 bool addModel(EnergyCalculator* model);
75
76 /**
77 * Remove the model with the identifier @a identifier from the manager.
78 * @return True on success, false on failure.
79 */
80 bool removeModel(const std::string& identifier);
81
82 /**
83 * New instance of the model for the specified @p identifier. Ownership
84 * is passed to the caller.
85 * @param identifier The unique identifier of the model.
86 * @return Instance of the model, nullptr if not found. Ownership passes to
87 * the caller.
88 */
89 EnergyCalculator* model(const std::string& identifier) const;
90
91 /**
92 * Get a list of all loaded identifiers
93 */
94 std::set<std::string> identifiers() const;
95
96 /**
97 * @brief Get a list of models that work for this molecule.
98 *
99 * This is probably the method you want to get a list for a user
100 */
101 std::set<std::string> identifiersForMolecule(
102 const Core::Molecule& molecule) const;
103
104 /**
105 * @brief Get a recommended model for this molecule.
106 *
107 * This returns the identifier for a model that works,
108 * given the charge, unit cell, spin states, etc.
109 * @return The recommended model identifier
110 */
111 std::string recommendedModel(const Core::Molecule& molecule) const;
112
113 /**
114 * @brief Get the name of the model for the specified identifier.
115 *
116 * The name is a user-visible string, and may be translated.
117 * @param identifier The unique identifier of the model.
118 * @return The name of the model, or an empty string if not found.
119 */
120 std::string nameForModel(const std::string& identifier) const;
121
122 /**
123 * Get any errors that have been logged when loading models.
124 */
125 std::string error() const { return m_error; }
126
127 private:
128 using ModelIdMap = std::map<std::string, size_t>;
129
130 EnergyManager();
131 ~EnergyManager();
132
133 EnergyManager(const EnergyManager&); // Not implemented.
134 EnergyManager& operator=(const EnergyManager&); // Not implemented.
135
136 /**
137 * @brief Append warnings/errors to the error message string.
138 * @param errorMessage The error message to append.
139 */
140 void appendError(const std::string& errorMessage);
141
142 std::vector<EnergyCalculator*> m_models;
143 mutable ModelIdMap m_identifiers;
144 mutable std::map<std::string, std::string> m_identifierToName;
145
146 std::string m_error;
147 };
148
149 } // namespace Calc
150 } // namespace Avogadro
151
152 #endif // AVOGADRO_CALC_ENERGYMANAGER_H