votca 2026-dev
Loading...
Searching...
No Matches
xtpdft.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 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 <cstdio>
22#include <iomanip>
23
24// Third party includes
25#include <boost/algorithm/string.hpp>
26#include <boost/format.hpp>
27
28// VOTCA includes
30
31// Local private VOTCA includes
32#include "xtpdft.h"
33
34namespace votca {
35namespace xtp {
36using namespace std;
37
38Eigen::Matrix3d XTPDFT::GetPolarizability() const {
39 const std::string file = run_dir_ + "/" + log_file_name_;
40 Orbitals orb;
41 orb.ReadFromCpt(file);
42 if (!orb.hasPolarizability()) {
43 throw std::runtime_error(file +
44 " contains no polarizability; run xtpdft with "
45 "dftpackage.xtpdft.polarizability=true");
46 }
47 XTP_LOG(Log::error, *pLog_) << "Polarizability read from " << file << flush;
48 return orb.getPolarizability();
49}
50
52 const std::string job_name = options.get("temporary_file").as<std::string>();
53 log_file_name_ = job_name + ".orb";
55}
56
57bool XTPDFT::WriteInputFile(const Orbitals& orbitals) {
58 orbitals_ = orbitals;
59 orbitals_.setQMpackage(getPackageName());
60 orbitals_.setChargeAndSpin(charge_, spin_);
61 return true;
62}
63
68 DFTEngine xtpdft;
69 xtpdft.Initialize(options_);
70 xtpdft.setLogger(pLog_);
72
73 if (!externalsites_.empty()) {
75 }
76 if (has_ewaldgrid_) {
80 }
81 }
82
83 if (setup_cache_) {
84 xtpdft.setSetupCache(setup_cache_.get());
85 }
87
88 bool success = xtpdft.Evaluate(orbitals_);
89 xtpdft.ReturnSetupCache();
90 std::string file_name = run_dir_ + "/" + log_file_name_;
92 << "Writing result to " << log_file_name_ << flush;
93 orbitals_.WriteToCpt(file_name);
94 return success;
95}
96
98 DFTEngine xtpdft;
99 xtpdft.Initialize(options_);
100 xtpdft.setLogger(pLog_);
101
102 if (!externalsites_.empty()) {
104 }
105
106 bool success = xtpdft.EvaluateActiveRegion(orbitals_) &&
108 std::string file_name = run_dir_ + "/" + log_file_name_;
110 << "Writing embedding result to " << log_file_name_ << flush;
111 orbitals_.WriteToCpt(file_name);
112 return success;
113}
114
116 if (cleanup_.size() != 0) {
117 XTP_LOG(Log::info, *pLog_) << "Removing " << cleanup_ << " files" << flush;
118 std::vector<std::string> cleanup_info =
120 for (const std::string& substring : cleanup_info) {
121 if (substring == "log") {
122 std::string file_name = run_dir_ + "/" + log_file_name_;
123 remove(file_name.c_str());
124 }
125 }
126 }
127
128 return;
129}
130
134bool XTPDFT::ParseMOsFile(Orbitals&) { return true; }
135
137 try {
138 std::string file_name = run_dir_ + "/" + log_file_name_;
139 orbitals.ReadFromCpt(file_name);
140 XTP_LOG(Log::info, *pLog_) << (boost::format("QM energy[Hrt]: %4.8f ") %
141 orbitals.getDFTTotalEnergy())
142 .str()
143 << flush;
144 } catch (std::runtime_error& error) {
146 << "Reading" << log_file_name_ << " failed" << flush;
147 return false;
148 }
149 return true;
150}
151
152} // namespace xtp
153} // namespace votca
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
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
Electronic ground-state via Density-Functional Theory.
Definition dftengine.h:88
void setWarmStart(bool warm_start)
Definition dftengine.h:119
void setExternalcharges(std::vector< std::unique_ptr< StaticSite > > *externalsites)
Definition dftengine.h:98
bool EvaluateTruncatedActiveRegion(Orbitals &trunc_orb)
void setEwaldgrid(const Vxc_Grid &ewaldgrid)
Definition dftengine.h:103
void setSCFToleranceFloor(double energy, double error)
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:94
bool EvaluateActiveRegion(Orbitals &orb)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:99
void setEwaldNuclearEnergy(double energy)
Definition dftengine.h:113
bool Evaluate(Orbitals &orb)
Definition dftengine.cc:814
void setSetupCache(DFTSetupCache *cache)
Definition dftengine.h:124
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
bool hasPolarizability() const
Definition orbitals.h:305
double getDFTTotalEnergy() const
Return the stored total DFT energy.
Definition orbitals.h:292
Eigen::Matrix3d getPolarizability() const
Definition orbitals.h:306
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1222
std::string log_file_name_
Definition qmpackage.h:170
std::string run_dir_
Definition qmpackage.h:172
std::vector< std::unique_ptr< StaticSite > > externalsites_
Definition qmpackage.h:179
std::string mo_file_name_
Definition qmpackage.h:171
std::string cleanup_
Definition qmpackage.h:168
tools::Property options_
Definition qmpackage.h:175
bool ParseLogFile(Orbitals &orbitals) final
Definition xtpdft.cc:136
Orbitals orbitals_
Definition xtpdft.h:118
double scf_error_floor_
Definition xtpdft.h:116
Eigen::Matrix3d GetPolarizability() const final
Definition xtpdft.cc:38
double scf_energy_floor_
Definition xtpdft.h:115
bool RunDFT() final
Definition xtpdft.cc:67
void ParseSpecificOptions(const tools::Property &options) final
Definition xtpdft.cc:51
void CleanUp() final
Definition xtpdft.cc:115
std::string getPackageName() const final
Definition xtpdft.h:46
bool WriteInputFile(const Orbitals &orbitals) final
writes a coordinate file WITHOUT taking into account PBCs
Definition xtpdft.cc:57
std::shared_ptr< DFTSetupCache > setup_cache_
Definition xtpdft.h:114
bool ParseMOsFile(Orbitals &orbitals) final
Definition xtpdft.cc:134
bool RunActiveDFT() final
Definition xtpdft.cc:97
#define XTP_LOG(level, log)
Definition logger.h:40
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33