| 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 |  | #ifndef SELECTION_SELECTIONMANAGER_HPP | 
| 44 |  | #define SELECTION_SELECTIONMANAGER_HPP | 
| 45 |  |  | 
| 46 | < | #include "utils/BitSet.hpp" | 
| 46 | > | #include "selection/SelectionSet.hpp" | 
| 47 |  | #include "primitives/StuntDouble.hpp" | 
| 48 | < | namespace oopse { | 
| 48 | > | #include "primitives/Bond.hpp" | 
| 49 | > | #include "primitives/Bend.hpp" | 
| 50 | > | #include "primitives/Torsion.hpp" | 
| 51 | > | #include "primitives/Inversion.hpp" | 
| 52 |  |  | 
| 53 | < | class SimInfo; | 
| 50 | < | /** | 
| 51 | < | * @class SelectionManager SelectionManager.hpp "selection/SelectionManager.hpp" | 
| 52 | < | * @brief | 
| 53 | < | */ | 
| 54 | < | class SelectionManager { | 
| 55 | < | public: | 
| 56 | < | SelectionManager(SimInfo* info); | 
| 53 | > | namespace OpenMD { | 
| 54 |  |  | 
| 55 | < | void addSelection(StuntDouble* sd) { | 
| 56 | < | bsSelection_.setBitOn(sd->getGlobalIndex()); | 
| 57 | < | } | 
| 58 | < |  | 
| 62 | < | void addSelectionSet(const BitSet& bs) { | 
| 63 | < | bsSelection_ |= bs; | 
| 64 | < | } | 
| 55 | > | class SimInfo; | 
| 56 | > | class SelectionManager { | 
| 57 | > | public: | 
| 58 | > | SelectionManager(SimInfo* info); | 
| 59 |  |  | 
| 60 | < | void setSelection(StuntDouble* sd) { | 
| 61 | < | bsSelection_.clearAll(); | 
| 62 | < | bsSelection_.setBitOn(sd->getGlobalIndex()); | 
| 63 | < | } | 
| 60 | > | void addSelection(StuntDouble* sd) { | 
| 61 | > |  | 
| 62 | > | ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); | 
| 63 | > | } | 
| 64 | > | void addSelection(Bond* b) { | 
| 65 | > | ss_.bitsets_[BOND].setBitOn(b->getGlobalIndex()); | 
| 66 | > | } | 
| 67 | > | void addSelection(Bend* b) { | 
| 68 | > | ss_.bitsets_[BEND].setBitOn(b->getGlobalIndex()); | 
| 69 | > | } | 
| 70 | > | void addSelection(Torsion* t) { | 
| 71 | > | ss_.bitsets_[TORSION].setBitOn(t->getGlobalIndex()); | 
| 72 | > | } | 
| 73 | > | void addSelection(Inversion* i) { | 
| 74 | > | ss_.bitsets_[INVERSION].setBitOn(i->getGlobalIndex()); | 
| 75 | > | } | 
| 76 |  |  | 
| 77 | < | void setSelectionSet(const BitSet& bs) { | 
| 78 | < | bsSelection_ = bs; | 
| 79 | < | } | 
| 77 | > | void addSelectionSet(const SelectionSet& bs) { | 
| 78 | > | ss_.bitsets_[STUNTDOUBLE] |= bs.bitsets_[STUNTDOUBLE]; | 
| 79 | > | } | 
| 80 | > | void addBondSelectionSet(const SelectionSet& bs) { | 
| 81 | > | ss_.bitsets_[BOND] |= bs.bitsets_[BOND]; | 
| 82 | > | } | 
| 83 | > | void addBendSelectionSet(const SelectionSet& bs) { | 
| 84 | > | ss_.bitsets_[BEND] |= bs.bitsets_[BEND]; | 
| 85 | > | } | 
| 86 | > | void addTorsionSelectionSet(const SelectionSet& bs) { | 
| 87 | > | ss_.bitsets_[TORSION] |= bs.bitsets_[TORSION]; | 
| 88 | > | } | 
| 89 | > | void addInversionSelectionSet(const SelectionSet& bs) { | 
| 90 | > | ss_.bitsets_[INVERSION] |= bs.bitsets_[INVERSION]; | 
| 91 | > | } | 
| 92 |  |  | 
| 93 | < | void toggleSelection(StuntDouble* sd) { | 
| 94 | < | bsSelection_.flip(sd->getGlobalIndex()); | 
| 95 | < | } | 
| 93 | > | bool isEmpty() { | 
| 94 | > | return ss_.bitsets_[STUNTDOUBLE].none() && ss_.bitsets_[BOND].none() | 
| 95 | > | && ss_.bitsets_[BEND].none()  && ss_.bitsets_[TORSION].none() | 
| 96 | > | && ss_.bitsets_[INVERSION].none(); | 
| 97 | > | } | 
| 98 |  |  | 
| 99 | < | void toggleSelection() { | 
| 100 | < | bsSelection_.flip(); | 
| 101 | < | } | 
| 102 | < |  | 
| 83 | < | void selectAll() { | 
| 84 | < | bsSelection_.setAll(); | 
| 85 | < | } | 
| 99 | > | void setSelectionSet(const SelectionSet& bs) { | 
| 100 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 101 | > | ss_.bitsets_[i] = bs.bitsets_[i]; | 
| 102 | > | } | 
| 103 |  |  | 
| 104 | < | void clearSelection() { | 
| 105 | < | bsSelection_.clearAll(); | 
| 106 | < | } | 
| 104 | > | //void setSelectionSet(const SelectionSet& bs) { | 
| 105 | > | //  ss_.bitsets_[STUNTDOUBLE] = bs.bitsets_[]; | 
| 106 | > | //} | 
| 107 | > | void setBondSelectionSet(const SelectionSet& bs) { | 
| 108 | > | ss_.bitsets_[BOND] = bs.bitsets_[BOND]; | 
| 109 | > | } | 
| 110 | > | void setBendSelectionSet(const SelectionSet& bs) { | 
| 111 | > | ss_.bitsets_[BEND] = bs.bitsets_[BEND]; | 
| 112 | > | } | 
| 113 | > | void setTorsionSelectionSet(const SelectionSet& bs) { | 
| 114 | > | ss_.bitsets_[TORSION] = bs.bitsets_[TORSION]; | 
| 115 | > | } | 
| 116 | > | void setInversionSelectionSet(const SelectionSet& bs) { | 
| 117 | > | ss_.bitsets_[INVERSION] = bs.bitsets_[INVERSION]; | 
| 118 | > | } | 
| 119 |  |  | 
| 120 | < | void clearSelection(StuntDouble* sd) { | 
| 121 | < | bsSelection_.setBitOff(sd->getGlobalIndex()); | 
| 122 | < | } | 
| 120 | > | std::vector<int> getSelectionCounts() { | 
| 121 | > | std::vector<int> counts(N_SELECTIONTYPES,0); | 
| 122 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) { | 
| 123 | > | counts[i] = ss_.bitsets_[i].countBits(); | 
| 124 | > | } | 
| 125 | > | return counts; | 
| 126 | > | } | 
| 127 | > |  | 
| 128 | > | int getSelectionCount() { | 
| 129 | > | return ss_.bitsets_[STUNTDOUBLE].countBits(); | 
| 130 | > | } | 
| 131 | > | int getBondSelectionCount() { | 
| 132 | > | return ss_.bitsets_[BOND].countBits(); | 
| 133 | > | } | 
| 134 | > | int getBendSelectionCount() { | 
| 135 | > | return ss_.bitsets_[BEND].countBits(); | 
| 136 | > | } | 
| 137 | > | int getTorsionSelectionCount() { | 
| 138 | > | return ss_.bitsets_[TORSION].countBits(); | 
| 139 | > | } | 
| 140 | > | int getInversionSelectionCount() { | 
| 141 | > | return ss_.bitsets_[INVERSION].countBits(); | 
| 142 | > | } | 
| 143 | > |  | 
| 144 | > | SelectionSet getSelectionSet() { | 
| 145 | > | return ss_; | 
| 146 | > | } | 
| 147 | > | /*    SelectionSet getBondSelectionSet() { | 
| 148 | > | return ss_.bitsets_[BOND]; | 
| 149 | > | } | 
| 150 | > | SelectionSet getBendSelectionSet() { | 
| 151 | > | return ss_.bitsets_[BEND]; | 
| 152 | > | } | 
| 153 | > | SelectionSet getTorsionSelectionSet() { | 
| 154 | > | return ss_.bitsets_[TORSION]; | 
| 155 | > | } | 
| 156 | > | SelectionSet getInversionSelectionSet() { | 
| 157 | > | return ss_.bitsets_[INVERSION]; | 
| 158 | > | } | 
| 159 | > | */ | 
| 160 |  |  | 
| 161 | < | bool isSelected(StuntDouble* sd) { | 
| 162 | < | return bsSelection_[sd->getGlobalIndex()]; | 
| 163 | < | } | 
| 161 | > | void setSelection(StuntDouble* sd) { | 
| 162 | > | ss_.bitsets_[STUNTDOUBLE].clearAll(); | 
| 163 | > | ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); | 
| 164 | > | } | 
| 165 | > | void setSelection(Bond* b) { | 
| 166 | > | ss_.bitsets_[BOND].clearAll(); | 
| 167 | > | ss_.bitsets_[BOND].setBitOn(b->getGlobalIndex()); | 
| 168 | > | } | 
| 169 | > | void setSelection(Bend* b) { | 
| 170 | > | ss_.bitsets_[BEND].clearAll(); | 
| 171 | > | ss_.bitsets_[BEND].setBitOn(b->getGlobalIndex()); | 
| 172 | > | } | 
| 173 | > | void setSelection(Torsion* t) { | 
| 174 | > | ss_.bitsets_[TORSION].clearAll(); | 
| 175 | > | ss_.bitsets_[TORSION].setBitOn(t->getGlobalIndex()); | 
| 176 | > | } | 
| 177 | > | void setSelection(Inversion* i) { | 
| 178 | > | ss_.bitsets_[INVERSION].clearAll(); | 
| 179 | > | ss_.bitsets_[INVERSION].setBitOn(i->getGlobalIndex()); | 
| 180 | > | } | 
| 181 |  |  | 
| 182 | < | bool isEmpty() { | 
| 183 | < | return bsSelection_.none(); | 
| 184 | < | } | 
| 182 | > | void toggleSelection(StuntDouble* sd) { | 
| 183 | > | ss_.bitsets_[STUNTDOUBLE].flip(sd->getGlobalIndex()); | 
| 184 | > | } | 
| 185 | > | void toggleSelection(Bond* b) { | 
| 186 | > | ss_.bitsets_[BOND].flip(b->getGlobalIndex()); | 
| 187 | > | } | 
| 188 | > | void toggleSelection(Bend* b) { | 
| 189 | > | ss_.bitsets_[BEND].flip(b->getGlobalIndex()); | 
| 190 | > | } | 
| 191 | > | void toggleSelection(Torsion* t) { | 
| 192 | > | ss_.bitsets_[TORSION].flip(t->getGlobalIndex()); | 
| 193 | > | } | 
| 194 | > | void toggleSelection(Inversion* i) { | 
| 195 | > | ss_.bitsets_[INVERSION].flip(i->getGlobalIndex()); | 
| 196 | > | } | 
| 197 |  |  | 
| 198 | < | int getSelectionCount() { | 
| 199 | < | return bsSelection_.countBits(); | 
| 200 | < | } | 
| 198 | > | void toggleSelection() { | 
| 199 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 200 | > | ss_.bitsets_[i].flip(); | 
| 201 | > | } | 
| 202 | > |  | 
| 203 | > | void selectAll() { | 
| 204 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 205 | > | ss_.bitsets_[i].setAll(); | 
| 206 | > | } | 
| 207 |  |  | 
| 208 | < | BitSet getSelectionSet() { | 
| 209 | < | return bsSelection_; | 
| 210 | < | } | 
| 208 | > | void clearSelection() { | 
| 209 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 210 | > | ss_.bitsets_[i].clearAll(); | 
| 211 | > | } | 
| 212 |  |  | 
| 213 | + | void clearSelection(StuntDouble* sd) { | 
| 214 | + | ss_.bitsets_[STUNTDOUBLE].setBitOff(sd->getGlobalIndex()); | 
| 215 | + | } | 
| 216 | + | void clearSelection(Bond* b) { | 
| 217 | + | ss_.bitsets_[BOND].setBitOff(b->getGlobalIndex()); | 
| 218 | + | } | 
| 219 | + | void clearSelection(Bend* b) { | 
| 220 | + | ss_.bitsets_[BEND].setBitOff(b->getGlobalIndex()); | 
| 221 | + | } | 
| 222 | + | void clearSelection(Torsion* t) { | 
| 223 | + | ss_.bitsets_[TORSION].setBitOff(t->getGlobalIndex()); | 
| 224 | + | } | 
| 225 | + | void clearSelection(Inversion* i) { | 
| 226 | + | ss_.bitsets_[INVERSION].setBitOff(i->getGlobalIndex()); | 
| 227 | + | } | 
| 228 |  |  | 
| 229 | < | StuntDouble* beginSelected(int& i); | 
| 230 | < | StuntDouble* nextSelected(int& i); | 
| 229 | > | bool isSelected(StuntDouble* sd) { | 
| 230 | > | return ss_.bitsets_[STUNTDOUBLE][sd->getGlobalIndex()]; | 
| 231 | > | } | 
| 232 | > | bool isSelected(Bond* b) { | 
| 233 | > | return ss_.bitsets_[BOND][b->getGlobalIndex()]; | 
| 234 | > | } | 
| 235 | > | bool isSelected(Bend* b) { | 
| 236 | > | return ss_.bitsets_[BEND][b->getGlobalIndex()]; | 
| 237 | > | } | 
| 238 | > | bool isSelected(Torsion* t) { | 
| 239 | > | return ss_.bitsets_[TORSION][t->getGlobalIndex()]; | 
| 240 | > | } | 
| 241 | > | bool isSelected(Inversion* i) { | 
| 242 | > | return ss_.bitsets_[INVERSION][i->getGlobalIndex()]; | 
| 243 | > | } | 
| 244 |  |  | 
| 245 | < | StuntDouble* beginUnselected(int& i); | 
| 246 | < | StuntDouble* nextUnSelected(int& i); | 
| 245 | > | StuntDouble* beginSelected(int& i); | 
| 246 | > | StuntDouble* nextSelected(int& i); | 
| 247 | > | StuntDouble* beginUnselected(int& i); | 
| 248 | > | StuntDouble* nextUnSelected(int& i); | 
| 249 |  |  | 
| 250 | < | SelectionManager& operator&= (const SelectionManager &sman) { | 
| 251 | < | bsSelection_ &= sman.bsSelection_; | 
| 252 | < | return *this; | 
| 253 | < | } | 
| 250 | > | Bond* beginSelectedBond(int& i); | 
| 251 | > | Bond* nextSelectedBond(int& i); | 
| 252 | > | Bond* beginUnselectedBond(int& i); | 
| 253 | > | Bond* nextUnSelectedBond(int& i); | 
| 254 | > |  | 
| 255 | > | Bend* beginSelectedBend(int& i); | 
| 256 | > | Bend* nextSelectedBend(int& i); | 
| 257 | > | Bend* beginUnselectedBend(int& i); | 
| 258 | > | Bend* nextUnSelectedBend(int& i); | 
| 259 | > |  | 
| 260 | > | Torsion* beginSelectedTorsion(int& i); | 
| 261 | > | Torsion* nextSelectedTorsion(int& i); | 
| 262 | > | Torsion* beginUnselectedTorsion(int& i); | 
| 263 | > | Torsion* nextUnSelectedTorsion(int& i); | 
| 264 | > |  | 
| 265 | > | Inversion* beginSelectedInversion(int& i); | 
| 266 | > | Inversion* nextSelectedInversion(int& i); | 
| 267 | > | Inversion* beginUnselectedInversion(int& i); | 
| 268 | > | Inversion* nextUnSelectedInversion(int& i); | 
| 269 | > |  | 
| 270 | > | SelectionManager& operator&= (const SelectionManager &sman) { | 
| 271 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 272 | > | ss_.bitsets_[i] &= sman.ss_.bitsets_[i]; | 
| 273 | > | return *this; | 
| 274 | > | } | 
| 275 |  |  | 
| 276 | < | SelectionManager& operator|= (const SelectionManager &sman) { | 
| 277 | < | bsSelection_ |= sman.bsSelection_; | 
| 278 | < | return *this; | 
| 279 | < | } | 
| 276 | > | SelectionManager& operator|= (const SelectionManager &sman) { | 
| 277 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 278 | > | ss_.bitsets_[i] |= sman.ss_.bitsets_[i]; | 
| 279 | > | return *this; | 
| 280 | > | } | 
| 281 |  |  | 
| 282 | < | SelectionManager& operator^= (const SelectionManager &sman) { | 
| 283 | < | bsSelection_ ^= sman.bsSelection_; | 
| 284 | < | return *this; | 
| 285 | < | } | 
| 282 | > | SelectionManager& operator^= (const SelectionManager &sman) { | 
| 283 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 284 | > | ss_.bitsets_[i] ^= sman.ss_.bitsets_[i]; | 
| 285 | > | return *this; | 
| 286 | > | } | 
| 287 |  |  | 
| 288 | < | SelectionManager& operator-= (const SelectionManager &sman) { | 
| 289 | < | bsSelection_ -= sman.bsSelection_; | 
| 290 | < | return *this; | 
| 291 | < | } | 
| 288 | > | SelectionManager& operator-= (const SelectionManager &sman) { | 
| 289 | > | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 290 | > | ss_.bitsets_[i] -= sman.ss_.bitsets_[i]; | 
| 291 | > | return *this; | 
| 292 | > | } | 
| 293 |  |  | 
| 294 | < | friend SelectionManager operator| (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 295 | < | friend SelectionManager operator& (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 296 | < | friend SelectionManager operator^ (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 297 | < | friend SelectionManager operator-(const SelectionManager& sman1, const SelectionManager& sman2); | 
| 294 | > | friend SelectionManager operator| (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 295 | > | friend SelectionManager operator& (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 296 | > | friend SelectionManager operator^ (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 297 | > | friend SelectionManager operator-(const SelectionManager& sman1, const SelectionManager& sman2); | 
| 298 |  |  | 
| 299 | < | private: | 
| 300 | < | SimInfo* info_; | 
| 301 | < | BitSet bsSelection_; | 
| 302 | < | std::vector<StuntDouble*> stuntdoubles_; | 
| 303 | < | }; | 
| 299 | > | private: | 
| 300 | > | SimInfo* info_; | 
| 301 | > | SelectionSet ss_; | 
| 302 | > | std::vector<int> nObjects_; | 
| 303 | > | std::vector<StuntDouble*> stuntdoubles_; | 
| 304 | > | std::vector<Bond*> bonds_; | 
| 305 | > | std::vector<Bend*> bends_; | 
| 306 | > | std::vector<Torsion*> torsions_; | 
| 307 | > | std::vector<Inversion*> inversions_; | 
| 308 | > | }; | 
| 309 |  |  | 
| 310 |  | } | 
| 311 |  | #endif |