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

File Contents

# User Rev Content
1 gezelter 1953 /*
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 gezelter 2052 MOLECULE = 5, /**< Molecules */
64     N_SELECTIONTYPES = 6
65 gezelter 1953 };
66    
67     class SelectionSet {
68     public:
69     /** */
70     SelectionSet() { bitsets_.resize(N_SELECTIONTYPES); }
71     /** */
72     SelectionSet(std::vector<int> nbits);
73    
74     /** Returns the number of bits set to true in this SelectionSet. */
75     std::vector<int> countBits();
76    
77     /** Sets the bit at the specified index to to the complement of its current value. */
78     void flip(std::vector<int> bitIndex);
79    
80     /** Sets each bit from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the complement of its current value. */
81     void flip(std::vector<int> fromIndex, std::vector<int> toIndex);
82    
83     /** Sets each bit to the complement of its current value. */
84     void flip();
85    
86     /** Returns the value of the bit with the specified index. */
87     std::vector<bool> get(std::vector<int> bitIndex);
88    
89     /** Returns a new SelectionSet composed of bits from this SelectionSet from fromIndex(inclusive) to toIndex(exclusive). */
90     SelectionSet get(std::vector<int> fromIndex, std::vector<int> toIndex);
91    
92     /** Returns true if any bits are set to true */
93     std::vector<bool> any();
94    
95     /** Returns true if no bits are set to true */
96     std::vector<bool> none();
97    
98     std::vector<int> firstOffBit() const;
99    
100     /** Returns the index of the first bit that is set to false that occurs on or after the specified starting index.*/
101     std::vector<int> nextOffBit(std::vector<int> fromIndex) const;
102    
103     std::vector<int> firstOnBit() const;
104    
105     /** Returns the index of the first bit that is set to true that occurs on or after the specified starting index. */
106     std::vector<int> nextOnBit(std::vector<int> fromIndex) const;
107    
108     /** Performs a logical AND of this target bit set with the argument bit set. */
109     void andOperator (const SelectionSet& bs);
110    
111     /** Performs a logical OR of this bit set with the bit set argument. */
112     void orOperator (const SelectionSet& bs);
113    
114     /** Performs a logical XOR of this bit set with the bit set argument. */
115     void xorOperator (const SelectionSet& bs);
116    
117     void setBitOn(std::vector<int> bitIndex);
118    
119     void setBitOff(std::vector<int> bitIndex);
120    
121     //void setRangeOn(std::vector<int> fromIndex, std::vector<int> toIndex) { setBits(fromIndex, toIndex, true); }
122    
123     //void setRangeOff(std::vector<int> fromIndex, std::vector<int> toIndex) { setBits(fromIndex, toIndex, false); }
124    
125     /** Sets all of the bits in this SelectionSet to false. */
126     void clearAll();
127    
128     void setAll();
129    
130     /** Returns the number of bits of space actually in use by this SelectionSet to represent bit values. */
131     std::vector<int> size() const;
132    
133     /** Changes the size of SelectionSet*/
134     void resize(std::vector<int> nbits);
135    
136     SelectionSet& operator&= (const SelectionSet &ss) { andOperator (ss); return *this; }
137     SelectionSet& operator|= (const SelectionSet &ss) { orOperator (ss); return *this; }
138     SelectionSet& operator^= (const SelectionSet &ss) { xorOperator (ss); return *this; }
139     SelectionSet& operator-= (const SelectionSet &ss) {
140     SelectionSet tmp = *this ^ ss;
141     *this &= tmp;
142     return *this;
143     }
144    
145     SelectionSet parallelReduce();
146    
147     std::vector<bool> operator[] (std::vector<int> bitIndex) const {
148     std::vector<bool> result(N_SELECTIONTYPES);
149     for (int i = 0; i < N_SELECTIONTYPES; i++)
150     result[i] = bitsets_[i][bitIndex[i]];
151     return result;
152     }
153    
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     friend SelectionSet operator- (const SelectionSet& bs1, const SelectionSet& bs2);
158    
159     friend bool operator== (const SelectionSet & bs1, const SelectionSet &bs2);
160    
161     //friend std::istream& operator>> ( std::istream&, const SelectionSet& bs);
162     friend std::ostream& operator<< ( std::ostream&, const SelectionSet& bs) ;
163    
164     std::vector<OpenMDBitSet> bitsets_;
165    
166    
167    
168     private:
169    
170     /** Sets the bit at the specified index to the specified value. */
171     //void setBit(std::vector<int> bitIndex, bool value);
172    
173     /** Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the specified value. */
174     //void setBits(std::vector<int> fromIndex, std::vector<int> toIndex, bool value);
175    
176    
177     };
178    
179    
180     }
181     #endif

Properties

Name Value
svn:eol-style native