votca 2024.1-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
58void PolarSite::setpolarization(const Eigen::Matrix3d& pol) {
59 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es;
60 es.computeDirect(pol);
61 pinv_ = es.eigenvectors() * es.eigenvalues().cwiseInverse().asDiagonal() *
62 es.eigenvectors().transpose();
63 eigendamp_invsqrt_ = 1.0 / std::sqrt(es.eigenvalues().maxCoeff());
64}
65
66std::string PolarSite::writepolarization() const {
67 double conv_pol = std::pow(tools::conv::bohr2ang, 3);
68 Eigen::MatrixX3d pol = pinv_.inverse() * conv_pol;
69 return (boost::format(" P %1$+1.7f %2$+1.7f %3$+1.7f %4$+1.7f %5$+1.7f "
70 "%6$+1.7f\n") %
71 pol(0, 0) % pol(1, 0) % pol(2, 0) % pol(1, 1) % pol(1, 2) % pol(2, 2))
72 .str();
73}
74
76 table.addCol<Index>("index", HOFFSET(data, id));
77 table.addCol<std::string>("type", HOFFSET(data, element));
78
79 table.addCol<double>("posX", HOFFSET(data, posX));
80 table.addCol<double>("posY", HOFFSET(data, posY));
81 table.addCol<double>("posZ", HOFFSET(data, posZ));
82 // same type as rank
83 table.addCol<Index>("rank", HOFFSET(data, rank));
84
85 table.addCol<double>("Q00", HOFFSET(data, Q00));
86 table.addCol<double>("Q11c", HOFFSET(data, Q11c));
87 table.addCol<double>("Q11s", HOFFSET(data, Q11s));
88 table.addCol<double>("Q10", HOFFSET(data, Q10));
89 table.addCol<double>("Q20", HOFFSET(data, Q20));
90 table.addCol<double>("Q21c", HOFFSET(data, Q21c));
91 table.addCol<double>("Q21s", HOFFSET(data, Q21s));
92 table.addCol<double>("Q22c", HOFFSET(data, Q22c));
93 table.addCol<double>("Q22s", HOFFSET(data, Q22s));
94
95 table.addCol<double>("Vx", HOFFSET(data, Vx));
96 table.addCol<double>("Vy", HOFFSET(data, Vy));
97 table.addCol<double>("Vz", HOFFSET(data, Vz));
98
99 table.addCol<double>("Vx_noE", HOFFSET(data, Vx_noE));
100 table.addCol<double>("Vy_NoE", HOFFSET(data, Vy_noE));
101 table.addCol<double>("Vz_noE", HOFFSET(data, Vz_noE));
102 // P_inv and P have same polarization so no problem, as only data type counts
103 table.addCol<double>("pxx", HOFFSET(data, pxx));
104 table.addCol<double>("pxy", HOFFSET(data, pxy));
105 table.addCol<double>("pxz", HOFFSET(data, pxz));
106 table.addCol<double>("pyy", HOFFSET(data, pyy));
107 table.addCol<double>("pyz", HOFFSET(data, pyz));
108 table.addCol<double>("pzz", HOFFSET(data, pzz));
109
110 table.addCol<double>("d_ind_x", HOFFSET(data, d_x_ind));
111 table.addCol<double>("d_ind_y", HOFFSET(data, d_y_ind));
112 table.addCol<double>("d_ind_z", HOFFSET(data, d_z_ind));
113}
114
116 d.id = id_;
117 d.element = const_cast<char*>(element_.c_str());
118 d.posX = pos_[0];
119 d.posY = pos_[1];
120 d.posZ = pos_[2];
121
122 d.rank = rank_;
123
124 d.Q00 = Q_[0];
125 d.Q11c = Q_[1];
126 d.Q11s = Q_[2];
127 d.Q10 = Q_[3];
128 d.Q20 = Q_[4];
129 d.Q21c = Q_[5];
130 d.Q21s = Q_[6];
131 d.Q22c = Q_[7];
132 d.Q22s = Q_[8];
133
134 d.Vx = V_[0];
135 d.Vy = V_[1];
136 d.Vz = V_[2];
137
138 d.Vx_noE = V_noE_[0];
139 d.Vy_noE = V_noE_[1];
140 d.Vz_noE = V_noE_[2];
141
142 Eigen::Matrix3d P = pinv_.inverse();
143 d.pxx = P(0, 0);
144 d.pxy = P(0, 1);
145 d.pxz = P(0, 2);
146 d.pyy = P(1, 1);
147 d.pyz = P(1, 2);
148 d.pzz = P(2, 2);
149
150 d.d_x_ind = induced_dipole_.x();
151 d.d_y_ind = induced_dipole_.y();
152 d.d_z_ind = induced_dipole_.z();
153}
154
155void PolarSite::ReadData(const data& d) {
156 id_ = d.id;
157 element_ = std::string(d.element);
158 free(d.element);
159 pos_[0] = d.posX;
160 pos_[1] = d.posY;
161 pos_[2] = d.posZ;
162
163 rank_ = d.rank;
164
165 Q_[0] = d.Q00;
166 Q_[1] = d.Q11c;
167 Q_[2] = d.Q11s;
168 Q_[3] = d.Q10;
169 Q_[4] = d.Q20;
170 Q_[5] = d.Q21c;
171 Q_[6] = d.Q21s;
172 Q_[7] = d.Q22c;
173 Q_[8] = d.Q22s;
174
175 V_[0] = d.Vx;
176 V_[1] = d.Vy;
177 V_[2] = d.Vz;
178
179 V_noE_[0] = d.Vx_noE;
180 V_noE_[1] = d.Vy_noE;
181 V_noE_[2] = d.Vz_noE;
182
183 Eigen::Matrix3d Ps;
184 Ps(0, 0) = d.pxx;
185 Ps(0, 1) = d.pxy;
186 Ps(1, 0) = d.pxy;
187 Ps(0, 2) = d.pxz;
188 Ps(2, 0) = d.pxz;
189 Ps(1, 1) = d.pyy;
190 Ps(1, 2) = d.pyz;
191 Ps(2, 1) = d.pyz;
192 Ps(2, 2) = d.pzz;
193
194 this->setpolarization(Ps);
195
196 induced_dipole_.x() = d.d_x_ind;
197 induced_dipole_.y() = d.d_y_ind;
198 induced_dipole_.z() = d.d_z_ind;
199}
200
201} // namespace xtp
202} // 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:75
void WriteData(StaticSite::data &d) const =delete
Eigen::Vector3d V_noE_
Definition polarsite.h:156
Eigen::Vector3d induced_dipole_
Definition polarsite.h:158
void setpolarization(const Eigen::Matrix3d &pol) final
Definition polarsite.cc:58
Eigen::Matrix3d pinv_
Definition polarsite.h:159
std::string writepolarization() const final
Definition polarsite.cc:66
Eigen::Vector3d getDipole() const final
Definition polarsite.cc:54
void ReadData(StaticSite::data &d)=delete
Eigen::Vector3d V_
Definition polarsite.h:152
Class to represent Atom/Site in electrostatic.
Definition staticsite.h:37
Eigen::Vector3d pos_
Definition staticsite.h:133
STL namespace.
const double ang2bohr
Definition constants.h:48
const double bohr2ang
Definition constants.h:49
const double nm2bohr
Definition constants.h:47
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26