Debian Codegraph @

avogadro/core/gaussianset.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_CORE_GAUSSIANSET_H
7 #define AVOGADRO_CORE_GAUSSIANSET_H
8
9 #include "avogadrocoreexport.h"
10
11 #include "basisset.h"
12
13 #include <avogadro/core/matrix.h>
14 #include <avogadro/core/vector.h>
15
16 #include <vector>
17
18 namespace Avogadro::Core {
19
20 /**
21 * Enumeration of the SCF type.
22 */
23 enum ScfType
24 {
25 Rhf,
26 Uhf,
27 Rohf,
28 Unknown
29 };
30
31 /**
32 * @class GaussianSet gaussianset.h <avogadro/core/gaussianset.h>
33 * @brief A container for Gaussian type outputs from QM codes.
34 * @author Marcus D. Hanwell
35 *
36 * The GaussianSet class has a transparent data structure for storing the basis
37 * sets output by many quantum mechanical codes. It has a certain hierarchy
38 * where shells are built up from n primitives, in this case Gaussian Type
39 * Orbitals (GTOs). Each shell has a type (S, P, D, F, etc) and is composed of
40 * one or more GTOs. Each GTO has a contraction coefficient, c, and an exponent,
41 * a.
42 *
43 * When calculating Molecular Orbitals (MOs) each orthogonal shell has an
44 * independent coefficient. That is the S type orbitals have one coefficient,
45 * the P type orbitals have three coefficients (Px, Py and Pz), the D type
46 * orbitals have five (or six if cartesian types) coefficients, and so on.
47 */
48
49 class AVOGADROCORE_EXPORT GaussianSet : public BasisSet
50 {
51 public:
52 /**
53 * Constructor.
54 */
55 GaussianSet();
56
57 /**
58 * Destructor.
59 */
60 ~GaussianSet() override = default;
61
62 /**
63 * Clone.
64 */
65 GaussianSet* clone() const override { return new GaussianSet(*this); }
66
67 /**
68 * Enumeration of the Gaussian type orbitals.
69 */
70 enum orbital
71 {
72 S,
73 SP,
74 P,
75 D,
76 D5,
77 F,
78 F7,
79 G,
80 G9,
81 H,
82 H11,
83 I,
84 I13,
85 UU
86 };
87
88 /**
89 * Add a basis to the basis set.
90 * @param atom Index of the atom to add the Basis to.
91 * @param type The type of the Basis being added.
92 * @return The index of the added Basis.
93 */
94 unsigned int addBasis(unsigned int atom, orbital type);
95
96 /**
97 * Add a GTO to the supplied basis.
98 * @param basis The index of the Basis to add the GTO to.
99 * @param c The contraction coefficient of the GTO.
100 * @param a The exponent of the GTO.
101 * @return The index of the added GTO.
102 */
103 unsigned int addGto(unsigned int basis, double c, double a);
104
105 /**
106 * Set the molecular orbital (MO) coefficients to the GaussianSet.
107 * @param MOs Vector containing the MO coefficients for the GaussianSet.
108 * @param type The type of the MOs (Paired, Alpha, Beta).
109 */
110 void setMolecularOrbitals(const std::vector<double>& MOs,
111 ElectronType type = Paired);
112
113 /**
114 * Set the molecular orbital (MO) coefficients for a given index. Note
115 * that this must be used with coordinate sets to work correctly.
116 * @param MOs Vector containing the MO coefficients for the GaussianSet.
117 * @param type The type of the MOs (Paired, Alpha, Beta).
118 * @param index The index of the MO in the sequence.
119 */
120 void setMolecularOrbitals(const std::vector<double>& MOs, ElectronType type,
121 Index index);
122
123 /**
124 * Get the number of elements in the set.
125 */
126 int setCount() { return static_cast<int>(m_moMatrixSet[0].size()); }
127
128 /**
129 * Set the active element in the set, this expects a corresponding
130 * coordinate set element, and will change the active MO matrix.
131 */
132 bool setActiveSetStep(int index);
133
134 /**
135 * @brief This enables support of sparse orbital sets, and provides a mapping
136 * from the index in memory to the actual molecular orbital number.
137 * @param nums The MO numbers (starting with an index of 1 for the first one).
138 * @param type The MO type (Paired, Alpha, Beta).
139 */
140 void setMolecularOrbitalNumber(const std::vector<unsigned int>& nums,
141 ElectronType type = Paired);
142
143 /**
144 * Set the SCF density matrix for the GaussianSet.
145 */
146 bool setDensityMatrix(const MatrixX& m);
147
148 /**
149 * Set the spin density matrix for the GaussianSet.
150 */
151 bool setSpinDensityMatrix(const MatrixX& m);
152
153 /**
154 * @brief Generate the density matrix if we have the required information.
155 * @return True on success, false on failure.
156 */
157 bool generateDensityMatrix();
158
159 /**
160 * @brief Generate the spin density matrix if we have the required
161 * information.
162 * @return True on success, false on failure.
163 */
164 bool generateSpinDensityMatrix();
165
166 /**
167 * @return The number of molecular orbitals in the GaussianSet.
168 */
169 unsigned int molecularOrbitalCount(ElectronType type = Paired) const override;
170
171 /**
172 * Debug routine, outputs all of the data in the GaussianSet.
173 * @param type The electrons to output the information for.
174 */
175 void outputAll(ElectronType type = Paired);
176
177 /**
178 * @return True of the basis set is valid, false otherwise.
179 * Default is true, if false then the basis set is likely unusable.
180 */
181 bool isValid() override;
182
183 /**
184 * Set the SCF type for the object.
185 */
186 void setScfType(ScfType type) { m_scfType = type; }
187
188 /**
189 * Get the SCF type for the object.
190 */
191 ScfType scfType() const { return m_scfType; }
192
193 /**
194 * Set the functional name (if applicable).
195 */
196 void setFunctionalName(const std::string& name) { m_functionalName = name; }
197
198 /**
199 * Get the functional name (empty if none used).
200 */
201 std::string functionalName() const { return m_functionalName; }
202
203 /**
204 * Initialize the calculation, this must normally be done before anything.
205 */
206 void initCalculation();
207
208 /**
209 * Accessors for the various properties of the GaussianSet.
210 */
211 std::vector<int>& symmetry() { return m_symmetry; }
212 std::vector<int> symmetry() const { return m_symmetry; }
213 std::vector<unsigned int>& atomIndices() { return m_atomIndices; }
214 std::vector<unsigned int> atomIndices() const { return m_atomIndices; }
215 std::vector<unsigned int>& moIndices() { return m_moIndices; }
216 std::vector<unsigned int> moIndices() const { return m_moIndices; }
217 std::vector<unsigned int>& gtoIndices() { return m_gtoIndices; }
218 std::vector<unsigned int> gtoIndices() const { return m_gtoIndices; }
219 std::vector<unsigned int>& cIndices() { return m_cIndices; }
220 std::vector<unsigned int> cIndices() const { return m_cIndices; }
221 std::vector<double>& gtoA() { return m_gtoA; }
222 std::vector<double> gtoA() const { return m_gtoA; }
223 std::vector<double>& gtoC() { return m_gtoC; }
224 std::vector<double> gtoC() const { return m_gtoC; }
225 std::vector<double>& gtoCN()
226 {
227 initCalculation();
228 return m_gtoCN;
229 }
230
231 MatrixX& moMatrix(ElectronType type = Paired)
232 {
233 if (type == Paired || type == Alpha)
234 return m_moMatrix[0];
235 else
236 return m_moMatrix[1];
237 }
238
239 MatrixX moMatrix(ElectronType type = Paired) const
240 {
241 if (type == Paired || type == Alpha)
242 return m_moMatrix[0];
243 else
244 return m_moMatrix[1];
245 }
246
247 std::vector<unsigned int>& moNumber(ElectronType type = Paired)
248 {
249 if (type == Paired || type == Alpha)
250 return m_moNumber[0];
251 else
252 return m_moNumber[1];
253 }
254
255 std::vector<unsigned int> moNumber(ElectronType type = Paired) const
256 {
257 if (type == Paired || type == Alpha)
258 return m_moNumber[0];
259 else
260 return m_moNumber[1];
261 }
262
263 MatrixX& densityMatrix() { return m_density; }
264 MatrixX& spinDensityMatrix() { return m_spinDensity; }
265
266 private:
267 /**
268 * @brief This group is used once, and refers to the entire molecule.
269 */
270 std::vector<int> m_symmetry; //! Symmetry of the basis, S, P...
271 std::vector<unsigned int> m_atomIndices; //! Indices into the atomPos vector
272 std::vector<unsigned int> m_moIndices; //! Indices into the MO/density matrix
273 std::vector<unsigned int> m_gtoIndices; //! Indices into the GTO vector
274 std::vector<unsigned int> m_cIndices; //! Indices into m_gtoCN
275 std::vector<double> m_gtoA; //! The GTO exponent
276 std::vector<double> m_gtoC; //! The GTO contraction coefficient
277 std::vector<double> m_gtoCN; //! The GTO contraction coefficient (normalized)
278
279 /**
280 * @brief This block can be once (doubly) or in two parts (alpha and beta) for
281 * open shell calculations.
282 */
283 MatrixX m_moMatrix[2]; //! MO coefficient matrix
284
285 /**
286 * @brief If there are a sequence of related MOs, they are stored here, and
287 * set as the active MOs upon demand. Alpha will store Paired or the Alpha,
288 * Beta will store Beta coefficients for the appropriate calculation types.
289 */
290 std::vector<MatrixX> m_moMatrixSet[2];
291
292 /**
293 * @brief This stores the molecular orbital number (when they are sparse). It
294 * is used to lookup the actual index of the molecular orbital data.
295 */
296 std::vector<unsigned int> m_moNumber[2];
297
298 MatrixX m_density; //! Density matrix
299 MatrixX m_spinDensity; //! Spin Density matrix
300
301 unsigned int m_numMOs; //! The number of GTOs (not always!)
302 bool m_init; //! Has the calculation been initialised?
303
304 ScfType m_scfType;
305
306 std::string m_functionalName;
307 };
308
309 } // namespace Avogadro::Core
310
311 #endif