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/filesystem.hpp>
27#include <boost/format.hpp>
28
29// VOTCA includes
31
32// Local private VOTCA includes
33#include "xtpdft.h"
34
35namespace votca {
36namespace xtp {
37using namespace std;
38
40 const std::string job_name = options.get("temporary_file").as<std::string>();
41 log_file_name_ = job_name + ".orb";
43}
44
45bool XTPDFT::WriteInputFile(const Orbitals& orbitals) {
46 orbitals_ = orbitals;
47 orbitals_.setQMpackage(getPackageName());
48 orbitals_.setChargeAndSpin(charge_, spin_);
49 return true;
50}
51
56 DFTEngine xtpdft;
57 xtpdft.Initialize(options_);
58 xtpdft.setLogger(pLog_);
59
60 if (!externalsites_.empty()) {
62 }
63 if (has_ewaldgrid_) {
67 }
68 }
69
70 bool success = xtpdft.Evaluate(orbitals_);
71 std::string file_name = run_dir_ + "/" + log_file_name_;
73 << "Writing result to " << log_file_name_ << flush;
74 orbitals_.WriteToCpt(file_name);
75 return success;
76}
77
79 DFTEngine xtpdft;
80 xtpdft.Initialize(options_);
81 xtpdft.setLogger(pLog_);
82
83 if (!externalsites_.empty()) {
85 }
86
87 bool success = xtpdft.EvaluateActiveRegion(orbitals_) &&
89 std::string file_name = run_dir_ + "/" + log_file_name_;
91 << "Writing embedding result to " << log_file_name_ << flush;
92 orbitals_.WriteToCpt(file_name);
93 return success;
94}
95
97 if (cleanup_.size() != 0) {
98 XTP_LOG(Log::info, *pLog_) << "Removing " << cleanup_ << " files" << flush;
99 std::vector<std::string> cleanup_info =
101 for (const std::string& substring : cleanup_info) {
102 if (substring == "log") {
103 std::string file_name = run_dir_ + "/" + log_file_name_;
104 remove(file_name.c_str());
105 }
106 }
107 }
108
109 return;
110}
111
115bool XTPDFT::ParseMOsFile(Orbitals&) { return true; }
116
118 try {
119 std::string file_name = run_dir_ + "/" + log_file_name_;
120 orbitals.ReadFromCpt(file_name);
121 XTP_LOG(Log::info, *pLog_) << (boost::format("QM energy[Hrt]: %4.8f ") %
122 orbitals.getDFTTotalEnergy())
123 .str()
124 << flush;
125 } catch (std::runtime_error& error) {
127 << "Reading" << log_file_name_ << " failed" << flush;
128 return false;
129 }
130 return true;
131}
132
133} // namespace xtp
134} // 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:74
void setExternalcharges(std::vector< std::unique_ptr< StaticSite > > *externalsites)
Definition dftengine.h:84
bool EvaluateTruncatedActiveRegion(Orbitals &trunc_orb)
void setEwaldgrid(const Vxc_Grid &ewaldgrid)
Definition dftengine.h:89
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:80
bool EvaluateActiveRegion(Orbitals &orb)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:101
void setEwaldNuclearEnergy(double energy)
Definition dftengine.h:99
bool Evaluate(Orbitals &orb)
Definition dftengine.cc:911
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:1201
std::string log_file_name_
Definition qmpackage.h:150
std::string run_dir_
Definition qmpackage.h:152
std::vector< std::unique_ptr< StaticSite > > externalsites_
Definition qmpackage.h:159
std::string mo_file_name_
Definition qmpackage.h:151
std::string cleanup_
Definition qmpackage.h:148
tools::Property options_
Definition qmpackage.h:155
bool ParseLogFile(Orbitals &orbitals) final
Definition xtpdft.cc:117
Orbitals orbitals_
Definition xtpdft.h:105
bool RunDFT() final
Definition xtpdft.cc:55
void ParseSpecificOptions(const tools::Property &options) final
Definition xtpdft.cc:39
void CleanUp() final
Definition xtpdft.cc:96
std::string getPackageName() const final
Definition xtpdft.h:45
bool WriteInputFile(const Orbitals &orbitals) final
writes a coordinate file WITHOUT taking into account PBCs
Definition xtpdft.cc:45
bool ParseMOsFile(Orbitals &orbitals) final
Definition xtpdft.cc:115
bool RunActiveDFT() final
Definition xtpdft.cc:78
#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