48#include "selection/SelectionManager.hpp"
57 SelectionManager::SelectionManager(
SimInfo* info) : info_(info) {
58 nObjects_.push_back(info_->getNGlobalAtoms() +
59 info_->getNGlobalRigidBodies());
60 nObjects_.push_back(info_->getNGlobalBonds());
61 nObjects_.push_back(info_->getNGlobalBends());
62 nObjects_.push_back(info_->getNGlobalTorsions());
63 nObjects_.push_back(info_->getNGlobalInversions());
64 nObjects_.push_back(info_->getNGlobalMolecules());
66 stuntdoubles_.resize(nObjects_[STUNTDOUBLE]);
67 bonds_.resize(nObjects_[BOND]);
68 bends_.resize(nObjects_[BEND]);
69 torsions_.resize(nObjects_[TORSION]);
70 inversions_.resize(nObjects_[INVERSION]);
71 molecules_.resize(nObjects_[MOLECULE]);
73 ss_.resize(nObjects_);
75 SimInfo::MoleculeIterator mi;
76 Molecule::AtomIterator ai;
77 Molecule::RigidBodyIterator rbIter;
78 Molecule::BondIterator bondIter;
79 Molecule::BendIterator bendIter;
80 Molecule::TorsionIterator torsionIter;
81 Molecule::InversionIterator inversionIter;
91 for (mol = info_->beginMolecule(mi); mol != NULL;
92 mol = info_->nextMolecule(mi)) {
93 molecules_[mol->getGlobalIndex()] = mol;
95 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
96 stuntdoubles_[atom->getGlobalIndex()] = atom;
98 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
99 rb = mol->nextRigidBody(rbIter)) {
100 stuntdoubles_[rb->getGlobalIndex()] = rb;
102 for (bond = mol->beginBond(bondIter); bond != NULL;
103 bond = mol->nextBond(bondIter)) {
104 bonds_[bond->getGlobalIndex()] = bond;
106 for (bend = mol->beginBend(bendIter); bend != NULL;
107 bend = mol->nextBend(bendIter)) {
108 bends_[bend->getGlobalIndex()] = bend;
110 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
111 torsion = mol->nextTorsion(torsionIter)) {
112 torsions_[torsion->getGlobalIndex()] = torsion;
114 for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
115 inversion = mol->nextInversion(inversionIter)) {
116 inversions_[inversion->getGlobalIndex()] = inversion;
124 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
127 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
134 return i == -1 ? NULL : stuntdoubles_[i];
141 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
144 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
151 return i == -1 ? NULL : stuntdoubles_[i];
158 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
161 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
168 return i == -1 ? NULL : stuntdoubles_[i];
175 while (i <
static_cast<int>(ss_.bitsets_[
STUNTDOUBLE].size())) {
178 if (stuntdoubles_[i] != NULL)
return stuntdoubles_[i];
185 return i == -1 ? NULL : stuntdoubles_[i];
192 while (i <
static_cast<int>(ss_.bitsets_[
BOND].size())) {
193 if (ss_.bitsets_[
BOND][i]) {
195 if (bonds_[i] != NULL)
return bonds_[i];
201 i = ss_.bitsets_[
BOND].firstOnBit();
202 return i == -1 ? NULL : bonds_[i];
209 while (i <
static_cast<int>(ss_.bitsets_[
BOND].size())) {
210 if (ss_.bitsets_[
BOND][i]) {
212 if (bonds_[i] != NULL)
return bonds_[i];
218 i = ss_.bitsets_[
BOND].nextOnBit(i);
219 return i == -1 ? NULL : bonds_[i];
226 while (i <
static_cast<int>(ss_.bitsets_[
BOND].size())) {
227 if (!ss_.bitsets_[
BOND][i]) {
229 if (bonds_[i] != NULL)
return bonds_[i];
235 i = ss_.bitsets_[
BOND].firstOffBit();
236 return i == -1 ? NULL : bonds_[i];
243 while (i <
static_cast<int>(ss_.bitsets_[
BOND].size())) {
244 if (!ss_.bitsets_[
BOND][i]) {
246 if (bonds_[i] != NULL)
return bonds_[i];
252 i = ss_.bitsets_[
BOND].nextOffBit(i);
253 return i == -1 ? NULL : bonds_[i];
260 while (i <
static_cast<int>(ss_.bitsets_[
BEND].size())) {
261 if (ss_.bitsets_[
BEND][i]) {
263 if (bends_[i] != NULL)
return bends_[i];
269 i = ss_.bitsets_[
BEND].firstOnBit();
270 return i == -1 ? NULL : bends_[i];
277 while (i <
static_cast<int>(ss_.bitsets_[
BEND].size())) {
278 if (ss_.bitsets_[
BEND][i]) {
280 if (bends_[i] != NULL)
return bends_[i];
286 i = ss_.bitsets_[
BEND].nextOnBit(i);
287 return i == -1 ? NULL : bends_[i];
294 while (i <
static_cast<int>(ss_.bitsets_[
BEND].size())) {
295 if (!ss_.bitsets_[
BEND][i]) {
297 if (bends_[i] != NULL)
return bends_[i];
303 i = ss_.bitsets_[
BEND].firstOffBit();
304 return i == -1 ? NULL : bends_[i];
311 while (i <
static_cast<int>(ss_.bitsets_[
BEND].size())) {
312 if (!ss_.bitsets_[
BEND][i]) {
314 if (bends_[i] != NULL)
return bends_[i];
320 i = ss_.bitsets_[
BEND].nextOffBit(i);
321 return i == -1 ? NULL : bends_[i];
328 while (i <
static_cast<int>(ss_.bitsets_[
TORSION].size())) {
329 if (ss_.bitsets_[
TORSION][i]) {
331 if (torsions_[i] != NULL)
return torsions_[i];
337 i = ss_.bitsets_[
TORSION].firstOnBit();
338 return i == -1 ? NULL : torsions_[i];
345 while (i <
static_cast<int>(ss_.bitsets_[
TORSION].size())) {
346 if (ss_.bitsets_[
TORSION][i]) {
348 if (torsions_[i] != NULL)
return torsions_[i];
354 i = ss_.bitsets_[
TORSION].nextOnBit(i);
355 return i == -1 ? NULL : torsions_[i];
362 while (i <
static_cast<int>(ss_.bitsets_[
TORSION].size())) {
363 if (!ss_.bitsets_[
TORSION][i]) {
365 if (torsions_[i] != NULL)
return torsions_[i];
371 i = ss_.bitsets_[
TORSION].firstOffBit();
372 return i == -1 ? NULL : torsions_[i];
379 while (i <
static_cast<int>(ss_.bitsets_[
TORSION].size())) {
380 if (!ss_.bitsets_[
TORSION][i]) {
382 if (torsions_[i] != NULL)
return torsions_[i];
388 i = ss_.bitsets_[
TORSION].nextOffBit(i);
389 return i == -1 ? NULL : torsions_[i];
396 while (i <
static_cast<int>(ss_.bitsets_[
INVERSION].size())) {
399 if (inversions_[i] != NULL)
return inversions_[i];
405 i = ss_.bitsets_[
INVERSION].firstOnBit();
406 return i == -1 ? NULL : inversions_[i];
413 while (i <
static_cast<int>(ss_.bitsets_[
INVERSION].size())) {
416 if (inversions_[i] != NULL)
return inversions_[i];
422 i = ss_.bitsets_[
INVERSION].nextOnBit(i);
423 return i == -1 ? NULL : inversions_[i];
430 while (i <
static_cast<int>(ss_.bitsets_[
INVERSION].size())) {
433 if (inversions_[i] != NULL)
return inversions_[i];
439 i = ss_.bitsets_[
INVERSION].firstOffBit();
440 return i == -1 ? NULL : inversions_[i];
447 while (i <
static_cast<int>(ss_.bitsets_[
INVERSION].size())) {
450 if (inversions_[i] != NULL)
return inversions_[i];
456 i = ss_.bitsets_[
INVERSION].nextOffBit(i);
457 return i == -1 ? NULL : inversions_[i];
464 while (i <
static_cast<int>(ss_.bitsets_[
MOLECULE].size())) {
467 if (molecules_[i] != NULL)
return molecules_[i];
473 i = ss_.bitsets_[
MOLECULE].firstOnBit();
474 return i == -1 ? NULL : molecules_[i];
481 while (i <
static_cast<int>(ss_.bitsets_[
MOLECULE].size())) {
484 if (molecules_[i] != NULL)
return molecules_[i];
490 i = ss_.bitsets_[
MOLECULE].nextOnBit(i);
491 return i == -1 ? NULL : molecules_[i];
498 while (i <
static_cast<int>(ss_.bitsets_[
MOLECULE].size())) {
501 if (molecules_[i] != NULL)
return molecules_[i];
507 i = ss_.bitsets_[
MOLECULE].firstOffBit();
508 return i == -1 ? NULL : molecules_[i];
515 while (i <
static_cast<int>(ss_.bitsets_[
MOLECULE].size())) {
518 if (molecules_[i] != NULL)
return molecules_[i];
524 i = ss_.bitsets_[
MOLECULE].nextOffBit(i);
525 return i == -1 ? NULL : molecules_[i];
532 i = ss_.bitsets_[
MOLECULE].nthOnBit(n);
533 if (i == -1)
return NULL;
535 if (molecules_[i] != NULL)
return molecules_[i];
538 i = ss_.bitsets_[
MOLECULE].nthOnBit(n);
539 return i == -1 ? NULL : molecules_[i];
551 AtomTypeSet atomTypes;
553 for (
size_t i = 0; i < ss_.bitsets_[
STUNTDOUBLE].size(); ++i) {
556 if (stuntdoubles_[i] != NULL) {
557 if (stuntdoubles_[i]->isAtom()) {
558 Atom* atom =
static_cast<Atom*
>(stuntdoubles_[i]);
569 std::vector<int> foundTypes;
570 AtomTypeSet::iterator i;
571 for (i = atomTypes.begin(); i != atomTypes.end(); ++i)
572 foundTypes.push_back((*i)->getIdent());
575 int count_local = foundTypes.size();
578 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
582 std::vector<int> counts(nproc, 0);
583 std::vector<int> disps(nproc, 0);
586 MPI_Allgather(&count_local, 1, MPI_INT, &counts[0], 1, MPI_INT,
591 int totalCount = counts[0];
592 for (
int iproc = 1; iproc < nproc; iproc++) {
593 disps[iproc] = disps[iproc - 1] + counts[iproc - 1];
594 totalCount += counts[iproc];
597 if (totalCount > 0) {
599 std::vector<int> ftGlobal(totalCount);
602 MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT, &ftGlobal[0],
603 &counts[0], &disps[0], MPI_INT, MPI_COMM_WORLD);
605 std::vector<int>::iterator j;
609 std::set<int> foundIdents;
611 for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j)
612 foundIdents.insert((*j));
616 ForceField* forceField_ = info_->getForceField();
617 std::set<int>::iterator it;
618 for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
626 MoleculeStampSet SelectionManager::getSelectedMoleculeStamps() {
627 MoleculeStampSet moleculeStamps;
629 for (
size_t i = 0; i < ss_.bitsets_[
MOLECULE].size(); ++i) {
632 if (molecules_[i] != NULL) {
634 moleculeStamps.insert(mol->getMolStamp());
640 std::vector<int> foundStamps;
641 MoleculeStampSet::iterator i;
642 for (i = moleculeStamps.begin(); i != moleculeStamps.end(); ++i)
643 foundStamps.push_back((*i)->getIdent());
646 int count_local = foundStamps.size();
649 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
653 std::vector<int> counts(nproc, 0);
654 std::vector<int> disps(nproc, 0);
657 MPI_Allgather(&count_local, 1, MPI_INT, &counts[0], 1, MPI_INT,
662 int totalCount = counts[0];
663 for (
int iproc = 1; iproc < nproc; iproc++) {
664 disps[iproc] = disps[iproc - 1] + counts[iproc - 1];
665 totalCount += counts[iproc];
668 if (totalCount > 0) {
670 std::vector<int> fsGlobal(totalCount);
673 MPI_Allgatherv(&foundStamps[0], count_local, MPI_INT, &fsGlobal[0],
674 &counts[0], &disps[0], MPI_INT, MPI_COMM_WORLD);
676 std::vector<int>::iterator j;
678 for (j = fsGlobal.begin(); j != fsGlobal.end(); ++j)
679 moleculeStamps.insert(info_->getMoleculeStamp(*j));
683 return moleculeStamps;
686 SelectionManager SelectionManager::replaceRigidBodiesWithAtoms()
const {
687 SelectionSet ssAtoms(nObjects_);
690 SelectionSet ssRBs(nObjects_);
693 SelectionManager tempSeleMan = *
this;
697 std::vector<Atom*>::iterator ai;
699 for (sd = tempSeleMan.beginSelected(isd); sd != NULL;
700 sd = tempSeleMan.nextSelected(isd)) {
701 if (sd->isRigidBody()) {
702 RigidBody* rb =
static_cast<RigidBody*
>(sd);
703 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
704 ssAtoms.bitsets_[
STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
707 ssRBs.bitsets_[
STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
713 tempSeleMan.ss_ |= ssAtoms;
714 tempSeleMan.ss_ -= ssRBs;
719 SelectionManager SelectionManager::removeAtomsInRigidBodies()
const {
720 SelectionSet ssAtoms(nObjects_);
723 SelectionManager tempSeleMan = *
this;
727 std::vector<Atom*>::iterator ai;
729 for (sd = tempSeleMan.beginSelected(isd); sd != NULL;
730 sd = tempSeleMan.nextSelected(isd)) {
731 if (sd->isRigidBody()) {
732 RigidBody* rb =
static_cast<RigidBody*
>(sd);
733 for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
734 ssAtoms.bitsets_[
STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
740 tempSeleMan.ss_ -= ssAtoms;
745 SelectionManager operator|(
const SelectionManager& sman1,
746 const SelectionManager& sman2) {
747 SelectionManager result(sman1);
752 SelectionManager operator&(
const SelectionManager& sman1,
753 const SelectionManager& sman2) {
754 SelectionManager result(sman1);
759 SelectionManager operator^(
const SelectionManager& sman1,
760 const SelectionManager& sman2) {
761 SelectionManager result(sman1);
766 SelectionManager
operator-(
const SelectionManager& sman1,
767 const SelectionManager& sman2) {
768 SelectionManager result(sman1);
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType * getAtomType(const std::string &at)
getAtomType by string
Bend * nextUnselectedBend(int &i)
Finds the next unselected Bend.
Bend * beginUnselectedBend(int &i)
Finds the first unselected Bend.
Bend * nextSelectedBend(int &i)
Finds the next selected Bend in the selection.
Bond * nextUnselectedBond(int &i)
Finds the next unselected Bond.
Torsion * nextUnselectedTorsion(int &i)
Finds the next unselected Torsion.
Molecule * nthSelectedMolecule(int &n)
Finds the n^th selected Molecule in the selection.
Bend * beginSelectedBend(int &i)
Finds the first selected Bend in the selection.
Bond * nextSelectedBond(int &i)
Finds the next selected Bond in the selection.
Bond * beginSelectedBond(int &i)
Finds the first selected Bond in the selection.
AtomTypeSet getSelectedAtomTypes()
getSelectedAtomTypes
Molecule * nextSelectedMolecule(int &i)
Finds the next selected Molecule in the selection.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * nextUnselected(int &i)
Finds the next unselected StuntDouble.
Inversion * beginUnselectedInversion(int &i)
Finds the first unselected Inversion.
Inversion * beginSelectedInversion(int &i)
Finds the first selected Inversion in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
Bond * beginUnselectedBond(int &i)
Finds the first unselected Bond.
Molecule * beginSelectedMolecule(int &i)
Finds the first selected Molecule in the selection.
Torsion * beginSelectedTorsion(int &i)
Finds the first selected Torsion in the selection.
Torsion * beginUnselectedTorsion(int &i)
Finds the first unselected Torsion.
Inversion * nextSelectedInversion(int &i)
Finds the next selected Inversion in the selection.
Inversion * nextUnselectedInversion(int &i)
Finds the next unselected Inversion.
Molecule * beginUnselectedMolecule(int &i)
Finds the first unselected Molecule.
Molecule * nextUnselectedMolecule(int &i)
Finds the next unselected Molecule.
StuntDouble * beginUnselected(int &i)
Finds the first unselected StuntDouble.
Torsion * nextSelectedTorsion(int &i)
Finds the next selected Torsion in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
"Don't move, or you're dead! Stand up! Captain, we've got them!"
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).