votca 2024.1-dev
Loading...
Searching...
No Matches
nblistgrid.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18// Local VOTCA includes
20#include "votca/csg/topology.h"
22
23namespace votca {
24namespace csg {
25
26using namespace std;
27
29 bool do_exclusions) {
30
31 do_exclusions_ = do_exclusions;
32 if (list1.empty()) {
33 return;
34 }
35 if (list2.empty()) {
36 return;
37 }
38
39 assert(&(list1.getTopology()) == &(list2.getTopology()));
40 const Topology &top = list1.getTopology();
41
43
44 // Add all beads of list1
45 for (auto &iter : list1) {
46 getCell(iter->getPos()).beads_.push_back(iter);
47 }
48
49 for (auto &iter : list2) {
50 cell_t &cell = getCell(iter->getPos());
51 TestBead(top, cell, iter);
52 }
53}
54
55void NBListGrid::Generate(BeadList &list, bool do_exclusions) {
56 do_exclusions_ = do_exclusions;
57 if (list.empty()) {
58 return;
59 }
60
61 const Topology &top = list.getTopology();
62
64
65 for (auto &iter : list) {
66 cell_t &cell = getCell(iter->getPos());
67 TestBead(top, cell, iter);
68 getCell(iter->getPos()).beads_.push_back(iter);
69 }
70}
71void NBListGrid::InitializeGrid(const Eigen::Matrix3d &box) {
72 box_a_ = box.col(0);
73 box_b_ = box.col(1);
74 box_c_ = box.col(2);
75
76 // create plane normals
77 norm_a_ = box_b_.cross(box_c_);
78 norm_b_ = box_c_.cross(box_a_);
79 norm_c_ = box_a_.cross(box_b_);
80
81 norm_a_.normalize();
82 norm_b_.normalize();
83 norm_c_.normalize();
84
85 double la = box_a_.dot(norm_a_);
86 double lb = box_b_.dot(norm_b_);
87 double lc = box_c_.dot(norm_c_);
88
89 // calculate grid size, each grid has to be at least size of cut-off
90 box_Na_ = Index(std::max(std::abs(la / cutoff_), 1.0));
91 box_Nb_ = Index(std::max(std::abs(lb / cutoff_), 1.0));
92 box_Nc_ = Index(std::max(std::abs(lc / cutoff_), 1.0));
93
94 norm_a_ = norm_a_ / box_a_.dot(norm_a_) * (double)box_Na_;
95 norm_b_ = norm_b_ / box_b_.dot(norm_b_) * (double)box_Nb_;
96 norm_c_ = norm_c_ / box_c_.dot(norm_c_) * (double)box_Nc_;
97
99
100 Index a1, a2, b1, b2, c1, c2;
101
102 a1 = b1 = c1 = -1;
103 a2 = b2 = c2 = 1;
104
105 if (box_Na_ < 3) {
106 a2 = 0;
107 }
108 if (box_Nb_ < 3) {
109 b2 = 0;
110 }
111 if (box_Nc_ < 3) {
112 c2 = 0;
113 }
114
115 if (box_Na_ < 2) {
116 a1 = 0;
117 }
118 if (box_Nb_ < 2) {
119 b1 = 0;
120 }
121 if (box_Nc_ < 2) {
122 c1 = 0;
123 }
124
125 // wow, setting up the neighbours is an ugly for construct!
126 // loop from N..2*N to avoid if and only use %
127 for (Index a = box_Na_; a < 2 * box_Na_; ++a) {
128 for (Index b = box_Nb_; b < 2 * box_Nb_; ++b) {
129 for (Index c = box_Nc_; c < 2 * box_Nc_; ++c) {
130 cell_t &cell = grid_(a % box_Na_, b % box_Nb_, c % box_Nc_);
131 for (Index aa = a + a1; aa <= a + a2; ++aa) {
132 for (Index bb = b + b1; bb <= b + b2; ++bb) {
133 for (Index cc = c + c1; cc <= c + c2; ++cc) {
134 cell_t *cell2 = &grid_(aa % box_Na_, bb % box_Nb_, cc % box_Nc_);
135 if (cell2 == &cell) {
136 continue; // ignore self
137 }
138 cell.neighbours_.push_back(
139 &grid_(aa % box_Na_, bb % box_Nb_, cc % box_Nc_));
140 }
141 }
142 }
143 }
144 }
145 }
146}
147
148NBListGrid::cell_t &NBListGrid::getCell(const Eigen::Vector3d &r) {
149 Index a = (Index)floor(r.dot(norm_a_));
150 Index b = (Index)floor(r.dot(norm_b_));
151 Index c = (Index)floor(r.dot(norm_c_));
152
153 if (a < 0) {
154 a = box_Na_ + a % box_Na_;
155 }
156 a %= box_Na_;
157
158 if (b < 0) {
159 b = box_Nb_ + b % box_Nb_;
160 }
161 b %= box_Nb_;
162
163 if (c < 0) {
164 c = box_Nc_ + c % box_Nc_;
165 }
166 c %= box_Nc_;
167
168 return grid_(a, b, c);
169}
170
172 Bead *bead) {
173 TestCell(top, cell, bead);
174 for (auto &neighbour : cell.neighbours_) {
175 TestCell(top, *neighbour, bead);
176 }
177}
178
180 Bead *bead) {
181 const Eigen::Vector3d &u = bead->getPos();
182
183 for (auto &bead_ : cell.beads_) {
184
185 const Eigen::Vector3d &v = bead_->getPos();
186 const Eigen::Vector3d &r = top.BCShortestConnection(v, u);
187 double d = r.norm();
188 if (d < cutoff_) {
189 if (do_exclusions_) {
190 if (top.getExclusions().IsExcluded(bead_, bead)) {
191 continue;
192 }
193 }
194 if ((*match_function_)(bead_, bead, r, d)) {
195 if (!FindPair(bead_, bead)) {
196 AddPair(pair_creator_(bead_, bead, r));
197 }
198 }
199 }
200 }
201}
202
203} // namespace csg
204} // namespace votca
virtual const Eigen::Vector3d & getPos() const
Definition basebead.h:166
const Topology & getTopology() const
Definition beadlist.h:63
void push_back(Bead *bead)
Definition beadlist.h:56
bool empty() const
Definition beadlist.h:54
information about a bead
Definition bead.h:50
bool IsExcluded(Bead *bead1, Bead *bead2) const
Eigen::Vector3d box_a_
Definition nblistgrid.h:46
void TestBead(const Topology &top, cell_t &cell, Bead *bead)
tools::NDimVector< cell_t, 3 > grid_
Definition nblistgrid.h:50
Eigen::Vector3d norm_a_
Definition nblistgrid.h:47
void TestCell(const Topology &top, cell_t &cell, Bead *bead)
Eigen::Vector3d norm_c_
Definition nblistgrid.h:47
Eigen::Vector3d norm_b_
Definition nblistgrid.h:47
cell_t & getCell(const Eigen::Vector3d &r)
Eigen::Vector3d box_c_
Definition nblistgrid.h:46
void InitializeGrid(const Eigen::Matrix3d &box)
Definition nblistgrid.cc:71
Eigen::Vector3d box_b_
Definition nblistgrid.h:46
void Generate(BeadList &list1, BeadList &list2, bool do_exclusions=true) override
Generate the neighbour list based on two bead lists (e.g. bead types)
Definition nblistgrid.cc:28
std::unique_ptr< Functor > match_function_
Definition nblist.h:150
bool do_exclusions_
take into account exclusions from topolgoy
Definition nblist.h:93
pair_creator_t pair_creator_
the current bead pair creator function
Definition nblist.h:104
double cutoff_
cutoff
Definition nblist.h:91
BeadPair * FindPair(Bead * e1, Bead * e2)
Definition pairlist.h:93
topology of the whole system
Definition topology.h:81
const Eigen::Matrix3d & getBox() const
Definition topology.h:298
ExclusionList & getExclusions()
Definition topology.h:391
Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const
calculate shortest vector connecting two points
Definition topology.cc:238
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
std::vector< cell_t * > neighbours_
Definition nblistgrid.h:43