votca 2026-dev
Loading...
Searching...
No Matches
dftgwbse.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 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// VOTCA includes
19#include <algorithm>
20#include <iomanip>
21#include <sstream>
24
25// Local VOTCA includes
26#include "votca/xtp/aomatrix.h"
27#include "votca/xtp/dftengine.h"
30#include "votca/xtp/qmstate.h"
31#include "votca/xtp/segment.h"
33
34// Local private VOTCA includes
35#include "dftgwbse.h"
37
38namespace votca {
39namespace xtp {
40
42
43 // molecule coordinates
44 xyzfile_ = job_name_ + ".xyz";
45
46 // options for dft package
47 package_options_ = options.get(".dftpackage");
48
49 // GWBSEENGINE options
50 gwbseengine_options_ = options;
51
52 // lets get the archive file name from the xyz file name
53 archive_file_ = job_name_ + ".orb";
54
55 // XML OUTPUT
56 xml_output_ = job_name_ + "_summary.xml";
57
58 if (options.exists(".excited_state_forces")) {
60 options.get(".excited_state_forces").as<std::string>();
61 }
62 {
63 const std::string tasks = options.get(".tasks").as<std::string>();
64 tools::Tokenizer tok(tasks, " ,");
65 const std::vector<std::string> list = tok.ToVector();
66 const bool has =
67 std::find(list.begin(), list.end(), "gradients") != list.end();
68 if (has && list.size() > 1) {
69 throw std::runtime_error(
70 "tasks: gradients cannot be combined with other tasks (with dft "
71 "and gwbse the gradients are computed in the same run anyway)");
72 }
73 gradients_only_ = has;
74 }
75 if (options.exists(".qp_gradients")) {
76 qp_gradients_ = options.get(".qp_gradients").as<std::string>();
77 }
78 if (options.exists(".relaxed_density")) {
79 relaxed_density_ = options.get(".relaxed_density").as<std::string>();
80 }
81 if (options.exists(".excited_state_forces_follow")) {
83 options.get(".excited_state_forces_follow").as<std::string>();
84 }
85 if (options.exists(".excited_state_forces_qp_response")) {
87 options.get(".excited_state_forces_qp_response").as<bool>();
88 }
89
90 if (options.exists(".mpsfile")) {
91 mpsfile_ = options.get(".mpsfile").as<std::string>();
92 }
93
94 // check if guess is requested
95 if (options.exists(".guess")) {
96 guess_file_ = options.get(".guess").as<std::string>();
97 }
98
99 // check if a separate MO-only guess is requested (see this class's
100 // own header comment on moguess_file_ for why this is a distinct
101 // option from .guess, not a variant of it)
102 if (options.exists(".moguess")) {
103 moguess_file_ = options.get(".moguess").as<std::string>();
104 }
105
106 // register all QM packages
108}
109
111
112 log_.setReportLevel(Log::current_level);
113
114 log_.setMultithreading(true);
115 log_.setCommonPreface("\n... ...");
116
117 // Get orbitals object
118 Orbitals orbitals;
119
120 // tasks = gradients: no DFT or GW-BSE, the requested gradients
121 // (qp_gradients, excited_state_forces) are computed from the data of an
122 // earlier run in the orb file and added to it
123 if (gradients_only_) {
124 if (excited_state_forces_.empty() && qp_gradients_.empty() &&
125 relaxed_density_.empty()) {
126 throw std::runtime_error(
127 "tasks gradients: set qp_gradients, excited_state_forces and/or "
128 "relaxed_density");
129 }
131 << "Gradients from the GW-BSE data in " << archive_file_ << std::flush;
132 orbitals.ReadFromCpt(archive_file_);
133 CheckStoredRun(orbitals);
134 if (!excited_state_forces_.empty()) {
136 }
137 if (!qp_gradients_.empty()) {
138 ComputeQPGradients(orbitals);
139 }
140 if (!relaxed_density_.empty()) {
141 ComputeRelaxedDensity(orbitals);
142 }
144 << "Saving data to " << archive_file_ << std::flush;
145 orbitals.WriteToCpt(archive_file_);
146 return true;
147 }
148
149 if (!guess_file_.empty()) {
151 << "Reading guess from " << guess_file_ << std::flush;
152 orbitals.ReadFromCpt(guess_file_);
153 } else {
155 << "Reading structure from " << xyzfile_ << std::flush;
156 orbitals.QMAtoms().LoadFromFile(xyzfile_);
157 }
158
159 // Warm-start the MOs from a PREVIOUS geometry step's own, separate
160 // .orb file, while keeping the geometry just loaded above (the
161 // CURRENT step's own xyzfile_, or guess_file_'s geometry if that
162 // path was used instead) -- deliberately independent of guess_file_
163 // itself, which ties geometry and MOs together from the same file
164 // and therefore cannot represent this "new geometry, warm-started
165 // MOs" case a geometry optimization needs between steps. Loaded
166 // into a separate, temporary Orbitals object so only its own
167 // MOs()/MOs_beta() get copied in -- moguess_orbitals's own geometry
168 // (the PREVIOUS step's) is deliberately discarded, never touching
169 // orbitals.QMAtoms() itself.
170 if (!moguess_file_.empty()) {
171 XTP_LOG(Log::error, log_) << "Reading MO guess (geometry unchanged) from "
172 << moguess_file_ << std::flush;
173 Orbitals moguess_orbitals;
174 moguess_orbitals.ReadFromCpt(moguess_file_);
175 orbitals.MOs() = moguess_orbitals.MOs();
176 if (moguess_orbitals.hasBetaMOs()) {
177 orbitals.MOs_beta() = moguess_orbitals.MOs_beta();
178 }
179 // Defensive, likely-redundant given charge/spin (and therefore the
180 // electron counts) should not change between geometry-optimization
181 // steps -- DFTEngine::Evaluate() itself may set these independently
182 // from package_options_ regardless of what orbitals already holds
183 // here. Kept as a safety net rather than removed outright, since
184 // this has not been confirmed either way by tracing through
185 // DFTEngine's own guess-path logic.
187 moguess_orbitals.getNumberOfAlphaElectrons());
189 moguess_orbitals.getNumberOfBetaElectrons());
190 }
191
192 std::unique_ptr<QMPackage> qmpackage =
193 std::unique_ptr<QMPackage>(QMPackageFactory().Create(
194 package_options_.get("name").as<std::string>()));
195 qmpackage->setLog(&log_);
196 qmpackage->Initialize(package_options_);
197 qmpackage->setRunDir(".");
198
199 if (!mpsfile_.empty()) {
200 StaticRegion region(0, log_);
201 StaticSegment seg = StaticSegment("", 0);
203 region.push_back(seg);
204 qmpackage->AddRegion(region);
205 }
206
207 GWBSEEngine gwbse_engine;
208 gwbse_engine.setLog(&log_);
209 gwbse_engine.setQMPackage(qmpackage.get());
211
212 QMMolecule fullMol = orbitals.QMAtoms();
213 gwbse_engine.ExcitationEnergies(orbitals);
214 // If truncation was enabled then rewrite full basis/aux-basis, MOs in full
215 // basis and full QMAtoms
216 if (orbitals.getCalculationType() == "Truncated") {
217 orbitals.QMAtoms().clearAtoms();
218 orbitals.QMAtoms() = fullMol;
219 orbitals.MOs().eigenvectors() = orbitals.getTruncMOsFullBasis();
220 orbitals.SetupDftBasis(orbitals.getDftBasis().Name());
221 if (orbitals.hasAuxbasisName()) {
222 orbitals.SetupAuxBasis(orbitals.getAuxBasis().Name());
223 }
224 }
225
226 if (!excited_state_forces_.empty()) {
228 }
229 if (!qp_gradients_.empty()) {
230 ComputeQPGradients(orbitals);
231 }
232 if (!relaxed_density_.empty()) {
233 if (orbitals.getCalculationType() == "Truncated") {
234 throw std::runtime_error("relaxed_density: not for truncated bases");
235 }
236 ComputeRelaxedDensity(orbitals);
237 }
238
239 XTP_LOG(Log::error, log_) << "Saving data to " << archive_file_ << std::flush;
240 orbitals.WriteToCpt(archive_file_);
241
242 tools::Property summary = gwbse_engine.ReportSummary();
243 if (summary.exists("output")) { // only do gwbse summary output if we
244 // actually did gwbse
246 << "Writing output to " << xml_output_ << std::flush;
247 std::ofstream ofout(xml_output_, std::ofstream::out);
248 ofout << (summary.get("output"));
249 ofout.close();
250 }
251 return true;
252}
253
254// Root following: the state of the requested type with the largest exciton
255// overlap (ExcitonOverlaps) with the state whose forces are stored in the
256// orb file of an earlier geometry (excited_state_forces_follow).
258 Orbitals ref;
260 if (ref.getExcitedStateForcesState().empty()) {
261 throw std::runtime_error(
262 "excited_state_forces_follow: " + excited_state_forces_follow_ +
263 " holds no excited-state forces");
264 }
265 const QMState ref_state(ref.getExcitedStateForcesState());
266 const Eigen::VectorXd ov =
267 ExcitonOverlaps(ref, ref_state, orbitals, ref_state.Type());
268 Index best = 0;
269 ov.maxCoeff(&best);
270 double second = 0.0;
271 for (Index i = 0; i < ov.size(); ++i) {
272 if (i != best) {
273 second = std::max(second, ov(i));
274 }
275 }
276 const QMState state(ref_state.Type(), best, false);
278 << TimeStamp() << " Root following: " << ref_state.ToString() << " of "
279 << excited_state_forces_follow_ << " is " << state.ToString()
280 << " here (overlap " << ov(best) << ", next largest " << second << ")"
281 << std::flush;
282 if (ov(best) < 0.5 || second > 0.8 * ov(best)) {
284 << TimeStamp()
285 << " WARNING: root following is ambiguous (states mix strongly or "
286 "the geometry step is large)"
287 << std::flush;
288 }
289 return state;
290}
291
292// Forces -dE/dR of one BSE state: the ground-state forces of the SCF
293// (xtpdft.compute_forces) minus the analytic gradient of the excitation
294// energy with fixed QP corrections (DFTEngine::BSEExcitationGradient).
295// Response of the QP corrections in the gradients (BSE states and QP
296// levels): the options of the GW run that the gradient has to reproduce.
298 const Orbitals& orbitals) {
299 // response of the QP corrections: implemented for G0W0 and evGW with
300 // the plasmon-pole and the exact self-energy; otherwise (cda) the
301 // corrections are kept fixed
304 input, orbitals, gwbseengine_options_.get("gwbse"), &log_)) {
306 << TimeStamp() << " Including the response of the QP corrections"
307 << std::flush;
308 } else {
310 << TimeStamp()
311 << " QP corrections kept fixed (excited_state_forces_qp_response "
312 "false, or not G0W0/evGW with sigma_integrator ppm or exact)"
313 << std::flush;
314 }
315}
316
317// relaxed_density: the relaxed density matrix of one state, stored in the
318// orb file (orbital relaxation and, as for the forces, the response of the
319// QP corrections where covered); at fixed external multipoles if mpsfile
320// is set
322 if (package_options_.get("name").as<std::string>() != "xtp") {
323 throw std::runtime_error("relaxed_density: needs the xtp DFT package");
324 }
326 DFTEngine dft;
327 dft.setLogger(&log_);
329 const Eigen::MatrixXd density = dft.RelaxedDensityMatrix(
330 orbitals, state, gwbseengine_options_.get("gwbse"),
332 orbitals.setRelaxedDensity(density, state.ToString());
333 // dipole change of the state (relaxed), = dE_state/dF for H0 -= F . r
334 AODipole dipole;
335 dipole.setCenter(orbitals.QMAtoms().getPos());
336 dipole.Fill(orbitals.getDftBasis());
337 const Eigen::MatrixXd diff = density - orbitals.DensityMatrixGroundState();
338 Eigen::Vector3d change;
339 for (Index k = 0; k < 3; ++k) {
340 change(k) = -(dipole.Matrix()[k].cwiseProduct(diff)).sum();
341 }
343 << TimeStamp() << " Relaxed density of " << state.ToString()
344 << " stored (relaxed_density); dipole change from the ground state "
345 "(e*bohr): "
346 << std::setprecision(8) << change.transpose() << std::flush;
347}
348
349// "homo-2:lumo+3", "lumo", "12:20" (absolute, 0-based MO indices)
350std::vector<Index> DftGwBse::ParseLevels(const std::string& text, Index homo) {
351 auto parse_one = [homo](std::string token) {
352 token.erase(std::remove_if(token.begin(), token.end(), ::isspace),
353 token.end());
354 std::transform(token.begin(), token.end(), token.begin(), ::tolower);
355 Index base = 0;
356 std::string rest = token;
357 if (token.rfind("homo", 0) == 0) {
358 base = homo;
359 rest = token.substr(4);
360 } else if (token.rfind("lumo", 0) == 0) {
361 base = homo + 1;
362 rest = token.substr(4);
363 }
364 if (rest.empty() && rest.size() != token.size()) {
365 return base;
366 }
367 std::size_t used = 0;
368 Index offset = 0;
369 try {
370 offset = Index(std::stol(rest, &used));
371 } catch (std::exception&) {
372 used = std::string::npos;
373 }
374 if (used != rest.size() || rest.empty() ||
375 (rest.size() != token.size() && rest[0] != '+' && rest[0] != '-')) {
376 throw std::runtime_error("qp_gradients: cannot read level '" + token +
377 "' (e.g. homo-2, lumo+3 or an MO index)");
378 }
379 return base + offset;
380 };
381 std::vector<Index> levels;
382 std::stringstream list(text);
383 std::string item;
384 while (std::getline(list, item, ',')) {
385 const std::size_t colon = item.find(':');
386 const Index first = parse_one(item.substr(0, colon));
387 const Index last = (colon == std::string::npos)
388 ? first
389 : parse_one(item.substr(colon + 1));
390 if (last < first) {
391 throw std::runtime_error("qp_gradients: empty range '" + item + "'");
392 }
393 for (Index level = first; level <= last; ++level) {
394 if (std::find(levels.begin(), levels.end(), level) == levels.end()) {
395 levels.push_back(level);
396 }
397 }
398 }
399 std::sort(levels.begin(), levels.end());
400 return levels;
401}
402
404 if (package_options_.get("name").as<std::string>() != "xtp") {
405 throw std::runtime_error("qp_gradients: needs the xtp DFT package");
406 }
407 if (!mpsfile_.empty() || orbitals.getCalculationType() == "Truncated") {
408 throw std::runtime_error(
409 "qp_gradients: embedding and truncated bases are not supported");
410 }
411 const std::vector<Index> requested =
412 ParseLevels(qp_gradients_, orbitals.getHomo());
413 // levels whose gradients are already in the orb file (tasks gradients on
414 // a file of an earlier run) are kept and not recomputed
415 const std::vector<Index> stored = orbitals.getQPGradientLevels();
416 const Eigen::MatrixXd stored_gradients = orbitals.getQPGradients();
417 std::vector<Index> levels;
418 for (Index level : requested) {
419 if (std::find(stored.begin(), stored.end(), level) == stored.end()) {
420 levels.push_back(level);
421 }
422 }
423 if (levels.empty()) {
425 << TimeStamp() << " QP gradients of all requested levels are "
426 << "already stored" << std::flush;
427 return;
428 }
429 if (levels.size() < requested.size()) {
431 << TimeStamp() << " QP gradients of "
432 << requested.size() - levels.size()
433 << " requested level(s) are already stored" << std::flush;
434 }
436 << TimeStamp() << " Analytic gradients of the QP energies of "
437 << levels.size() << " level(s), " << levels.front() << " to "
438 << levels.back() << " (HOMO is " << orbitals.getHomo() << ")"
439 << std::flush;
442 SetupQPResponse(input, orbitals);
443 DFTEngine dft;
444 dft.setLogger(&log_);
446 const DFTEngine::BSEGradientResult result =
447 dft.BSEExcitationGradient(orbitals, input);
448 if (input.qp_response) {
450 << TimeStamp() << " QP energies rebuilt for the gradient: max "
451 << "deviation " << result.qp_rebuild_error << " Ha" << std::flush;
452 if (result.qp_rebuild_error > 1e-4) {
453 throw std::runtime_error(
454 "qp_gradients: the QP energies rebuilt for the gradient differ "
455 "from the GW ones by " +
456 std::to_string(result.qp_rebuild_error) + " Ha");
457 }
458 }
459 const Index natoms = orbitals.QMAtoms().size();
460 // stored and new levels, sorted
461 std::vector<std::pair<Index, Eigen::MatrixXd>> merged;
462 for (std::size_t l = 0; l < stored.size(); ++l) {
463 merged.emplace_back(stored[l],
464 stored_gradients.middleRows(Index(l) * natoms, natoms));
465 }
466 for (std::size_t l = 0; l < levels.size(); ++l) {
467 merged.emplace_back(levels[l], result.qp_gradients[l]);
468 }
469 std::sort(merged.begin(), merged.end(),
470 [](const auto& a, const auto& b) { return a.first < b.first; });
471 Eigen::MatrixXd all(Index(merged.size()) * natoms, 3);
472 std::vector<Index> all_levels;
473 for (std::size_t l = 0; l < merged.size(); ++l) {
474 all.middleRows(Index(l) * natoms, natoms) = merged[l].second;
475 all_levels.push_back(merged[l].first);
476 }
477 orbitals.setQPGradients(all, all_levels);
478}
479
480// tasks = gradients: the options must be those of the run that wrote the
481// orb file. What is stored there is compared; a different GW setup shows
482// up in the rebuilt QP and excitation energies of the gradient.
483void DftGwBse::CheckStoredRun(const Orbitals& orbitals) const {
484 auto lower = [](std::string text) {
485 std::transform(text.begin(), text.end(), text.begin(), ::tolower);
486 return text;
487 };
488 auto check = [&](const std::string& what, const std::string& stored,
489 const std::string& option) {
490 if (lower(stored) != lower(option)) {
491 throw std::runtime_error("tasks gradients: " + what + " of " +
492 archive_file_ + " is " + stored +
493 ", the options say " + option +
494 "; use the options of the run that wrote "
495 "the file");
496 }
497 };
498 if (!orbitals.hasQMAtoms() || orbitals.MOs().eigenvalues().size() == 0 ||
499 orbitals.RPAInputEnergies().size() == 0) {
500 throw std::runtime_error("tasks gradients: " + archive_file_ +
501 " has no GW data");
502 }
503 check("the basis set", orbitals.getDftBasis().Name(),
504 package_options_.get("basisset").as<std::string>());
505 check("the functional", orbitals.getXCFunctionalName(),
506 package_options_.get("functional").as<std::string>());
507 if (orbitals.hasAuxbasisName()) {
508 check("the auxiliary basis set", orbitals.getAuxBasis().Name(),
509 package_options_.get("auxbasisset").as<std::string>());
510 }
511}
512
515 if (!excited_state_forces_follow_.empty()) {
516 state = FollowState(orbitals);
517 }
518 const bool singlet = state.Type() == QMStateType::Singlet;
519 if (!singlet && state.Type() != QMStateType::Triplet) {
520 throw std::runtime_error(
521 "excited_state_forces: only singlet or triplet BSE states (e.g. s1)");
522 }
523 if (package_options_.get("name").as<std::string>() != "xtp") {
524 throw std::runtime_error("excited_state_forces: needs the xtp DFT package");
525 }
526 if (!mpsfile_.empty() || orbitals.getCalculationType() == "Truncated") {
527 throw std::runtime_error(
528 "excited_state_forces: embedding and truncated bases are not "
529 "supported");
530 }
531 if (!orbitals.hasForces()) {
532 throw std::runtime_error(
533 "excited_state_forces: needs the ground-state forces, set "
534 "dftpackage.xtpdft.compute_forces to true");
535 }
537 << TimeStamp() << " Analytic forces of BSE state " << state.ToString()
538 << (orbitals.getTDAApprox() ? " (TDA)" : " (full BSE)") << std::flush;
539
541 orbitals, singlet, state.StateIdx());
542 SetupQPResponse(input, orbitals);
543 DFTEngine dft;
544 dft.setLogger(&log_);
546 const DFTEngine::BSEGradientResult result =
547 dft.BSEExcitationGradient(orbitals, input);
548
549 const double omega =
550 (singlet ? orbitals.BSESinglets() : orbitals.BSETriplets())
551 .eigenvalues()(state.StateIdx());
552 // the gradient belongs to the Rayleigh quotient of the stored exciton,
553 // which differs from the Davidson eigenvalue at the level of the
554 // Davidson residual (bse.davidson.tolerance; for full BSE to first
555 // order); a different GW-BSE setup gives deviations of 1e-3 Ha and more
556 const double omega_error = std::abs(result.omega - omega);
558 << TimeStamp() << " Excitation energy rebuilt for the gradient: "
559 << "deviation from the BSE eigenvalue " << omega_error << " Ha"
560 << std::flush;
561 if (omega_error > 1e-4) {
562 throw std::runtime_error(
563 "excited_state_forces: the excitation energy rebuilt for the "
564 "gradient (" +
565 std::to_string(result.omega) +
566 " Ha) differs from the BSE eigenvalue (" + std::to_string(omega) +
567 " Ha); the GW-BSE setup (e.g. environment screening, dynamical "
568 "screening of the BSE kernel) is not covered by the gradient");
569 }
570 if (omega_error > 1e-6) {
572 << TimeStamp()
573 << " WARNING: the BSE eigenvalue is converged only to about "
574 << omega_error
575 << " Ha; tighten bse.davidson.tolerance (strict or lapack) for "
576 "energies consistent with the forces"
577 << std::flush;
578 }
579 if (input.qp_response) {
581 << TimeStamp() << " QP energies rebuilt for the gradient: max "
582 << "deviation " << result.qp_rebuild_error << " Ha" << std::flush;
583 }
584 if (input.qp_selfconsistent) {
586 << TimeStamp() << " RPA energies rebuilt for the gradient: max "
587 << "deviation " << result.rpa_rebuild_error << " Ha" << std::flush;
588 }
589 // the QP solver and the interpolated pole sums of GW are converged to
590 // about 1e-6 Ha; a larger deviation means a different setup
591 if (input.qp_response && result.qp_rebuild_error > 1e-4) {
592 throw std::runtime_error(
593 "excited_state_forces: the QP energies rebuilt for the gradient "
594 "differ from the GW ones by " +
595 std::to_string(result.qp_rebuild_error) + " Ha");
596 }
597 const Eigen::MatrixXd forces = orbitals.getForces() - result.gradient;
598 orbitals.setExcitedStateForces(forces, state.ToString());
600 << TimeStamp() << " Excited-state forces (Hartree/Bohr) of "
601 << state.ToString() << ", Omega = " << omega << " Ha:\n"
602 << forces << std::flush;
603}
604
605} // namespace xtp
606} // 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
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
break string into words
Definition tokenizer.h:72
const std::string & Name() const
Definition aobasis.h:81
void setCenter(const Eigen::Vector3d &r)
Definition aomatrix.h:98
const std::array< Eigen::MatrixXd, 3 > & Matrix() const
Definition aomatrix.h:96
void Fill(const AOBasis &aobasis) final
const Eigen::Vector3d & getPos() const
void LoadFromFile(std::string filename)
Electronic ground-state via Density-Functional Theory.
Definition dftengine.h:89
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:95
Eigen::MatrixXd RelaxedDensityMatrix(const Orbitals &orb, const QMState &state, const tools::Property &gwbse, bool qp_response=true)
static BSEGradientInput QPGradientInputFromOrbitals(const Orbitals &orb, const std::vector< Index > &levels)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:99
BSEGradientResult BSEExcitationGradient(const Orbitals &orb, const BSEGradientInput &input)
static BSEGradientInput BSEGradientInputFromOrbitals(const Orbitals &orb, bool singlet, Index index)
static bool ConfigureQPResponse(BSEGradientInput &input, const Orbitals &orb, const tools::Property &gwbse, Logger *log)
void ParseOptions(const tools::Property &user_options)
Definition dftgwbse.cc:41
std::string guess_file_
Definition dftgwbse.h:50
tools::Property package_options_
Definition dftgwbse.h:84
std::string mpsfile_
Definition dftgwbse.h:60
std::string archive_file_
Definition dftgwbse.h:82
std::string excited_state_forces_
Definition dftgwbse.h:62
void ComputeExcitedStateForces(Orbitals &orbitals)
Definition dftgwbse.cc:513
bool excited_state_forces_qp_response_
Definition dftgwbse.h:63
std::string moguess_file_
Definition dftgwbse.h:59
std::string xml_output_
Definition dftgwbse.h:81
void SetupQPResponse(DFTEngine::BSEGradientInput &input, const Orbitals &orbitals)
Definition dftgwbse.cc:297
QMState FollowState(const Orbitals &orbitals)
Definition dftgwbse.cc:257
std::string excited_state_forces_follow_
Definition dftgwbse.h:65
std::string relaxed_density_
Definition dftgwbse.h:70
tools::Property gwbseengine_options_
Definition dftgwbse.h:85
static std::vector< Index > ParseLevels(const std::string &text, Index homo)
Definition dftgwbse.cc:350
std::string qp_gradients_
Definition dftgwbse.h:68
void CheckStoredRun(const Orbitals &orbitals) const
Definition dftgwbse.cc:483
void ComputeQPGradients(Orbitals &orbitals)
Definition dftgwbse.cc:403
void ComputeRelaxedDensity(Orbitals &orbitals)
Definition dftgwbse.cc:321
std::string xyzfile_
Definition dftgwbse.h:80
Electronic Excitations via Density-Functional Theory.
Definition gwbseengine.h:43
void ExcitationEnergies(Orbitals &orbitals)
const tools::Property & ReportSummary() const
Definition gwbseengine.h:58
void setLog(Logger *pLog)
Definition gwbseengine.h:50
void setQMPackage(QMPackage *qmpackage)
Definition gwbseengine.h:52
void Initialize(tools::Property &options, std::string archive_filename)
void push_back(const T &seg)
Definition mmregion.h:78
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
void setRelaxedDensity(const Eigen::MatrixXd &density, const std::string &state)
Definition orbitals.h:363
const Eigen::MatrixXd getTruncMOsFullBasis() const
Return truncated active-region orbitals represented in the full AO basis.
Definition orbitals.h:69
const tools::EigenSystem & BSETriplets() const
Return read-only access to triplet BSE eigenpairs.
Definition orbitals.h:541
const Eigen::MatrixXd & getQPGradients() const
Definition orbitals.h:345
Index getHomo() const
Return the default HOMO index used by spin-agnostic callers.
Definition orbitals.h:107
bool hasAuxbasisName() const
Report whether an auxiliary basis-set name has been stored.
Definition orbitals.h:414
bool hasForces() const
Report whether nuclear forces have been stored.
Definition orbitals.h:301
const tools::EigenSystem & MOs_beta() const
Return read-only access to beta-spin molecular orbitals.
Definition orbitals.h:202
const tools::EigenSystem & BSESinglets() const
Return read-only access to singlet BSE eigenpairs.
Definition orbitals.h:554
bool getTDAApprox() const
Return whether the Tamm-Dancoff approximation is enabled.
Definition orbitals.h:460
const std::vector< Index > & getQPGradientLevels() const
Definition orbitals.h:346
const AOBasis & getAuxBasis() const
Return the auxiliary AO basis, throwing if it has not been initialized.
Definition orbitals.h:397
Index getNumberOfAlphaElectrons() const
Return the stored number of alpha electrons.
Definition orbitals.h:159
std::string getCalculationType() const
Return the stored calculation-type tag.
Definition orbitals.h:242
bool hasQMAtoms() const
Report whether a molecular geometry has been stored.
Definition orbitals.h:259
void setNumberOfAlphaElectrons(Index electrons)
Store the total number of alpha electrons.
Definition orbitals.h:139
void SetupAuxBasis(std::string aux_basis_name)
Definition orbitals.cc:108
void setNumberOfBetaElectrons(Index electrons)
Store the total number of beta electrons.
Definition orbitals.h:144
const std::string & getExcitedStateForcesState() const
Definition orbitals.h:332
const Eigen::VectorXd & RPAInputEnergies() const
Return read-only access to the RPA input energies.
Definition orbitals.h:501
const tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
Definition orbitals.h:192
Eigen::MatrixXd DensityMatrixGroundState() const
Build the ground-state AO density matrix from the stored orbitals.
Definition orbitals.cc:224
const QMMolecule & QMAtoms() const
Return read-only access to the molecular geometry.
Definition orbitals.h:262
const std::string & getXCFunctionalName() const
Return the exchange-correlation functional label.
Definition orbitals.h:280
void setQPGradients(const Eigen::MatrixXd &gradients, const std::vector< Index > &levels)
Definition orbitals.h:349
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1242
void setExcitedStateForces(const Eigen::MatrixXd &forces, const std::string &state)
Definition orbitals.h:335
void WriteToCpt(const std::string &filename) const
Write the orbital container to a checkpoint file on disk.
Definition orbitals.cc:1119
bool hasBetaMOs() const
Report whether beta-spin molecular orbitals are available.
Definition orbitals.h:187
void SetupDftBasis(std::string basis_name)
Build and attach the DFT AO basis from the stored molecular geometry.
Definition orbitals.cc:99
const Eigen::MatrixXd & getForces() const
Return the stored nuclear forces (Natoms x 3, Hartree/Bohr).
Definition orbitals.h:318
Index getNumberOfBetaElectrons() const
Return the stored number of beta electrons.
Definition orbitals.h:161
const AOBasis & getDftBasis() const
Return the DFT AO basis, throwing if it has not been initialized.
Definition orbitals.h:386
void LoadFromFile(std::string filename)
Definition qmmolecule.cc:45
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
std::string ToString() const
Definition qmstate.cc:155
Index StateIdx() const
Definition qmstate.h:157
const QMStateType & Type() const
Definition qmstate.h:154
std::string job_name_
Definition qmtool.h:50
Timestamp returns the current time as a string Example: cout << TimeStamp().
Definition logger.h:224
#define XTP_LOG(level, log)
Definition logger.h:40
Charge transport classes.
Definition ERIs.h:28
ClassicalSegment< StaticSite > StaticSegment
Eigen::VectorXd ExcitonOverlaps(const Orbitals &ref, const QMState &ref_state, const Orbitals &cur, QMStateType type)
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
double qp_rebuild_error
with qp_response: max |E - rebuilt QP energy| over the QP window
Definition dftengine.h:247
double omega
X^T H X from the rebuilt BSE Hamiltonian (equals the BSE eigenvalue).
Definition dftengine.h:232
double rpa_rebuild_error
with qp_selfconsistent: max |R - rebuilt RPA energy|
Definition dftengine.h:249
std::vector< Eigen::MatrixXd > qp_gradients
for qp_levels: dE_p/dR per level (natoms x 3 each), Hartree/Bohr
Definition dftengine.h:237