votca 2024.2-dev
Loading...
Searching...
No Matches
gencube.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// Standard includes
21#include <cstdio>
22
23// Third party includes
24#include <boost/format.hpp>
25
26// VOTCA includes
29#include <votca/tools/getline.h>
30
31// Local VOTCA includes
32#include "votca/xtp/aobasis.h"
34#include "votca/xtp/orbitals.h"
35
36// Local private VOTCA includes
37#include "gencube.h"
38
39namespace votca {
40namespace xtp {
41
43
44 orbfile_ = options.ifExistsReturnElseReturnDefault<std::string>(
45 ".input", job_name_ + ".orb");
46 output_file_ = options.ifExistsReturnElseReturnDefault<std::string>(
47 ".output", job_name_ + ".cube");
48
49 // padding
50 padding_ = options.get(".padding").as<double>();
51
52 // steps
53 steps_.y() = options.get(".ysteps").as<Index>();
54 steps_.x() = options.get(".xsteps").as<Index>();
55 steps_.z() = options.get(".zsteps").as<Index>();
56
57 state_ = options.get(".state").as<QMState>();
58 dostateonly_ = options.get(".diff2gs").as<bool>();
59
60 mode_ = options.get(".mode").as<std::string>();
61 if (mode_ == "subtract") {
62 infile1_ = options.get(".infile1").as<std::string>();
63 infile2_ = options.get(".infile2").as<std::string>();
64 }
65}
66
68
70 << "Reading serialized QM data from " << orbfile_ << std::flush;
71
72 Orbitals orbitals;
73 orbitals.ReadFromCpt(orbfile_);
74
76 XTP_LOG(Log::error, log_) << "Created cube grid" << std::flush;
77 writer.WriteFile(output_file_, orbitals, state_, dostateonly_);
79 << "Wrote cube data to " << output_file_ << std::flush;
80 return;
81}
82
84
85 // open infiles for reading
86 std::ifstream in1;
88 << " Reading first cube from " << infile1_ << std::flush;
89 in1.open(infile1_, std::ios::in);
90 std::ifstream in2;
92 << " Reading second cube from " << infile2_ << std::flush;
93 in2.open(infile2_, std::ios::in);
94 std::string s;
95
96 std::ofstream out(output_file_);
97
98 // first two lines of header are garbage
99 tools::getline(in1, s);
100 out << s << "\n";
101 tools::getline(in1, s);
102 out << s << " substraction\n";
103 tools::getline(in2, s);
104 tools::getline(in2, s);
105
106 // read rest from header
107 Index natoms;
108 double xstart;
109 double ystart;
110 double zstart;
111 // first line
112 in1 >> natoms;
113 bool do_amplitude = false;
114 if (natoms < 0) {
115 do_amplitude = true;
116 }
117 in1 >> xstart;
118 in1 >> ystart;
119 in1 >> zstart;
120 // check from second file
121 Index tempint;
122 double tempdouble;
123 in2 >> tempint;
124 if (tempint != natoms) {
125 throw std::runtime_error("Atom numbers do not match");
126 }
127 in2 >> tempdouble;
128 if (tempdouble != xstart) {
129 throw std::runtime_error("Xstart does not match");
130 }
131 in2 >> tempdouble;
132 if (tempdouble != ystart) {
133 throw std::runtime_error("Ystart does not match");
134 }
135 in2 >> tempdouble;
136 if (tempdouble != zstart) {
137 throw std::runtime_error("Zstart does not match");
138 }
139
140 out << boost::format("%1$lu %2$f %3$f %4$f \n") % natoms % xstart % ystart %
141 zstart;
142
143 // grid information from first cube
144 double xincr;
145 double yincr;
146 double zincr;
147 Index xsteps;
148 Index ysteps;
149 Index zsteps;
150 in1 >> xsteps;
151 in1 >> xincr;
152 in1 >> tempdouble;
153 in1 >> tempdouble;
154 in1 >> ysteps;
155 in1 >> tempdouble;
156 in1 >> yincr;
157 in1 >> tempdouble;
158 in1 >> zsteps;
159 in1 >> tempdouble;
160 in1 >> tempdouble;
161 in1 >> zincr;
162
163 // check second cube
164 in2 >> tempint;
165 if (tempint != xsteps) {
166 throw std::runtime_error("xsteps does not match");
167 }
168 in2 >> tempdouble;
169 if (tempdouble != xincr) {
170 throw std::runtime_error("xincr does not match");
171 }
172 in2 >> tempdouble;
173 in2 >> tempdouble;
174 in2 >> tempint;
175 if (tempint != ysteps) {
176 throw std::runtime_error("ysteps does not match");
177 }
178 in2 >> tempdouble;
179 in2 >> tempdouble;
180 if (tempdouble != yincr) {
181 throw std::runtime_error("yincr does not match");
182 }
183 in2 >> tempdouble;
184 in2 >> tempint;
185 if (tempint != zsteps) {
186 throw std::runtime_error("zsteps does not match");
187 }
188 in2 >> tempdouble;
189 in2 >> tempdouble;
190 in2 >> tempdouble;
191 if (tempdouble != zincr) {
192 throw std::runtime_error("zincr does not match");
193 }
194
195 out << boost::format("%1$d %2$f 0.0 0.0 \n") % xsteps % xincr;
196 out << boost::format("%1$d 0.0 %2$f 0.0 \n") % ysteps % yincr;
197 out << boost::format("%1$d 0.0 0.0 %2$f \n") % zsteps % zincr;
198
199 // atom information
200
201 for (Index iatom = 0; iatom < std::abs(natoms); iatom++) {
202 // get center coordinates in Bohr
203 double x;
204 double y;
205 double z;
206 Index atnum;
207 double crg;
208
209 // get from first cube
210 in1 >> atnum;
211 in1 >> crg;
212 in1 >> x;
213 in1 >> y;
214 in1 >> z;
215
216 // check second cube
217 in2 >> tempint;
218 if (tempint != atnum) {
219 throw std::runtime_error("atnum does not match");
220 }
221 in2 >> tempdouble;
222 if (tempdouble != crg) {
223 throw std::runtime_error("crg does not match");
224 }
225 in2 >> tempdouble;
226 if (tempdouble != x) {
227 throw std::runtime_error("x does not match");
228 }
229 in2 >> tempdouble;
230 if (tempdouble != y) {
231 throw std::runtime_error("y does not match");
232 }
233 in2 >> tempdouble;
234 if (tempdouble != z) {
235 throw std::runtime_error("z does not match");
236 }
237 out << boost::format("%1$d %2$f %3$f %4$f %5$f\n") % atnum % crg % x % y %
238 z;
239 }
240
241 if (do_amplitude) {
242 Index ntotal;
243 Index nis;
244 in1 >> ntotal;
245 in1 >> nis;
246
247 in2 >> tempint;
248 if (tempint != ntotal) {
249 throw std::runtime_error("ntotal does not match");
250 }
251 in2 >> tempint;
252 if (tempint != nis) {
253 throw std::runtime_error("nis does not match");
254 }
255 out << boost::format(" 1 %1$d \n") % nis;
256 }
257 // now read data
258 double val1;
259 double val2;
260 for (Index ix = 0; ix < xsteps; ix++) {
261 for (Index iy = 0; iy < ysteps; iy++) {
262 Index Nrecord = 0;
263 for (Index iz = 0; iz < zsteps; iz++) {
264 Nrecord++;
265 in1 >> val1;
266 in2 >> val2;
267 if (Nrecord == 6 || iz == zsteps - 1) {
268 out << boost::format("%1$E \n") % (val1 - val2);
269 Nrecord = 0;
270 } else {
271 out << boost::format("%1$E ") % (val1 - val2);
272 }
273 }
274 }
275 }
276
277 out.close();
279 << "Wrote subtracted cube data to " << output_file_ << std::flush;
280}
281
283
286
287 log_.setCommonPreface("\n... ...");
288
289 // calculate new cube
290 if (mode_ == "new") {
292 } else if (mode_ == "subtract") {
294 }
295
296 return true;
297}
298} // namespace xtp
299} // 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 as() const
return value as type
Definition property.h:283
T ifExistsReturnElseReturnDefault(const std::string &key, T defaultvalue) const
Definition property.h:321
void WriteFile(const std::string &filename, const Orbitals &orb, QMState state, bool dostateonly) const
std::string infile1_
Definition gencube.h:51
void ParseOptions(const tools::Property &user_options)
Definition gencube.cc:42
Eigen::Array< Index, 3, 1 > steps_
Definition gencube.h:57
std::string output_file_
Definition gencube.h:50
std::string orbfile_
Definition gencube.h:49
std::string infile2_
Definition gencube.h:52
std::string mode_
Definition gencube.h:59
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setMultithreading(bool maverick)
Definition logger.h:186
void setCommonPreface(const std::string &preface)
Definition logger.h:198
container for molecular orbitals
Definition orbitals.h:46
void ReadFromCpt(const std::string &filename)
Definition orbitals.cc:692
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
std::string job_name_
Definition qmtool.h:50
#define XTP_LOG(level, log)
Definition logger.h:40
std::istream & getline(std::istream &is, std::string &str)
Wrapper for a getline function.
Definition getline.h:35
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static Level current_level
Definition globals.h:30