votca 2024.2-dev
Loading...
Searching...
No Matches
ecpbasisset.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 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/tools/globals.h"
25#include "votca/xtp/basisset.h"
27
28namespace votca {
29namespace xtp {
30
31void ECPBasisSet::Load(const std::string& name) {
32 tools::Property basis_property;
33
34 // if name contains .xml, assume a ecp .xml file is located in the working
35 // directory
36 std::size_t found_xml = name.find(".xml");
37 std::string xmlFile;
38 if (found_xml != std::string::npos) {
39 xmlFile = name;
40 } else {
41 xmlFile = tools::GetVotcaShare() + "/xtp/ecps/" + name + ".xml";
42 }
43 basis_property.LoadFromXML(xmlFile);
44 name_ =
45 basis_property.get("pseudopotential").getAttribute<std::string>("name");
46 std::vector<tools::Property*> elementProps =
47 basis_property.Select("pseudopotential.element");
48
49 for (tools::Property* elementProp : elementProps) {
50 std::string elementName = elementProp->getAttribute<std::string>("name");
51 Index lmax = elementProp->getAttribute<Index>("lmax");
52 if (lmax > Index(L::I)) {
53 throw std::runtime_error("In ecps lmax larger " +
54 std::to_string(Index(L::I)) + " is not allowed");
55 }
56 Index ncore = elementProp->getAttribute<Index>("ncore");
57
58 ECPElement& element = addElement(elementName, static_cast<L>(lmax), ncore);
59
60 std::vector<tools::Property*> shellProps = elementProp->Select("shell");
61 for (tools::Property* shellProp : shellProps) {
62 std::string shellType = shellProp->getAttribute<std::string>("type");
63 if (shellType.size() > 1) {
64 throw std::runtime_error(
65 "In ecps no combined shells e.g. SP are allowed. Here:" +
66 shellType);
67 }
68 ECPShell& shell = element.addShell(StringToEnum(shellType));
69 std::vector<tools::Property*> constProps = shellProp->Select("constant");
70 for (tools::Property* constProp : constProps) {
71 Index power = constProp->getAttribute<Index>("power");
72 double decay = constProp->getAttribute<double>("decay");
73 double contraction = constProp->getAttribute<double>("contraction");
74 shell.addGaussian(power, decay, contraction);
75 }
76 }
77 }
78 return;
79}
80
81// adding an Element to a Pseudopotential Library
82ECPElement& ECPBasisSet::addElement(std::string elementType, L lmax,
83 Index ncore) {
84 std::shared_ptr<ECPElement> element(new ECPElement(elementType, lmax, ncore));
85 elements_[elementType] = element;
86 return *element;
87}
88
89const ECPElement& ECPBasisSet::getElement(std::string element_type) const {
90 std::map<std::string, std::shared_ptr<ECPElement> >::const_iterator itm =
91 elements_.find(element_type);
92 if (itm == elements_.end()) {
93 throw std::runtime_error("Basis set " + name_ +
94 " does not have element of type " + element_type);
95 }
96 const ECPElement& element = *((*itm).second);
97 return element;
98}
99
100std::ostream& operator<<(std::ostream& out, const ECPShell& shell) {
101
102 out << "Type:" << xtp::EnumToString(shell.getL())
103 << " Func: " << shell.getnumofFunc() << "\n";
104 for (const auto& gaussian : shell.gaussians_) {
105 out << " Gaussian Decay: " << gaussian.decay_;
106 out << " Power: " << gaussian.power_;
107 out << " Contraction:" << gaussian.contraction_ << "\n";
108 }
109 return out;
110}
111
112std::ostream& operator<<(std::ostream& out, const ECPElement& element) {
113 out << "Element:" << element.getType() << " Lmax:" << element.getLmax()
114 << " Ncore:" << element.getNcore() << "\n";
115 for (const auto& shell : element) {
116 out << shell;
117 }
118 return out;
119}
120
121std::ostream& operator<<(std::ostream& out, const ECPBasisSet& basis) {
122 out << "BasisSet:" << basis.name_ << "\n";
123 for (const auto& element : basis) {
124 out << (*element.second);
125 }
126 out << std::flush;
127 return out;
128}
129
130// adds a Gaussian of a pseudopotential
132 double contraction) {
133 gaussians_.push_back(ECPGaussianPrimitive(power, decay, contraction));
134 return gaussians_.back();
135}
136
137} // namespace xtp
138} // 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
ECPElement & addElement(std::string elementType, L lmax, Index ncore)
void Load(const std::string &name)
std::map< std::string, std::shared_ptr< ECPElement > > elements_
const ECPElement & getElement(std::string element_type) const
ECPGaussianPrimitive & addGaussian(Index power, double decay, double contraction)
std::vector< ECPGaussianPrimitive > gaussians_
Definition ecpbasisset.h:70
Index getnumofFunc() const
Definition ecpbasisset.h:48
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
std::string EnumToString(L l)
Definition basisset.cc:60
L StringToEnum(const std::string &type)
Definition basisset.cc:30
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26