ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionManager.hpp
Revision: 1953
Committed: Thu Dec 5 18:19:26 2013 UTC (11 years, 5 months ago) by gezelter
File size: 10676 byte(s)
Log Message:
Rewrote much of selection module, added a bond correlation function

File Contents

# User Rev Content
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    
53 gezelter 1390 namespace OpenMD {
54 tim 277
55 gezelter 507 class SimInfo;
56     class SelectionManager {
57     public:
58     SelectionManager(SimInfo* info);
59 tim 277
60 gezelter 507 void addSelection(StuntDouble* sd) {
61 gezelter 1953
62     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 tim 283
77 gezelter 1953 void addSelectionSet(const SelectionSet& bs) {
78     ss_.bitsets_[STUNTDOUBLE] |= bs.bitsets_[STUNTDOUBLE];
79 gezelter 507 }
80 gezelter 1953 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 tim 278
93 gezelter 1953 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 gezelter 507 void setSelection(StuntDouble* sd) {
162 gezelter 1953 ss_.bitsets_[STUNTDOUBLE].clearAll();
163     ss_.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
164 gezelter 507 }
165 gezelter 1953 void setSelection(Bond* b) {
166     ss_.bitsets_[BOND].clearAll();
167     ss_.bitsets_[BOND].setBitOn(b->getGlobalIndex());
168 gezelter 507 }
169 gezelter 1953 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 tim 283
182 gezelter 507 void toggleSelection(StuntDouble* sd) {
183 gezelter 1953 ss_.bitsets_[STUNTDOUBLE].flip(sd->getGlobalIndex());
184 gezelter 507 }
185 gezelter 1953 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 tim 283
198 gezelter 507 void toggleSelection() {
199 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
200     ss_.bitsets_[i].flip();
201 gezelter 507 }
202 tim 283
203 gezelter 507 void selectAll() {
204 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
205     ss_.bitsets_[i].setAll();
206 gezelter 507 }
207 tim 283
208 gezelter 507 void clearSelection() {
209 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
210     ss_.bitsets_[i].clearAll();
211 gezelter 507 }
212 tim 283
213 gezelter 507 void clearSelection(StuntDouble* sd) {
214 gezelter 1953 ss_.bitsets_[STUNTDOUBLE].setBitOff(sd->getGlobalIndex());
215 gezelter 507 }
216 gezelter 1953 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 tim 283
229 gezelter 507 bool isSelected(StuntDouble* sd) {
230 gezelter 1953 return ss_.bitsets_[STUNTDOUBLE][sd->getGlobalIndex()];
231 gezelter 507 }
232 gezelter 1953 bool isSelected(Bond* b) {
233     return ss_.bitsets_[BOND][b->getGlobalIndex()];
234 gezelter 507 }
235 gezelter 1953 bool isSelected(Bend* b) {
236     return ss_.bitsets_[BEND][b->getGlobalIndex()];
237 gezelter 507 }
238 gezelter 1953 bool isSelected(Torsion* t) {
239     return ss_.bitsets_[TORSION][t->getGlobalIndex()];
240 gezelter 507 }
241 gezelter 1953 bool isSelected(Inversion* i) {
242     return ss_.bitsets_[INVERSION][i->getGlobalIndex()];
243     }
244 tim 315
245 gezelter 507 StuntDouble* beginSelected(int& i);
246     StuntDouble* nextSelected(int& i);
247     StuntDouble* beginUnselected(int& i);
248     StuntDouble* nextUnSelected(int& i);
249 tim 353
250 gezelter 1953 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 gezelter 507 SelectionManager& operator&= (const SelectionManager &sman) {
271 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
272     ss_.bitsets_[i] &= sman.ss_.bitsets_[i];
273 gezelter 507 return *this;
274     }
275 tim 283
276 gezelter 507 SelectionManager& operator|= (const SelectionManager &sman) {
277 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
278     ss_.bitsets_[i] |= sman.ss_.bitsets_[i];
279 gezelter 507 return *this;
280     }
281 tim 353
282 gezelter 507 SelectionManager& operator^= (const SelectionManager &sman) {
283 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
284     ss_.bitsets_[i] ^= sman.ss_.bitsets_[i];
285 gezelter 507 return *this;
286     }
287 tim 353
288 gezelter 507 SelectionManager& operator-= (const SelectionManager &sman) {
289 gezelter 1953 for (int i = 0; i < N_SELECTIONTYPES; i++)
290     ss_.bitsets_[i] -= sman.ss_.bitsets_[i];
291 gezelter 507 return *this;
292     }
293 tim 353
294 gezelter 507 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 tim 353
299 gezelter 507 private:
300     SimInfo* info_;
301 gezelter 1953 SelectionSet ss_;
302     std::vector<int> nObjects_;
303 gezelter 507 std::vector<StuntDouble*> stuntdoubles_;
304 gezelter 1953 std::vector<Bond*> bonds_;
305     std::vector<Bend*> bends_;
306     std::vector<Torsion*> torsions_;
307     std::vector<Inversion*> inversions_;
308 gezelter 507 };
309 tim 277
310     }
311     #endif

Properties

Name Value
svn:keywords Author Id Revision Date