votca
2024.2-dev
Loading...
Searching...
No Matches
xtp
src
libxtp
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
28
#include <
votca/tools/constants.h
>
29
30
// Local VOTCA includes
31
#include "
votca/xtp/checkpointtable.h
"
32
#include "
votca/xtp/polarsite.h
"
33
34
using namespace
std
;
35
36
namespace
votca
{
37
namespace
xtp {
38
39
PolarSite::PolarSite
(
Index
id
, std::string element, Eigen::Vector3d pos)
40
:
StaticSite
(id, element, pos) {
41
tools::Elements
e
;
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
52
PolarSite::PolarSite
(
const
data
& d) {
ReadData
(d); }
53
54
Eigen::Vector3d
PolarSite::getDipole
()
const
{
55
return
Q_
.segment<3>(1) +
induced_dipole_
;
56
}
57
58
void
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
66
std::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
75
void
PolarSite::SetupCptTable
(
CptTable
& table) {
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
115
void
PolarSite::WriteData
(
data
& d)
const
{
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
155
void
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
checkpointtable.h
votca::tools::Elements
information about an element
Definition
elements.h:42
votca::xtp::CptTable
Definition
checkpointtable.h:48
votca::xtp::CptTable::addCol
void addCol(const std::string &name, const size_t &offset)
Definition
checkpointtable.h:206
votca::xtp::PolarSite::PolarSite
PolarSite(Index id, std::string element, Eigen::Vector3d pos)
Definition
polarsite.cc:39
votca::xtp::PolarSite::SetupCptTable
static void SetupCptTable(CptTable &table)
Definition
polarsite.cc:75
votca::xtp::PolarSite::WriteData
void WriteData(StaticSite::data &d) const =delete
votca::xtp::PolarSite::V_noE_
Eigen::Vector3d V_noE_
Definition
polarsite.h:156
votca::xtp::PolarSite::induced_dipole_
Eigen::Vector3d induced_dipole_
Definition
polarsite.h:158
votca::xtp::PolarSite::setpolarization
void setpolarization(const Eigen::Matrix3d &pol) final
Definition
polarsite.cc:58
votca::xtp::PolarSite::pinv_
Eigen::Matrix3d pinv_
Definition
polarsite.h:159
votca::xtp::PolarSite::writepolarization
std::string writepolarization() const final
Definition
polarsite.cc:66
votca::xtp::PolarSite::getDipole
Eigen::Vector3d getDipole() const final
Definition
polarsite.cc:54
votca::xtp::PolarSite::ReadData
void ReadData(StaticSite::data &d)=delete
votca::xtp::PolarSite::V_
Eigen::Vector3d V_
Definition
polarsite.h:152
votca::xtp::PolarSite::eigendamp_invsqrt_
double eigendamp_invsqrt_
Definition
polarsite.h:160
votca::xtp::StaticSite
Class to represent Atom/Site in electrostatic.
Definition
staticsite.h:37
votca::xtp::StaticSite::Q_
Vector9d Q_
Definition
staticsite.h:136
votca::xtp::StaticSite::id_
Index id_
Definition
staticsite.h:131
votca::xtp::StaticSite::rank_
Index rank_
Definition
staticsite.h:134
votca::xtp::StaticSite::element_
std::string element_
Definition
staticsite.h:132
votca::xtp::StaticSite::pos_
Eigen::Vector3d pos_
Definition
staticsite.h:133
constants.h
std
STL namespace.
votca::tools::conv::ang2bohr
const double ang2bohr
Definition
constants.h:48
votca::tools::conv::bohr2ang
const double bohr2ang
Definition
constants.h:49
votca::tools::conv::nm2bohr
const double nm2bohr
Definition
constants.h:47
votca::tools::e
@ e
Definition
unitconverter.h:59
votca::xtp::L::P
@ P
votca
base class for all analysis tools
Definition
basebead.h:33
votca::Index
Eigen::Index Index
Definition
types.h:26
polarsite.h
votca::xtp::PolarSite::data
Definition
polarsite.h:90
votca::xtp::PolarSite::data::Vx
double Vx
Definition
polarsite.h:109
votca::xtp::PolarSite::data::Q11c
double Q11c
Definition
polarsite.h:100
votca::xtp::PolarSite::data::Vy
double Vy
Definition
polarsite.h:110
votca::xtp::PolarSite::data::Q21c
double Q21c
Definition
polarsite.h:104
votca::xtp::PolarSite::data::Q22c
double Q22c
Definition
polarsite.h:106
votca::xtp::PolarSite::data::Q10
double Q10
Definition
polarsite.h:102
votca::xtp::PolarSite::data::Q21s
double Q21s
Definition
polarsite.h:105
votca::xtp::PolarSite::data::pxy
double pxy
Definition
polarsite.h:118
votca::xtp::PolarSite::data::Q11s
double Q11s
Definition
polarsite.h:101
votca::xtp::PolarSite::data::Vz
double Vz
Definition
polarsite.h:111
votca::xtp::PolarSite::data::d_x_ind
double d_x_ind
Definition
polarsite.h:124
votca::xtp::PolarSite::data::Vx_noE
double Vx_noE
Definition
polarsite.h:113
votca::xtp::PolarSite::data::element
char * element
Definition
polarsite.h:92
votca::xtp::PolarSite::data::posY
double posY
Definition
polarsite.h:94
votca::xtp::PolarSite::data::pxx
double pxx
Definition
polarsite.h:117
votca::xtp::PolarSite::data::rank
Index rank
Definition
polarsite.h:97
votca::xtp::PolarSite::data::pxz
double pxz
Definition
polarsite.h:119
votca::xtp::PolarSite::data::posX
double posX
Definition
polarsite.h:93
votca::xtp::PolarSite::data::id
Index id
Definition
polarsite.h:91
votca::xtp::PolarSite::data::d_y_ind
double d_y_ind
Definition
polarsite.h:125
votca::xtp::PolarSite::data::Q20
double Q20
Definition
polarsite.h:103
votca::xtp::PolarSite::data::pzz
double pzz
Definition
polarsite.h:122
votca::xtp::PolarSite::data::Vy_noE
double Vy_noE
Definition
polarsite.h:114
votca::xtp::PolarSite::data::Q00
double Q00
Definition
polarsite.h:99
votca::xtp::PolarSite::data::Q22s
double Q22s
Definition
polarsite.h:107
votca::xtp::PolarSite::data::posZ
double posZ
Definition
polarsite.h:95
votca::xtp::PolarSite::data::pyz
double pyz
Definition
polarsite.h:121
votca::xtp::PolarSite::data::d_z_ind
double d_z_ind
Definition
polarsite.h:126
votca::xtp::PolarSite::data::pyy
double pyy
Definition
polarsite.h:120
votca::xtp::PolarSite::data::Vz_noE
double Vz_noE
Definition
polarsite.h:115
Generated by
1.12.0