Debian Codegraph @

avogadro/calc/chargemodel.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_CHARGEMODEL_H
7 #define AVOGADRO_CALC_CHARGEMODEL_H
8
9 #include "avogadrocalcexport.h"
10
11 #include <avogadro/core/array.h>
12 #include <avogadro/core/avogadrocore.h>
13 #include <avogadro/core/molecule.h>
14 #include <avogadro/core/vector.h>
15
16 #include <string>
17
18 namespace Avogadro::Calc {
19
20 /**
21 * @class ChargeModel chargemodel.h <avogadro/calc/chargemodel.h>
22 * @brief General API for charge / electrostatics models
23 * @author Geoffrey R. Hutchison
24 *
25 * This serves as the common base class for electrostatics models.
26 * Many use atomic point charges, but we also allow for custom models
27 * for Slater / Gaussian distributions, distributed electrostatics,
28 * use of quantum mechanics, etc.
29 *
30 * Key methods are to determine either atomic partial charges or
31 * electrostatic potentials at particular points in space.
32 *
33 * There is a default implementation for the electrostatic potential
34 * at points in space, based on the atomic partial charges. If you
35 * implement a different mechanism, you should override this method.
36 */
37
38 class AVOGADROCALC_EXPORT ChargeModel
39 {
40 public:
41 ChargeModel() = default;
42 virtual ~ChargeModel() = default;
43
44 /**
45 * Create a new instance of the model. Ownership passes to the
46 * caller.
47 */
48 virtual ChargeModel* newInstance() const = 0;
49
50 /**
51 * @brief A unique identifier, used to retrieve models programmatically.
52 * EEM2, NPA, etc. A runtime warning will be generated if the identifier
53 * is not unique.
54 */
55 virtual std::string identifier() const = 0;
56
57 /**
58 * @brief A user-visible name of the model (e.g., "Natural Population
59 * Analysis")
60 */
61 virtual std::string name() const = 0;
62
63 /**
64 * @brief Indicate if your method only treats a subset of elements
65 * @return an element mask corresponding to the defined subset
66 */
67 virtual Core::Molecule::ElementMask elements() const = 0;
68
69 /**
70 * Set the dielectric constant for the model.
71 * @param dielectric constant.
72 */
73 virtual void setDielectric(float dielectric) { m_dielectric = dielectric; };
74
75 /**
76 * @return The dielectric constant.
77 */
78 virtual float dielectric() const { return m_dielectric; }
79
80 virtual MatrixX partialCharges(Core::Molecule& mol) const = 0;
81
82 virtual MatrixX partialCharges(const Core::Molecule& mol) const = 0;
83
84 /**
85 * @brief Calculate the dipole moment of the molecule.
86 *
87 * Defaults to using the partial charges and atomic positions
88 * to calculate the net dipole moment.
89 * @return The dipole moment vector of the molecule
90 */
91 virtual Vector3 dipoleMoment(const Core::Molecule& mol) const;
92
93 /**
94 * @brief Calculate the electrostatic potential at a particular point in
95 * space.
96 * @param mol The molecule to calculate the potential for.
97 * @param point The point in space to calculate the potential at.
98 * @return The electrostatic potential at the point.
99 */
100 virtual double potential(Core::Molecule& mol, const Vector3& point) const;
101
102 /**
103 * @brief Calculate the electrostatic potential at multiple points
104 * @param mol The molecule to calculate the potential for.
105 * @param points The points in space to calculate the potential at.
106 * @return The electrostatic potential at the points in an array.
107 *
108 * This method is used for batch calculation and defaults to simply
109 * calculating each point at a time. Some methods work faster in batches.
110 */
111 virtual Core::Array<double> potentials(
112 Core::Molecule& mol, const Core::Array<Vector3>& points) const;
113
114 protected:
115 /**
116 * @brief Append an error to the error string for the model.
117 * @param errorString The error to be added.
118 * @param newLine Add a new line after the error string?
119 */
120 void appendError(const std::string& errorString, bool newLine = true) const;
121
122 private:
123 mutable std::string m_error;
124
125 float m_dielectric = 1.0f;
126 };
127
128 } // namespace Avogadro::Calc
129
130 #endif // AVOGADRO_CALC_CHARGEMODEL_H