votca 2026-dev
Loading...
Searching...
No Matches
polarsite.h
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#pragma once
21#ifndef VOTCA_XTP_POLARSITE_H
22#define VOTCA_XTP_POLARSITE_H
23
24// Local VOTCA includes
25#include "eigen.h"
26#include "staticsite.h"
27
28namespace votca {
29namespace xtp {
30
36class PolarSite final : public StaticSite {
37
38 public:
39 // delete these two functions because we do not want to be able to read
40 // StaticSite::data but PolarSite::data
41 void WriteData(StaticSite::data& d) const = delete;
42 void ReadData(StaticSite::data& d) = delete;
43
44 PolarSite(Index id, std::string element, Eigen::Vector3d pos);
45 PolarSite(Index id, std::string element)
46 : PolarSite(id, element, Eigen::Vector3d::Zero()) {};
47
48 ~PolarSite() final = default;
49
50 void setpolarization(const Eigen::Matrix3d& pol) final;
51
52 Eigen::Matrix3d getpolarization() const { return pinv_.inverse(); }
53
54 const Eigen::Matrix3d& getPInv() const { return pinv_; }
55
56 // MULTIPOLES DEFINITION
57 Eigen::Vector3d getDipole() const final;
58 Eigen::Vector3d getStaticDipole() const final;
59 Eigen::Vector3d getInducedDipole() const final;
60
61 double getSqrtInvEigenDamp() const { return eigendamp_invsqrt_; }
62
63 void Rotate(const Eigen::Matrix3d& R, const Eigen::Vector3d& ref_pos) final {
64 StaticSite::Rotate(R, ref_pos);
65 pinv_ = R.transpose() * pinv_ * R;
66 }
67
68 const Eigen::Vector3d& V() const { return V_; }
69
70 Eigen::Vector3d& V() { return V_; }
71
72 const Eigen::Vector3d& V_noE() const { return V_noE_; }
73
74 Eigen::Vector3d& V_noE() { return V_noE_; }
75
76 // Electrostatic potential at the site, accumulated like V() and V_noE()
77 // (same split by region); only used by charge-response sites.
78 double Phi() const { return phi_; }
79 double& Phi() { return phi_; }
80 double Phi_noE() const { return phi_noE_; }
81 double& Phi_noE() { return phi_noE_; }
82
83 void Reset() {
84 V_.setZero();
85 V_noE_.setZero();
86 phi_ = 0.0;
87 phi_noE_ = 0.0;
88 }
89
90 void Depolarize() {
91 this->Reset();
92 this->setInduced_Dipole(Eigen::Vector3d::Zero());
93 induced_charge_ = 0.0;
94 }
95
96 double deltaQ_V_ext() const {
97 return induced_dipole_.dot(V_) + induced_charge_ * phi_;
98 }
99
100 // Charge-response site (see ChargeResponse): besides its induced dipole
101 // (the residual polarizability) it carries an induced charge, and for
102 // induced-induced and QM couplings both are Gaussians of width
103 // CRWidth() (bohr, density ~ exp(-r^2/s^2)). Dipole-dipole couplings
104 // with a charge-response site use Thole damping instead of the Gaussian
105 // kernel if CRTholeDipoles(). Ordinary (Thole) sites are points.
106 bool isChargeResponse() const { return cr_; }
107 double CRWidth() const { return cr_width_; }
108 bool CRTholeDipoles() const { return cr_thole_dipoles_; }
109 void setChargeResponse(double width, bool thole_dipoles) {
110 cr_ = true;
111 cr_width_ = width;
112 cr_thole_dipoles_ = thole_dipoles;
113 }
114 double Induced_Charge() const { return induced_charge_; }
115 void setInduced_Charge(double dq) { induced_charge_ = dq; }
116
117 double InternalEnergy() const {
118 return 0.5 * induced_dipole_.transpose() * pinv_ * induced_dipole_;
119 }
120
121 const Eigen::Vector3d& Induced_Dipole() const { return induced_dipole_; }
122 void setInduced_Dipole(const Eigen::Vector3d& induced_dipole) {
123 induced_dipole_ = induced_dipole;
124 }
125
126 struct data {
128 char* element;
129 double posX;
130 double posY;
131 double posZ;
132
134
135 double Q00;
136 double Q11c;
137 double Q11s;
138 double Q10;
139 double Q20;
140 double Q21c;
141 double Q21s;
142 double Q22c;
143 double Q22s;
144
145 double Vx;
146 double Vy;
147 double Vz;
148
149 double Vx_noE;
150 double Vy_noE;
151 double Vz_noE;
152
153 double pxx;
154 double pxy;
155 double pxz;
156 double pyy;
157 double pyz;
158 double pzz;
159
160 double d_x_ind;
161 double d_y_ind;
162 double d_z_ind;
163 };
164 // do not move up has to be below data definition
165 PolarSite(const data& d);
166
167 double DipoleChange() const;
168
169 static void SetupCptTable(CptTable& table);
170 void WriteData(data& d) const;
171 void ReadData(const data& d);
172
173 std::string identify() const final { return "polarsite"; }
174
175 friend std::ostream& operator<<(std::ostream& out, const PolarSite& site) {
176 out << site.getId() << " " << site.getElement() << " " << site.getRank();
177 out << " " << site.getPos().transpose() << " "
178 << site.Induced_Dipole().transpose() << "\n";
179 return out;
180 }
181
182 private:
183 std::string writepolarization() const final;
184
185 // PolarSite has two external fields,
186 // the first is used for interaction with regions, which are further out, i.e.
187 // the interaction energy with it is included in the polar region energy
188 Eigen::Vector3d V_ = Eigen::Vector3d::Zero();
189 // the second is used for interaction with regions, which are further inside,
190 // i.e. the interaction energy with it is included in the other region's
191 // energy
192 Eigen::Vector3d V_noE_ = Eigen::Vector3d::Zero();
193
194 Eigen::Vector3d induced_dipole_ = Eigen::Vector3d::Zero();
195 Eigen::Matrix3d pinv_ = Eigen::Matrix3d::Zero();
196 double eigendamp_invsqrt_ = 0.0;
197
198 // potentials belonging to V_ and V_noE_ (charge-response sites)
199 double phi_ = 0.0;
200 double phi_noE_ = 0.0;
201 bool cr_ = false;
202 double cr_width_ = 0.0;
203 bool cr_thole_dipoles_ = false;
204 double induced_charge_ = 0.0;
205};
206
207} // namespace xtp
208} // namespace votca
209
210#endif // VOTCA_XTP_POLARSITE_H
Eigen::Vector3d & V_noE()
Definition polarsite.h:74
double DipoleChange() const
double deltaQ_V_ext() const
Definition polarsite.h:96
double getSqrtInvEigenDamp() const
Definition polarsite.h:61
double InternalEnergy() const
Definition polarsite.h:117
void setInduced_Dipole(const Eigen::Vector3d &induced_dipole)
Definition polarsite.h:122
const Eigen::Matrix3d & getPInv() const
Definition polarsite.h:54
PolarSite(Index id, std::string element, Eigen::Vector3d pos)
Definition polarsite.cc:39
const Eigen::Vector3d & Induced_Dipole() const
Definition polarsite.h:121
static void SetupCptTable(CptTable &table)
Definition polarsite.cc:79
double CRWidth() const
Definition polarsite.h:107
friend std::ostream & operator<<(std::ostream &out, const PolarSite &site)
Definition polarsite.h:175
PolarSite(Index id, std::string element)
Definition polarsite.h:45
const Eigen::Vector3d & V_noE() const
Definition polarsite.h:72
bool CRTholeDipoles() const
Definition polarsite.h:108
void WriteData(StaticSite::data &d) const =delete
void Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &ref_pos) final
Definition polarsite.h:63
Eigen::Vector3d V_noE_
Definition polarsite.h:192
Eigen::Vector3d induced_dipole_
Definition polarsite.h:194
void setChargeResponse(double width, bool thole_dipoles)
Definition polarsite.h:109
double Phi_noE() const
Definition polarsite.h:80
void setpolarization(const Eigen::Matrix3d &pol) final
Definition polarsite.cc:62
Eigen::Matrix3d getpolarization() const
Definition polarsite.h:52
std::string identify() const final
Definition polarsite.h:173
bool isChargeResponse() const
Definition polarsite.h:106
Eigen::Matrix3d pinv_
Definition polarsite.h:195
Eigen::Vector3d getStaticDipole() const final
Definition polarsite.cc:58
const Eigen::Vector3d & V() const
Definition polarsite.h:68
Eigen::Vector3d getInducedDipole() const final
Definition polarsite.cc:60
std::string writepolarization() const final
Definition polarsite.cc:70
Eigen::Vector3d getDipole() const final
Definition polarsite.cc:54
Eigen::Vector3d & V()
Definition polarsite.h:70
double Induced_Charge() const
Definition polarsite.h:114
double Phi() const
Definition polarsite.h:78
void ReadData(StaticSite::data &d)=delete
void setInduced_Charge(double dq)
Definition polarsite.h:115
~PolarSite() final=default
Eigen::Vector3d V_
Definition polarsite.h:188
const std::string & getElement() const
Definition staticsite.h:79
Index getId() const
Definition staticsite.h:77
const Eigen::Vector3d & getPos() const
Definition staticsite.h:80
StaticSite(Index id, std::string element, Eigen::Vector3d pos)
Definition staticsite.h:59
Index getRank() const
Definition staticsite.h:78
virtual void Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &refPos)
Definition staticsite.cc:66
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26