1 |
tim |
295 |
/* |
2 |
chuckv |
1434 |
* Copyright (c) 2005, 2010 The University of Notre Dame. All Rights Reserved. |
3 |
tim |
295 |
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
10 |
tim |
295 |
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
tim |
295 |
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
gezelter |
1390 |
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
35 |
|
|
* |
36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
gezelter |
1879 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
gezelter |
1782 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
tim |
295 |
*/ |
42 |
|
|
|
43 |
gezelter |
1802 |
#ifdef IS_MPI |
44 |
|
|
#include <mpi.h> |
45 |
|
|
#endif |
46 |
|
|
|
47 |
gezelter |
1938 |
#include "selection/DistanceFinder.hpp" |
48 |
|
|
#include "primitives/Molecule.hpp" |
49 |
|
|
|
50 |
gezelter |
1390 |
namespace OpenMD { |
51 |
gezelter |
1811 |
|
52 |
gezelter |
507 |
DistanceFinder::DistanceFinder(SimInfo* info) : info_(info) { |
53 |
gezelter |
1811 |
|
54 |
tim |
295 |
nStuntDoubles_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(); |
55 |
|
|
stuntdoubles_.resize(nStuntDoubles_); |
56 |
|
|
|
57 |
|
|
SimInfo::MoleculeIterator mi; |
58 |
|
|
Molecule* mol; |
59 |
|
|
Molecule::AtomIterator ai; |
60 |
|
|
Atom* atom; |
61 |
|
|
Molecule::RigidBodyIterator rbIter; |
62 |
|
|
RigidBody* rb; |
63 |
|
|
|
64 |
gezelter |
1811 |
|
65 |
gezelter |
1801 |
for (mol = info_->beginMolecule(mi); mol != NULL; |
66 |
|
|
mol = info_->nextMolecule(mi)) { |
67 |
tim |
295 |
|
68 |
gezelter |
1801 |
for(atom = mol->beginAtom(ai); atom != NULL; |
69 |
|
|
atom = mol->nextAtom(ai)) { |
70 |
gezelter |
507 |
stuntdoubles_[atom->getGlobalIndex()] = atom; |
71 |
|
|
} |
72 |
tim |
295 |
|
73 |
gezelter |
1801 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
74 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
75 |
gezelter |
507 |
stuntdoubles_[rb->getGlobalIndex()] = rb; |
76 |
|
|
} |
77 |
gezelter |
1801 |
} |
78 |
gezelter |
507 |
} |
79 |
tim |
295 |
|
80 |
gezelter |
1390 |
OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance) { |
81 |
tim |
295 |
StuntDouble * center; |
82 |
|
|
Vector3d centerPos; |
83 |
|
|
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
84 |
gezelter |
1802 |
OpenMDBitSet bsResult(nStuntDoubles_); |
85 |
tim |
295 |
assert(bsResult.size() == bs.size()); |
86 |
gezelter |
1802 |
|
87 |
|
|
#ifdef IS_MPI |
88 |
|
|
int mol; |
89 |
|
|
int proc; |
90 |
|
|
RealType data[3]; |
91 |
|
|
int worldRank = MPI::COMM_WORLD.Get_rank(); |
92 |
|
|
#endif |
93 |
|
|
|
94 |
gezelter |
1782 |
for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { |
95 |
chuckv |
1434 |
if (stuntdoubles_[j]->isRigidBody()) { |
96 |
|
|
RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]); |
97 |
|
|
rb->updateAtoms(); |
98 |
|
|
} |
99 |
|
|
} |
100 |
gezelter |
1802 |
|
101 |
|
|
OpenMDBitSet bsTemp(nStuntDoubles_); |
102 |
|
|
bsTemp = bs; |
103 |
|
|
bsTemp.parallelReduce(); |
104 |
gezelter |
1801 |
|
105 |
gezelter |
1802 |
for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) { |
106 |
|
|
|
107 |
|
|
// Now, if we own stuntdouble i, we can use the position, but in |
108 |
|
|
// parallel, we'll need to let everyone else know what that |
109 |
|
|
// position is! |
110 |
|
|
|
111 |
|
|
#ifdef IS_MPI |
112 |
|
|
mol = info_->getGlobalMolMembership(i); |
113 |
|
|
proc = info_->getMolToProc(mol); |
114 |
|
|
|
115 |
|
|
if (proc == worldRank) { |
116 |
|
|
center = stuntdoubles_[i]; |
117 |
|
|
centerPos = center->getPos(); |
118 |
|
|
data[0] = centerPos.x(); |
119 |
|
|
data[1] = centerPos.y(); |
120 |
|
|
data[2] = centerPos.z(); |
121 |
|
|
MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); |
122 |
|
|
} else { |
123 |
|
|
MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); |
124 |
|
|
centerPos = Vector3d(data); |
125 |
|
|
} |
126 |
|
|
#else |
127 |
gezelter |
507 |
center = stuntdoubles_[i]; |
128 |
|
|
centerPos = center->getPos(); |
129 |
gezelter |
1802 |
#endif |
130 |
|
|
|
131 |
gezelter |
1782 |
for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { |
132 |
gezelter |
507 |
Vector3d r =centerPos - stuntdoubles_[j]->getPos(); |
133 |
|
|
currSnapshot->wrapVector(r); |
134 |
|
|
if (r.length() <= distance) { |
135 |
|
|
bsResult.setBitOn(j); |
136 |
|
|
} |
137 |
|
|
} |
138 |
tim |
295 |
} |
139 |
|
|
return bsResult; |
140 |
gezelter |
507 |
} |
141 |
gezelter |
1816 |
|
142 |
|
|
|
143 |
|
|
OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance, int frame ) { |
144 |
|
|
StuntDouble * center; |
145 |
|
|
Vector3d centerPos; |
146 |
|
|
Snapshot* currSnapshot = info_->getSnapshotManager()->getSnapshot(frame); |
147 |
|
|
OpenMDBitSet bsResult(nStuntDoubles_); |
148 |
|
|
assert(bsResult.size() == bs.size()); |
149 |
|
|
|
150 |
|
|
#ifdef IS_MPI |
151 |
|
|
int mol; |
152 |
|
|
int proc; |
153 |
|
|
RealType data[3]; |
154 |
|
|
int worldRank = MPI::COMM_WORLD.Get_rank(); |
155 |
|
|
#endif |
156 |
|
|
|
157 |
|
|
for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { |
158 |
|
|
if (stuntdoubles_[j]->isRigidBody()) { |
159 |
|
|
RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]); |
160 |
|
|
rb->updateAtoms(frame); |
161 |
|
|
} |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
OpenMDBitSet bsTemp(nStuntDoubles_); |
165 |
|
|
bsTemp = bs; |
166 |
|
|
bsTemp.parallelReduce(); |
167 |
|
|
|
168 |
|
|
for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) { |
169 |
|
|
|
170 |
|
|
// Now, if we own stuntdouble i, we can use the position, but in |
171 |
|
|
// parallel, we'll need to let everyone else know what that |
172 |
|
|
// position is! |
173 |
|
|
|
174 |
|
|
#ifdef IS_MPI |
175 |
|
|
mol = info_->getGlobalMolMembership(i); |
176 |
|
|
proc = info_->getMolToProc(mol); |
177 |
|
|
|
178 |
|
|
if (proc == worldRank) { |
179 |
|
|
center = stuntdoubles_[i]; |
180 |
|
|
centerPos = center->getPos(frame); |
181 |
|
|
data[0] = centerPos.x(); |
182 |
|
|
data[1] = centerPos.y(); |
183 |
|
|
data[2] = centerPos.z(); |
184 |
|
|
MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); |
185 |
|
|
} else { |
186 |
|
|
MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); |
187 |
|
|
centerPos = Vector3d(data); |
188 |
|
|
} |
189 |
|
|
#else |
190 |
|
|
center = stuntdoubles_[i]; |
191 |
|
|
centerPos = center->getPos(frame); |
192 |
|
|
#endif |
193 |
|
|
|
194 |
|
|
for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { |
195 |
|
|
Vector3d r =centerPos - stuntdoubles_[j]->getPos(frame); |
196 |
|
|
currSnapshot->wrapVector(r); |
197 |
|
|
if (r.length() <= distance) { |
198 |
|
|
bsResult.setBitOn(j); |
199 |
|
|
} |
200 |
|
|
} |
201 |
|
|
} |
202 |
|
|
return bsResult; |
203 |
|
|
} |
204 |
tim |
295 |
} |