votca 2026-dev
Loading...
Searching...
No Matches
podcouplingtool.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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#include "podcouplingtool.h"
21#include "votca/xtp/qmstate.h"
22#include <sstream>
23
24using std::flush;
25
26namespace votca {
27namespace xtp {
28
30
31 log_.setReportLevel(Log::current_level);
32 log_.setMultithreading(true);
33 log_.setCommonPreface("\n...");
34
35 tools::Property options = user_options;
36
37 orb_file_ = options.get(".orb_file").as<std::string>();
38
39 // Atom index lists in IndexParser syntax (e.g. "1 3 13:17"), as for
40 // cdft.indices and the fragments in diabatization.xml.
41 std::string fragment_A_str = options.get(".fragment_A").as<std::string>();
42 std::string fragment_B_str = options.get(".fragment_B").as<std::string>();
43 if (fragment_A_str.empty() || fragment_B_str.empty()) {
44 throw std::runtime_error(
45 "PodCouplingTool: fragment_A and fragment_B must both be given, "
46 "e.g. '0:5' and '6:11' (same syntax as cdft.indices).");
47 }
50
51 // Number of occupied and virtual levels per fragment; option names and
52 // meaning as in DFTcoupling (levA/levB).
55
56 XTP_LOG(Log::error, log_) << "Fragment A: " << fragment_A_atoms_.size()
57 << " atoms, levA=" << numberofstatesA_ << flush;
58 XTP_LOG(Log::error, log_) << "Fragment B: " << fragment_B_atoms_.size()
59 << " atoms, levB=" << numberofstatesB_ << flush;
60
61 // Optional cube-file export; grid options as in gencube.xml.
63 options.ifExistsReturnElseReturnDefault<bool>("write_cube_files", false);
65 cube_steps_.x() =
66 options.ifExistsReturnElseReturnDefault<Index>("xsteps", 25);
67 cube_steps_.y() =
68 options.ifExistsReturnElseReturnDefault<Index>("ysteps", 25);
69 cube_steps_.z() =
70 options.ifExistsReturnElseReturnDefault<Index>("zsteps", 25);
72 options.ifExistsReturnElseReturnDefault<double>("padding", 6.5);
73 }
74}
75
77
79
80 log_.setReportLevel(Log::current_level);
81 log_.setMultithreading(true);
82 log_.setCommonPreface("\n...");
83
85 << TimeStamp() << " Reading orbitals from: " << orb_file_ << flush;
86
87 Orbitals orbitals;
88 orbitals.ReadFromCpt(orb_file_);
89
92
93 Index homoA = pod.getFragmentAHomoIndex();
94 Index lumoA = pod.getFragmentALumoIndex();
95 Index homoB = pod.getFragmentBHomoIndex();
96 Index lumoB = pod.getFragmentBLumoIndex();
97
98 // Full coupling matrix over the requested range, as in DFTcoupling,
99 // labeled by absolute fragment orbital indices.
101 << " Full coupling matrix [eV] (fragment A orbital "
102 "index -> fragment B orbital index):"
103 << flush;
104 for (Index levelA = homoA - numberofstatesA_ + 1;
105 levelA <= lumoA + numberofstatesA_ - 1; ++levelA) {
106 std::ostringstream row;
107 row << " A[" << levelA << (levelA == homoA ? "=HOMO" : "")
108 << (levelA == lumoA ? "=LUMO" : "") << "]:";
109 for (Index levelB = homoB - numberofstatesB_ + 1;
110 levelB <= lumoB + numberofstatesB_ - 1; ++levelB) {
111 double coupling_ev =
113 row << boost::format(" B[%1%]=%2$+1.6f") % levelB % coupling_ev;
114 }
115 XTP_LOG(Log::error, log_) << row.str() << flush;
116 }
117
118 // HOMO-HOMO (hole) and LUMO-LUMO (electron) couplings separately.
119 double homo_homo_ev =
121 double lumo_lumo_ev =
124 << boost::format("POD2 Coupling, HOMO-HOMO (hole): %1$+1.12f eV") %
125 homo_homo_ev
126 << flush;
128 << boost::format("POD2 Coupling, LUMO-LUMO (electron): %1$+1.12f eV") %
129 lumo_lumo_ev
130 << flush;
131
132 // Cube files of the computed fragment orbitals. CubeFile_Writer only
133 // reads orb.MOs().eigenvectors().col(index), so each orbital, embedded
134 // in the full AO basis (PODCoupling::GetFragmentOrbital), is stored as
135 // the single MO of a copy of orbitals and written as in gencube.cc.
136 if (write_cube_files_) {
138 << TimeStamp()
139 << " Writing cube files for the computed fragment "
140 "orbitals..."
141 << flush;
143 auto WriteFragmentOrbitalCube = [&](bool fragment_A, Index level,
144 const std::string& label) {
145 Eigen::VectorXd orbital = pod.GetFragmentOrbital(fragment_A, level);
146 Orbitals orbitals_copy = orbitals;
147 orbitals_copy.MOs().eigenvectors() = orbital;
148 orbitals_copy.MOs().eigenvalues() = Eigen::VectorXd::Zero(1);
149 std::string filename =
150 "podcoupling_" + label + "_orb" + std::to_string(level) + ".cube";
151 writer.WriteFile(filename, orbitals_copy,
152 QMState(QMStateType::KSstate, 0, false), false);
153 XTP_LOG(Log::error, log_) << " wrote " << filename << flush;
154 // Dominant AOs of the orbital, e.g. to identify which AO's tail
155 // causes density in the region of the other fragment.
157 << pod.DescribeFragmentOrbitalComposition(fragment_A, level) << flush;
158 };
159 for (Index levelA = homoA - numberofstatesA_ + 1;
160 levelA <= lumoA + numberofstatesA_ - 1; ++levelA) {
161 WriteFragmentOrbitalCube(true, levelA, "fragA");
162 }
163 for (Index levelB = homoB - numberofstatesB_ + 1;
164 levelB <= lumoB + numberofstatesB_ - 1; ++levelB) {
165 WriteFragmentOrbitalCube(false, levelB, "fragB");
166 }
167 }
168
169 std::cout << log_;
170 // Trailing newline: xtp_tools does not print one after Evaluate(), so
171 // the shell prompt would follow the last output line directly.
172 std::cout << std::endl;
173
174 return true;
175}
176
177} // namespace xtp
178} // namespace votca
const Eigen::VectorXd & eigenvalues() const
Definition eigensystem.h:30
const Eigen::MatrixXd & eigenvectors() const
Definition eigensystem.h:33
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
void WriteFile(const std::string &filename, const Orbitals &orb, QMState state, bool dostateonly) const
std::vector< Index > CreateIndexVector(const std::string &Ids) const
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
const tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
Definition orbitals.h:192
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1222
Index getFragmentAHomoIndex() const
Definition podcoupling.h:78
void CalculateCouplings(Index numberofstatesA, Index numberofstatesB)
double getCouplingElement(Index levelA, Index levelB) const
Eigen::VectorXd GetFragmentOrbital(bool fragment_A, Index level) const
Index getFragmentBLumoIndex() const
Definition podcoupling.h:81
Index getFragmentALumoIndex() const
Definition podcoupling.h:79
Index getFragmentBHomoIndex() const
Definition podcoupling.h:80
std::string DescribeFragmentOrbitalComposition(bool fragment_A, Index level, Index top_n=5) const
Eigen::Array< Index, 3, 1 > cube_steps_
std::vector< Index > fragment_B_atoms_
std::vector< Index > fragment_A_atoms_
void ParseOptions(const tools::Property &user_options) final
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
Timestamp returns the current time as a string Example: cout << TimeStamp().
Definition logger.h:224
#define XTP_LOG(level, log)
Definition logger.h:40
const double hrt2ev
Definition constants.h:53
void setMaxThreads(Index)
Definition eigen.h:175
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