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 bool success = xtpdft.Evaluate(orbitals_);
64 std::string file_name = run_dir_ + "/" + log_file_name_;
66 << "Writing result to " << log_file_name_ << flush;
67 orbitals_.WriteToCpt(file_name);
68 return success;
69}
70
72 DFTEngine xtpdft;
73 xtpdft.Initialize(options_);
74 xtpdft.setLogger(pLog_);
75
76 if (!externalsites_.empty()) {
78 }
79
80 bool success = xtpdft.EvaluateActiveRegion(orbitals_) &&
82 std::string file_name = run_dir_ + "/" + log_file_name_;
84 << "Writing embedding result to " << log_file_name_ << flush;
85 orbitals_.WriteToCpt(file_name);
86 return success;
87}
88
90 if (cleanup_.size() != 0) {
91 XTP_LOG(Log::info, *pLog_) << "Removing " << cleanup_ << " files" << flush;
92 std::vector<std::string> cleanup_info =
94 for (const std::string& substring : cleanup_info) {
95 if (substring == "log") {
96 std::string file_name = run_dir_ + "/" + log_file_name_;
97 remove(file_name.c_str());
98 }
99 }
100 }
101
102 return;
103}
104
108bool XTPDFT::ParseMOsFile(Orbitals&) { return true; }
109
111 try {
112 std::string file_name = run_dir_ + "/" + log_file_name_;
113 orbitals.ReadFromCpt(file_name);
114 XTP_LOG(Log::info, *pLog_) << (boost::format("QM energy[Hrt]: %4.8f ") %
115 orbitals.getDFTTotalEnergy())
116 .str()
117 << flush;
118 } catch (std::runtime_error& error) {
120 << "Reading" << log_file_name_ << " failed" << flush;
121 return false;
122 }
123 return true;
124}
125
126} // namespace xtp
127} // 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:54
void setExternalcharges(std::vector< std::unique_ptr< StaticSite > > *externalsites)
Definition dftengine.h:64
bool EvaluateTruncatedActiveRegion(Orbitals &trunc_orb)
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:60
bool EvaluateActiveRegion(Orbitals &orb)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:60
bool Evaluate(Orbitals &orb)
Definition dftengine.cc:303
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:289
void ReadFromCpt(const std::string &filename)
Read the orbital container from a checkpoint file on disk.
Definition orbitals.cc:770
std::string log_file_name_
Definition qmpackage.h:135
std::string run_dir_
Definition qmpackage.h:137
std::vector< std::unique_ptr< StaticSite > > externalsites_
Definition qmpackage.h:144
std::string mo_file_name_
Definition qmpackage.h:136
std::string cleanup_
Definition qmpackage.h:133
tools::Property options_
Definition qmpackage.h:140
bool ParseLogFile(Orbitals &orbitals) final
Definition xtpdft.cc:110
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:89
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:108
bool RunActiveDFT() final
Definition xtpdft.cc:71
#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