votca 2026-dev
Loading...
Searching...
No Matches
polarsite.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// Standard includes
21#include <fstream>
22#include <string>
23
24// Third party includes
25#include <boost/format.hpp>
26
27// VOTCA includes
29
30// Local VOTCA includes
32#include "votca/xtp/polarsite.h"
33
34using namespace std;
35
36namespace votca {
37namespace xtp {
38
39PolarSite::PolarSite(Index id, std::string element, Eigen::Vector3d pos)
40 : StaticSite(id, element, pos) {
42 double default_pol = std::pow(tools::conv::ang2bohr, 3);
43 try {
44 default_pol =
45 e.getPolarizability(element) * std::pow(tools::conv::nm2bohr, 3);
46 } catch (const std::runtime_error&) {
47 ;
48 }
49 setpolarization(default_pol * Eigen::Matrix3d::Identity());
50}
51
53
54Eigen::Vector3d PolarSite::getDipole() const {
55 return Q_.segment<3>(1) + induced_dipole_;
56}
57
58Eigen::Vector3d PolarSite::getStaticDipole() const { return Q_.segment<3>(1); }
59
60Eigen::Vector3d PolarSite::getInducedDipole() const { return induced_dipole_; }
61
62void PolarSite::setpolarization(const Eigen::Matrix3d& pol) {
63 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es;
64 es.computeDirect(pol);
65 pinv_ = es.eigenvectors() * es.eigenvalues().cwiseInverse().asDiagonal() *
66 es.eigenvectors().transpose();
67 eigendamp_invsqrt_ = 1.0 / std::sqrt(es.eigenvalues().maxCoeff());
68}
69
70std::string PolarSite::writepolarization() const {
71 double conv_pol = std::pow(tools::conv::bohr2ang, 3);
72 Eigen::MatrixX3d pol = pinv_.inverse() * conv_pol;
73 return (boost::format(" P %1$+1.7f %2$+1.7f %3$+1.7f %4$+1.7f %5$+1.7f "
74 "%6$+1.7f\n") %
75 pol(0, 0) % pol(1, 0) % pol(2, 0) % pol(1, 1) % pol(1, 2) % pol(2, 2))
76 .str();
77}
78
80 table.addCol<Index>("index", HOFFSET(data, id));
81 table.addCol<std::string>("type", HOFFSET(data, element));
82
83 table.addCol<double>("posX", HOFFSET(data, posX));
84 table.addCol<double>("posY", HOFFSET(data, posY));
85 table.addCol<double>("posZ", HOFFSET(data, posZ));
86 // same type as rank
87 table.addCol<Index>("rank", HOFFSET(data, rank));
88
89 table.addCol<double>("Q00", HOFFSET(data, Q00));
90 table.addCol<double>("Q11c", HOFFSET(data, Q11c));
91 table.addCol<double>("Q11s", HOFFSET(data, Q11s));
92 table.addCol<double>("Q10", HOFFSET(data, Q10));
93 table.addCol<double>("Q20", HOFFSET(data, Q20));
94 table.addCol<double>("Q21c", HOFFSET(data, Q21c));
95 table.addCol<double>("Q21s", HOFFSET(data, Q21s));
96 table.addCol<double>("Q22c", HOFFSET(data, Q22c));
97 table.addCol<double>("Q22s", HOFFSET(data, Q22s));
98
99 table.addCol<double>("Vx", HOFFSET(data, Vx));
100 table.addCol<double>("Vy", HOFFSET(data, Vy));
101 table.addCol<double>("Vz", HOFFSET(data, Vz));
102
103 table.addCol<double>("Vx_noE", HOFFSET(data, Vx_noE));
104 table.addCol<double>("Vy_NoE", HOFFSET(data, Vy_noE));
105 table.addCol<double>("Vz_noE", HOFFSET(data, Vz_noE));
106 // P_inv and P have same polarization so no problem, as only data type counts
107 table.addCol<double>("pxx", HOFFSET(data, pxx));
108 table.addCol<double>("pxy", HOFFSET(data, pxy));
109 table.addCol<double>("pxz", HOFFSET(data, pxz));
110 table.addCol<double>("pyy", HOFFSET(data, pyy));
111 table.addCol<double>("pyz", HOFFSET(data, pyz));
112 table.addCol<double>("pzz", HOFFSET(data, pzz));
113
114 table.addCol<double>("d_ind_x", HOFFSET(data, d_x_ind));
115 table.addCol<double>("d_ind_y", HOFFSET(data, d_y_ind));
116 table.addCol<double>("d_ind_z", HOFFSET(data, d_z_ind));
117}
118
120 d.id = id_;
121 d.element = const_cast<char*>(element_.c_str());
122 d.posX = pos_[0];
123 d.posY = pos_[1];
124 d.posZ = pos_[2];
125
126 d.rank = rank_;
127
128 d.Q00 = Q_[0];
129 d.Q11c = Q_[1];
130 d.Q11s = Q_[2];
131 d.Q10 = Q_[3];
132 d.Q20 = Q_[4];
133 d.Q21c = Q_[5];
134 d.Q21s = Q_[6];
135 d.Q22c = Q_[7];
136 d.Q22s = Q_[8];
137
138 d.Vx = V_[0];
139 d.Vy = V_[1];
140 d.Vz = V_[2];
141
142 d.Vx_noE = V_noE_[0];
143 d.Vy_noE = V_noE_[1];
144 d.Vz_noE = V_noE_[2];
145
146 Eigen::Matrix3d P = pinv_.inverse();
147 d.pxx = P(0, 0);
148 d.pxy = P(0, 1);
149 d.pxz = P(0, 2);
150 d.pyy = P(1, 1);
151 d.pyz = P(1, 2);
152 d.pzz = P(2, 2);
153
154 d.d_x_ind = induced_dipole_.x();
155 d.d_y_ind = induced_dipole_.y();
156 d.d_z_ind = induced_dipole_.z();
157}
158
159void PolarSite::ReadData(const data& d) {
160 id_ = d.id;
161 element_ = std::string(d.element);
162 free(d.element);
163 pos_[0] = d.posX;
164 pos_[1] = d.posY;
165 pos_[2] = d.posZ;
166
167 rank_ = d.rank;
168
169 Q_[0] = d.Q00;
170 Q_[1] = d.Q11c;
171 Q_[2] = d.Q11s;
172 Q_[3] = d.Q10;
173 Q_[4] = d.Q20;
174 Q_[5] = d.Q21c;
175 Q_[6] = d.Q21s;
176 Q_[7] = d.Q22c;
177 Q_[8] = d.Q22s;
178
179 V_[0] = d.Vx;
180 V_[1] = d.Vy;
181 V_[2] = d.Vz;
182
183 V_noE_[0] = d.Vx_noE;
184 V_noE_[1] = d.Vy_noE;
185 V_noE_[2] = d.Vz_noE;
186
187 Eigen::Matrix3d Ps;
188 Ps(0, 0) = d.pxx;
189 Ps(0, 1) = d.pxy;
190 Ps(1, 0) = d.pxy;
191 Ps(0, 2) = d.pxz;
192 Ps(2, 0) = d.pxz;
193 Ps(1, 1) = d.pyy;
194 Ps(1, 2) = d.pyz;
195 Ps(2, 1) = d.pyz;
196 Ps(2, 2) = d.pzz;
197
198 this->setpolarization(Ps);
199
200 induced_dipole_.x() = d.d_x_ind;
201 induced_dipole_.y() = d.d_y_ind;
202 induced_dipole_.z() = d.d_z_ind;
203}
204
205} // namespace xtp
206} // namespace votca
information about an element
Definition elements.h:42
void addCol(const std::string &name, const size_t &offset)
PolarSite(Index id, std::string element, Eigen::Vector3d pos)
Definition polarsite.cc:39
static void SetupCptTable(CptTable &table)
Definition polarsite.cc:79
void WriteData(StaticSite::data &d) const =delete
Eigen::Vector3d V_noE_
Definition polarsite.h:163
Eigen::Vector3d induced_dipole_
Definition polarsite.h:165
void setpolarization(const Eigen::Matrix3d &pol) final
Definition polarsite.cc:62
Eigen::Matrix3d pinv_
Definition polarsite.h:166
Eigen::Vector3d getStaticDipole() const final
Definition polarsite.cc:58
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
void ReadData(StaticSite::data &d)=delete
Eigen::Vector3d V_
Definition polarsite.h:159
StaticSite(Index id, std::string element, Eigen::Vector3d pos)
Definition staticsite.h:59
Eigen::Vector3d pos_
Definition staticsite.h:160
STL namespace.
const double ang2bohr
Definition constants.h:48
const double bohr2ang
Definition constants.h:49
const double nm2bohr
Definition constants.h:47
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26