1 |
/* |
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 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* |
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. |
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 |
* |
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 "selection/SelectionSet.hpp" |
47 |
#include "primitives/StuntDouble.hpp" |
48 |
#include "primitives/Bond.hpp" |
49 |
#include "primitives/Bend.hpp" |
50 |
#include "primitives/Torsion.hpp" |
51 |
#include "primitives/Inversion.hpp" |
52 |
|
53 |
namespace OpenMD { |
54 |
|
55 |
class SimInfo; |
56 |
class SelectionManager { |
57 |
public: |
58 |
SelectionManager(SimInfo* info); |
59 |
|
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 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 |
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 setSelectionSet(const SelectionSet& bs) { |
100 |
for (int i = 0; i < N_SELECTIONTYPES; i++) |
101 |
ss_.bitsets_[i] = bs.bitsets_[i]; |
102 |
} |
103 |
|
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 |
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 |
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 |
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 |
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 |
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 |
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* beginSelected(int& i); |
246 |
StuntDouble* nextSelected(int& i); |
247 |
StuntDouble* beginUnselected(int& i); |
248 |
StuntDouble* nextUnSelected(int& i); |
249 |
|
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 |
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 |
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 |
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); |
298 |
|
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 |