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

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_SELECTIONSET_HPP
44 #define SELECTION_SELECTIONSET_HPP
45
46 #include <iostream>
47 #include <vector>
48 #include "utils/OpenMDBitSet.hpp"
49
50 namespace OpenMD {
51
52 /**
53 * The SelectionType enum.
54 *
55 * This is used to sort different types of selections by object type
56 */
57 enum SelectionType {
58 STUNTDOUBLE = 0, /**< StuntDoubles (Atoms & RigidBodies) */
59 BOND = 1, /**< Bonds */
60 BEND = 2, /**< Bends */
61 TORSION = 3, /**< Torsions */
62 INVERSION = 4, /**< Inversions */
63 N_SELECTIONTYPES = 5
64 };
65
66 class SelectionSet {
67 public:
68 /** */
69 SelectionSet() { bitsets_.resize(N_SELECTIONTYPES); }
70 /** */
71 SelectionSet(std::vector<int> nbits);
72
73 /** Returns the number of bits set to true in this SelectionSet. */
74 std::vector<int> countBits();
75
76 /** Sets the bit at the specified index to to the complement of its current value. */
77 void flip(std::vector<int> bitIndex);
78
79 /** Sets each bit from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the complement of its current value. */
80 void flip(std::vector<int> fromIndex, std::vector<int> toIndex);
81
82 /** Sets each bit to the complement of its current value. */
83 void flip();
84
85 /** Returns the value of the bit with the specified index. */
86 std::vector<bool> get(std::vector<int> bitIndex);
87
88 /** Returns a new SelectionSet composed of bits from this SelectionSet from fromIndex(inclusive) to toIndex(exclusive). */
89 SelectionSet get(std::vector<int> fromIndex, std::vector<int> toIndex);
90
91 /** Returns true if any bits are set to true */
92 std::vector<bool> any();
93
94 /** Returns true if no bits are set to true */
95 std::vector<bool> none();
96
97 std::vector<int> firstOffBit() const;
98
99 /** Returns the index of the first bit that is set to false that occurs on or after the specified starting index.*/
100 std::vector<int> nextOffBit(std::vector<int> fromIndex) const;
101
102 std::vector<int> firstOnBit() const;
103
104 /** Returns the index of the first bit that is set to true that occurs on or after the specified starting index. */
105 std::vector<int> nextOnBit(std::vector<int> fromIndex) const;
106
107 /** Performs a logical AND of this target bit set with the argument bit set. */
108 void andOperator (const SelectionSet& bs);
109
110 /** Performs a logical OR of this bit set with the bit set argument. */
111 void orOperator (const SelectionSet& bs);
112
113 /** Performs a logical XOR of this bit set with the bit set argument. */
114 void xorOperator (const SelectionSet& bs);
115
116 void setBitOn(std::vector<int> bitIndex);
117
118 void setBitOff(std::vector<int> bitIndex);
119
120 //void setRangeOn(std::vector<int> fromIndex, std::vector<int> toIndex) { setBits(fromIndex, toIndex, true); }
121
122 //void setRangeOff(std::vector<int> fromIndex, std::vector<int> toIndex) { setBits(fromIndex, toIndex, false); }
123
124 /** Sets all of the bits in this SelectionSet to false. */
125 void clearAll();
126
127 void setAll();
128
129 /** Returns the number of bits of space actually in use by this SelectionSet to represent bit values. */
130 std::vector<int> size() const;
131
132 /** Changes the size of SelectionSet*/
133 void resize(std::vector<int> nbits);
134
135 SelectionSet& operator&= (const SelectionSet &ss) { andOperator (ss); return *this; }
136 SelectionSet& operator|= (const SelectionSet &ss) { orOperator (ss); return *this; }
137 SelectionSet& operator^= (const SelectionSet &ss) { xorOperator (ss); return *this; }
138 SelectionSet& operator-= (const SelectionSet &ss) {
139 SelectionSet tmp = *this ^ ss;
140 *this &= tmp;
141 return *this;
142 }
143
144 SelectionSet parallelReduce();
145
146 std::vector<bool> operator[] (std::vector<int> bitIndex) const {
147 std::vector<bool> result(N_SELECTIONTYPES);
148 for (int i = 0; i < N_SELECTIONTYPES; i++)
149 result[i] = bitsets_[i][bitIndex[i]];
150 return result;
151 }
152
153 friend SelectionSet operator| (const SelectionSet& bs1, const SelectionSet& bs2);
154 friend SelectionSet operator& (const SelectionSet& bs1, const SelectionSet& bs2);
155 friend SelectionSet operator^ (const SelectionSet& bs1, const SelectionSet& bs2);
156 friend SelectionSet operator- (const SelectionSet& bs1, const SelectionSet& bs2);
157
158 friend bool operator== (const SelectionSet & bs1, const SelectionSet &bs2);
159
160 //friend std::istream& operator>> ( std::istream&, const SelectionSet& bs);
161 friend std::ostream& operator<< ( std::ostream&, const SelectionSet& bs) ;
162
163 std::vector<OpenMDBitSet> bitsets_;
164
165
166
167 private:
168
169 /** Sets the bit at the specified index to the specified value. */
170 //void setBit(std::vector<int> bitIndex, bool value);
171
172 /** Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the specified value. */
173 //void setBits(std::vector<int> fromIndex, std::vector<int> toIndex, bool value);
174
175
176 };
177
178
179 }
180 #endif

Properties

Name Value
svn:eol-style native