votca 2024.2-dev
Loading...
Searching...
No Matches
grid.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 <cmath> /* ceil */
22
23// VOTCA includes
26
27// Local VOTCA includes
28#include "votca/xtp/grid.h"
29
30namespace votca {
31namespace xtp {
32
33void Grid::printGridtoxyzfile(std::string filename) {
34 // unit is Angstrom in xyz file
35 std::ofstream points;
36 points.open(filename, std::ofstream::out);
37 points << gridpoints_.size() << std::endl;
38 points << std::endl;
39 for (const auto& point : gridpoints_) {
40 points << "X " << point.x() * tools::conv::bohr2ang << " "
41 << point.y() * tools::conv::bohr2ang << " "
42 << point.z() * tools::conv::bohr2ang << std::endl;
43 }
44 points.close();
45 return;
46}
47
48void Grid::setupgrid(const QMMolecule& Atomlist) {
49
50 tools::Elements elements;
51 std::pair<Eigen::Vector3d, Eigen::Vector3d> extension =
52 Atomlist.CalcSpatialMinMax();
53 Eigen::Array3d min = extension.first.array();
54 Eigen::Array3d max = extension.second.array();
55 Eigen::Array3d doublesteps = (max - min + 2 * padding_) / gridspacing_;
56 Eigen::Array<votca::Index, 3, 1> steps = (doublesteps.ceil()).cast<Index>();
57
58 // needed to symmetrize grid around molecule
59 Eigen::Array3d padding =
60 (doublesteps - steps.cast<double>()) * gridspacing_ * 0.5 + padding_;
61 Eigen::Array3d minpos = min - padding;
62 for (Index i = 0; i <= steps.x(); i++) {
63 double x = minpos.x() + double(i) * gridspacing_;
64 for (Index j = 0; j <= steps.y(); j++) {
65 double y = minpos.y() + double(j) * gridspacing_;
66 for (Index k = 0; k <= steps.z(); k++) {
67 double z = minpos.z() + double(k) * gridspacing_;
68 bool is_valid = false;
69 Eigen::Vector3d gridpos(x, y, z);
70 for (const QMAtom& atom : Atomlist) {
71 const Eigen::Vector3d& atompos = atom.getPos();
72 double distance2 = (gridpos - atompos).squaredNorm();
73 double atomcutoff =
74 elements.getVdWChelpG(atom.getElement()) * tools::conv::ang2bohr;
75 if (distance2 < (atomcutoff * atomcutoff)) {
76 is_valid = false;
77 break;
78 } else if (distance2 < (cutoff_ * cutoff_)) {
79 is_valid = true;
80 }
81 }
82 if (is_valid) {
83 gridpoints_.push_back(gridpos);
84 }
85 }
86 }
87 }
88
89 gridvalues_ = Eigen::VectorXd::Zero(gridpoints_.size());
90 return;
91}
92
93} // namespace xtp
94} // namespace votca
information about an element
Definition elements.h:42
double getVdWChelpG(std::string name)
Definition elements.cc:75
std::pair< Eigen::Vector3d, Eigen::Vector3d > CalcSpatialMinMax() const
double gridspacing_
Definition grid.h:71
std::vector< Eigen::Vector3d > gridpoints_
Definition grid.h:67
Eigen::VectorXd gridvalues_
Definition grid.h:68
double cutoff_
Definition grid.h:70
void setupgrid(const QMMolecule &Atomlist)
Definition grid.cc:48
double padding_
Definition grid.h:72
void printGridtoxyzfile(std::string filename)
Definition grid.cc:33
container for QM atoms
Definition qmatom.h:37
const double ang2bohr
Definition constants.h:48
const double bohr2ang
Definition constants.h:49
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26