GQCP
Loading...
Searching...
No Matches
ShellSet.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
23#include "Molecule/Molecule.hpp"
26
27#include <algorithm>
28#include <initializer_list>
29#include <vector>
30
31
32namespace GQCP {
33
34
40template <typename _Shell>
41class ShellSet {
42public:
43 // The type of shell that this shell set contains.
44 using Shell = _Shell;
45
46 // The type of primitives that this shell set contains.
47 using Primitive = typename Shell::Primitive;
48
49 // The type of basis functions that this shell contains.
50 using BasisFunction = typename Shell::BasisFunction;
51
52
53private:
54 // The collection of shells represented by a vector.
55 std::vector<Shell> shells;
56
57
58public:
59 /*
60 * MARK: Constructors
61 */
62
66 ShellSet(const std::vector<Shell>& shells) :
67 shells {shells} {}
68
69
75 ShellSet(const std::initializer_list<GTOShell>& list) :
76 shells {list} {}
77
78
79 /*
80 * MARK: Normalization
81 */
82
87
88 for (auto& shell : this->shells) {
89 shell.embedNormalizationFactor();
90 }
91 }
92
93
100
101 for (auto& shell : this->shells) {
102 shell.embedNormalizationFactorsOfPrimitives();
103 }
104 }
105
106
113
114 for (auto& shell : this->shells) {
115 shell.unEmbedNormalizationFactorsOfPrimitives();
116 }
117 }
118
119
120 /*
121 * MARK: Basis functions
122 */
123
127 size_t numberOfBasisFunctions() const {
128
129 size_t value {};
130 for (const auto& shell : this->shells) {
131 value += shell.numberOfBasisFunctions();
132 }
133
134 return value;
135 }
136
137
141 std::vector<BasisFunction> basisFunctions() const {
142
143 std::vector<BasisFunction> basis_functions;
144 basis_functions.reserve(this->numberOfBasisFunctions());
145 for (const auto& shell : this->shells) {
146 const auto shell_basis_functions = shell.basisFunctions();
147 for (const auto& shell_basis_function : shell_basis_functions) {
148 basis_functions.push_back(shell_basis_function);
149 }
150 }
151
152 return basis_functions;
153 }
154
155
161 size_t basisFunctionIndex(const size_t shell_index) const {
162
163 // Count the number of basis functions before the given index.
164 size_t bf_index {};
165 for (size_t i = 0; i < shell_index; i++) {
166 bf_index += this->shells[i].numberOfBasisFunctions();
167 }
168
169 return bf_index;
170 }
171
172
173 /*
174 * MARK: General information
175 */
176
180 const std::vector<Shell>& asVector() const { return this->shells; }
181
185 size_t numberOfShells() const { return this->shells.size(); }
186
190 std::vector<Nucleus> nuclei() const {
191
192 // Append every unique nucleus in this shell set's shells.
193 std::vector<Nucleus> nuclei {};
194 for (const auto& shell : this->shells) {
195 const auto& nucleus = shell.nucleus();
196
197 const auto unary_predicate = [nucleus](const Nucleus& other) {
198 return Nucleus::equalityComparer()(nucleus, other);
199 };
200 const auto& p = std::find_if(nuclei.begin(), nuclei.end(), unary_predicate);
201
202 if (p == nuclei.end()) { // If the nucleus is unique.
203 nuclei.push_back(nucleus);
204 }
205 }
206
207 return nuclei;
208 }
209
210
214 size_t maximumAngularMomentum() const {
215
216 // Generate a list of all the angular momenta and then check its maximum.
217 std::vector<size_t> angular_momenta {}; // This will contain the number of primitives for each of the shells.
218 angular_momenta.reserve(this->numberOfShells());
219
220 for (const auto& shell : this->asVector()) {
221 angular_momenta.push_back(shell.angularMomentum());
222 }
223
224 const auto it = std::max_element(angular_momenta.begin(), angular_momenta.end()); // 'it' for iterator.
225 return *it;
226 }
227
228
233
234 // Generate a list of all the number of primitives momenta and then check its maximum.
235 std::vector<size_t> number_of_primitives {}; // This will contain the number of primitives for each of the shells.
236 number_of_primitives.reserve(this->numberOfShells());
237
238 for (const auto& shell : this->asVector()) {
239 number_of_primitives.push_back(shell.contractionSize());
240 }
241
242 const auto it = std::max_element(number_of_primitives.begin(), number_of_primitives.end()); // 'it' for iterator.
243 return *it;
244 }
245
246
247 /*
248 * MARK: London modifications
249 */
250
258 template <typename Z = Shell>
260
261 // Run over each `GTOShell` and construct the corresponding `LondonGTOShell`.
262 std::vector<LondonGTOShell> london_shells;
263 london_shells.reserve(this->numberOfShells());
264 for (const auto& gto_shell : this->asVector()) {
265 LondonGTOShell london_shell {gto_shell, B};
266 london_shells.push_back(london_shell);
267 }
268
269 return ShellSet<LondonGTOShell>(london_shells);
270 }
271};
272
273
274} // namespace GQCP
Definition: HomogeneousMagneticField.hpp:30
Definition: LondonGTOShell.hpp:32
Definition: Nucleus.hpp:36
static std::function< bool(const Nucleus &, const Nucleus &)> equalityComparer(const double tolerance=1.0e-08)
Definition: Nucleus.cpp:117
Definition: ShellSet.hpp:41
enable_if_t< std::is_same< Z, GTOShell >::value, ShellSet< LondonGTOShell > > applyLondonModification(const HomogeneousMagneticField &B) const
Definition: ShellSet.hpp:259
void embedNormalizationFactors()
Definition: ShellSet.hpp:86
typename Shell::Primitive Primitive
Definition: ShellSet.hpp:47
typename Shell::BasisFunction BasisFunction
Definition: ShellSet.hpp:50
_Shell Shell
Definition: ShellSet.hpp:44
const std::vector< Shell > & asVector() const
Definition: ShellSet.hpp:180
size_t maximumAngularMomentum() const
Definition: ShellSet.hpp:214
std::vector< BasisFunction > basisFunctions() const
Definition: ShellSet.hpp:141
void unEmbedNormalizationFactorsOfPrimitives()
Definition: ShellSet.hpp:112
size_t numberOfShells() const
Definition: ShellSet.hpp:185
ShellSet(const std::vector< Shell > &shells)
Definition: ShellSet.hpp:66
std::vector< Nucleus > nuclei() const
Definition: ShellSet.hpp:190
size_t numberOfBasisFunctions() const
Definition: ShellSet.hpp:127
ShellSet(const std::initializer_list< GTOShell > &list)
Definition: ShellSet.hpp:75
void embedNormalizationFactorsOfPrimitives()
Definition: ShellSet.hpp:99
size_t maximumNumberOfPrimitives() const
Definition: ShellSet.hpp:232
size_t basisFunctionIndex(const size_t shell_index) const
Definition: ShellSet.hpp:161
Definition: BaseOneElectronIntegralBuffer.hpp:25
typename std::enable_if< B, T >::type enable_if_t
Definition: type_traits.hpp:37