votca 2024.2-dev
Loading...
Searching...
No Matches
qmpackage.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2022 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// Third party includes
21#include <boost/algorithm/string.hpp>
22
23// Local VOTCA includes
24#include "votca/tools/getline.h"
25#include "votca/tools/globals.h"
27#include "votca/xtp/orbitals.h"
28#include "votca/xtp/qmpackage.h"
30
31namespace votca {
32namespace xtp {
33using std::flush;
34
36 charge_ = options.get("charge").as<Index>();
37 spin_ = options.get("spin").as<Index>();
38 basisset_name_ = options.get("basisset").as<std::string>();
39
40 cleanup_ = options.get("cleanup").as<std::string>();
41 scratch_dir_ = options.get("scratch").as<std::string>();
42
43 options_ = options;
44
45 ParseSpecificOptions(options);
46}
47
49 std::chrono::time_point<std::chrono::system_clock> start =
50 std::chrono::system_clock::now();
51
52 bool error_value = RunDFT();
53
54 std::chrono::duration<double> elapsed_time =
55 std::chrono::system_clock::now() - start;
56 XTP_LOG(Log::error, *pLog_) << TimeStamp() << " DFT calculation took "
57 << elapsed_time.count() << " seconds." << flush;
58 return error_value;
59}
60
62 std::chrono::time_point<std::chrono::system_clock> start =
63 std::chrono::system_clock::now();
64
65 bool error_value = RunActiveDFT();
66
67 std::chrono::duration<double> elapsed_time =
68 std::chrono::system_clock::now() - start;
69 XTP_LOG(Log::error, *pLog_) << TimeStamp() << " DFT in DFT embedding took "
70 << elapsed_time.count() << " seconds." << flush;
71 return error_value;
72}
73
74void QMPackage::ReorderOutput(Orbitals& orbitals) const {
75 if (!orbitals.hasQMAtoms()) {
76 throw std::runtime_error("Orbitals object has no QMAtoms");
77 }
78
79 AOBasis dftbasis = orbitals.getDftBasis();
80 // necessary to update nuclear charges on qmatoms
81 if (orbitals.hasECPName()) {
82 ECPBasisSet ecps;
83 ecps.Load(orbitals.getECPName());
84 ECPAOBasis ecpbasis;
85 ecpbasis.Fill(ecps, orbitals.QMAtoms());
86 }
87
88 if (orbitals.hasMOs()) {
90 reorder.reorderOrbitals(orbitals.MOs().eigenvectors(), dftbasis);
91 XTP_LOG(Log::info, *pLog_) << "Reordered MOs" << flush;
92 }
93
94 return;
95}
96
97Eigen::MatrixXd QMPackage::ReorderMOsBack(const Orbitals& orbitals) const {
98 if (!orbitals.hasQMAtoms()) {
99 throw std::runtime_error("Orbitals object has no QMAtoms");
100 }
101 AOBasis dftbasis = orbitals.getDftBasis();
102 Eigen::MatrixXd result = orbitals.MOs().eigenvectors();
103 bool reverseOrder = true;
104 OrbReorder reorder(ShellReorder(), ShellMulitplier(), reverseOrder);
105 reorder.reorderOrbitals(result, dftbasis);
106 return result;
107}
108
109std::vector<QMPackage::MinimalMMCharge> QMPackage::SplitMultipoles(
110 const StaticSite& aps) const {
111
112 std::vector<QMPackage::MinimalMMCharge> multipoles_split;
113 // Calculate virtual charge positions
114 double a = options_.get("dipole_spacing").as<double>(); // this is in a0
115 double mag_d = aps.getDipole().norm(); // this is in e * a0
116 const Eigen::Vector3d dir_d = aps.getDipole().normalized();
117 const Eigen::Vector3d A = aps.getPos() + 0.5 * a * dir_d;
118 const Eigen::Vector3d B = aps.getPos() - 0.5 * a * dir_d;
119 double qA = mag_d / a;
120 double qB = -qA;
121 if (std::abs(qA) > 1e-12) {
122 multipoles_split.push_back(MinimalMMCharge(A, qA));
123 multipoles_split.push_back(MinimalMMCharge(B, qB));
124 }
125
126 if (aps.getRank() > 1) {
127 const Eigen::Matrix3d components = aps.CalculateCartesianMultipole();
128 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es;
129 es.computeDirect(components);
130 double a2 = 2 * a;
131 for (Index i = 0; i < 3; i++) {
132 double q = es.eigenvalues()[i] / (a2 * a2);
133 const Eigen::Vector3d vec1 =
134 aps.getPos() + 0.5 * a2 * es.eigenvectors().col(i);
135 const Eigen::Vector3d vec2 =
136 aps.getPos() - 0.5 * a2 * es.eigenvectors().col(i);
137 multipoles_split.push_back(MinimalMMCharge(vec1, q));
138 multipoles_split.push_back(MinimalMMCharge(vec2, q));
139 }
140 }
141 return multipoles_split;
142}
143
144std::vector<std::string> QMPackage::GetLineAndSplit(
145 std::ifstream& input_file, const std::string separators) const {
146 std::string line;
147 tools::getline(input_file, line);
148 boost::trim(line);
149 return tools::Tokenizer(line, separators).ToVector();
150}
151
152} // namespace xtp
153} // 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
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
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
Container to hold ECPs for all atoms.
Definition ecpaobasis.h:43
std::vector< std::string > Fill(const ECPBasisSet &bs, QMMolecule &atoms)
Definition ecpaobasis.cc:69
void Load(const std::string &name)
void reorderOrbitals(Eigen::MatrixXd &moCoefficients, const AOBasis &basis)
Definition orbreorder.cc:74
container for molecular orbitals
Definition orbitals.h:46
bool hasMOs() const
Definition orbitals.h:117
bool hasQMAtoms() const
Definition orbitals.h:170
bool hasECPName() const
Definition orbitals.h:102
const tools::EigenSystem & MOs() const
Definition orbitals.h:122
const QMMolecule & QMAtoms() const
Definition orbitals.h:172
const std::string & getECPName() const
Definition orbitals.h:104
const AOBasis & getDftBasis() const
Definition orbitals.h:208
virtual const std::array< Index, 49 > & ShellReorder() const =0
std::vector< std::string > GetLineAndSplit(std::ifstream &input_file, const std::string separators) const
Definition qmpackage.cc:144
Eigen::MatrixXd ReorderMOsBack(const Orbitals &orbitals) const
Definition qmpackage.cc:97
std::vector< MinimalMMCharge > SplitMultipoles(const StaticSite &site) const
Definition qmpackage.cc:109
virtual void ParseSpecificOptions(const tools::Property &options)=0
virtual bool RunDFT()=0
virtual bool RunActiveDFT()=0
std::string basisset_name_
Definition qmpackage.h:132
std::string cleanup_
Definition qmpackage.h:133
void Initialize(const tools::Property &options)
Definition qmpackage.cc:35
virtual const std::array< Index, 49 > & ShellMulitplier() const =0
tools::Property options_
Definition qmpackage.h:140
std::string scratch_dir_
Definition qmpackage.h:138
void ReorderOutput(Orbitals &orbitals) const
Definition qmpackage.cc:74
Class to represent Atom/Site in electrostatic.
Definition staticsite.h:37
Eigen::Matrix3d CalculateCartesianMultipole() const
Definition staticsite.cc:37
virtual Eigen::Vector3d getDipole() const
Definition staticsite.h:105
const Eigen::Vector3d & getPos() const
Definition staticsite.h:80
Index getRank() const
Definition staticsite.h:78
Timestamp returns the current time as a string Example: cout << TimeStamp()
Definition logger.h:224
#define XTP_LOG(level, log)
Definition logger.h:40
std::istream & getline(std::istream &is, std::string &str)
Wrapper for a getline function.
Definition getline.h:35
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26