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
20
21// Local VOTCA includes
24#include "votca/xtp/segment.h"
26
27// Local private VOTCA includes
28#include "dftgwbse.h"
29
30namespace votca {
31namespace xtp {
32
34
35 // molecule coordinates
36 xyzfile_ = job_name_ + ".xyz";
37
38 // options for dft package
39 package_options_ = options.get(".dftpackage");
40
41 // GWBSEENGINE options
42 gwbseengine_options_ = options;
43
44 // lets get the archive file name from the xyz file name
45 archive_file_ = job_name_ + ".orb";
46
47 // XML OUTPUT
48 xml_output_ = job_name_ + "_summary.xml";
49
50 if (options.exists(".mpsfile")) {
51 mpsfile_ = options.get(".mpsfile").as<std::string>();
52 }
53
54 // check if guess is requested
55 if (options.exists(".guess")) {
56 guess_file_ = options.get(".guess").as<std::string>();
57 }
58
59 // check if a separate MO-only guess is requested (see this class's
60 // own header comment on moguess_file_ for why this is a distinct
61 // option from .guess, not a variant of it)
62 if (options.exists(".moguess")) {
63 moguess_file_ = options.get(".moguess").as<std::string>();
64 }
65
66 // register all QM packages
68}
69
71
72 log_.setReportLevel(Log::current_level);
73
74 log_.setMultithreading(true);
75 log_.setCommonPreface("\n... ...");
76
77 // Get orbitals object
78 Orbitals orbitals;
79
80 if (!guess_file_.empty()) {
82 << "Reading guess from " << guess_file_ << std::flush;
83 orbitals.ReadFromCpt(guess_file_);
84 } else {
86 << "Reading structure from " << xyzfile_ << std::flush;
87 orbitals.QMAtoms().LoadFromFile(xyzfile_);
88 }
89
90 // Warm-start the MOs from a PREVIOUS geometry step's own, separate
91 // .orb file, while keeping the geometry just loaded above (the
92 // CURRENT step's own xyzfile_, or guess_file_'s geometry if that
93 // path was used instead) -- deliberately independent of guess_file_
94 // itself, which ties geometry and MOs together from the same file
95 // and therefore cannot represent this "new geometry, warm-started
96 // MOs" case a geometry optimization needs between steps. Loaded
97 // into a separate, temporary Orbitals object so only its own
98 // MOs()/MOs_beta() get copied in -- moguess_orbitals's own geometry
99 // (the PREVIOUS step's) is deliberately discarded, never touching
100 // orbitals.QMAtoms() itself.
101 if (!moguess_file_.empty()) {
102 XTP_LOG(Log::error, log_) << "Reading MO guess (geometry unchanged) from "
103 << moguess_file_ << std::flush;
104 Orbitals moguess_orbitals;
105 moguess_orbitals.ReadFromCpt(moguess_file_);
106 orbitals.MOs() = moguess_orbitals.MOs();
107 if (moguess_orbitals.hasBetaMOs()) {
108 orbitals.MOs_beta() = moguess_orbitals.MOs_beta();
109 }
110 // Defensive, likely-redundant given charge/spin (and therefore the
111 // electron counts) should not change between geometry-optimization
112 // steps -- DFTEngine::Evaluate() itself may set these independently
113 // from package_options_ regardless of what orbitals already holds
114 // here. Kept as a safety net rather than removed outright, since
115 // this has not been confirmed either way by tracing through
116 // DFTEngine's own guess-path logic.
118 moguess_orbitals.getNumberOfAlphaElectrons());
120 moguess_orbitals.getNumberOfBetaElectrons());
121 }
122
123 std::unique_ptr<QMPackage> qmpackage =
124 std::unique_ptr<QMPackage>(QMPackageFactory().Create(
125 package_options_.get("name").as<std::string>()));
126 qmpackage->setLog(&log_);
127 qmpackage->Initialize(package_options_);
128 qmpackage->setRunDir(".");
129
130 if (!mpsfile_.empty()) {
131 StaticRegion region(0, log_);
132 StaticSegment seg = StaticSegment("", 0);
134 region.push_back(seg);
135 qmpackage->AddRegion(region);
136 }
137
138 GWBSEEngine gwbse_engine;
139 gwbse_engine.setLog(&log_);
140 gwbse_engine.setQMPackage(qmpackage.get());
142
143 QMMolecule fullMol = orbitals.QMAtoms();
144 gwbse_engine.ExcitationEnergies(orbitals);
145 // If truncation was enabled then rewrite full basis/aux-basis, MOs in full
146 // basis and full QMAtoms
147 if (orbitals.getCalculationType() == "Truncated") {
148 orbitals.QMAtoms().clearAtoms();
149 orbitals.QMAtoms() = fullMol;
150 orbitals.MOs().eigenvectors() = orbitals.getTruncMOsFullBasis();
151 orbitals.SetupDftBasis(orbitals.getDftBasis().Name());
152 if (orbitals.hasAuxbasisName()) {
153 orbitals.SetupAuxBasis(orbitals.getAuxBasis().Name());
154 }
155 }
156
157 XTP_LOG(Log::error, log_) << "Saving data to " << archive_file_ << std::flush;
158 orbitals.WriteToCpt(archive_file_);
159
160 tools::Property summary = gwbse_engine.ReportSummary();
161 if (summary.exists("output")) { // only do gwbse summary output if we
162 // actually did gwbse
164 << "Writing output to " << xml_output_ << std::flush;
165 std::ofstream ofout(xml_output_, std::ofstream::out);
166 ofout << (summary.get("output"));
167 ofout.close();
168 }
169 return true;
170}
171
172} // namespace xtp
173} // namespace votca
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
const std::string & Name() const
Definition aobasis.h:81
void LoadFromFile(std::string filename)
void ParseOptions(const tools::Property &user_options)
Definition dftgwbse.cc:33
std::string guess_file_
Definition dftgwbse.h:47
tools::Property package_options_
Definition dftgwbse.h:63
std::string mpsfile_
Definition dftgwbse.h:57
std::string archive_file_
Definition dftgwbse.h:61
std::string moguess_file_
Definition dftgwbse.h:56
std::string xml_output_
Definition dftgwbse.h:60
tools::Property gwbseengine_options_
Definition dftgwbse.h:64
std::string xyzfile_
Definition dftgwbse.h:59
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
const Eigen::MatrixXd getTruncMOsFullBasis() const
Return truncated active-region orbitals represented in the full AO basis.
Definition orbitals.h:69
bool hasAuxbasisName() const
Report whether an auxiliary basis-set name has been stored.
Definition orbitals.h:356
const tools::EigenSystem & MOs_beta() const
Return read-only access to beta-spin molecular orbitals.
Definition orbitals.h:202
const AOBasis & getAuxBasis() const
Return the auxiliary AO basis, throwing if it has not been initialized.
Definition orbitals.h:339
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
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 tools::EigenSystem & MOs() const
Return read-only access to alpha/restricted molecular orbitals.
Definition orbitals.h:192
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:1201
void WriteToCpt(const std::string &filename) const
Write the orbital container to a checkpoint file on disk.
Definition orbitals.cc:1105
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
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:328
void LoadFromFile(std::string filename)
Definition qmmolecule.cc:45
std::string job_name_
Definition qmtool.h:50
#define XTP_LOG(level, log)
Definition logger.h:40
Charge transport classes.
Definition ERIs.h:28
ClassicalSegment< StaticSite > StaticSegment
Provides a means for comparing floating point numbers.
Definition basebead.h:33
static Level current_level
Definition globals.h:30