| 1 | tim | 277 | /* | 
| 2 |  |  | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 |  |  | * | 
| 4 |  |  | * The University of Notre Dame grants you ("Licensee") a | 
| 5 |  |  | * non-exclusive, royalty free, license to use, modify and | 
| 6 |  |  | * redistribute this software in source and binary code form, provided | 
| 7 |  |  | * that the following conditions are met: | 
| 8 |  |  | * | 
| 9 | gezelter | 1390 | * 1. Redistributions of source code must retain the above copyright | 
| 10 | tim | 277 | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  |  | * | 
| 12 | gezelter | 1390 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | tim | 277 | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  |  | *    documentation and/or other materials provided with the | 
| 15 |  |  | *    distribution. | 
| 16 |  |  | * | 
| 17 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 18 |  |  | * kind. All express or implied conditions, representations and | 
| 19 |  |  | * warranties, including any implied warranty of merchantability, | 
| 20 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 23 |  |  | * using, modifying or distributing the software or its | 
| 24 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 25 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 27 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 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 | gezelter | 1390 | * | 
| 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 | gezelter | 1879 | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | gezelter | 1782 | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 |  |  | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | tim | 277 | */ | 
| 42 |  |  |  | 
| 43 |  |  | #ifndef SELECTION_SELECTIONMANAGER_HPP | 
| 44 |  |  | #define SELECTION_SELECTIONMANAGER_HPP | 
| 45 |  |  |  | 
| 46 | gezelter | 1953 | #include "selection/SelectionSet.hpp" | 
| 47 | tim | 288 | #include "primitives/StuntDouble.hpp" | 
| 48 | gezelter | 1953 | #include "primitives/Bond.hpp" | 
| 49 |  |  | #include "primitives/Bend.hpp" | 
| 50 |  |  | #include "primitives/Torsion.hpp" | 
| 51 |  |  | #include "primitives/Inversion.hpp" | 
| 52 | gezelter | 2052 | #include "primitives/Molecule.hpp" | 
| 53 | gezelter | 1953 |  | 
| 54 | gezelter | 1390 | namespace OpenMD { | 
| 55 | tim | 277 |  | 
| 56 | gezelter | 507 | class SimInfo; | 
| 57 |  |  | class SelectionManager { | 
| 58 |  |  | public: | 
| 59 |  |  | SelectionManager(SimInfo* info); | 
| 60 | tim | 277 |  | 
| 61 | gezelter | 2052 | void addSelection(StuntDouble* sd) { | 
| 62 | gezelter | 1953 | ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); | 
| 63 | gezelter | 507 | } | 
| 64 | gezelter | 1953 | 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 | gezelter | 2052 | void addSelection(Molecule* m) { | 
| 77 |  |  | ss_.bitsets_[MOLECULE].setBitOn(m->getGlobalIndex()); | 
| 78 |  |  | } | 
| 79 | tim | 283 |  | 
| 80 | gezelter | 1953 | void addSelectionSet(const SelectionSet& bs) { | 
| 81 |  |  | ss_.bitsets_[STUNTDOUBLE] |= bs.bitsets_[STUNTDOUBLE]; | 
| 82 | gezelter | 507 | } | 
| 83 | gezelter | 1953 | void addBondSelectionSet(const SelectionSet& bs) { | 
| 84 |  |  | ss_.bitsets_[BOND] |= bs.bitsets_[BOND]; | 
| 85 |  |  | } | 
| 86 |  |  | void addBendSelectionSet(const SelectionSet& bs) { | 
| 87 |  |  | ss_.bitsets_[BEND] |= bs.bitsets_[BEND]; | 
| 88 |  |  | } | 
| 89 |  |  | void addTorsionSelectionSet(const SelectionSet& bs) { | 
| 90 |  |  | ss_.bitsets_[TORSION] |= bs.bitsets_[TORSION]; | 
| 91 |  |  | } | 
| 92 |  |  | void addInversionSelectionSet(const SelectionSet& bs) { | 
| 93 |  |  | ss_.bitsets_[INVERSION] |= bs.bitsets_[INVERSION]; | 
| 94 |  |  | } | 
| 95 | gezelter | 2052 | void addMoleculeSelectionSet(const SelectionSet& bs) { | 
| 96 |  |  | ss_.bitsets_[MOLECULE] |= bs.bitsets_[MOLECULE]; | 
| 97 |  |  | } | 
| 98 | tim | 278 |  | 
| 99 | gezelter | 1953 | bool isEmpty() { | 
| 100 |  |  | return ss_.bitsets_[STUNTDOUBLE].none() && ss_.bitsets_[BOND].none() | 
| 101 |  |  | && ss_.bitsets_[BEND].none()  && ss_.bitsets_[TORSION].none() | 
| 102 | gezelter | 2052 | && ss_.bitsets_[INVERSION].none() && ss_.bitsets_[MOLECULE].none(); | 
| 103 | gezelter | 1953 | } | 
| 104 |  |  |  | 
| 105 |  |  | void setSelectionSet(const SelectionSet& bs) { | 
| 106 |  |  | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 107 |  |  | ss_.bitsets_[i] = bs.bitsets_[i]; | 
| 108 |  |  | } | 
| 109 |  |  |  | 
| 110 |  |  | //void setSelectionSet(const SelectionSet& bs) { | 
| 111 |  |  | //  ss_.bitsets_[STUNTDOUBLE] = bs.bitsets_[]; | 
| 112 |  |  | //} | 
| 113 |  |  | void setBondSelectionSet(const SelectionSet& bs) { | 
| 114 |  |  | ss_.bitsets_[BOND] = bs.bitsets_[BOND]; | 
| 115 |  |  | } | 
| 116 |  |  | void setBendSelectionSet(const SelectionSet& bs) { | 
| 117 |  |  | ss_.bitsets_[BEND] = bs.bitsets_[BEND]; | 
| 118 |  |  | } | 
| 119 |  |  | void setTorsionSelectionSet(const SelectionSet& bs) { | 
| 120 |  |  | ss_.bitsets_[TORSION] = bs.bitsets_[TORSION]; | 
| 121 |  |  | } | 
| 122 |  |  | void setInversionSelectionSet(const SelectionSet& bs) { | 
| 123 |  |  | ss_.bitsets_[INVERSION] = bs.bitsets_[INVERSION]; | 
| 124 |  |  | } | 
| 125 | gezelter | 2052 | void setMoleculeSelectionSet(const SelectionSet& bs) { | 
| 126 |  |  | ss_.bitsets_[MOLECULE] = bs.bitsets_[MOLECULE]; | 
| 127 |  |  | } | 
| 128 | gezelter | 1953 |  | 
| 129 |  |  | std::vector<int> getSelectionCounts() { | 
| 130 |  |  | std::vector<int> counts(N_SELECTIONTYPES,0); | 
| 131 |  |  | for (int i = 0; i < N_SELECTIONTYPES; i++) { | 
| 132 |  |  | counts[i] = ss_.bitsets_[i].countBits(); | 
| 133 |  |  | } | 
| 134 |  |  | return counts; | 
| 135 |  |  | } | 
| 136 |  |  |  | 
| 137 |  |  | int getSelectionCount() { | 
| 138 |  |  | return ss_.bitsets_[STUNTDOUBLE].countBits(); | 
| 139 |  |  | } | 
| 140 |  |  | int getBondSelectionCount() { | 
| 141 |  |  | return ss_.bitsets_[BOND].countBits(); | 
| 142 |  |  | } | 
| 143 |  |  | int getBendSelectionCount() { | 
| 144 |  |  | return ss_.bitsets_[BEND].countBits(); | 
| 145 |  |  | } | 
| 146 |  |  | int getTorsionSelectionCount() { | 
| 147 |  |  | return ss_.bitsets_[TORSION].countBits(); | 
| 148 |  |  | } | 
| 149 |  |  | int getInversionSelectionCount() { | 
| 150 |  |  | return ss_.bitsets_[INVERSION].countBits(); | 
| 151 |  |  | } | 
| 152 | gezelter | 2052 | int getMoleculeSelectionCount() { | 
| 153 |  |  | return ss_.bitsets_[MOLECULE].countBits(); | 
| 154 |  |  | } | 
| 155 | gezelter | 1953 |  | 
| 156 |  |  | SelectionSet getSelectionSet() { | 
| 157 |  |  | return ss_; | 
| 158 |  |  | } | 
| 159 |  |  | /*    SelectionSet getBondSelectionSet() { | 
| 160 |  |  | return ss_.bitsets_[BOND]; | 
| 161 |  |  | } | 
| 162 |  |  | SelectionSet getBendSelectionSet() { | 
| 163 |  |  | return ss_.bitsets_[BEND]; | 
| 164 |  |  | } | 
| 165 |  |  | SelectionSet getTorsionSelectionSet() { | 
| 166 |  |  | return ss_.bitsets_[TORSION]; | 
| 167 |  |  | } | 
| 168 |  |  | SelectionSet getInversionSelectionSet() { | 
| 169 |  |  | return ss_.bitsets_[INVERSION]; | 
| 170 |  |  | } | 
| 171 |  |  | */ | 
| 172 |  |  |  | 
| 173 | gezelter | 507 | void setSelection(StuntDouble* sd) { | 
| 174 | gezelter | 1953 | ss_.bitsets_[STUNTDOUBLE].clearAll(); | 
| 175 |  |  | ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); | 
| 176 | gezelter | 507 | } | 
| 177 | gezelter | 1953 | void setSelection(Bond* b) { | 
| 178 |  |  | ss_.bitsets_[BOND].clearAll(); | 
| 179 |  |  | ss_.bitsets_[BOND].setBitOn(b->getGlobalIndex()); | 
| 180 | gezelter | 507 | } | 
| 181 | gezelter | 1953 | void setSelection(Bend* b) { | 
| 182 |  |  | ss_.bitsets_[BEND].clearAll(); | 
| 183 |  |  | ss_.bitsets_[BEND].setBitOn(b->getGlobalIndex()); | 
| 184 |  |  | } | 
| 185 |  |  | void setSelection(Torsion* t) { | 
| 186 |  |  | ss_.bitsets_[TORSION].clearAll(); | 
| 187 |  |  | ss_.bitsets_[TORSION].setBitOn(t->getGlobalIndex()); | 
| 188 |  |  | } | 
| 189 |  |  | void setSelection(Inversion* i) { | 
| 190 |  |  | ss_.bitsets_[INVERSION].clearAll(); | 
| 191 |  |  | ss_.bitsets_[INVERSION].setBitOn(i->getGlobalIndex()); | 
| 192 |  |  | } | 
| 193 | gezelter | 2052 | void setSelection(Molecule* m) { | 
| 194 |  |  | ss_.bitsets_[MOLECULE].clearAll(); | 
| 195 |  |  | ss_.bitsets_[MOLECULE].setBitOn(m->getGlobalIndex()); | 
| 196 |  |  | } | 
| 197 | tim | 283 |  | 
| 198 | gezelter | 507 | void toggleSelection(StuntDouble* sd) { | 
| 199 | gezelter | 1953 | ss_.bitsets_[STUNTDOUBLE].flip(sd->getGlobalIndex()); | 
| 200 | gezelter | 507 | } | 
| 201 | gezelter | 1953 | void toggleSelection(Bond* b) { | 
| 202 |  |  | ss_.bitsets_[BOND].flip(b->getGlobalIndex()); | 
| 203 |  |  | } | 
| 204 |  |  | void toggleSelection(Bend* b) { | 
| 205 |  |  | ss_.bitsets_[BEND].flip(b->getGlobalIndex()); | 
| 206 |  |  | } | 
| 207 |  |  | void toggleSelection(Torsion* t) { | 
| 208 |  |  | ss_.bitsets_[TORSION].flip(t->getGlobalIndex()); | 
| 209 |  |  | } | 
| 210 |  |  | void toggleSelection(Inversion* i) { | 
| 211 |  |  | ss_.bitsets_[INVERSION].flip(i->getGlobalIndex()); | 
| 212 |  |  | } | 
| 213 | gezelter | 2052 | void toggleSelection(Molecule* m) { | 
| 214 |  |  | ss_.bitsets_[MOLECULE].flip(m->getGlobalIndex()); | 
| 215 |  |  | } | 
| 216 | tim | 283 |  | 
| 217 | gezelter | 507 | void toggleSelection() { | 
| 218 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 219 |  |  | ss_.bitsets_[i].flip(); | 
| 220 | gezelter | 507 | } | 
| 221 | tim | 283 |  | 
| 222 | gezelter | 507 | void selectAll() { | 
| 223 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 224 |  |  | ss_.bitsets_[i].setAll(); | 
| 225 | gezelter | 507 | } | 
| 226 | tim | 283 |  | 
| 227 | gezelter | 507 | void clearSelection() { | 
| 228 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 229 |  |  | ss_.bitsets_[i].clearAll(); | 
| 230 | gezelter | 507 | } | 
| 231 | tim | 283 |  | 
| 232 | gezelter | 507 | void clearSelection(StuntDouble* sd) { | 
| 233 | gezelter | 1953 | ss_.bitsets_[STUNTDOUBLE].setBitOff(sd->getGlobalIndex()); | 
| 234 | gezelter | 507 | } | 
| 235 | gezelter | 1953 | void clearSelection(Bond* b) { | 
| 236 |  |  | ss_.bitsets_[BOND].setBitOff(b->getGlobalIndex()); | 
| 237 |  |  | } | 
| 238 |  |  | void clearSelection(Bend* b) { | 
| 239 |  |  | ss_.bitsets_[BEND].setBitOff(b->getGlobalIndex()); | 
| 240 |  |  | } | 
| 241 |  |  | void clearSelection(Torsion* t) { | 
| 242 |  |  | ss_.bitsets_[TORSION].setBitOff(t->getGlobalIndex()); | 
| 243 |  |  | } | 
| 244 |  |  | void clearSelection(Inversion* i) { | 
| 245 |  |  | ss_.bitsets_[INVERSION].setBitOff(i->getGlobalIndex()); | 
| 246 |  |  | } | 
| 247 | gezelter | 2052 | void clearSelection(Molecule* m) { | 
| 248 |  |  | ss_.bitsets_[MOLECULE].setBitOff(m->getGlobalIndex()); | 
| 249 |  |  | } | 
| 250 | tim | 283 |  | 
| 251 | gezelter | 507 | bool isSelected(StuntDouble* sd) { | 
| 252 | gezelter | 1953 | return ss_.bitsets_[STUNTDOUBLE][sd->getGlobalIndex()]; | 
| 253 | gezelter | 507 | } | 
| 254 | gezelter | 1953 | bool isSelected(Bond* b) { | 
| 255 |  |  | return ss_.bitsets_[BOND][b->getGlobalIndex()]; | 
| 256 | gezelter | 507 | } | 
| 257 | gezelter | 1953 | bool isSelected(Bend* b) { | 
| 258 |  |  | return ss_.bitsets_[BEND][b->getGlobalIndex()]; | 
| 259 | gezelter | 507 | } | 
| 260 | gezelter | 1953 | bool isSelected(Torsion* t) { | 
| 261 |  |  | return ss_.bitsets_[TORSION][t->getGlobalIndex()]; | 
| 262 | gezelter | 507 | } | 
| 263 | gezelter | 1953 | bool isSelected(Inversion* i) { | 
| 264 |  |  | return ss_.bitsets_[INVERSION][i->getGlobalIndex()]; | 
| 265 |  |  | } | 
| 266 | gezelter | 2052 | bool isSelected(Molecule* m) { | 
| 267 |  |  | return ss_.bitsets_[MOLECULE][m->getGlobalIndex()]; | 
| 268 |  |  | } | 
| 269 | tim | 315 |  | 
| 270 | gezelter | 507 | StuntDouble* beginSelected(int& i); | 
| 271 |  |  | StuntDouble* nextSelected(int& i); | 
| 272 |  |  | StuntDouble* beginUnselected(int& i); | 
| 273 |  |  | StuntDouble* nextUnSelected(int& i); | 
| 274 | tim | 353 |  | 
| 275 | gezelter | 1953 | Bond* beginSelectedBond(int& i); | 
| 276 |  |  | Bond* nextSelectedBond(int& i); | 
| 277 |  |  | Bond* beginUnselectedBond(int& i); | 
| 278 |  |  | Bond* nextUnSelectedBond(int& i); | 
| 279 |  |  |  | 
| 280 |  |  | Bend* beginSelectedBend(int& i); | 
| 281 |  |  | Bend* nextSelectedBend(int& i); | 
| 282 |  |  | Bend* beginUnselectedBend(int& i); | 
| 283 |  |  | Bend* nextUnSelectedBend(int& i); | 
| 284 |  |  |  | 
| 285 |  |  | Torsion* beginSelectedTorsion(int& i); | 
| 286 |  |  | Torsion* nextSelectedTorsion(int& i); | 
| 287 |  |  | Torsion* beginUnselectedTorsion(int& i); | 
| 288 |  |  | Torsion* nextUnSelectedTorsion(int& i); | 
| 289 |  |  |  | 
| 290 |  |  | Inversion* beginSelectedInversion(int& i); | 
| 291 |  |  | Inversion* nextSelectedInversion(int& i); | 
| 292 |  |  | Inversion* beginUnselectedInversion(int& i); | 
| 293 |  |  | Inversion* nextUnSelectedInversion(int& i); | 
| 294 |  |  |  | 
| 295 | gezelter | 2052 | Molecule* beginSelectedMolecule(int& i); | 
| 296 |  |  | Molecule* nextSelectedMolecule(int& i); | 
| 297 |  |  | Molecule* beginUnselectedMolecule(int& i); | 
| 298 |  |  | Molecule* nextUnSelectedMolecule(int& i); | 
| 299 |  |  |  | 
| 300 | gezelter | 507 | SelectionManager& operator&= (const SelectionManager &sman) { | 
| 301 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 302 |  |  | ss_.bitsets_[i] &= sman.ss_.bitsets_[i]; | 
| 303 | gezelter | 507 | return *this; | 
| 304 |  |  | } | 
| 305 | tim | 283 |  | 
| 306 | gezelter | 507 | SelectionManager& operator|= (const SelectionManager &sman) { | 
| 307 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 308 |  |  | ss_.bitsets_[i] |= sman.ss_.bitsets_[i]; | 
| 309 | gezelter | 507 | return *this; | 
| 310 |  |  | } | 
| 311 | tim | 353 |  | 
| 312 | gezelter | 507 | SelectionManager& operator^= (const SelectionManager &sman) { | 
| 313 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 314 |  |  | ss_.bitsets_[i] ^= sman.ss_.bitsets_[i]; | 
| 315 | gezelter | 507 | return *this; | 
| 316 |  |  | } | 
| 317 | tim | 353 |  | 
| 318 | gezelter | 507 | SelectionManager& operator-= (const SelectionManager &sman) { | 
| 319 | gezelter | 1953 | for (int i = 0; i < N_SELECTIONTYPES; i++) | 
| 320 |  |  | ss_.bitsets_[i] -= sman.ss_.bitsets_[i]; | 
| 321 | gezelter | 507 | return *this; | 
| 322 |  |  | } | 
| 323 | tim | 353 |  | 
| 324 | gezelter | 507 | friend SelectionManager operator| (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 325 |  |  | friend SelectionManager operator& (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 326 |  |  | friend SelectionManager operator^ (const SelectionManager& sman1, const SelectionManager& sman2); | 
| 327 |  |  | friend SelectionManager operator-(const SelectionManager& sman1, const SelectionManager& sman2); | 
| 328 | tim | 353 |  | 
| 329 | gezelter | 507 | private: | 
| 330 |  |  | SimInfo* info_; | 
| 331 | gezelter | 1953 | SelectionSet ss_; | 
| 332 |  |  | std::vector<int> nObjects_; | 
| 333 | gezelter | 507 | std::vector<StuntDouble*> stuntdoubles_; | 
| 334 | gezelter | 1953 | std::vector<Bond*> bonds_; | 
| 335 |  |  | std::vector<Bend*> bends_; | 
| 336 |  |  | std::vector<Torsion*> torsions_; | 
| 337 |  |  | std::vector<Inversion*> inversions_; | 
| 338 | gezelter | 2052 | std::vector<Molecule*> molecules_; | 
| 339 | gezelter | 507 | }; | 
| 340 | tim | 277 |  | 
| 341 |  |  | } | 
| 342 |  |  | #endif |