votca 2026-dev
Loading...
Searching...
No Matches
latticegen.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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 <fstream>
22#include <iomanip>
23#include <numeric>
24
25// VOTCA includes
28
29// Local VOTCA includes
31
32// Local private VOTCA includes
33#include "latticegen.h"
34
35namespace votca {
36namespace xtp {
37
39 statefile_ = options.ifExistsReturnElseReturnDefault<std::string>(
40 ".statefile", job_name_ + ".hdf5");
42 options.ifExistsReturnElseReturnDefault<std::string>(".energyfile", "");
43
44 std::vector<Index> dims = options.get(".dims").as<std::vector<Index>>();
45 if (dims.size() != 3) {
46 throw std::runtime_error("latticegen: dims needs three numbers");
47 }
48 lattice_.dims = {dims[0], dims[1], dims[2]};
49 lattice_.spacing =
50 options.get(".spacing").as<double>() * tools::conv::nm2bohr;
51 lattice_.cutoff = options.get(".cutoff").as<double>() * tools::conv::nm2bohr;
53 lattice_.J2 = options.get(".J2").as<double>() * ev2;
54 lattice_.decay_length =
55 options.get(".decaylength").as<double>() * tools::conv::nm2bohr;
56 lattice_.reorganization =
57 options.get(".reorganization").as<double>() * tools::conv::ev2hrt;
58 lattice_.mean_energy =
59 options.get(".energy.mean").as<double>() * tools::conv::ev2hrt;
60 lattice_.sigma =
61 options.get(".energy.sigma").as<double>() * tools::conv::ev2hrt;
63 options.get(".energy.disorder").as<std::string>());
64 lattice_.eta_a = options.get(".energy.eta_a").as<double>();
65 lattice_.eta_b = options.get(".energy.eta_b").as<double>();
66 lattice_.l_b = options.get(".energy.l_b").as<Index>();
67 lattice_.l_c = options.get(".energy.l_c").as<Index>();
68 lattice_.include_self = options.get(".energy.includeself").as<bool>();
69 lattice_.seed = options.get(".energy.seed").as<std::uint64_t>();
70
71 std::vector<std::string> states =
72 options.get(".states").as<std::vector<std::string>>();
73 lattice_.states.clear();
74 for (const std::string& s : states) {
75 QMStateType type(s);
76 if (!type.isKMCState()) {
77 throw std::runtime_error("latticegen: " + s +
78 " is not a hopping state (e, h, s, t)");
79 }
80 lattice_.states.push_back(type);
81 }
82 lattice_.segment_name = options.get(".segmentname").as<std::string>();
83}
84
86 log_.setReportLevel(Log::current_level);
87 log_.setMultithreading(true);
88 log_.setCommonPreface("\n... ...");
89
91 throw std::runtime_error("latticegen: " + statefile_ +
92 " exists already, remove it or choose another "
93 "statefile name");
94 }
95
97 Topology top;
98 model.BuildTopology(top);
99
100 const std::vector<double>& e = model.SiteEnergies();
101 double mean = std::accumulate(e.begin(), e.end(), 0.0) / double(e.size());
102 double var = std::accumulate(e.begin(), e.end(), 0.0,
103 [mean](double acc, double x) {
104 return acc + (x - mean) * (x - mean);
105 }) /
106 double(e.size());
108 << "Lattice " << lattice_.dims[0] << "x" << lattice_.dims[1] << "x"
109 << lattice_.dims[2] << ": " << model.NumberOfSites() << " sites, "
110 << top.NBList().size() << " pairs" << std::flush;
112 << "Site energies: mean " << mean * tools::conv::hrt2ev
113 << " eV, standard deviation " << std::sqrt(var) * tools::conv::hrt2ev
114 << " eV" << std::flush;
115
116 StateSaver saver(statefile_);
117 saver.WriteFrame(top);
118 XTP_LOG(Log::error, log_) << "Wrote " << statefile_ << std::flush;
119
120 if (!energyfile_.empty()) {
121 std::ofstream out(energyfile_);
122 out << "# segment id, x, y, z [nm], site energy [eV]\n";
123 out << std::setprecision(12);
124 const std::vector<Eigen::Vector3d>& pos = model.Positions();
125 for (Index i = 0; i < model.NumberOfSites(); ++i) {
126 Eigen::Vector3d p = pos[i] * tools::conv::bohr2nm;
127 out << i << " " << p.x() << " " << p.y() << " " << p.z() << " "
128 << e[i] * tools::conv::hrt2ev << "\n";
129 }
131 << "Wrote site energies to " << energyfile_ << std::flush;
132 }
133 return true;
134}
135
136} // namespace xtp
137} // namespace votca
Index size() const
Definition pairlist.h:53
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:332
LatticeModel::Options lattice_
Definition latticegen.h:48
std::string statefile_
Definition latticegen.h:49
std::string energyfile_
Definition latticegen.h:50
void ParseOptions(const tools::Property &options) override
Definition latticegen.cc:38
bool Run() override
Definition latticegen.cc:85
Surrogate lattice model of a hopping system, written as an ordinary XTP topology (segments with one p...
Index NumberOfSites() const
static Disorder DisorderFromString(const std::string &name)
const std::vector< Eigen::Vector3d > & Positions() const
Positions in segment order.
void BuildTopology(Topology &top) const
Fill an empty topology with segments, box and neighbour list.
const std::vector< double > & SiteEnergies() const
Site energies in segment order.
bool isKMCState() const
Definition qmstate.h:78
std::string job_name_
Definition qmtool.h:50
void WriteFrame(const Topology &top)
Definition statesaver.cc:44
Container for segments and box and atoms.
Definition topology.h:41
QMNBList & NBList()
Definition topology.h:70
#define XTP_LOG(level, log)
Definition logger.h:40
const double ev2hrt
Definition constants.h:54
const double bohr2nm
Definition constants.h:46
const double hrt2ev
Definition constants.h:53
const double nm2bohr
Definition constants.h:47
bool FileExists(const std::string &filename)
Definition filesystem.cc:50
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static Level current_level
Definition globals.h:30