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
39 const std::string job_name = options.get("temporary_file").as<std::string>();
40 log_file_name_ = job_name + ".orb";
42}
43
44bool XTPDFT::WriteInputFile(const Orbitals& orbitals) {
45 orbitals_ = orbitals;
46 orbitals_.setQMpackage(getPackageName());
47 orbitals_.setChargeAndSpin(charge_, spin_);
48 return true;
49}
50
55 DFTEngine xtpdft;
56 xtpdft.Initialize(options_);
57 xtpdft.setLogger(pLog_);
59
60 if (!externalsites_.empty()) {
62 }
63 if (has_ewaldgrid_) {
67 }
68 }
69
70 if (setup_cache_) {
71 xtpdft.setSetupCache(setup_cache_.get());
72 }
74
75 bool success = xtpdft.Evaluate(orbitals_);
76 xtpdft.ReturnSetupCache();
77 std::string file_name = run_dir_ + "/" + log_file_name_;
79 << "Writing result to " << log_file_name_ << flush;
80 orbitals_.WriteToCpt(file_name);
81 return success;
82}
83
85 DFTEngine xtpdft;
86 xtpdft.Initialize(options_);
87 xtpdft.setLogger(pLog_);
88
89 if (!externalsites_.empty()) {
91 }
92
93 bool success = xtpdft.EvaluateActiveRegion(orbitals_) &&
95 std::string file_name = run_dir_ + "/" + log_file_name_;
97 << "Writing embedding result to " << log_file_name_ << flush;
98 orbitals_.WriteToCpt(file_name);
99 return success;
100}
101
103 if (cleanup_.size() != 0) {
104 XTP_LOG(Log::info, *pLog_) << "Removing " << cleanup_ << " files" << flush;
105 std::vector<std::string> cleanup_info =
107 for (const std::string& substring : cleanup_info) {
108 if (substring == "log") {
109 std::string file_name = run_dir_ + "/" + log_file_name_;
110 remove(file_name.c_str());
111 }
112 }
113 }
114
115 return;
116}
117
121bool XTPDFT::ParseMOsFile(Orbitals&) { return true; }
122
124 try {
125 std::string file_name = run_dir_ + "/" + log_file_name_;
126 orbitals.ReadFromCpt(file_name);
127 XTP_LOG(Log::info, *pLog_) << (boost::format("QM energy[Hrt]: %4.8f ") %
128 orbitals.getDFTTotalEnergy())
129 .str()
130 << flush;
131 } catch (std::runtime_error& error) {
133 << "Reading" << log_file_name_ << " failed" << flush;
134 return false;
135 }
136 return true;
137}
138
139} // namespace xtp
140} // 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:95
void setWarmStart(bool warm_start)
Definition dftengine.h:126
void setExternalcharges(std::vector< std::unique_ptr< StaticSite > > *externalsites)
Definition dftengine.h:105
bool EvaluateTruncatedActiveRegion(Orbitals &trunc_orb)
void setEwaldgrid(const Vxc_Grid &ewaldgrid)
Definition dftengine.h:110
void setSCFToleranceFloor(double energy, double error)
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:101
bool EvaluateActiveRegion(Orbitals &orb)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:102
void setEwaldNuclearEnergy(double energy)
Definition dftengine.h:120
bool Evaluate(Orbitals &orb)
Definition dftengine.cc:970
void setSetupCache(DFTSetupCache *cache)
Definition dftengine.h:131
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
double getDFTTotalEnergy() const
Return the stored total DFT energy.
Definition orbitals.h:292
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:1215
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:123
Orbitals orbitals_
Definition xtpdft.h:119
double scf_error_floor_
Definition xtpdft.h:117
double scf_energy_floor_
Definition xtpdft.h:116
bool RunDFT() final
Definition xtpdft.cc:54
void ParseSpecificOptions(const tools::Property &options) final
Definition xtpdft.cc:38
void CleanUp() final
Definition xtpdft.cc:102
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:44
std::shared_ptr< DFTSetupCache > setup_cache_
Definition xtpdft.h:115
bool ParseMOsFile(Orbitals &orbitals) final
Definition xtpdft.cc:121
bool RunActiveDFT() final
Definition xtpdft.cc:84
#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