45#include "selection/SelectionManager.hpp"
54 SelectionManager::SelectionManager(SimInfo* info) : info_(info) {
55 nObjects_.push_back(info_->getNGlobalAtoms() +
56 info_->getNGlobalRigidBodies());
57 nObjects_.push_back(info_->getNGlobalBonds());
58 nObjects_.push_back(info_->getNGlobalBends());
59 nObjects_.push_back(info_->getNGlobalTorsions());
60 nObjects_.push_back(info_->getNGlobalInversions());
61 nObjects_.push_back(info_->getNGlobalMolecules());
63 stuntdoubles_.resize(nObjects_[STUNTDOUBLE]);
64 bonds_.resize(nObjects_[BOND]);
65 bends_.resize(nObjects_[BEND]);
66 torsions_.resize(nObjects_[TORSION]);
67 inversions_.resize(nObjects_[INVERSION]);
68 molecules_.resize(nObjects_[MOLECULE]);
70 ss_.resize(nObjects_);
72 SimInfo::MoleculeIterator mi;
73 Molecule::AtomIterator ai;
74 Molecule::RigidBodyIterator rbIter;
75 Molecule::BondIterator bondIter;
76 Molecule::BendIterator bendIter;
77 Molecule::TorsionIterator torsionIter;
78 Molecule::InversionIterator inversionIter;
88 for (mol = info_->beginMolecule(mi); mol != NULL;
89 mol = info_->nextMolecule(mi)) {
90 molecules_[mol->getGlobalIndex()] = mol;
92 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
93 stuntdoubles_[atom->getGlobalIndex()] = atom;
95 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
96 rb = mol->nextRigidBody(rbIter)) {
97 stuntdoubles_[rb->getGlobalIndex()] = rb;
99 for (bond = mol->beginBond(bondIter); bond != NULL;
100 bond = mol->nextBond(bondIter)) {
101 bonds_[bond->getGlobalIndex()] = bond;
103 for (bend = mol->beginBend(bendIter); bend != NULL;
104 bend = mol->nextBend(bendIter)) {
105 bends_[bend->getGlobalIndex()] = bend;
107 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
108 torsion = mol->nextTorsion(torsionIter)) {
109 torsions_[torsion->getGlobalIndex()] = torsion;
111 for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
112 inversion = mol->nextInversion(inversionIter)) {
113 inversions_[inversion->getGlobalIndex()] = inversion;
121 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
124 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
131 return i == -1 ? NULL : stuntdoubles_[i];
138 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
141 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
148 return i == -1 ? NULL : stuntdoubles_[i];
155 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
158 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
165 return i == -1 ? NULL : stuntdoubles_[i];
172 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
175 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
182 return i == -1 ? NULL : stuntdoubles_[i];
186 Bond* SelectionManager::beginSelectedBond(
int& i) {
189 while (i <
static_cast<int>(ss_.bitsets_[BOND].size())) {
190 if (ss_.bitsets_[BOND][i]) {
192 if (bonds_[i] != NULL)
return bonds_[i];
198 i = ss_.bitsets_[BOND].firstOnBit();
199 return i == -1 ? NULL : bonds_[i];
203 Bond* SelectionManager::nextSelectedBond(
int& i) {
206 while (i <
static_cast<int>(ss_.bitsets_[BOND].size())) {
207 if (ss_.bitsets_[BOND][i]) {
209 if (bonds_[i] != NULL)
return bonds_[i];
215 i = ss_.bitsets_[BOND].nextOnBit(i);
216 return i == -1 ? NULL : bonds_[i];
220 Bond* SelectionManager::beginUnselectedBond(
int& i) {
223 while (i <
static_cast<int>(ss_.bitsets_[BOND].size())) {
224 if (!ss_.bitsets_[BOND][i]) {
226 if (bonds_[i] != NULL)
return bonds_[i];
232 i = ss_.bitsets_[BOND].firstOffBit();
233 return i == -1 ? NULL : bonds_[i];
237 Bond* SelectionManager::nextUnselectedBond(
int& i) {
240 while (i <
static_cast<int>(ss_.bitsets_[BOND].size())) {
241 if (!ss_.bitsets_[BOND][i]) {
243 if (bonds_[i] != NULL)
return bonds_[i];
249 i = ss_.bitsets_[BOND].nextOffBit(i);
250 return i == -1 ? NULL : bonds_[i];
254 Bend* SelectionManager::beginSelectedBend(
int& i) {
257 while (i <
static_cast<int>(ss_.bitsets_[BEND].size())) {
258 if (ss_.bitsets_[BEND][i]) {
260 if (bends_[i] != NULL)
return bends_[i];
266 i = ss_.bitsets_[BEND].firstOnBit();
267 return i == -1 ? NULL : bends_[i];
271 Bend* SelectionManager::nextSelectedBend(
int& i) {
274 while (i <
static_cast<int>(ss_.bitsets_[BEND].size())) {
275 if (ss_.bitsets_[BEND][i]) {
277 if (bends_[i] != NULL)
return bends_[i];
283 i = ss_.bitsets_[BEND].nextOnBit(i);
284 return i == -1 ? NULL : bends_[i];
288 Bend* SelectionManager::beginUnselectedBend(
int& i) {
291 while (i <
static_cast<int>(ss_.bitsets_[BEND].size())) {
292 if (!ss_.bitsets_[BEND][i]) {
294 if (bends_[i] != NULL)
return bends_[i];
300 i = ss_.bitsets_[BEND].firstOffBit();
301 return i == -1 ? NULL : bends_[i];
305 Bend* SelectionManager::nextUnselectedBend(
int& i) {
308 while (i <
static_cast<int>(ss_.bitsets_[BEND].size())) {
309 if (!ss_.bitsets_[BEND][i]) {
311 if (bends_[i] != NULL)
return bends_[i];
317 i = ss_.bitsets_[BEND].nextOffBit(i);
318 return i == -1 ? NULL : bends_[i];
322 Torsion* SelectionManager::beginSelectedTorsion(
int& i) {
325 while (i <
static_cast<int>(ss_.bitsets_[TORSION].size())) {
326 if (ss_.bitsets_[TORSION][i]) {
328 if (torsions_[i] != NULL)
return torsions_[i];
334 i = ss_.bitsets_[TORSION].firstOnBit();
335 return i == -1 ? NULL : torsions_[i];
339 Torsion* SelectionManager::nextSelectedTorsion(
int& i) {
342 while (i <
static_cast<int>(ss_.bitsets_[TORSION].size())) {
343 if (ss_.bitsets_[TORSION][i]) {
345 if (torsions_[i] != NULL)
return torsions_[i];
351 i = ss_.bitsets_[TORSION].nextOnBit(i);
352 return i == -1 ? NULL : torsions_[i];
356 Torsion* SelectionManager::beginUnselectedTorsion(
int& i) {
359 while (i <
static_cast<int>(ss_.bitsets_[TORSION].size())) {
360 if (!ss_.bitsets_[TORSION][i]) {
362 if (torsions_[i] != NULL)
return torsions_[i];
368 i = ss_.bitsets_[TORSION].firstOffBit();
369 return i == -1 ? NULL : torsions_[i];
373 Torsion* SelectionManager::nextUnselectedTorsion(
int& i) {
376 while (i <
static_cast<int>(ss_.bitsets_[TORSION].size())) {
377 if (!ss_.bitsets_[TORSION][i]) {
379 if (torsions_[i] != NULL)
return torsions_[i];
385 i = ss_.bitsets_[TORSION].nextOffBit(i);
386 return i == -1 ? NULL : torsions_[i];
390 Inversion* SelectionManager::beginSelectedInversion(
int& i) {
393 while (i <
static_cast<int>(ss_.bitsets_[INVERSION].size())) {
394 if (ss_.bitsets_[INVERSION][i]) {
396 if (inversions_[i] != NULL)
return inversions_[i];
402 i = ss_.bitsets_[INVERSION].firstOnBit();
403 return i == -1 ? NULL : inversions_[i];
407 Inversion* SelectionManager::nextSelectedInversion(
int& i) {
410 while (i <
static_cast<int>(ss_.bitsets_[INVERSION].size())) {
411 if (ss_.bitsets_[INVERSION][i]) {
413 if (inversions_[i] != NULL)
return inversions_[i];
419 i = ss_.bitsets_[INVERSION].nextOnBit(i);
420 return i == -1 ? NULL : inversions_[i];
424 Inversion* SelectionManager::beginUnselectedInversion(
int& i) {
427 while (i <
static_cast<int>(ss_.bitsets_[INVERSION].size())) {
428 if (!ss_.bitsets_[INVERSION][i]) {
430 if (inversions_[i] != NULL)
return inversions_[i];
436 i = ss_.bitsets_[INVERSION].firstOffBit();
437 return i == -1 ? NULL : inversions_[i];
441 Inversion* SelectionManager::nextUnselectedInversion(
int& i) {
444 while (i <
static_cast<int>(ss_.bitsets_[INVERSION].size())) {
445 if (!ss_.bitsets_[INVERSION][i]) {
447 if (inversions_[i] != NULL)
return inversions_[i];
453 i = ss_.bitsets_[INVERSION].nextOffBit(i);
454 return i == -1 ? NULL : inversions_[i];
458 Molecule* SelectionManager::beginSelectedMolecule(
int& i) {
461 while (i <
static_cast<int>(ss_.bitsets_[MOLECULE].size())) {
462 if (ss_.bitsets_[MOLECULE][i]) {
464 if (molecules_[i] != NULL)
return molecules_[i];
470 i = ss_.bitsets_[MOLECULE].firstOnBit();
471 return i == -1 ? NULL : molecules_[i];
475 Molecule* SelectionManager::nextSelectedMolecule(
int& i) {
478 while (i <
static_cast<int>(ss_.bitsets_[MOLECULE].size())) {
479 if (ss_.bitsets_[MOLECULE][i]) {
481 if (molecules_[i] != NULL)
return molecules_[i];
487 i = ss_.bitsets_[MOLECULE].nextOnBit(i);
488 return i == -1 ? NULL : molecules_[i];
492 Molecule* SelectionManager::beginUnselectedMolecule(
int& i) {
495 while (i <
static_cast<int>(ss_.bitsets_[MOLECULE].size())) {
496 if (!ss_.bitsets_[MOLECULE][i]) {
498 if (molecules_[i] != NULL)
return molecules_[i];
504 i = ss_.bitsets_[MOLECULE].firstOffBit();
505 return i == -1 ? NULL : molecules_[i];
509 Molecule* SelectionManager::nextUnselectedMolecule(
int& i) {
512 while (i <
static_cast<int>(ss_.bitsets_[MOLECULE].size())) {
513 if (!ss_.bitsets_[MOLECULE][i]) {
515 if (molecules_[i] != NULL)
return molecules_[i];
521 i = ss_.bitsets_[MOLECULE].nextOffBit(i);
522 return i == -1 ? NULL : molecules_[i];
526 Molecule* SelectionManager::nthSelectedMolecule(
int& n) {
529 i = ss_.bitsets_[MOLECULE].nthOnBit(n);
530 if (i == -1)
return NULL;
532 if (molecules_[i] != NULL)
return molecules_[i];
535 i = ss_.bitsets_[MOLECULE].nthOnBit(n);
536 return i == -1 ? NULL : molecules_[i];
547 AtomTypeSet SelectionManager::getSelectedAtomTypes() {
548 AtomTypeSet atomTypes;
550 for (
size_t i = 0; i < ss_.bitsets_[
STUNTDOUBLE].size(); ++i) {
553 if (stuntdoubles_[i] != NULL) {
554 if (stuntdoubles_[i]->isAtom()) {
555 Atom* atom =
static_cast<Atom*
>(stuntdoubles_[i]);
566 std::vector<int> foundTypes;
567 AtomTypeSet::iterator i;
568 for (i = atomTypes.begin(); i != atomTypes.end(); ++i)
569 foundTypes.push_back((*i)->getIdent());
572 int count_local = foundTypes.size();
575 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
579 std::vector<int> counts(nproc, 0);
580 std::vector<int> disps(nproc, 0);
583 MPI_Allgather(&count_local, 1, MPI_INT, &counts[0], 1, MPI_INT,
588 int totalCount = counts[0];
589 for (
int iproc = 1; iproc < nproc; iproc++) {
590 disps[iproc] = disps[iproc - 1] + counts[iproc - 1];
591 totalCount += counts[iproc];
595 std::vector<int> ftGlobal(totalCount);
598 MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT, &ftGlobal[0],
599 &counts[0], &disps[0], MPI_INT, MPI_COMM_WORLD);
601 std::vector<int>::iterator j;
605 std::set<int> foundIdents;
607 for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j)
608 foundIdents.insert((*j));
612 ForceField* forceField_ = info_->getForceField();
613 std::set<int>::iterator it;
614 for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
632 std::vector<Atom*>::iterator ai;
638 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
648 tempSeleMan.ss_ |= ssAtoms;
649 tempSeleMan.ss_ -= ssRBs;
654 SelectionManager SelectionManager::removeAtomsInRigidBodies()
const {
655 SelectionSet ssAtoms(nObjects_);
658 SelectionManager tempSeleMan = *
this;
662 std::vector<Atom*>::iterator ai;
664 for (sd = tempSeleMan.beginSelected(isd); sd != NULL;
665 sd = tempSeleMan.nextSelected(isd)) {
666 if (sd->isRigidBody()) {
667 RigidBody* rb =
static_cast<RigidBody*
>(sd);
668 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
669 ssAtoms.bitsets_[
STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
675 tempSeleMan.ss_ -= ssAtoms;
680 SelectionManager operator|(
const SelectionManager& sman1,
681 const SelectionManager& sman2) {
682 SelectionManager result(sman1);
687 SelectionManager operator&(
const SelectionManager& sman1,
688 const SelectionManager& sman2) {
689 SelectionManager result(sman1);
694 SelectionManager operator^(
const SelectionManager& sman1,
695 const SelectionManager& sman2) {
696 SelectionManager result(sman1);
701 SelectionManager
operator-(
const SelectionManager& sman1,
702 const SelectionManager& sman2) {
703 SelectionManager result(sman1);
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType * getAtomType(const std::string &at)
getAtomType by string
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
bool isRigidBody()
Tests if this stuntDouble is a rigid body.
int getGlobalIndex()
Returns the global index of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
DynamicRectMatrix< Real > operator-(const DynamicRectMatrix< Real > &m)
Negate the value of every element of this matrix.
@ STUNTDOUBLE
StuntDoubles (Atoms & RigidBodies)