votca 2024.2-dev
Loading...
Searching...
No Matches
density_integration.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// Local VOTCA includes
23
24namespace votca {
25namespace xtp {
26
27template <class Grid>
29 const Eigen::Vector3d& rvector) const {
30
31 double result = 0.0;
32 assert(!densities_.empty() && "Density not calculated");
33 for (Index i = 0; i < grid_.getBoxesSize(); i++) {
34 const std::vector<Eigen::Vector3d>& points = grid_[i].getGridPoints();
35 const std::vector<double>& densities = densities_[i];
36 for (Index j = 0; j < grid_[i].size(); j++) {
37 double dist = (points[j] - rvector).norm();
38 result -= densities[j] / dist;
39 }
40 }
41 return result;
42}
43
44template <class Grid>
46 const Eigen::Vector3d& rvector) const {
47
48 Eigen::Vector3d result = Eigen::Vector3d::Zero();
49 assert(!densities_.empty() && "Density not calculated");
50 for (Index i = 0; i < grid_.getBoxesSize(); i++) {
51 const std::vector<Eigen::Vector3d>& points = grid_[i].getGridPoints();
52 const std::vector<double>& densities = densities_[i];
53 for (Index j = 0; j < grid_[i].size(); j++) {
54 Eigen::Vector3d r = points[j] - rvector;
55 result -= densities[j] * r / std::pow(r.norm(), 3); // x,y,z
56 }
57 }
58 return result;
59}
60
61template <class Grid>
63 densities_ = std::vector<std::vector<double> >(grid_.getBoxesSize());
64 for (Index i = 0; i < grid_.getBoxesSize(); i++) {
65 densities_[i] = std::vector<double>(grid_[i].size(), 0.0);
66 }
67}
68
69template <class Grid>
71 const Eigen::MatrixXd& density_matrix) {
72
73 double N = 0.0;
74 SetupDensityContainer();
75
76#pragma omp parallel for schedule(guided) reduction(+ : N)
77 for (Index i = 0; i < grid_.getBoxesSize(); ++i) {
78 const GridBox& box = grid_[i];
79 if (!box.Matrixsize()) {
80 continue;
81 }
82 const Eigen::MatrixXd DMAT_here = box.ReadFromBigMatrix(density_matrix);
83 const std::vector<Eigen::Vector3d>& points = box.getGridPoints();
84 const std::vector<double>& weights = box.getGridWeights();
85 // iterate over gridpoints
86 for (Index p = 0; p < box.size(); p++) {
87 AOShell::AOValues ao = box.CalcAOValues(points[p]);
88 double rho = ao.values.dot(DMAT_here * ao.values) * weights[p];
89 densities_[i][p] = rho;
90 N += rho;
91 }
92 }
93 return N;
94}
95
96template <class Grid>
98 const Eigen::MatrixXd& density_matrix) {
99 double N = 0.0;
100 Eigen::Vector3d centroid = Eigen::Vector3d::Zero();
101 Eigen::Matrix3d gyration = Eigen::Matrix3d::Zero();
102
103 SetupDensityContainer();
104#pragma omp parallel for schedule(guided) reduction(+ : N) \
105 reduction(+ : centroid) reduction(+ : gyration)
106 for (Index i = 0; i < grid_.getBoxesSize(); ++i) {
107 const GridBox& box = grid_[i];
108 if (!box.Matrixsize()) {
109 continue;
110 }
111
112 const Eigen::MatrixXd DMAT_here = box.ReadFromBigMatrix(density_matrix);
113 const std::vector<Eigen::Vector3d>& points = box.getGridPoints();
114 const std::vector<double>& weights = box.getGridWeights();
115 // iterate over gridpoints
116 for (Index p = 0; p < box.size(); p++) {
117 AOShell::AOValues ao = box.CalcAOValues(points[p]);
118 double rho = ao.values.dot(DMAT_here * ao.values) * weights[p];
119 densities_[i][p] = rho;
120 N += rho;
121 centroid += rho * points[p];
122 gyration += rho * points[p] * points[p].transpose();
123 }
124 }
125
126 // Normalize
127 centroid = centroid / N;
128 gyration = gyration / N;
129 gyration = gyration - centroid * centroid.transpose();
130 Gyrationtensor gyro;
131 gyro.mass = N;
132 gyro.centroid = centroid;
133 gyro.gyration = gyration;
134
135 return gyro;
136}
137template <class Grid>
139 const AOBasis& externalbasis) const {
140 Eigen::MatrixXd Potential = Eigen::MatrixXd::Zero(
141 externalbasis.AOBasisSize(), externalbasis.AOBasisSize());
142
143 assert(!densities_.empty() && "Density not calculated");
144 for (Index i = 0; i < grid_.getBoxesSize(); i++) {
145 const std::vector<Eigen::Vector3d>& points = grid_[i].getGridPoints();
146 const std::vector<double>& densities = densities_[i];
147 for (Index j = 0; j < grid_[i].size(); j++) {
148 if (densities[j] < 1e-12) {
149 continue;
150 }
151 AOMultipole esp;
152 esp.FillPotential(externalbasis, points[j]);
153 Potential += densities[j] * esp.Matrix();
154 }
155 }
156 return Potential;
157}
158
159template class DensityIntegration<Vxc_Grid>;
161
162} // namespace xtp
163} // namespace votca
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
Index AOBasisSize() const
Definition aobasis.h:46
void FillPotential(const AOBasis &aobasis, const QMMolecule &atoms)
const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix() const
Definition aopotential.h:39
Gyrationtensor IntegrateGyrationTensor(const Eigen::MatrixXd &density_matrix)
double IntegratePotential(const Eigen::Vector3d &rvector) const
Eigen::Vector3d IntegrateField(const Eigen::Vector3d &rvector) const
double IntegrateDensity(const Eigen::MatrixXd &density_matrix)
const std::vector< Eigen::Vector3d > & getGridPoints() const
Definition gridbox.h:41
Eigen::MatrixXd ReadFromBigMatrix(const Eigen::MatrixXd &bigmatrix) const
Definition gridbox.cc:68
const std::vector< double > & getGridWeights() const
Definition gridbox.h:43
AOShell::AOValues CalcAOValues(const Eigen::Vector3d &point) const
Definition gridbox.cc:44
Index size() const
Definition gridbox.h:51
Index Matrixsize() const
Definition gridbox.h:55
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26