votca 2026-dev
Loading...
Searching...
No Matches
ipodcoupling.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 <filesystem>
22#include <fstream>
23#include <limits>
24#include <set>
25
26// Third party includes
27#include <boost/format.hpp>
28#include <boost/lexical_cast.hpp>
29
30// VOTCA includes
32
33// Local VOTCA includes
36#include "votca/xtp/logger.h"
40
41// Local private VOTCA includes
42#include "ipodcoupling.h"
43
44namespace votca {
45namespace xtp {
46
49
50 // Task names follow IQM::ParseSpecificOptions (iqm.cc), plus the
51 // additional "podcoupling" task.
52 std::string tasks_string = options.get(".tasks").as<std::string>();
53
54 // We split either on a space or a comma
55 tools::Tokenizer tokenizedTasks(tasks_string, " ,");
56 std::vector<std::string> tasks = tokenizedTasks.ToVector();
57
58 do_dft_input_ = std::find(tasks.begin(), tasks.end(), "input") != tasks.end();
59 do_dft_run_ = std::find(tasks.begin(), tasks.end(), "dft") != tasks.end();
60 do_dft_parse_ = std::find(tasks.begin(), tasks.end(), "parse") != tasks.end();
62 std::find(tasks.begin(), tasks.end(), "podcoupling") != tasks.end();
63
65 options.ifExistsReturnElseReturnDefault<bool>(".store_dft", store_dft_);
67 ".include_linkers", include_linkers_);
68
69 dftpackage_options_ = options.get(".dftpackage");
70 if (options.exists(".podcoupling")) {
71 podcoupling_options_ = options.get(".podcoupling");
73 podcoupling_options_.ifExistsReturnElseReturnDefault<Index>(
74 "levA", numberofstatesA_);
76 podcoupling_options_.ifExistsReturnElseReturnDefault<Index>(
77 "levB", numberofstatesB_);
78 }
79}
80
82 // One job per neighbor-list pair, as in IQM::WriteJobFile (iqm.cc).
83 std::cout << std::endl
84 << "... ... Writing job file " << jobfile_ << std::flush;
85 std::ofstream ofs;
86 ofs.open(jobfile_, std::ofstream::out);
87 if (!ofs.is_open()) {
88 throw std::runtime_error("\nERROR: bad file handle: " + jobfile_);
89 }
90
91 const QMNBList& nblist = top.NBList();
92
93 Index jobCount = 0;
94 if (nblist.size() == 0) {
95 std::cout << std::endl
96 << "... ... No pairs in neighbor list, skip." << std::flush;
97 return;
98 }
99
100 ofs << "<jobs>" << std::endl;
101 std::string tag = "";
102
103 for (const QMPair* pair : nblist) {
104 if (pair->getType() == QMPair::Excitoncl) {
105 continue;
106 }
107 Index id1 = pair->Seg1()->getId();
108 std::string name1 = pair->Seg1()->getType();
109 Index id2 = pair->Seg2()->getId();
110 std::string name2 = pair->Seg2()->getType();
111 Index id = jobCount;
112 tools::Property Input;
113 tools::Property& pInput = Input.add("input", "");
114 tools::Property& pSegmentA =
115 pInput.add("segment", boost::lexical_cast<std::string>(id1));
116 pSegmentA.setAttribute<std::string>("type", name1);
117 pSegmentA.setAttribute<Index>("id", id1);
118 tools::Property& pSegmentB =
119 pInput.add("segment", boost::lexical_cast<std::string>(id2));
120 pSegmentB.setAttribute<std::string>("type", name2);
121 pSegmentB.setAttribute<Index>("id", id2);
122 Job job(id, tag, Input, Job::AVAILABLE);
123 job.ToStream(ofs);
124 jobCount++;
125 }
126 ofs << "</jobs>" << std::endl;
127 ofs.close();
128 std::cout << std::endl
129 << "... ... In total " << jobCount << " jobs" << std::flush;
130 return;
131}
132
134 const Segment& seg, Index target_segment_id) const {
135 for (const Atom& atom : seg) {
136 if (atom.hasExternalBond() &&
137 atom.getExternalBondPartnerSegmentId() == target_segment_id) {
138 return atom;
139 }
140 }
141 throw std::runtime_error(
142 "IPodCoupling::FindBoundaryAtomTowardSegment: segment " +
143 std::to_string(seg.getId()) +
144 " has no atom with an external bond toward segment " +
145 std::to_string(target_segment_id) +
146 ", although FindLinkingSegments() reported a bond path between them. "
147 "Check the underlying mapping/checkpoint data.");
148}
149
151 const Topology& top, const Segment& seg1_positioned,
152 const std::vector<const Segment*>& linkers,
153 const Segment& seg2_positioned) const {
154 std::vector<Segment> results;
155 if (linkers.empty()) {
156 return results;
157 }
158 // Required, not an optimization: previous_positioned points into
159 // results, and a reallocating push_back() would invalidate it.
160 results.reserve(linkers.size());
161
162 // Walk the chain one covalent bond at a time instead of applying a
163 // single whole-chain shift: each linker may be wrapped into a different
164 // periodic image than its neighbors. Each hop is a bond length, far
165 // shorter than the box, so the minimum-image convention is unambiguous
166 // at every step.
167 const Segment* previous_positioned = &seg1_positioned;
168 for (const Segment* current_raw : linkers) {
169 const Atom& prev_boundary = FindBoundaryAtomTowardSegment(
170 *previous_positioned, current_raw->getId());
171 const Atom& curr_boundary = FindBoundaryAtomTowardSegment(
172 *current_raw, previous_positioned->getId());
173
174 // Approximate position of the current segment's boundary atom, seen
175 // from the already positioned previous segment's side of the bond
176 // (same construction as FragmentSaturator::SaturateExternalBonds).
177 Eigen::Vector3d expected_partner_pos =
178 prev_boundary.getPos() +
181
182 // Shift for the whole current segment that moves its boundary atom
183 // to the closest periodic image of expected_partner_pos.
184 // PbShortestConnect(r_i, r_j) returns r_j - r_i (minimum image), so
185 // the argument order matters.
186 Eigen::Vector3d shift =
187 top.PbShortestConnect(curr_boundary.getPos(), expected_partner_pos);
188
189 Segment current_shifted = *current_raw;
190 current_shifted.Translate(shift);
191 results.push_back(current_shifted);
192 previous_positioned = &results.back();
193 }
194
195 // Validate the last hop into seg2_positioned as well (throws if the
196 // last linker is not bonded to it). seg2_positioned itself is not
197 // shifted; it is already positioned, typically via QMPair::Seg2PbCopy().
198 FindBoundaryAtomTowardSegment(*previous_positioned, seg2_positioned.getId());
199 FindBoundaryAtomTowardSegment(seg2_positioned, previous_positioned->getId());
200
201 return results;
202}
203
205 QMThread& opThread) {
207 Logger& pLog = opThread.getLogger();
208
209 std::string ipodcoupling_work_dir = "OR_FILES";
210 std::string frame_dir =
211 "frame_" + boost::lexical_cast<std::string>(top.getStep());
212
213 QMMapper mapper(pLog);
215
216 // Segment ids and optional "qm_geometry" states (default: ground
217 // state "n"), as in IQM::EvalJob (iqm.cc).
218 tools::Property job_input = job.getInput();
219 std::vector<tools::Property*> segment_list = job_input.Select("segment");
220 Index ID_A = segment_list.front()->getAttribute<Index>("id");
221 Index ID_B = segment_list.back()->getAttribute<Index>("id");
222
223 std::string qmgeo_state_A = "n";
224 if (segment_list.front()->exists("qm_geometry")) {
225 qmgeo_state_A =
226 segment_list.front()->getAttribute<std::string>("qm_geometry");
227 }
228 std::string qmgeo_state_B = "n";
229 if (segment_list.back()->exists("qm_geometry")) {
230 qmgeo_state_B =
231 segment_list.back()->getAttribute<std::string>("qm_geometry");
232 }
233 QMState stateA(qmgeo_state_A);
234 QMState stateB(qmgeo_state_B);
235
236 const Segment& seg_A = top.getSegment(ID_A);
237 const Segment& seg_B = top.getSegment(ID_B);
238 const QMNBList& nblist = top.NBList();
239 const QMPair* pair = nblist.FindPair(&seg_A, &seg_B);
240 if (pair == nullptr) {
241 SetJobToFailed(jres, pLog,
242 "No pair " + std::to_string(ID_A) + ":" +
243 std::to_string(ID_B) + " found in the neighbor list.");
244 return jres;
245 }
246
247 // Path naming as in IQM::EvalJob (iqm.cc), but without the monomer
248 // orbital files (orbFileA/orbFileB, eqm_work_dir): there is no dimer
249 // guess, since monomer calculations are not wanted or not possible here.
250 // "pairs_ipodcoupling" avoids collisions with IQM's "pairs_iqm".
251 std::string pair_dir =
252 (boost::format("%1%%2%%3%%4%%5%") % "pair" % "_" % ID_A % "_" % ID_B)
253 .str();
254 std::filesystem::path arg_path;
255 std::string orbFileAB =
256 (arg_path / ipodcoupling_work_dir / "pairs_ipodcoupling" / frame_dir /
257 (boost::format("%1%%2%%3%%4%%5%") % "pair_" % ID_A % "_" % ID_B % ".orb")
258 .str())
259 .generic_string();
260 std::string package_append = "workdir_" + Identify();
261 std::string work_dir =
262 (arg_path / ipodcoupling_work_dir / package_append / frame_dir / pair_dir)
263 .generic_string();
264
265 // PBC-correct positioning of the pair via QMPair::Seg2PbCopy(), as in
266 // IQM::EvalJob.
267 const Segment* seg1 = pair->Seg1();
268 Segment seg2 = pair->Seg2PbCopy();
269
270 // Repeats the check of Md2QmEngine::map (md2qmengine.cc), whose warning
271 // is printed only once at xtp_map time and is easily missed: without
272 // MD-level bond data (Atom::getBondedPartnerIds()) no external bonds are
273 // detected, so H-saturation does nothing and dangling valences reach the
274 // DFT calculation.
275 bool seg1_has_any_bonds = false;
276 for (const Atom& atom : *seg1) {
277 if (atom.getBondedPartnerIds()[0] != -1) {
278 seg1_has_any_bonds = true;
279 break;
280 }
281 }
282 bool seg2_has_any_bonds = false;
283 for (const Atom& atom : seg2) {
284 if (atom.getBondedPartnerIds()[0] != -1) {
285 seg2_has_any_bonds = true;
286 break;
287 }
288 }
289 if (!seg1_has_any_bonds && !seg2_has_any_bonds) {
290 XTP_LOG(Log::error, pLog)
291 << "WARNING: neither segment " << seg1->getId() << " nor segment "
292 << seg_B.getId()
293 << " has any MD-level bond connectivity; H-saturation of cut "
294 "segment boundaries will do nothing for this pair. The topology "
295 "reader used at xtp_map time probably provided no bond data."
296 << std::flush;
297 }
298
299 // Linker segments: discovery (Topology::FindLinkingSegments) and
300 // PBC-correct positioning (PositionLinkersAlongChain). Declared before
301 // segments, which holds pointers into positioned_linkers.
302 std::vector<Segment> positioned_linkers;
303 if (include_linkers_) {
304 std::vector<const Segment*> linkers = top.FindLinkingSegments(*seg1, seg_B);
305 if (!linkers.empty()) {
306 positioned_linkers = PositionLinkersAlongChain(top, *seg1, linkers, seg2);
307 }
308 }
309
310 std::vector<const Segment*> segments = {seg1, &seg2};
311 for (const Segment& linker : positioned_linkers) {
312 segments.push_back(&linker);
313 }
314
315 QMMolecule qmmol = mapper.map(*seg1, stateA);
316 // Mapped atom count of fragment A. Not taken from seg1->size(): the
317 // mapping need not map every MD atom.
318 Index n_fragment_A_atoms = qmmol.size();
319 qmmol.AddContainer(mapper.map(seg2, stateB));
320 // Mapped atom count of fragments A and B without linker atoms (unlike
321 // n_original_atoms below); upper bound of fragment B's atom range.
322 Index n_fragment_AB_atoms = qmmol.size();
323
324 // Linkers are always mapped in the ground state ("n"): they are
325 // selected by bond connectivity, not by segment type, so no per-type
326 // state map as in IQM's linker_names is needed, and they are treated
327 // as neutral bridges not involved in the charge transfer.
328 //
329 // linker_atom_ids holds the pre-saturation atom ids of all linker
330 // atoms; these belong to neither fragment_A_atoms nor fragment_B_atoms.
331 std::set<Index> linker_atom_ids;
332 for (const Segment& linker : positioned_linkers) {
333 Index linker_start_atom_id = qmmol.size();
334 qmmol.AddContainer(mapper.map(linker, QMState("n")));
335 for (Index i = linker_start_atom_id; i < qmmol.size(); i++) {
336 linker_atom_ids.insert(i);
337 }
338 }
339
340 // An external bond whose partner segment is part of this supermolecule
341 // is satisfied internally and must not be saturated with H.
342 std::set<Index> present_segment_ids;
343 for (const Segment* seg : segments) {
344 present_segment_ids.insert(seg->getId());
345 }
346
347 // SaturateExternalBonds() saturates every atom with hasExternalBond().
348 // Clear the external bonds that are internal to this supermolecule
349 // beforehand. This only modifies the local QMMolecule copy, not the
350 // MD-level data (see QMAtom::clearExternalBond()).
351 Index n_original_atoms = qmmol.size();
352 for (QMAtom& atom : qmmol) {
353 if (!atom.hasExternalBond()) {
354 continue;
355 }
356 if (present_segment_ids.count(atom.getExternalBondPartnerSegmentId()) > 0) {
357 atom.clearExternalBond();
358 }
359 }
360
361 FragmentSaturator::SaturationResult saturation_result =
363 QMMolecule relaxed =
364 FragmentSaturator::RelaxNewAtoms(saturation_result.mol, n_original_atoms);
365
366 // Fragment atom lists for PODCoupling. Original atoms are classified by
367 // id: [0, n_fragment_A_atoms) is fragment A,
368 // [n_fragment_A_atoms, n_fragment_AB_atoms) fragment B, linker atoms
369 // (mapped last) belong to neither. A saturating H atom inherits the
370 // fragment of the atom it saturates
371 // (saturation_result.new_atom_parent_ids).
372 std::vector<Index> fragment_A_atoms;
373 std::vector<Index> fragment_B_atoms;
374 for (const QMAtom& atom : relaxed) {
375 Index owning_atom_id = atom.getId();
376 if (owning_atom_id >= n_original_atoms) {
377 owning_atom_id = saturation_result.new_atom_parent_ids[owning_atom_id];
378 }
379 if (linker_atom_ids.count(owning_atom_id) > 0) {
380 continue;
381 }
382 if (owning_atom_id < n_fragment_A_atoms) {
383 fragment_A_atoms.push_back(atom.getId());
384 } else if (owning_atom_id < n_fragment_AB_atoms) {
385 fragment_B_atoms.push_back(atom.getId());
386 }
387 }
388
389 Orbitals orbitalsAB;
390 orbitalsAB.QMAtoms() = relaxed;
391
393 std::string qmpackage_work_dir = work_dir;
394
395 Logger dft_logger(Log::current_level);
396 dft_logger.setMultithreading(false);
397 dft_logger.setPreface(Log::info, (boost::format("\nDFT INF ...")).str());
398 dft_logger.setPreface(Log::error, (boost::format("\nDFT ERR ...")).str());
399 dft_logger.setPreface(Log::warning, (boost::format("\nDFT WAR ...")).str());
400 dft_logger.setPreface(Log::debug, (boost::format("\nDFT DBG ...")).str());
401 std::string package = dftpackage_options_.get("name").as<std::string>();
402 std::unique_ptr<QMPackage> qmpackage = QMPackageFactory().Create(package);
403 qmpackage->setLog(&dft_logger);
404 qmpackage->setRunDir(qmpackage_work_dir);
405 qmpackage->Initialize(dftpackage_options_);
406
407 if (do_dft_input_) {
408 std::filesystem::create_directories(qmpackage_work_dir);
409 // Always use the DFT package's default starting guess. The dimer
410 // guess of IQM::EvalJob does not apply: orbitalsAB is the relaxed,
411 // H-saturated supermolecule, and the added H atoms have no monomer
412 // orbitals. A requested guess is ignored with a warning.
413 if (qmpackage->GuessRequested()) {
414 XTP_LOG(Log::warning, pLog)
415 << "A DFT guess was requested in the dftpackage options, but "
416 "IPodCoupling does not support it (the saturating H atoms "
417 "have no monomer orbitals). Using the DFT package's default "
418 "starting guess instead."
419 << std::flush;
420 }
421 qmpackage->WriteInputFile(orbitalsAB);
422 }
423
424 if (do_dft_run_) {
425 XTP_LOG(Log::error, pLog) << "Running DFT" << std::flush;
426 bool run_dft_status = qmpackage->Run();
427 if (!run_dft_status) {
428 SetJobToFailed(jres, pLog, qmpackage->getPackageName() + " run failed");
429 WriteLoggerToFile(work_dir + "/dft.log", dft_logger);
430 return jres;
431 }
432 }
433
434 if (do_dft_parse_) {
435 bool parse_log_status = qmpackage->ParseLogFile(orbitalsAB);
436 if (!parse_log_status) {
437 SetJobToFailed(jres, pLog, "LOG parsing failed");
438 return jres;
439 }
440 bool parse_orbitals_status = qmpackage->ParseMOsFile(orbitalsAB);
441 if (!parse_orbitals_status) {
442 SetJobToFailed(jres, pLog, "Orbitals parsing failed");
443 return jres;
444 }
445 }
446 qmpackage->CleanUp();
447 WriteLoggerToFile(work_dir + "/dft.log", dft_logger);
448 } else {
449 try {
450 orbitalsAB.ReadFromCpt(orbFileAB);
451 } catch (std::runtime_error&) {
452 SetJobToFailed(jres, pLog,
453 "Do input: failed loading orbitals from " + orbFileAB);
454 return jres;
455 }
456 }
457
458 if (store_dft_) {
459 std::filesystem::create_directories(
460 std::filesystem::path(orbFileAB).parent_path());
461 orbitalsAB.WriteToCpt(orbFileAB);
462 }
463
464 // POD coupling on the converged orbitalsAB (parsed above or read from
465 // orbFileAB). Guarded by do_podcoupling_: PODCoupling needs converged
466 // orbitals with a basis set name, which do not exist after the "input"
467 // task alone (an empty name gives a "basis_sets/.xml" error).
468 tools::Property job_summary;
469 tools::Property& job_output = job_summary.add("output", "");
470 if (do_podcoupling_) {
471 try {
472 // The fragment assignment is otherwise not visible in any output.
473 // Printed at Log::debug, i.e. only with -v/--verbose2
474 // (application.cc).
475 XTP_LOG(Log::debug, pLog)
476 << "PODCoupling: fragment_A_atoms (" << fragment_A_atoms.size()
477 << " atoms):" << std::flush;
478 for (Index a : fragment_A_atoms) {
479 XTP_LOG(Log::debug, pLog) << " " << a << std::flush;
480 }
481 XTP_LOG(Log::debug, pLog)
482 << "PODCoupling: fragment_B_atoms (" << fragment_B_atoms.size()
483 << " atoms):" << std::flush;
484 for (Index b : fragment_B_atoms) {
485 XTP_LOG(Log::debug, pLog) << " " << b << std::flush;
486 }
487 if (!linker_atom_ids.empty()) {
488 XTP_LOG(Log::debug, pLog)
489 << "PODCoupling: linker_atom_ids, excluded from both fragments ("
490 << linker_atom_ids.size() << " atoms):" << std::flush;
491 for (Index l : linker_atom_ids) {
492 XTP_LOG(Log::debug, pLog) << " " << l << std::flush;
493 }
494 }
495
496 PODCoupling pod(orbitalsAB, &pLog, fragment_A_atoms, fragment_B_atoms);
498
499 // Output format of DFTcoupling::WriteToProperty (dftcoupling.cc):
500 // one coupling element with levelA, levelB and j attributes per
501 // level pair. The monomer data of DFTcoupling::Addoutput does not
502 // exist for POD2, which has no isolated monomer calculations.
503 tools::Property& podcoupling_summary = job_output.add(Identify(), "");
504 Index homoA = pod.getFragmentAHomoIndex();
505 Index lumoA = pod.getFragmentALumoIndex();
506 Index homoB = pod.getFragmentBHomoIndex();
507 Index lumoB = pod.getFragmentBLumoIndex();
508 // homoA/homoB attributes (lumo = homo + 1), as in
509 // DFTcoupling::Addoutput; ReadJobFile uses them to select the hole
510 // and electron couplings among the coupling elements below.
511 podcoupling_summary.setAttribute("homoA", homoA);
512 podcoupling_summary.setAttribute("homoB", homoB);
513 for (Index levelA = homoA - numberofstatesA_ + 1;
514 levelA <= lumoA + numberofstatesA_ - 1; ++levelA) {
515 for (Index levelB = homoB - numberofstatesB_ + 1;
516 levelB <= lumoB + numberofstatesB_ - 1; ++levelB) {
517 double J_hartree = pod.getCouplingElement(levelA, levelB);
518 // getCouplingElement() returns Hartree; "j" is written in eV,
519 // as in IQM (GetDFTCouplingFromProp, iqm.cc, converts back).
520 double J_ev = J_hartree * tools::conv::hrt2ev;
521 tools::Property& coupling = podcoupling_summary.add("coupling", "");
522 coupling.setAttribute("levelA", levelA);
523 coupling.setAttribute("levelB", levelB);
524 coupling.setAttribute("j", (boost::format("%1$1.6e") % J_ev).str());
525 }
526 }
527 } catch (std::runtime_error& error) {
528 SetJobToFailed(jres, pLog, std::string("PODCoupling: ") + error.what());
529 return jres;
530 }
531 }
532
533 jres.setOutput(job_summary);
535 return jres;
536}
537
539 Index levelA, Index levelB) const {
540 for (const tools::Property* state : podprop.Select("coupling")) {
541 Index state1 = state->getAttribute<Index>("levelA");
542 Index state2 = state->getAttribute<Index>("levelB");
543 if (state1 == levelA && state2 == levelB) {
544 return state->getAttribute<double>("j") * tools::conv::ev2hrt;
545 }
546 }
547 return std::numeric_limits<double>::quiet_NaN();
548}
549
551 // Structure as in IQM::ReadJobFile (iqm.cc), but with a single
552 // podcoupling node and no configurable level map: the HOMO-HOMO
553 // coupling is stored as the hole coupling, LUMO-LUMO (lumo = homo + 1)
554 // as the electron coupling.
555 QMNBList& nblist = top.NBList();
556 Index number_of_pairs = nblist.size();
557 Index updated_h = 0;
558 Index updated_e = 0;
559 Index incomplete_jobs = 0;
560 Logger log;
562
563 tools::Property xml;
565
566 for (tools::Property* job : xml.Select("jobs.job")) {
567 if (!job->exists("status")) {
568 throw std::runtime_error(
569 "Jobfile is malformed. <status> tag missing on job.");
570 }
571 if (job->get("status").as<std::string>() != "COMPLETE" ||
572 !job->exists("output")) {
573 incomplete_jobs++;
574 continue;
575 }
576
577 std::vector<Index> id;
578 for (tools::Property* segment : job->Select("input.segment")) {
579 id.push_back(segment->getAttribute<Index>("id"));
580 }
581 if (id.size() != 2) {
582 throw std::runtime_error(
583 "Getting pair ids from jobfile failed, check jobfile.");
584 }
585
586 Segment& segA = top.getSegment(id[0]);
587 Segment& segB = top.getSegment(id[1]);
588 QMPair* qmp = nblist.FindPair(&segA, &segB);
589 if (qmp == nullptr) {
590 XTP_LOG(Log::error, log)
591 << "No pair " << id[0] << ":" << id[1]
592 << " found in the neighbor list. Ignoring" << std::flush;
593 continue;
594 }
595 if (qmp->getType() != QMPair::PairType::Hopping) {
596 XTP_LOG(Log::error, log) << "WARNING Pair " << qmp->getId()
597 << " is not of any of the "
598 "Hopping type. Skipping pair"
599 << std::flush;
600 continue;
601 }
602
603 const tools::Property& pair_property = job->get("output");
604 if (!pair_property.exists(Identify())) {
605 continue;
606 }
607 const tools::Property& podprop = pair_property.get(Identify());
608 Index homoA = podprop.getAttribute<Index>("homoA");
609 Index homoB = podprop.getAttribute<Index>("homoB");
610 Index lumoA = homoA + 1;
611 Index lumoB = homoB + 1;
612
614 double J_hole = GetPODCouplingFromProp(podprop, homoA, homoB);
615 if (!std::isnan(J_hole)) {
616 qmp->setJeff(J_hole, hole);
617 qmp->setJeff2(J_hole * J_hole, hole);
618 updated_h++;
619 }
620
622 double J_electron = GetPODCouplingFromProp(podprop, lumoA, lumoB);
623 if (!std::isnan(J_electron)) {
624 qmp->setJeff(J_electron, electron);
625 qmp->setJeff2(J_electron * J_electron, electron);
626 updated_e++;
627 }
628 }
629 XTP_LOG(Log::error, log) << "Pairs [total:updated(e,h)] " << number_of_pairs
630 << ":(" << updated_e << "," << updated_h
631 << ") Incomplete jobs: " << incomplete_jobs << "\n"
632 << std::flush;
633 std::cout << log;
634}
635
637 const std::string& errormessage) {
638 XTP_LOG(Log::error, pLog) << errormessage << std::flush;
639 std::cout << pLog;
640 jres.setError(errormessage);
642}
643
644void IPodCoupling::WriteLoggerToFile(const std::string& logfile,
645 Logger& logger) {
646 std::ofstream ofs;
647 ofs.open(logfile, std::ofstream::out);
648 if (!ofs.is_open()) {
649 throw std::runtime_error("Bad file handle: " + logfile);
650 }
651 ofs << logger << std::endl;
652 ofs.close();
653}
654
655} // namespace xtp
656} // namespace votca
pair_type * FindPair(element_type e1, element_type e2)
Definition pairlist.h:93
Index size() const
Definition pairlist.h:53
virtual std::unique_ptr< T > Create(const key_t &key, args_t &&...arguments)
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 ifExistsReturnElseReturnDefault(const std::string &key, T defaultvalue) const
Definition property.h:332
T getAttribute(const std::string &attribute) const
return attribute as type
Definition property.h:319
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:325
void LoadFromXML(std::string filename)
Definition property.cc:238
break string into words
Definition tokenizer.h:72
void Translate(const Eigen::Vector3d &shift)
const Eigen::Vector3d & getPos() const
Definition atom.h:77
const Eigen::Vector3d & getExternalBondDirection() const
Definition atom.h:91
static QMMolecule RelaxNewAtoms(const QMMolecule &mol, Index n_original_atoms, Index n_steps=500)
static constexpr double kDefaultCHBondLengthAngstrom
static SaturationResult SaturateExternalBonds(const QMMolecule &mol, double bond_length_angstrom=kDefaultCHBondLengthAngstrom)
void WriteJobFile(const Topology &top)
std::string Identify() const
Calculator name.
void ParseSpecificOptions(const tools::Property &user_options)
std::vector< Segment > PositionLinkersAlongChain(const Topology &top, const Segment &seg1_positioned, const std::vector< const Segment * > &linkers, const Segment &seg2_positioned) const
void ReadJobFile(Topology &top)
tools::Property podcoupling_options_
Job::JobResult EvalJob(const Topology &top, Job &job, QMThread &opThread)
const Atom & FindBoundaryAtomTowardSegment(const Segment &seg, Index target_segment_id) const
tools::Property dftpackage_options_
void WriteLoggerToFile(const std::string &logfile, Logger &logger)
void SetJobToFailed(Job::JobResult &jres, Logger &pLog, const std::string &errormessage)
double GetPODCouplingFromProp(const tools::Property &podprop, Index levelA, Index levelB) const
void setError(std::string error)
Definition job.h:67
void setOutput(std::string output)
Definition job.h:50
void setStatus(JobStatus stat)
Definition job.h:49
tools::Property & getInput()
Definition job.h:87
Logger is used for thread-safe output of messages.
Definition logger.h:164
void setPreface(Log::Level level, const std::string &preface)
Definition logger.h:194
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setMultithreading(bool maverick)
Definition logger.h:186
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
const QMMolecule & QMAtoms() const
Return read-only access to the molecular geometry.
Definition orbitals.h:262
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1238
void WriteToCpt(const std::string &filename) const
Write the orbital container to a checkpoint file on disk.
Definition orbitals.cc:1119
Index getFragmentAHomoIndex() const
Definition podcoupling.h:78
void CalculateCouplings(Index numberofstatesA, Index numberofstatesB)
double getCouplingElement(Index levelA, Index levelB) const
Index getFragmentBLumoIndex() const
Definition podcoupling.h:81
Index getFragmentALumoIndex() const
Definition podcoupling.h:79
Index getFragmentBHomoIndex() const
Definition podcoupling.h:80
typename std::vector< Job >::value_type Job
container for QM atoms
Definition qmatom.h:37
void AddContainer(const AtomContainer< QMAtom > &container)
Definition qmmolecule.h:40
void setJeff2(double Jeff2, QMStateType state)
Definition qmpair.h:121
const PairType & getType() const
Definition qmpair.h:138
Index getId() const
Definition qmpair.h:95
void setJeff(double Jeff, QMStateType state)
Definition qmpair.h:118
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
Logger & getLogger()
Definition qmthread.h:55
void LoadMappingFile(const std::string &mapfile)
AtomContainer map(const Segment &seg, const SegId &segid) const
Container for segments and box and atoms.
Definition topology.h:41
Index getStep() const
Definition topology.h:75
Eigen::Vector3d PbShortestConnect(const Eigen::Vector3d &r1, const Eigen::Vector3d &r2) const
Definition topology.cc:140
std::vector< const Segment * > FindLinkingSegments(const Segment &seg1, const Segment &seg2) const
Definition topology.cc:182
QMNBList & NBList()
Definition topology.h:70
Segment & getSegment(Index id)
Definition topology.h:55
#define XTP_LOG(level, log)
Definition logger.h:40
const double ev2hrt
Definition constants.h:54
const double ang2bohr
Definition constants.h:48
const double hrt2ev
Definition constants.h:53
Charge transport classes.
Definition ERIs.h:28
SegmentMapper< QMMolecule > QMMapper
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