| 6 |  | * redistribute this software in source and binary code form, provided | 
| 7 |  | * that the following conditions are met: | 
| 8 |  | * | 
| 9 | < | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | < | *    publication of scientific results based in part on use of the | 
| 11 | < | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | < | *    the article in which the program was described (Matthew | 
| 13 | < | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | < | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | < | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | < | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | < | * | 
| 18 | < | * 2. Redistributions of source code must retain the above copyright | 
| 9 | > | * 1. Redistributions of source code must retain the above copyright | 
| 10 |  | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  | * | 
| 12 | < | * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | > | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 |  | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  | *    documentation and/or other materials provided with the | 
| 15 |  | *    distribution. | 
| 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 | + | * | 
| 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 | + | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | + | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | + | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 |  | */ | 
| 42 |  |  | 
| 43 |  | #include "selection/SelectionManager.hpp" | 
| 44 |  | #include "primitives/Molecule.hpp" | 
| 45 |  | #include "brains/SimInfo.hpp" | 
| 46 | < | namespace oopse { | 
| 46 | > | namespace OpenMD { | 
| 47 |  | SelectionManager::SelectionManager(SimInfo* info) : info_(info){ | 
| 48 | + | nObjects_.push_back(info_->getNGlobalAtoms()+info_->getNGlobalRigidBodies()); | 
| 49 | + | nObjects_.push_back(info_->getNGlobalBonds()); | 
| 50 | + | nObjects_.push_back(info_->getNGlobalBends()); | 
| 51 | + | nObjects_.push_back(info_->getNGlobalTorsions()); | 
| 52 | + | nObjects_.push_back(info_->getNGlobalInversions()); | 
| 53 |  |  | 
| 54 | < | int nStuntDoubles = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(); | 
| 55 | < |  | 
| 56 | < | bsSelection_.resize(nStuntDoubles); | 
| 57 | < | stuntdoubles_.resize(nStuntDoubles); | 
| 54 | > | stuntdoubles_.resize(nObjects_[STUNTDOUBLE]); | 
| 55 | > | bonds_.resize(nObjects_[BOND]); | 
| 56 | > | bends_.resize(nObjects_[BEND]); | 
| 57 | > | torsions_.resize(nObjects_[TORSION]); | 
| 58 | > | inversions_.resize(nObjects_[INVERSION]); | 
| 59 |  |  | 
| 60 |  | SimInfo::MoleculeIterator mi; | 
| 54 | – | Molecule* mol; | 
| 61 |  | Molecule::AtomIterator ai; | 
| 56 | – | Atom* atom; | 
| 62 |  | Molecule::RigidBodyIterator rbIter; | 
| 63 | < | RigidBody* rb; | 
| 63 | > | Molecule::BondIterator bondIter; | 
| 64 | > | Molecule::BendIterator bendIter; | 
| 65 | > | Molecule::TorsionIterator torsionIter; | 
| 66 | > | Molecule::InversionIterator inversionIter; | 
| 67 |  |  | 
| 68 | < |  | 
| 69 | < | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 68 | > | Molecule* mol; | 
| 69 | > | Atom* atom; | 
| 70 | > | RigidBody* rb; | 
| 71 | > | Bond* bond; | 
| 72 | > | Bend* bend; | 
| 73 | > | Torsion* torsion; | 
| 74 | > | Inversion* inversion; | 
| 75 |  |  | 
| 76 | < | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 76 | > | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 77 | > | mol = info_->nextMolecule(mi)) { | 
| 78 | > |  | 
| 79 | > | for(atom = mol->beginAtom(ai); atom != NULL; | 
| 80 | > | atom = mol->nextAtom(ai)) { | 
| 81 |  | stuntdoubles_[atom->getGlobalIndex()] = atom; | 
| 82 | < | } | 
| 83 | < |  | 
| 84 | < | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 82 | > | } | 
| 83 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 84 | > | rb = mol->nextRigidBody(rbIter)) { | 
| 85 |  | stuntdoubles_[rb->getGlobalIndex()] = rb; | 
| 86 | < | } | 
| 87 | < |  | 
| 88 | < | } | 
| 89 | < |  | 
| 86 | > | } | 
| 87 | > | for (bond = mol->beginBond(bondIter); bond != NULL; | 
| 88 | > | bond = mol->nextBond(bondIter)) { | 
| 89 | > | bonds_[bond->getGlobalIndex()] = bond; | 
| 90 | > | } | 
| 91 | > | for (bend = mol->beginBend(bendIter); bend != NULL; | 
| 92 | > | bend = mol->nextBend(bendIter)) { | 
| 93 | > | bends_[bend->getGlobalIndex()] = bend; | 
| 94 | > | } | 
| 95 | > | for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; | 
| 96 | > | torsion = mol->nextTorsion(torsionIter)) { | 
| 97 | > | torsions_[torsion->getGlobalIndex()] = torsion; | 
| 98 | > | } | 
| 99 | > | for (inversion = mol->beginInversion(inversionIter); inversion != NULL; | 
| 100 | > | inversion = mol->nextInversion(inversionIter)) { | 
| 101 | > | inversions_[inversion->getGlobalIndex()] = inversion; | 
| 102 | > | } | 
| 103 | > | } | 
| 104 |  | } | 
| 105 |  |  | 
| 75 | – |  | 
| 106 |  | StuntDouble* SelectionManager::beginSelected(int& i) { | 
| 107 | < | i = bsSelection_.firstOnBit(); | 
| 107 | > | i = ss_.bitsets_[STUNTDOUBLE].firstOnBit(); | 
| 108 |  | return i == -1 ? NULL : stuntdoubles_[i]; | 
| 109 |  | } | 
| 110 | + |  | 
| 111 |  | StuntDouble* SelectionManager::nextSelected(int& i) { | 
| 112 | < | i = bsSelection_.nextOnBit(i); | 
| 112 | > | i = ss_.bitsets_[STUNTDOUBLE].nextOnBit(i); | 
| 113 |  | return i == -1 ? NULL : stuntdoubles_[i]; | 
| 114 |  | } | 
| 115 |  |  | 
| 116 |  | StuntDouble* SelectionManager::beginUnselected(int& i){ | 
| 117 | < | i = bsSelection_.firstOffBit(); | 
| 117 | > | i = ss_.bitsets_[STUNTDOUBLE].firstOffBit(); | 
| 118 |  | return i == -1 ? NULL : stuntdoubles_[i]; | 
| 119 |  | } | 
| 120 | + |  | 
| 121 |  | StuntDouble* SelectionManager::nextUnSelected(int& i) { | 
| 122 | < | i = bsSelection_.nextOffBit(i); | 
| 122 | > | i = ss_.bitsets_[STUNTDOUBLE].nextOffBit(i); | 
| 123 |  | return i == -1 ? NULL : stuntdoubles_[i]; | 
| 124 |  | } | 
| 125 |  |  | 
| 126 | + | Bond* SelectionManager::beginSelectedBond(int& i) { | 
| 127 | + | i = ss_.bitsets_[BOND].firstOnBit(); | 
| 128 | + | return i == -1 ? NULL : bonds_[i]; | 
| 129 | + | } | 
| 130 |  |  | 
| 131 | < | SelectionManager operator| (const SelectionManager& sman1, const SelectionManager& sman2) { | 
| 131 | > | Bond* SelectionManager::nextSelectedBond(int& i) { | 
| 132 | > | i = ss_.bitsets_[BOND].nextOnBit(i); | 
| 133 | > | return i == -1 ? NULL : bonds_[i]; | 
| 134 | > | } | 
| 135 | > |  | 
| 136 | > | Bond* SelectionManager::beginUnselectedBond(int& i){ | 
| 137 | > | i = ss_.bitsets_[BOND].firstOffBit(); | 
| 138 | > | return i == -1 ? NULL : bonds_[i]; | 
| 139 | > | } | 
| 140 | > |  | 
| 141 | > | Bond* SelectionManager::nextUnSelectedBond(int& i) { | 
| 142 | > | i = ss_.bitsets_[BOND].nextOffBit(i); | 
| 143 | > | return i == -1 ? NULL : bonds_[i]; | 
| 144 | > | } | 
| 145 | > |  | 
| 146 | > | Bend* SelectionManager::beginSelectedBend(int& i) { | 
| 147 | > | i = ss_.bitsets_[BEND].firstOnBit(); | 
| 148 | > | return i == -1 ? NULL : bends_[i]; | 
| 149 | > | } | 
| 150 | > |  | 
| 151 | > | Bend* SelectionManager::nextSelectedBend(int& i) { | 
| 152 | > | i = ss_.bitsets_[BEND].nextOnBit(i); | 
| 153 | > | return i == -1 ? NULL : bends_[i]; | 
| 154 | > | } | 
| 155 | > |  | 
| 156 | > | Bend* SelectionManager::beginUnselectedBend(int& i){ | 
| 157 | > | i = ss_.bitsets_[BEND].firstOffBit(); | 
| 158 | > | return i == -1 ? NULL : bends_[i]; | 
| 159 | > | } | 
| 160 | > |  | 
| 161 | > | Bend* SelectionManager::nextUnSelectedBend(int& i) { | 
| 162 | > | i = ss_.bitsets_[BEND].nextOffBit(i); | 
| 163 | > | return i == -1 ? NULL : bends_[i]; | 
| 164 | > | } | 
| 165 | > |  | 
| 166 | > | Torsion* SelectionManager::beginSelectedTorsion(int& i) { | 
| 167 | > | i = ss_.bitsets_[TORSION].firstOnBit(); | 
| 168 | > | return i == -1 ? NULL : torsions_[i]; | 
| 169 | > | } | 
| 170 | > |  | 
| 171 | > | Torsion* SelectionManager::nextSelectedTorsion(int& i) { | 
| 172 | > | i = ss_.bitsets_[TORSION].nextOnBit(i); | 
| 173 | > | return i == -1 ? NULL : torsions_[i]; | 
| 174 | > | } | 
| 175 | > |  | 
| 176 | > | Torsion* SelectionManager::beginUnselectedTorsion(int& i){ | 
| 177 | > | i = ss_.bitsets_[TORSION].firstOffBit(); | 
| 178 | > | return i == -1 ? NULL : torsions_[i]; | 
| 179 | > | } | 
| 180 | > |  | 
| 181 | > | Torsion* SelectionManager::nextUnSelectedTorsion(int& i) { | 
| 182 | > | i = ss_.bitsets_[TORSION].nextOffBit(i); | 
| 183 | > | return i == -1 ? NULL : torsions_[i]; | 
| 184 | > | } | 
| 185 | > |  | 
| 186 | > | Inversion* SelectionManager::beginSelectedInversion(int& i) { | 
| 187 | > | i = ss_.bitsets_[INVERSION].firstOnBit(); | 
| 188 | > | return i == -1 ? NULL : inversions_[i]; | 
| 189 | > | } | 
| 190 | > |  | 
| 191 | > | Inversion* SelectionManager::nextSelectedInversion(int& i) { | 
| 192 | > | i = ss_.bitsets_[INVERSION].nextOnBit(i); | 
| 193 | > | return i == -1 ? NULL : inversions_[i]; | 
| 194 | > | } | 
| 195 | > |  | 
| 196 | > | Inversion* SelectionManager::beginUnselectedInversion(int& i){ | 
| 197 | > | i = ss_.bitsets_[INVERSION].firstOffBit(); | 
| 198 | > | return i == -1 ? NULL : inversions_[i]; | 
| 199 | > | } | 
| 200 | > |  | 
| 201 | > | Inversion* SelectionManager::nextUnSelectedInversion(int& i) { | 
| 202 | > | i = ss_.bitsets_[INVERSION].nextOffBit(i); | 
| 203 | > | return i == -1 ? NULL : inversions_[i]; | 
| 204 | > | } | 
| 205 | > |  | 
| 206 | > | SelectionManager operator| (const SelectionManager& sman1, | 
| 207 | > | const SelectionManager& sman2) { | 
| 208 |  | SelectionManager result(sman1); | 
| 209 |  | result |= sman2; | 
| 210 |  | return result; | 
| 211 |  | } | 
| 212 | < | SelectionManager operator& (const SelectionManager& sman1, const SelectionManager& sman2) { | 
| 212 | > |  | 
| 213 | > | SelectionManager operator& (const SelectionManager& sman1, | 
| 214 | > | const SelectionManager& sman2) { | 
| 215 |  | SelectionManager result(sman1); | 
| 216 |  | result &= sman2; | 
| 217 |  | return result; | 
| 104 | – |  | 
| 218 |  | } | 
| 219 | < | SelectionManager operator^ (const SelectionManager& sman1, const SelectionManager& sman2) { | 
| 219 | > |  | 
| 220 | > | SelectionManager operator^ (const SelectionManager& sman1, | 
| 221 | > | const SelectionManager& sman2) { | 
| 222 |  | SelectionManager result(sman1); | 
| 223 |  | result ^= sman2; | 
| 224 |  | return result; | 
| 110 | – |  | 
| 225 |  | } | 
| 226 | < | SelectionManager operator-(const SelectionManager& sman1, const SelectionManager& sman2){ | 
| 226 | > |  | 
| 227 | > | SelectionManager operator-(const SelectionManager& sman1, | 
| 228 | > | const SelectionManager& sman2){ | 
| 229 |  | SelectionManager result(sman1); | 
| 230 |  | result -= sman2; | 
| 231 |  | return result; | 
| 116 | – |  | 
| 232 |  | } | 
| 233 |  |  | 
| 234 |  | } |