45#include "selection/DistanceFinder.hpp"
55 DistanceFinder::DistanceFinder(SimInfo* info) : info_(info) {
56 nObjects_.push_back(info_->getNGlobalAtoms() +
57 info_->getNGlobalRigidBodies());
58 nObjects_.push_back(info_->getNGlobalBonds());
59 nObjects_.push_back(info_->getNGlobalBends());
60 nObjects_.push_back(info_->getNGlobalTorsions());
61 nObjects_.push_back(info_->getNGlobalInversions());
62 nObjects_.push_back(info_->getNGlobalMolecules());
64 stuntdoubles_.resize(nObjects_[STUNTDOUBLE]);
65 bonds_.resize(nObjects_[BOND]);
66 bends_.resize(nObjects_[BEND]);
67 torsions_.resize(nObjects_[TORSION]);
68 inversions_.resize(nObjects_[INVERSION]);
69 molecules_.resize(nObjects_[MOLECULE]);
71 SimInfo::MoleculeIterator mi;
72 Molecule::AtomIterator ai;
73 Molecule::RigidBodyIterator rbIter;
74 Molecule::BondIterator bondIter;
75 Molecule::BendIterator bendIter;
76 Molecule::TorsionIterator torsionIter;
77 Molecule::InversionIterator inversionIter;
87 for (mol = info_->beginMolecule(mi); mol != NULL;
88 mol = info_->nextMolecule(mi)) {
89 molecules_[mol->getGlobalIndex()] = mol;
91 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
92 stuntdoubles_[atom->getGlobalIndex()] = atom;
94 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
95 rb = mol->nextRigidBody(rbIter)) {
96 stuntdoubles_[rb->getGlobalIndex()] = rb;
98 for (bond = mol->beginBond(bondIter); bond != NULL;
99 bond = mol->nextBond(bondIter)) {
100 bonds_[bond->getGlobalIndex()] = bond;
102 for (bend = mol->beginBend(bendIter); bend != NULL;
103 bend = mol->nextBend(bendIter)) {
104 bends_[bend->getGlobalIndex()] = bend;
106 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
107 torsion = mol->nextTorsion(torsionIter)) {
108 torsions_[torsion->getGlobalIndex()] = torsion;
110 for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
111 inversion = mol->nextInversion(inversionIter)) {
112 inversions_[inversion->getGlobalIndex()] = inversion;
117 SelectionSet DistanceFinder::find(
const SelectionSet& bs, RealType distance) {
120 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
121 SelectionSet bsResult(nObjects_);
122 assert(bsResult.size() == bs.size());
129 MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
132 for (
unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
133 if (stuntdoubles_[j] != NULL) {
134 if (stuntdoubles_[j]->isRigidBody()) {
135 RigidBody* rb =
static_cast<RigidBody*
>(stuntdoubles_[j]);
141 SelectionSet bsTemp = bs;
142 bsTemp = bsTemp.parallelReduce();
144 for (
size_t i = 0; i < bsTemp.bitsets_[
STUNTDOUBLE].size(); ++i) {
145 if (bsTemp.bitsets_[STUNTDOUBLE][i]) {
152 mol = info_->getGlobalMolMembership(i);
153 proc = info_->getMolToProc(mol);
155 if (proc == worldRank) {
156 center = stuntdoubles_[i];
157 centerPos = center->getPos();
158 data[0] = centerPos.x();
159 data[1] = centerPos.y();
160 data[2] = centerPos.z();
161 MPI_Bcast(data, 3, MPI_REALTYPE, proc, MPI_COMM_WORLD);
163 MPI_Bcast(data, 3, MPI_REALTYPE, proc, MPI_COMM_WORLD);
164 centerPos = Vector3d(data);
167 center = stuntdoubles_[i];
168 centerPos = center->getPos();
170 for (
size_t j = 0; j < molecules_.size(); ++j) {
171 if (molecules_[j] != NULL) {
172 Vector3d r = centerPos - molecules_[j]->getCom();
173 currSnapshot->wrapVector(r);
174 if (r.length() <= distance) {
175 bsResult.bitsets_[MOLECULE].setBitOn(j);
179 for (
size_t j = 0; j < stuntdoubles_.size(); ++j) {
180 if (stuntdoubles_[j] != NULL) {
181 Vector3d r = centerPos - stuntdoubles_[j]->getPos();
182 currSnapshot->wrapVector(r);
183 if (r.length() <= distance) {
188 for (
size_t j = 0; j < bonds_.size(); ++j) {
189 if (bonds_[j] != NULL) {
190 Vector3d loc = bonds_[j]->getAtomA()->getPos();
191 loc += bonds_[j]->getAtomB()->getPos();
193 Vector3d r = centerPos - loc;
194 currSnapshot->wrapVector(r);
195 if (r.length() <= distance) { bsResult.bitsets_[BOND].setBitOn(j); }
198 for (
size_t j = 0; j < bends_.size(); ++j) {
199 if (bends_[j] != NULL) {
200 Vector3d loc = bends_[j]->getAtomA()->getPos();
201 loc += bends_[j]->getAtomB()->getPos();
202 loc += bends_[j]->getAtomC()->getPos();
204 Vector3d r = centerPos - loc;
205 currSnapshot->wrapVector(r);
206 if (r.length() <= distance) { bsResult.bitsets_[BEND].setBitOn(j); }
209 for (
size_t j = 0; j < torsions_.size(); ++j) {
210 if (torsions_[j] != NULL) {
211 Vector3d loc = torsions_[j]->getAtomA()->getPos();
212 loc += torsions_[j]->getAtomB()->getPos();
213 loc += torsions_[j]->getAtomC()->getPos();
214 loc += torsions_[j]->getAtomD()->getPos();
216 Vector3d r = centerPos - loc;
217 currSnapshot->wrapVector(r);
218 if (r.length() <= distance) {
219 bsResult.bitsets_[TORSION].setBitOn(j);
223 for (
size_t j = 0; j < inversions_.size(); ++j) {
224 if (inversions_[j] != NULL) {
225 Vector3d loc = inversions_[j]->getAtomA()->getPos();
226 loc += inversions_[j]->getAtomB()->getPos();
227 loc += inversions_[j]->getAtomC()->getPos();
228 loc += inversions_[j]->getAtomD()->getPos();
230 Vector3d r = centerPos - loc;
231 currSnapshot->wrapVector(r);
232 if (r.length() <= distance) {
233 bsResult.bitsets_[INVERSION].setBitOn(j);
242 SelectionSet DistanceFinder::find(
const SelectionSet& bs, RealType distance,
246 Snapshot* currSnapshot = info_->getSnapshotManager()->getSnapshot(frame);
247 SelectionSet bsResult(nObjects_);
248 assert(bsResult.size() == bs.size());
255 MPI_Comm_rank(MPI_COMM_WORLD, &worldRank);
258 for (
unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
259 if (stuntdoubles_[j] != NULL) {
260 if (stuntdoubles_[j]->isRigidBody()) {
261 RigidBody* rb =
static_cast<RigidBody*
>(stuntdoubles_[j]);
262 rb->updateAtoms(frame);
267 SelectionSet bsTemp = bs;
268 bsTemp = bsTemp.parallelReduce();
270 for (
size_t i = 0; i < bsTemp.bitsets_[
STUNTDOUBLE].size(); ++i) {
271 if (bsTemp.bitsets_[STUNTDOUBLE][i]) {
277 mol = info_->getGlobalMolMembership(i);
278 proc = info_->getMolToProc(mol);
280 if (proc == worldRank) {
281 center = stuntdoubles_[i];
282 centerPos = center->getPos(frame);
283 data[0] = centerPos.x();
284 data[1] = centerPos.y();
285 data[2] = centerPos.z();
286 MPI_Bcast(data, 3, MPI_REALTYPE, proc, MPI_COMM_WORLD);
288 MPI_Bcast(data, 3, MPI_REALTYPE, proc, MPI_COMM_WORLD);
289 centerPos = Vector3d(data);
292 center = stuntdoubles_[i];
293 centerPos = center->getPos(frame);
295 for (
size_t j = 0; j < molecules_.size(); ++j) {
296 if (molecules_[j] != NULL) {
297 Vector3d r = centerPos - molecules_[j]->getCom(frame);
298 currSnapshot->wrapVector(r);
299 if (r.length() <= distance) {
300 bsResult.bitsets_[MOLECULE].setBitOn(j);
305 for (
size_t j = 0; j < stuntdoubles_.size(); ++j) {
306 if (stuntdoubles_[j] != NULL) {
307 Vector3d r = centerPos - stuntdoubles_[j]->getPos(frame);
308 currSnapshot->wrapVector(r);
309 if (r.length() <= distance) {
314 for (
size_t j = 0; j < bonds_.size(); ++j) {
315 if (bonds_[j] != NULL) {
316 Vector3d loc = bonds_[j]->getAtomA()->getPos(frame);
317 loc += bonds_[j]->getAtomB()->getPos(frame);
319 Vector3d r = centerPos - loc;
320 currSnapshot->wrapVector(r);
321 if (r.length() <= distance) { bsResult.bitsets_[BOND].setBitOn(j); }
324 for (
size_t j = 0; j < bends_.size(); ++j) {
325 if (bends_[j] != NULL) {
326 Vector3d loc = bends_[j]->getAtomA()->getPos(frame);
327 loc += bends_[j]->getAtomB()->getPos(frame);
328 loc += bends_[j]->getAtomC()->getPos(frame);
330 Vector3d r = centerPos - loc;
331 currSnapshot->wrapVector(r);
332 if (r.length() <= distance) { bsResult.bitsets_[BEND].setBitOn(j); }
335 for (
size_t j = 0; j < torsions_.size(); ++j) {
336 if (torsions_[j] != NULL) {
337 Vector3d loc = torsions_[j]->getAtomA()->getPos(frame);
338 loc += torsions_[j]->getAtomB()->getPos(frame);
339 loc += torsions_[j]->getAtomC()->getPos(frame);
340 loc += torsions_[j]->getAtomD()->getPos(frame);
342 Vector3d r = centerPos - loc;
343 currSnapshot->wrapVector(r);
344 if (r.length() <= distance) {
345 bsResult.bitsets_[TORSION].setBitOn(j);
349 for (
size_t j = 0; j < inversions_.size(); ++j) {
350 if (inversions_[j] != NULL) {
351 Vector3d loc = inversions_[j]->getAtomA()->getPos(frame);
352 loc += inversions_[j]->getAtomB()->getPos(frame);
353 loc += inversions_[j]->getAtomC()->getPos(frame);
354 loc += inversions_[j]->getAtomD()->getPos(frame);
356 Vector3d r = centerPos - loc;
357 currSnapshot->wrapVector(r);
358 if (r.length() <= distance) {
359 bsResult.bitsets_[INVERSION].setBitOn(j);
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ STUNTDOUBLE
StuntDoubles (Atoms & RigidBodies)