ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionManager.hpp
Revision: 2052
Committed: Fri Jan 9 19:06:35 2015 UTC (10 years, 3 months ago) by gezelter
File size: 11862 byte(s)
Log Message:
Updating Hydrogen Bonding structures, and selection syntax to include molecule selections:

File Contents

# Content
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 #include "primitives/Molecule.hpp"
53
54 namespace OpenMD {
55
56 class SimInfo;
57 class SelectionManager {
58 public:
59 SelectionManager(SimInfo* info);
60
61 void addSelection(StuntDouble* sd) {
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 void addSelection(Molecule* m) {
77 ss_.bitsets_[MOLECULE].setBitOn(m->getGlobalIndex());
78 }
79
80 void addSelectionSet(const SelectionSet& bs) {
81 ss_.bitsets_[STUNTDOUBLE] |= bs.bitsets_[STUNTDOUBLE];
82 }
83 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 void addMoleculeSelectionSet(const SelectionSet& bs) {
96 ss_.bitsets_[MOLECULE] |= bs.bitsets_[MOLECULE];
97 }
98
99 bool isEmpty() {
100 return ss_.bitsets_[STUNTDOUBLE].none() && ss_.bitsets_[BOND].none()
101 && ss_.bitsets_[BEND].none() && ss_.bitsets_[TORSION].none()
102 && ss_.bitsets_[INVERSION].none() && ss_.bitsets_[MOLECULE].none();
103 }
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 void setMoleculeSelectionSet(const SelectionSet& bs) {
126 ss_.bitsets_[MOLECULE] = bs.bitsets_[MOLECULE];
127 }
128
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 int getMoleculeSelectionCount() {
153 return ss_.bitsets_[MOLECULE].countBits();
154 }
155
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 void setSelection(StuntDouble* sd) {
174 ss_.bitsets_[STUNTDOUBLE].clearAll();
175 ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
176 }
177 void setSelection(Bond* b) {
178 ss_.bitsets_[BOND].clearAll();
179 ss_.bitsets_[BOND].setBitOn(b->getGlobalIndex());
180 }
181 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 void setSelection(Molecule* m) {
194 ss_.bitsets_[MOLECULE].clearAll();
195 ss_.bitsets_[MOLECULE].setBitOn(m->getGlobalIndex());
196 }
197
198 void toggleSelection(StuntDouble* sd) {
199 ss_.bitsets_[STUNTDOUBLE].flip(sd->getGlobalIndex());
200 }
201 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 void toggleSelection(Molecule* m) {
214 ss_.bitsets_[MOLECULE].flip(m->getGlobalIndex());
215 }
216
217 void toggleSelection() {
218 for (int i = 0; i < N_SELECTIONTYPES; i++)
219 ss_.bitsets_[i].flip();
220 }
221
222 void selectAll() {
223 for (int i = 0; i < N_SELECTIONTYPES; i++)
224 ss_.bitsets_[i].setAll();
225 }
226
227 void clearSelection() {
228 for (int i = 0; i < N_SELECTIONTYPES; i++)
229 ss_.bitsets_[i].clearAll();
230 }
231
232 void clearSelection(StuntDouble* sd) {
233 ss_.bitsets_[STUNTDOUBLE].setBitOff(sd->getGlobalIndex());
234 }
235 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 void clearSelection(Molecule* m) {
248 ss_.bitsets_[MOLECULE].setBitOff(m->getGlobalIndex());
249 }
250
251 bool isSelected(StuntDouble* sd) {
252 return ss_.bitsets_[STUNTDOUBLE][sd->getGlobalIndex()];
253 }
254 bool isSelected(Bond* b) {
255 return ss_.bitsets_[BOND][b->getGlobalIndex()];
256 }
257 bool isSelected(Bend* b) {
258 return ss_.bitsets_[BEND][b->getGlobalIndex()];
259 }
260 bool isSelected(Torsion* t) {
261 return ss_.bitsets_[TORSION][t->getGlobalIndex()];
262 }
263 bool isSelected(Inversion* i) {
264 return ss_.bitsets_[INVERSION][i->getGlobalIndex()];
265 }
266 bool isSelected(Molecule* m) {
267 return ss_.bitsets_[MOLECULE][m->getGlobalIndex()];
268 }
269
270 StuntDouble* beginSelected(int& i);
271 StuntDouble* nextSelected(int& i);
272 StuntDouble* beginUnselected(int& i);
273 StuntDouble* nextUnSelected(int& i);
274
275 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 Molecule* beginSelectedMolecule(int& i);
296 Molecule* nextSelectedMolecule(int& i);
297 Molecule* beginUnselectedMolecule(int& i);
298 Molecule* nextUnSelectedMolecule(int& i);
299
300 SelectionManager& operator&= (const SelectionManager &sman) {
301 for (int i = 0; i < N_SELECTIONTYPES; i++)
302 ss_.bitsets_[i] &= sman.ss_.bitsets_[i];
303 return *this;
304 }
305
306 SelectionManager& operator|= (const SelectionManager &sman) {
307 for (int i = 0; i < N_SELECTIONTYPES; i++)
308 ss_.bitsets_[i] |= sman.ss_.bitsets_[i];
309 return *this;
310 }
311
312 SelectionManager& operator^= (const SelectionManager &sman) {
313 for (int i = 0; i < N_SELECTIONTYPES; i++)
314 ss_.bitsets_[i] ^= sman.ss_.bitsets_[i];
315 return *this;
316 }
317
318 SelectionManager& operator-= (const SelectionManager &sman) {
319 for (int i = 0; i < N_SELECTIONTYPES; i++)
320 ss_.bitsets_[i] -= sman.ss_.bitsets_[i];
321 return *this;
322 }
323
324 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
329 private:
330 SimInfo* info_;
331 SelectionSet ss_;
332 std::vector<int> nObjects_;
333 std::vector<StuntDouble*> stuntdoubles_;
334 std::vector<Bond*> bonds_;
335 std::vector<Bend*> bends_;
336 std::vector<Torsion*> torsions_;
337 std::vector<Inversion*> inversions_;
338 std::vector<Molecule*> molecules_;
339 };
340
341 }
342 #endif

Properties

Name Value
svn:keywords Author Id Revision Date