votca 2024-dev
Loading...
Searching...
No Matches
ecpaobasis.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// Standard includes
21#include <vector>
22
23// Local VOTCA includes
28namespace votca {
29namespace xtp {
30
32 int maxL = 0;
33 for (const auto& potential : aopotentials_) {
34 maxL = std::max(potential.getL(), maxL);
35 }
36 return Index(maxL);
37}
38
40 for (Index i = 0; i < mol.size(); i++) {
41 mol[i].ecpcharge_ = ncore_perAtom_[i];
42 }
43}
44
46 name_ = "";
47 aopotentials_.clear();
48 ncore_perAtom_.clear();
49}
50
52 for (libecpint::ECP& potential : aopotentials_) {
53 const Eigen::Vector3d pos = mol[potential.atom_id].getPos();
54 potential.center_ = {pos.x(), pos.y(), pos.z()};
55 }
56}
57
58void ECPAOBasis::add(const ECPAOBasis& other) {
59 Index atomindex_offset = Index(ncore_perAtom_.size());
60 for (libecpint::ECP potential : other) {
61 potential.atom_id += int(atomindex_offset);
62 aopotentials_.push_back(potential);
63 }
64
65 ncore_perAtom_.insert(ncore_perAtom_.end(), other.ncore_perAtom_.begin(),
66 other.ncore_perAtom_.end());
67}
68
69std::vector<std::string> ECPAOBasis::Fill(const ECPBasisSet& bs,
70 QMMolecule& atoms) {
71 aopotentials_.clear();
72 ncore_perAtom_.clear();
73 name_ = bs.Name();
74 std::vector<std::string> non_ecp_elements;
75 for (QMAtom& atom : atoms) {
76 std::string name = atom.getElement();
77
78 bool element_exists = true;
79
80 try {
81 bs.getElement(name);
82 } catch (std::runtime_error& error) {
83 element_exists = false;
84
85 if (std::find(non_ecp_elements.begin(), non_ecp_elements.end(), name) !=
86 non_ecp_elements.end()) {
87 non_ecp_elements.push_back(name);
88 }
89 }
90
91 if (element_exists) {
92 const ECPElement& element = bs.getElement(name);
93 ncore_perAtom_.push_back(element.getNcore());
94
95 libecpint::ECP potential(atom.getPos().data());
96 for (const ECPShell& shell : element) {
97 for (const auto& gaussian : shell) {
98 potential.addPrimitive(int(gaussian.power_), int(shell.getL()),
99 gaussian.decay_, gaussian.contraction_);
100 }
101 }
102 aopotentials_.push_back(potential);
103 aopotentials_.back().atom_id =
104 int(atom.getId()); // add atom id here because copyconstructor of
105 // libecpint::ECP is broken
106 } else {
107 ncore_perAtom_.push_back(0);
108 }
109 }
110
112 return non_ecp_elements;
113}
114
115// This class is purely for hdf5 input output, because the libecpint classes do
116// not have the member functions required.
118
119 public:
120 struct data {
122 double x;
123 double y;
124 double z;
127 double coeff;
128 double decay;
129 };
130
131 static void SetupCptTable(CptTable& table) {
132 table.addCol<Index>("atomid", HOFFSET(data, atomid));
133 table.addCol<double>("posX", HOFFSET(data, x));
134 table.addCol<double>("posY", HOFFSET(data, y));
135 table.addCol<double>("posZ", HOFFSET(data, z));
136 table.addCol<Index>("power", HOFFSET(data, power));
137 table.addCol<Index>("L", HOFFSET(data, l));
138 table.addCol<double>("coeff", HOFFSET(data, coeff));
139 table.addCol<double>("decay", HOFFSET(data, decay));
140 }
141};
142
144 w(name_, "name");
145
146 w(ncore_perAtom_, "atomic ecp charges");
147 Index numofprimitives = 0;
148 for (const auto& potential : aopotentials_) {
149 numofprimitives += potential.getN();
150 }
151
152 CptTable table = w.openTable<PotentialIO>("Potentials", numofprimitives);
153
154 std::vector<PotentialIO::data> dataVec;
155 dataVec.reserve(numofprimitives);
156 for (const auto& potential : aopotentials_) {
157 for (const auto& contrib : potential.gaussians) {
159 d.l = Index(contrib.l);
160 d.power = Index(contrib.n);
161 d.coeff = contrib.d;
162 d.decay = contrib.a;
163 d.atomid = Index(potential.atom_id);
164 d.x = potential.center_[0];
165 d.y = potential.center_[1];
166 d.z = potential.center_[2];
167 dataVec.push_back(d);
168 }
169 }
170
171 table.write(dataVec);
172}
173
175 clear();
176 r(name_, "name");
177 r(ncore_perAtom_, "atomic ecp charges");
178
179 CptTable table = r.openTable<PotentialIO>("Potentials");
180 std::vector<PotentialIO::data> dataVec(table.numRows());
181 table.read(dataVec);
182 Index atomindex = -1;
183 for (const PotentialIO::data& d : dataVec) {
184 if (d.atomid > atomindex) {
185 Eigen::Vector3d pos(d.x, d.y, d.z);
186 aopotentials_.push_back(libecpint::ECP(pos.data()));
187 aopotentials_.back().atom_id = int(d.atomid);
188 atomindex = d.atomid;
189 }
190 // +2 because constructor of libecpint::primitve always subtracts 2
191 aopotentials_.back().addPrimitive(int(d.power) + 2, int(d.l), d.decay,
192 d.coeff);
193 }
194}
195
196std::ostream& operator<<(std::ostream& out, const libecpint::ECP& potential) {
197 out << " AtomId: " << potential.atom_id << " Components: " << potential.getN()
198 << "\n";
199 for (const auto& gaussian : potential.gaussians) {
200 out << " L: " << gaussian.l;
201 out << " Gaussian Decay: " << gaussian.a;
202 out << " Power: " << gaussian.n;
203 out << " Contractions: " << gaussian.d << "\n";
204 }
205 return out;
206}
207
208std::ostream& operator<<(std::ostream& out, const ECPAOBasis& ecp) {
209
210 out << "Name:" << ecp.Name() << "\n";
211 out << " Potentials:" << ecp.aopotentials_.size() << "\n";
212 for (const auto& potential : ecp) {
213 out << potential;
214 }
215 out << "\n"
216 << " Atomcharges:";
217 for (Index i = 0; i < Index(ecp.ncore_perAtom_.size()); i++) {
218 out << i << ":" << ecp.ncore_perAtom_[i] << " ";
219 }
220 return out;
221}
222
223} // namespace xtp
224} // namespace votca
const Eigen::Vector3d & getPos() const
CptTable openTable(const std::string &name)
CptTable openTable(const std::string &name, std::size_t nRows, bool compact=false)
void write(void *buffer, const std::size_t &startIdx, const std::size_t &endIdx)
void read(void *buffer, const std::size_t &startIdx, const std::size_t &endIdx)
void addCol(const std::string &name, const size_t &offset)
Container to hold ECPs for all atoms.
Definition ecpaobasis.h:43
void ReadFromCpt(CheckpointReader &r)
Index getMaxL() const
Definition ecpaobasis.cc:31
std::vector< libecpint::ECP > aopotentials_
Definition ecpaobasis.h:76
const std::string & Name() const
Definition ecpaobasis.h:59
void UpdatePotentialPositions(const QMMolecule &mol)
Definition ecpaobasis.cc:51
std::vector< std::string > Fill(const ECPBasisSet &bs, QMMolecule &atoms)
Definition ecpaobasis.cc:69
void WriteToCpt(CheckpointWriter &w) const
std::vector< Index > ncore_perAtom_
Definition ecpaobasis.h:74
void AddECPChargeToMolecule(QMMolecule &mol) const
Definition ecpaobasis.cc:39
void add(const ECPAOBasis &other)
Definition ecpaobasis.cc:58
const std::string & Name() const
const ECPElement & getElement(std::string element_type) const
static void SetupCptTable(CptTable &table)
container for QM atoms
Definition qmatom.h:37
std::ostream & operator<<(std::ostream &out, const Correlate &c)
Definition correlate.h:53
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26