votca 2024.2-dev
Loading...
Searching...
No Matches
basisset.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// VOTCA includes
22
23// Local VOTCA includes
24#include "votca/xtp/basisset.h"
25#include <votca/tools/globals.h>
26
27namespace votca {
28namespace xtp {
29
30L StringToEnum(const std::string& type) {
31 assert(!type.empty() && "Shelltype must be non empty!");
32 assert(type.size() == 1 && "Shelltype size must be one");
33 const char t = type.back();
34 return StringToEnum(t);
35}
36
37L StringToEnum(char type) {
38 L l;
39 if (type == 'S') {
40 l = L::S;
41 } else if (type == 'P') {
42 l = L::P;
43 } else if (type == 'D') {
44 l = L::D;
45 } else if (type == 'F') {
46 l = L::F;
47 } else if (type == 'G') {
48 l = L::G;
49 } else if (type == 'H') {
50 l = L::H;
51 } else if (type == 'I') {
52 l = L::I;
53 } else {
54 throw std::runtime_error("FindLmax: Shelltype '" + std::string(1, type) +
55 "' not known");
56 }
57 return l;
58}
59
60std::string EnumToString(L l) {
61 switch (l) {
62 case L::S:
63 return "S";
64 case L::P:
65 return "P";
66 case L::D:
67 return "D";
68 case L::F:
69 return "F";
70 case L::G:
71 return "G";
72 case L::H:
73 return "H";
74 case L::I:
75 return "I";
76 }
77 return "";
78}
79
81 switch (l) {
82 case L::S:
83 return 0;
84 case L::P:
85 return 1;
86 case L::D:
87 return 4;
88 case L::F:
89 return 9;
90 case L::G:
91 return 16;
92 case L::H:
93 return 25;
94 case L::I:
95 return 36;
96 }
97 return -1;
98}
99
100Index NumFuncShell(L l) { return 2 * Index(l) + 1; }
101
103 Index lindex = Index(l);
104 return (lindex + 1) * (lindex + 2) / 2;
105}
106
108 switch (l) {
109 case L::S:
110 return 0;
111 case L::P:
112 return 1;
113 case L::D:
114 return 4;
115 case L::F:
116 return 10;
117 case L::G:
118 return 20;
119 case L::H:
120 return 35;
121 case L::I:
122 return 56;
123 }
124 return -1;
125}
126
127bool CheckShellType(const std::string& shelltype) {
128 if (shelltype.empty()) {
129 return false;
130 }
131 std::vector<char> allowed_shells = {'S', 'P', 'D', 'F', 'G', 'H', 'I'};
132 std::vector<char>::iterator it =
133 std::find(allowed_shells.begin(), allowed_shells.end(), shelltype[0]);
134 if (it == allowed_shells.end()) {
135 return false;
136 } else {
137 Index index = std::distance(allowed_shells.begin(), it);
138 for (Index i = 1; i < Index(shelltype.size()); i++) {
139 if (index + i > Index(allowed_shells.size()) ||
140 shelltype[i] != allowed_shells[index + i]) {
141 return false;
142 }
143 }
144 }
145
146 return true;
147}
148
149void BasisSet::Load(const std::string& name) {
150
151 // if name contains .xml, assume a basisset .xml file is located in the
152 // working directory
153 std::string xmlFile;
154 if (name.find(".xml") != std::string::npos) {
155 xmlFile = name;
156 } else {
157 xmlFile = tools::GetVotcaShare() + "/xtp/basis_sets/" + name + ".xml";
158 }
159 tools::Property basis_property;
160 basis_property.LoadFromXML(xmlFile);
161 name_ = basis_property.get("basis").getAttribute<std::string>("name");
162 std::vector<tools::Property*> elementProps =
163 basis_property.Select("basis.element");
164
165 for (tools::Property* elementProp : elementProps) {
166 std::string elementName = elementProp->getAttribute<std::string>("name");
167 Element& element = addElement(elementName);
168 std::vector<tools::Property*> shellProps = elementProp->Select("shell");
169 for (tools::Property* shellProp : shellProps) {
170 std::string shellType = shellProp->getAttribute<std::string>("type");
171 if (!CheckShellType(shellType)) {
172 throw std::runtime_error("Shelltype: '" + shellType +
173 "' is not a valid shelltype!");
174 }
175 for (char subtype : shellType) {
176
177 double shellScale = shellProp->getAttribute<double>("scale");
178
179 Shell& shell = element.addShell(StringToEnum(subtype), shellScale);
180 std::vector<tools::Property*> constProps =
181 shellProp->Select("constant");
182 for (tools::Property* constProp : constProps) {
183 double decay = constProp->getAttribute<double>("decay");
184 std::vector<tools::Property*> contrProps =
185 constProp->Select("contractions");
186 double contraction = 0.0;
187 for (tools::Property* contrProp : contrProps) {
188 std::string contrType =
189 contrProp->getAttribute<std::string>("type");
190 if (contrType != std::string(1, subtype)) {
191 continue;
192 }
193 contraction = contrProp->getAttribute<double>("factor");
194 }
195 shell.addGaussian(decay, contraction);
196 }
197 }
198 }
199 }
200 return;
201}
202
203// adding an Element to a Basis Set
204Element& BasisSet::addElement(std::string elementType) {
205 auto e = elements_.insert({elementType, Element(elementType)});
206 if (!e.second) {
207 throw std::runtime_error("Inserting element into basisset failed!");
208 }
209 return e.first->second;
210}
211
212const Element& BasisSet::getElement(std::string element_type) const {
213 std::map<std::string, Element>::const_iterator itm =
214 elements_.find(element_type);
215 if (itm == elements_.end()) {
216 throw std::runtime_error("Basis set " + name_ +
217 " does not have element of type " + element_type);
218 }
219 return itm->second;
220}
221
222std::ostream& operator<<(std::ostream& out, const Shell& shell) {
223
224 out << "Type:" << EnumToString(shell.getL()) << " Scale:" << shell.getScale()
225 << " Func: " << shell.getnumofFunc() << "\n";
226 for (const auto& gaussian : shell.gaussians_) {
227 out << " Gaussian Decay: " << gaussian.decay();
228 out << " Contraction: " << gaussian.contraction();
229 out << "\n";
230 }
231 return out;
232}
233
234std::ostream& operator<<(std::ostream& out, const Element& element) {
235 out << "Element:" << element.getType() << "\n";
236 for (const auto& shell : element) {
237 out << shell;
238 }
239 return out;
240}
241
242std::ostream& operator<<(std::ostream& out, const BasisSet& basis) {
243 out << "BasisSet:" << basis.name_ << "\n";
244 for (const auto& element : basis) {
245 out << element.second;
246 }
247 out << std::flush;
248 return out;
249}
250
251GaussianPrimitive& Shell::addGaussian(double decay, double contraction) {
252 gaussians_.push_back(GaussianPrimitive(decay, contraction));
253 return gaussians_.back();
254}
255
256} // namespace xtp
257} // namespace votca
class to manage program options with xml serialization functionality
Definition property.h:55
Property & get(const std::string &key)
get existing property
Definition property.cc:79
T getAttribute(const std::string &attribute) const
return attribute as type
Definition property.h:308
std::vector< Property * > Select(const std::string &filter)
select property based on a filter
Definition property.cc:185
void LoadFromXML(std::string filename)
Definition property.cc:238
const Element & getElement(std::string element_type) const
Definition basisset.cc:212
void Load(const std::string &name)
Definition basisset.cc:149
std::string name_
Definition basisset.h:156
std::map< std::string, Element > elements_
Definition basisset.h:157
Element & addElement(std::string elementType)
Definition basisset.cc:204
GaussianPrimitive & addGaussian(double decay, double contraction)
Definition basisset.cc:251
double getScale() const
Definition basisset.h:80
L getL() const
Definition basisset.h:74
std::vector< GaussianPrimitive > gaussians_
Definition basisset.h:101
Index getnumofFunc() const
Definition basisset.h:76
std::string GetVotcaShare()
Retrieves VOTCASHARE environment variable. Throws std::runtime_error if not set.
Definition globals.cc:27
std::ostream & operator<<(std::ostream &out, const Correlate &c)
Definition correlate.h:53
Index NumFuncShell(L l)
Definition basisset.cc:100
std::string EnumToString(L l)
Definition basisset.cc:60
bool CheckShellType(const std::string &shelltype)
Definition basisset.cc:127
Index OffsetFuncShell(L l)
Definition basisset.cc:80
Index NumFuncShell_cartesian(L l)
Definition basisset.cc:102
L StringToEnum(const std::string &type)
Definition basisset.cc:30
Index OffsetFuncShell_cartesian(L l)
Definition basisset.cc:107
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26