votca 2024.1-dev
Loading...
Searching...
No Matches
esp2multipole.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 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/format.hpp>
22#include <utility>
23
24// Local VOTCA includes
26#include "votca/xtp/espfit.h"
27#include "votca/xtp/nbo.h"
29
30namespace votca {
31namespace xtp {
32using std::flush;
33
35 do_svd_ = false;
36
37 use_mulliken_ = false;
38 use_CHELPG_ = false;
39 use_lowdin_ = false;
40 state_ = options.get(".state").as<QMState>();
41
42 method_ = options.get(".method").as<std::string>();
43
44 if (method_ == "mulliken") {
45 use_mulliken_ = true;
46 } else if (method_ == "loewdin") {
47 use_lowdin_ = true;
48 } else if (method_ == "CHELPG") {
49 use_CHELPG_ = true;
50 }
51
52 if (options.exists(".constraints")) {
53 std::vector<tools::Property*> prop_region =
54 options.Select(".constraints.region");
55 Index index = 0;
56 for (tools::Property* prop : prop_region) {
57 std::string indices = prop->get("indices").as<std::string>();
58 QMFragment<double> reg = QMFragment<double>(index, indices);
59 index++;
60 reg.value() = prop->get("charge").as<double>();
61 regionconstraint_.push_back(reg);
62 XTP_LOG(Log::error, log_) << "Fit constrained by Region" << flush;
63 XTP_LOG(Log::error, log_) << reg;
64 }
65 std::vector<tools::Property*> prop_pair =
66 options.Select(".constraints.pair");
67 for (tools::Property* prop : prop_pair) {
68 std::vector<Index> pairvec = prop->as<std::vector<Index>>();
69 pairconstraint_.emplace_back(pairvec[0], pairvec[1]);
70 XTP_LOG(Log::error, log_) << "Charges " << pairvec[0] << " " << pairvec[1]
71 << " constrained to be equal." << flush;
72 }
73 }
74
75 gridsize_ = options.get(".gridsize").as<std::string>();
76
77 if (options.exists(".svd")) {
78 do_svd_ = true;
79 conditionnumber_ = options.get(".svd.conditionnumber").as<double>();
80 }
81
82 return;
83}
84
86 const StaticSegment& seg) const {
87 Eigen::Vector3d classical_dip = seg.CalcDipole();
88
90 << "El Dipole from fitted charges [e*bohr]:\n\t\t"
91 << boost::format(
92 " dx = %1$+1.4f dy = %2$+1.4f dz = %3$+1.4f |d|^2 = %4$+1.4f") %
93 classical_dip.x() % classical_dip.y() % classical_dip.z() %
94 classical_dip.squaredNorm()
95 << flush;
96 Eigen::Vector3d qm_dip = orbitals.CalcElDipole(state_);
98 << "El Dipole from exact qm density [e*bohr]:\n\t\t"
99 << boost::format(
100 " dx = %1$+1.4f dy = %2$+1.4f dz = %3$+1.4f |d|^2 = %4$+1.4f") %
101 qm_dip.x() % qm_dip.y() % qm_dip.z() % qm_dip.squaredNorm()
102 << flush;
103}
104
106 XTP_LOG(Log::error, log_) << "===== Running on " << OPENMP::getMaxThreads()
107 << " threads ===== " << flush;
108 StaticSegment result("result", 0);
109 if (use_mulliken_) {
110 Mulliken mulliken;
111 result = mulliken.CalcChargeperAtom(orbitals, state_);
112 } else if (use_lowdin_) {
113 Lowdin lowdin;
114 result = lowdin.CalcChargeperAtom(orbitals, state_);
115 } else if (use_CHELPG_) {
116 Espfit esp = Espfit(log_);
117 if (pairconstraint_.size() > 0) {
119 }
120 if (regionconstraint_.size() > 0) {
122 }
123
124 if (do_svd_) {
126 }
127 result = esp.Fit2Density(orbitals, state_, gridsize_);
128 }
129
130 PrintDipoles(orbitals, result);
131 return result;
132}
133
134} // namespace xtp
135} // 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
bool exists(const std::string &key) const
check whether property exists
Definition property.cc:122
T as() const
return value as type
Definition property.h:283
std::vector< Property * > Select(const std::string &filter)
select property based on a filter
Definition property.cc:185
Eigen::Vector3d CalcDipole() const
std::vector< std::pair< Index, Index > > pairconstraint_
std::vector< QMFragment< double > > regionconstraint_
void Initialize(tools::Property &options)
void PrintDipoles(const Orbitals &orbitals, const StaticSegment &seg) const
StaticSegment Extractingcharges(const Orbitals &orbitals) const
void setRegionConstraint(std::vector< QMFragment< double > > regionconstraint)
Definition espfit.h:56
void setUseSVD(double conditionnumber)
Definition espfit.h:47
StaticSegment Fit2Density(const Orbitals &orbitals, const QMState &state, std::string gridsize)
Definition espfit.cc:35
void setPairConstraint(std::vector< std::pair< Index, Index > > pairconstraint)
Definition espfit.h:52
container for molecular orbitals
Definition orbitals.h:46
Eigen::Vector3d CalcElDipole(const QMState &state) const
Definition orbitals.cc:242
StaticSegment CalcChargeperAtom(const Orbitals &orbitals, const QMState &state) const
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
#define XTP_LOG(level, log)
Definition logger.h:40
Index getMaxThreads()
Definition eigen.h:128
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26