votca 2024.2-dev
Loading...
Searching...
No Matches
iexcitoncl.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// Third party includes
21#include <boost/format.hpp>
22
23// VOTCA includes
26
27// Local VOTCA includes
29#include "votca/xtp/logger.h"
31
32// Local private VOTCA includes
33#include "iexcitoncl.h"
34
35using namespace votca::tools;
36
37namespace votca {
38namespace xtp {
39
40// +++++++++++++++++++++++++++++ //
41// IEXCITON MEMBER FUNCTIONS //
42// +++++++++++++++++++++++++++++ //
43
45
46 if (options.exists("states")) {
47 std::string parse_string = options.get(".states").as<std::string>();
48 statemap_ = FillParseMaps(parse_string);
49 }
50}
51
52std::map<std::string, QMState> IEXCITON::FillParseMaps(
53 const std::string& Mapstring) {
54 Tokenizer split_options(Mapstring, ", \t\n");
55 std::map<std::string, QMState> type2level;
56 for (const std::string& substring : split_options) {
57 Tokenizer tok(substring, ":");
58 std::vector<std::string> segmentpnumber = tok.ToVector();
59 if (segmentpnumber.size() != 2) {
60 throw std::runtime_error("Parser iqm: Segment and exciton labels:" +
61 substring + "are not separated properly");
62 }
63 QMState state = QMState(segmentpnumber[1]);
64 if (!state.isTransition()) {
65 throw std::runtime_error("State to calculate must be a transition state");
66 }
67 std::string segmentname = segmentpnumber[0];
68 type2level[segmentname] = state;
69 }
70 return type2level;
71}
72
74 QMThread& opThread) {
75
76 // report back to the progress observer
78
79 // get the logger from the thread
80 Logger& pLog = opThread.getLogger();
81
82 // get the information about the job executed by the thread
83 Index job_ID = job.getId();
84 Property job_input = job.getInput();
85 std::vector<Property*> segment_list = job_input.Select("segment");
86 Index ID_A = segment_list.front()->getAttribute<Index>("id");
87 std::string type_A = segment_list.front()->getAttribute<std::string>("type");
88 std::string mps_fileA =
89 segment_list.front()->getAttribute<std::string>("mps_file");
90 Index ID_B = segment_list.back()->getAttribute<Index>("id");
91 std::string type_B = segment_list.back()->getAttribute<std::string>("type");
92 std::string mps_fileB =
93 segment_list.back()->getAttribute<std::string>("mps_file");
94
95 const Segment& seg_A = top.getSegment(ID_A);
96 if (type_A != seg_A.getType()) {
97 throw std::runtime_error("SegmentA: type " + seg_A.getType() +
98 " and type in jobfile " + type_A +
99 " do not agree for ID:" + std::to_string(ID_A));
100 }
101 const Segment& seg_B = top.getSegment(ID_B);
102 if (type_B != seg_B.getType()) {
103 throw std::runtime_error("SegmentB: type " + seg_B.getType() +
104 " and type in jobfile " + type_B +
105 " do not agree for ID:" + std::to_string(ID_B));
106 }
107 const QMNBList& nblist = top.NBList();
108 const QMPair* pair = nblist.FindPair(&seg_A, &seg_B);
109 if (pair == nullptr) {
110 throw std::runtime_error(
111 "pair between segments " + std::to_string(seg_A.getId()) + ":" +
112 std::to_string(seg_B.getId()) + " not found in neighborlist ");
113 }
114
115 XTP_LOG(Log::error, pLog) << TimeStamp() << " Evaluating pair " << job_ID
116 << " [" << ID_A << ":" << ID_B << "]" << std::flush;
117
118 StaticMapper map(pLog);
119 map.LoadMappingFile(mapfile_);
120 StaticSegment seg1 = map.map(*(pair->Seg1()), mps_fileA);
121 StaticSegment seg2 = map.map(pair->Seg2PbCopy(), mps_fileB);
122 eeInteractor actor;
123 double JAB = actor.CalcStaticEnergy(seg1, seg2);
124 cutoff_ = 0;
125 Property job_summary;
126 Property& job_output = job_summary.add("output", "");
127 Property& pair_summary = job_output.add("pair", "");
128 std::string nameA = seg_A.getType();
129 std::string nameB = seg_B.getType();
130 pair_summary.setAttribute("idA", ID_A);
131 pair_summary.setAttribute("idB", ID_B);
132 pair_summary.setAttribute("typeA", nameA);
133 pair_summary.setAttribute("typeB", nameB);
134 Property& coupling_summary = pair_summary.add("Coupling", "");
135 coupling_summary.setAttribute("jABstatic", JAB * tools::conv::hrt2ev);
136
137 jres.setOutput(job_summary);
139
140 return jres;
141}
142
143QMState IEXCITON::GetElementFromMap(const std::string& elementname) const {
144 QMState state;
145 try {
146 state = statemap_.at(elementname);
147 } catch (std::out_of_range&) {
148 std::string errormessage =
149 "Map does not have segment of type: " + elementname;
150 errormessage += "\n segments in map are:";
151 for (const auto& s : statemap_) {
152 errormessage += "\n\t" + s.first;
153 }
154 throw std::runtime_error(errormessage);
155 }
156 return state;
157}
158
160
161 std::cout << "\n... ... Writing job file " << jobfile_ << std::flush;
162 std::ofstream ofs;
163 ofs.open(jobfile_, std::ofstream::out);
164 if (!ofs.is_open()) {
165 throw std::runtime_error("\nERROR: bad file handle: " + jobfile_);
166 }
167 const QMNBList& nblist = top.NBList();
168 Index jobCount = 0;
169 if (nblist.size() == 0) {
170 std::cout << "\n... ... No pairs in neighbor list, skip." << std::flush;
171 return;
172 }
173
174 ofs << "<jobs>\n";
175 std::string tag = "";
176
177 for (const QMPair* pair : nblist) {
178 if (pair->getType() == QMPair::PairType::Excitoncl) {
179 Index id1 = pair->Seg1()->getId();
180 std::string name1 = pair->Seg1()->getType();
181 Index id2 = pair->Seg2()->getId();
182 std::string name2 = pair->Seg2()->getType();
183 Index id = jobCount;
184 QMState state1 = GetElementFromMap(name1);
185 QMState state2 = GetElementFromMap(name2);
186
187 std::string mps_file1 =
188 (boost::format("MP_FILES/%s_%s.mps") % name1 % state1.ToString())
189 .str();
190 std::string mps_file2 =
191 (boost::format("MP_FILES/%s_%s.mps") % name2 % state2.ToString())
192 .str();
193
194 Property Input;
195 Property& pInput = Input.add("input", "");
196 Property& pSegment1 =
197 pInput.add("segment", boost::lexical_cast<std::string>(id1));
198 pSegment1.setAttribute<std::string>("type", name1);
199 pSegment1.setAttribute<Index>("id", id1);
200 pSegment1.setAttribute<std::string>("mps_file", mps_file1);
201 Property& pSegment2 =
202 pInput.add("segment", boost::lexical_cast<std::string>(id2));
203 pSegment2.setAttribute<std::string>("type", name2);
204 pSegment2.setAttribute<Index>("id", id2);
205 pSegment2.setAttribute<std::string>("mps_file", mps_file2);
206
207 Job job(id, tag, Input, Job::AVAILABLE);
208 job.ToStream(ofs);
209 jobCount++;
210 }
211 }
212
213 // CLOSE STREAM
214 ofs << "</jobs>\n";
215 ofs.close();
216
217 std::cout << "\n... ... In total " << jobCount << " jobs" << std::flush;
218}
219
221
222 Logger log;
224 Property xml;
226 std::vector<Property*> jobProps = xml.Select("jobs.job");
227
228 Index updated_jobs = 0;
229 Index incomplete_jobs = 0;
230
231 // loop over all jobs = pair records in the job file
232 for (const Property* prop : jobProps) {
233 // if job produced an output, then continue with analysis
234 if (prop->exists("output") && prop->exists("output.pair")) {
235 const Property& poutput = prop->get("output.pair");
236 Index idA = poutput.getAttribute<Index>("idA");
237 Index idB = poutput.getAttribute<Index>("idB");
238 Segment& segA = top.getSegment(idA);
239 Segment& segB = top.getSegment(idB);
240 QMPair* qmp = top.NBList().FindPair(&segA, &segB);
241
242 if (qmp == nullptr) {
243 XTP_LOG(Log::error, log)
244 << "No pair " << idA << ":" << idB
245 << " found in the neighbor list. Ignoring" << std::flush;
246 } else if (qmp->getType() == QMPair::Excitoncl) {
247 updated_jobs++;
248 const Property& pCoupling = poutput.get("Coupling");
249 double jAB = pCoupling.getAttribute<double>("jABstatic");
250 double Jeff2 = jAB * jAB * tools::conv::ev2hrt * tools::conv::ev2hrt;
251 qmp->setJeff2(Jeff2, QMStateType::Singlet);
252 }
253 } else {
254 incomplete_jobs++;
255 }
256 }
257
258 XTP_LOG(Log::error, log) << "Neighborlist size " << top.NBList().size()
259 << std::flush;
260
261 XTP_LOG(Log::error, log) << "Pairs in jobfile [total:updated:incomplete] "
262 << jobProps.size() << ":" << updated_jobs << ":"
263 << incomplete_jobs << std::flush;
264 std::cout << log;
265}
266
267} // namespace xtp
268} // namespace votca
pair_type * FindPair(element_type e1, element_type e2)
Definition pairlist.h:93
Index size() const
Definition pairlist.h:53
class to manage program options with xml serialization functionality
Definition property.h:55
Property & add(const std::string &key, const std::string &value)
add a new property to structure
Definition property.cc:108
Property & get(const std::string &key)
get existing property
Definition property.cc:79
bool exists(const std::string &key) const
check whether property exists
Definition property.cc:122
T as() const
return value as type
Definition property.h:283
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 setAttribute(const std::string &attribute, const T &value)
set an attribute
Definition property.h:314
void LoadFromXML(std::string filename)
Definition property.cc:238
break string into words
Definition tokenizer.h:72
std::vector< T > ToVector()
store all words in a vector of type T, does type conversion.
Definition tokenizer.h:109
const std::string & getType() const
std::map< std::string, QMState > FillParseMaps(const std::string &Mapstring)
Definition iexcitoncl.cc:52
void ReadJobFile(Topology &top)
void ParseSpecificOptions(const tools::Property &user_options)
Definition iexcitoncl.cc:44
std::map< std::string, QMState > statemap_
Definition iexcitoncl.h:61
QMState GetElementFromMap(const std::string &elementname) const
Job::JobResult EvalJob(const Topology &top, Job &job, QMThread &opThread)
Definition iexcitoncl.cc:73
void WriteJobFile(const Topology &top)
void setOutput(std::string output)
Definition job.h:50
void setStatus(JobStatus stat)
Definition job.h:49
tools::Property & getInput()
Definition job.h:87
Index getId() const
Definition job.h:85
Logger is used for thread-safe output of messages.
Definition logger.h:164
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setJeff2(double Jeff2, QMStateType state)
Definition qmpair.h:113
const PairType & getType() const
Definition qmpair.h:130
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
std::string ToString() const
Definition qmstate.cc:146
bool isTransition() const
Definition qmstate.h:153
Logger & getLogger()
Definition qmthread.h:55
Timestamp returns the current time as a string Example: cout << TimeStamp()
Definition logger.h:224
Container for segments and box and atoms.
Definition topology.h:41
QMNBList & NBList()
Definition topology.h:70
Segment & getSegment(Index id)
Definition topology.h:55
Mediates interaction between polar and static sites.
double CalcStaticEnergy(const S1 &segment1, const S2 &segment2) const
#define XTP_LOG(level, log)
Definition logger.h:40
const double ev2hrt
Definition constants.h:54
const double hrt2ev
Definition constants.h:53
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