votca 2024.2-dev
Loading...
Searching...
No Matches
ianalyze.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18// Standard includes
19#include <cmath>
20#include <numeric>
21
22// VOTCA includes
24
25// Local VOTCA includes
26#include "votca/xtp/qmstate.h"
27#include "votca/xtp/topology.h"
28
29// Local private VOTCA includes
30#include "ianalyze.h"
31
32namespace votca {
33namespace xtp {
34
36
37 states_ = options.get(".states").as<std::vector<QMStateType>>();
38
39 resolution_logJ2_ = options.get(".resolution_logJ2").as<double>();
40 if (options.get(".do_pairtype").as<bool>()) {
41 do_pairtype_ = true;
42 std::string store_stdstring_ = options.get(".pairtype").as<std::string>();
43 if (store_stdstring_.find("Hopping") != std::string::npos) {
44 pairtype_.push_back(QMPair::Hopping);
45 }
46 if (store_stdstring_.find("Excitoncl") != std::string::npos) {
48 }
49 if (!pairtype_.size()) {
50 std::cout << "\n... ... No pairtypes recognized will output all pairs. ";
51 do_pairtype_ = false;
52 }
53 }
54 if (options.get(".do_resolution_spatial").as<bool>()) {
55 resolution_spatial_ = options.get(".resolution_spatial").as<double>();
56 if (resolution_spatial_ != 0.0) {
57 do_IRdependence_ = true;
58 }
59 }
60}
61
63 std::cout << std::endl;
64 QMNBList &nblist = top.NBList();
65 if (!nblist.size()) {
66 std::cout << std::endl << "... ... No pairs in topology. Skip...";
67 return false;
68 }
69 if (do_pairtype_) {
70 bool pairs_exist = false;
71 for (QMPair *pair : nblist) {
72 QMPair::PairType pairtype = pair->getType();
73 if (std::find(pairtype_.begin(), pairtype_.end(), pairtype) !=
74 pairtype_.end()) {
75 pairs_exist = true;
76 break;
77 }
78 }
79 if (!pairs_exist) {
80 std::cout << std::endl
81 << "... ... No pairs of given pairtypes in topology. Skip...";
82 return 0;
83 }
84 }
85 for (QMStateType state : states_) {
86 std::cout << "Calculating for state " << state.ToString() << " now."
87 << std::endl;
88 this->IHist(top, state);
89 if (do_IRdependence_) {
90 IRdependence(top, state);
91 }
92 }
93 return true;
94}
95
97 QMNBList &nblist = top.NBList();
98
99 // Collect J2s from pairs
100 std::vector<double> J2s;
101 for (QMPair *pair : nblist) {
102 if (do_pairtype_) {
103 QMPair::PairType pairtype = pair->getType();
104 if (!(std::find(pairtype_.begin(), pairtype_.end(), pairtype) !=
105 pairtype_.end())) {
106 continue;
107 }
108 }
109 double test =
110 pair->getJeff2(state) * tools::conv::hrt2ev * tools::conv::hrt2ev;
111 if (test <= 0) {
112 continue;
113 } // avoid -inf in output
114 double J2 = std::log10(test);
115 J2s.push_back(J2);
116 }
117
118 if (J2s.size() < 1) {
119 std::cout << "WARNING:" + state.ToLongString() +
120 " Couplings are all zero. You have not yet imported them! "
121 << std::endl;
122 return;
123 }
124
125 double MAX = *std::max_element(J2s.begin(), J2s.end());
126 double MIN = *std::min_element(J2s.begin(), J2s.end());
127 double sum = std::accumulate(J2s.begin(), J2s.end(), 0.0);
128 double AVG = sum / double(J2s.size());
129 double sq_sum = std::inner_product(J2s.begin(), J2s.end(), J2s.begin(), 0.0);
130 double STD = std::sqrt(sq_sum / double(J2s.size()) - AVG * AVG);
131 // Prepare bins
132 Index BIN = Index((MAX - MIN) / resolution_logJ2_ + 0.5) + 1;
133
135 hist.Initialize(MIN, MAX, BIN);
136 hist.ProcessRange<std::vector<double>::iterator>(J2s.begin(), J2s.end());
137 tools::Table &tab = hist.data();
138 std::string comment =
139 (boost::format("IANALYZE: PAIR-INTEGRAL J2 HISTOGRAM \n # AVG %1$4.7f "
140 "STD %2$4.7f MIN %3$4.7f MAX %4$4.7f") %
141 AVG % STD % MIN % MAX)
142 .str();
143 std::string filename = "ianalyze.ihist_" + state.ToString() + ".out";
144 tab.set_comment(comment);
145 tab.flags() = std::vector<char>(tab.size(), ' ');
146 tab.Save(filename);
147}
148
150
151 QMNBList &nblist = top.NBList();
152
153 // Collect J2s from pairs
154 std::vector<double> J2s;
155 J2s.reserve(nblist.size());
156 std::vector<double> distances;
157 distances.reserve(nblist.size());
158
159 for (QMPair *pair : nblist) {
160 double test =
161 pair->getJeff2(state) * tools::conv::hrt2ev * tools::conv::hrt2ev;
162 if (test <= 0) {
163 continue;
164 } // avoid -inf in output
165 double J2 = std::log10(test);
166 double distance = pair->R().norm() * tools::conv::bohr2nm;
167 distances.push_back(distance);
168 J2s.push_back(J2);
169 }
170
171 double MAXR = *std::max_element(distances.begin(), distances.end());
172 double MINR = *std::min_element(distances.begin(), distances.end());
173
174 // Prepare R bins
175 Index pointsR = Index((MAXR - MINR) / resolution_spatial_);
176 std::vector<std::vector<double>> rJ2;
177 rJ2.resize(pointsR);
178
179 // Loop over distance
180 for (Index i = 0; i < pointsR; ++i) {
181 double thisMINR = MINR + double(i) * resolution_spatial_;
182 double thisMAXR = MINR + double(i + 1) * resolution_spatial_;
183 // now count Js that lie within this R range
184 for (Index j = 0; j < Index(J2s.size()); ++j) {
185 if (thisMINR < distances[j] && distances[j] < thisMAXR) {
186 rJ2[i].push_back(J2s[j]);
187 }
188 }
189 }
190
191 tools::Table tab;
192 tab.SetHasYErr(true);
193 tab.resize(pointsR);
194
195 // make plot values
196 for (Index i = 0; i < Index(rJ2.size()); i++) {
197 const std::vector<double> &vec = rJ2[i];
198 double sum = std::accumulate(vec.begin(), vec.end(), 0.0);
199 double AVG = sum / double(vec.size());
200 double thisR = MINR + (double(i) + 0.5) * resolution_spatial_;
201 double sq_sum =
202 std::inner_product(vec.begin(), vec.end(), vec.begin(), 0.0);
203 double STD = std::sqrt(sq_sum / double(vec.size()) - AVG * AVG);
204 tab.set(i, thisR, AVG, ' ', STD);
205 }
206 std::string filename = "ianalyze.ispatial_" + state.ToString() + ".out";
207 std::string comment =
208 "# IANALYZE: SPATIAL DEPENDENCE OF log10(J2) "
209 "[r[nm],log10(J)[eV^2],error]";
210 tab.setErrorDetails(comment);
211 tab.Save(filename);
212}
213
214} // namespace xtp
215} // namespace votca
Index size() const
Definition pairlist.h:53
class to generate histograms
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
class to store tables like rdfs, tabulated potentials, etc
Definition table.h:36
Index size() const
Definition table.h:42
void SetHasYErr(bool has_yerr)
Definition table.h:81
void set(const Index &i, const double &x, const double &y)
Definition table.h:52
char & flags(Index i)
Definition table.h:49
void set_comment(const std::string comment)
Definition table.h:70
void resize(Index N)
Definition table.cc:38
void Save(std::string filename) const
Definition table.cc:59
void setErrorDetails(std::string str)
Definition table.h:113
double resolution_spatial_
Definition ianalyze.h:47
std::vector< QMPair::PairType > pairtype_
Definition ianalyze.h:48
bool Evaluate(Topology &top)
Definition ianalyze.cc:62
std::vector< QMStateType > states_
Definition ianalyze.h:46
void ParseOptions(const tools::Property &user_options)
Definition ianalyze.cc:35
void IHist(Topology &top, QMStateType state)
Definition ianalyze.cc:96
double resolution_logJ2_
Definition ianalyze.h:45
void IRdependence(Topology &top, QMStateType state)
Definition ianalyze.cc:149
std::string ToLongString() const
Definition qmstate.cc:69
std::string ToString() const
Definition qmstate.cc:35
Container for segments and box and atoms.
Definition topology.h:41
QMNBList & NBList()
Definition topology.h:70
const double bohr2nm
Definition constants.h:46
const double hrt2ev
Definition constants.h:53
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26