OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
SelectionSet.hpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#ifndef SELECTION_SELECTIONSET_HPP
46#define SELECTION_SELECTIONSET_HPP
47
48#include <iostream>
49#include <vector>
50
51#include "utils/OpenMDBitSet.hpp"
52
53namespace OpenMD {
54
55 /**
56 * The SelectionType enum.
57 *
58 * This is used to sort different types of selections by object type
59 */
61 STUNTDOUBLE = 0, /**< StuntDoubles (Atoms & RigidBodies) */
62 BOND = 1, /**< Bonds */
63 BEND = 2, /**< Bends */
64 TORSION = 3, /**< Torsions */
65 INVERSION = 4, /**< Inversions */
66 MOLECULE = 5, /**< Molecules */
67 N_SELECTIONTYPES = 6
68 };
69
71 public:
72 /** */
73 SelectionSet() { bitsets_.resize(N_SELECTIONTYPES); }
74 /** */
75 SelectionSet(std::vector<int> nbits);
76
77 /** Returns the number of bits set to true in this SelectionSet. */
78 std::vector<int> countBits();
79
80 /** Sets the bit at the specified index to to the complement of its current
81 * value. */
82 void flip(std::vector<int> bitIndex);
83
84 /** Sets each bit from the specified fromIndex(inclusive) to the specified
85 * toIndex(exclusive) to the complement of its current value. */
86 void flip(std::vector<int> fromIndex, std::vector<int> toIndex);
87
88 /** Sets each bit to the complement of its current value. */
89 void flip();
90
91 /** Returns the value of the bit with the specified index. */
92 std::vector<bool> get(std::vector<int> bitIndex);
93
94 /** Returns a new SelectionSet composed of bits from this SelectionSet from
95 * fromIndex(inclusive) to toIndex(exclusive). */
96 SelectionSet get(std::vector<int> fromIndex, std::vector<int> toIndex);
97
98 /** Returns true if any bits are set to true */
99 std::vector<bool> any();
100
101 /** Returns true if no bits are set to true */
102 std::vector<bool> none();
103
104 std::vector<int> firstOffBit() const;
105
106 /** Returns the index of the first bit that is set to false that occurs on
107 * or after the specified starting index.*/
108 std::vector<int> nextOffBit(std::vector<int> fromIndex) const;
109
110 std::vector<int> firstOnBit() const;
111
112 /** Returns the index of the first bit that is set to true that occurs on or
113 * after the specified starting index. */
114 std::vector<int> nextOnBit(std::vector<int> fromIndex) const;
115
116 /** Performs a logical AND of this target bit set with the argument bit set.
117 */
118 void andOperator(const SelectionSet& bs);
119
120 /** Performs a logical OR of this bit set with the bit set argument. */
121 void orOperator(const SelectionSet& bs);
122
123 /** Performs a logical XOR of this bit set with the bit set argument. */
124 void xorOperator(const SelectionSet& bs);
125
126 void setBitOn(std::vector<int> bitIndex);
127
128 void setBitOff(std::vector<int> bitIndex);
129
130 // void setRangeOn(std::vector<int> fromIndex, std::vector<int> toIndex) {
131 // setBits(fromIndex, toIndex, true); }
132
133 // void setRangeOff(std::vector<int> fromIndex, std::vector<int> toIndex) {
134 // setBits(fromIndex, toIndex, false); }
135
136 /** Sets all of the bits in this SelectionSet to false. */
137 void clearAll();
138
139 void setAll();
140
141 /** Returns the number of bits of space actually in use by this SelectionSet
142 * to represent bit values. */
143 std::vector<int> size() const;
144
145 /** Changes the size of SelectionSet*/
146 void resize(std::vector<int> nbits);
147
148 SelectionSet& operator&=(const SelectionSet& ss) {
149 andOperator(ss);
150 return *this;
151 }
152 SelectionSet& operator|=(const SelectionSet& ss) {
153 orOperator(ss);
154 return *this;
155 }
156 SelectionSet& operator^=(const SelectionSet& ss) {
157 xorOperator(ss);
158 return *this;
159 }
160 SelectionSet& operator-=(const SelectionSet& ss) {
161 SelectionSet tmp = *this ^ ss;
162 *this &= tmp;
163 return *this;
164 }
165
166 SelectionSet parallelReduce();
167
168 std::vector<bool> operator[](std::vector<int> bitIndex) const {
169 std::vector<bool> result(N_SELECTIONTYPES);
170 for (int i = 0; i < N_SELECTIONTYPES; i++)
171 result[i] = bitsets_[i][bitIndex[i]];
172 return result;
173 }
174
175 friend SelectionSet operator|(const SelectionSet& bs1,
176 const SelectionSet& bs2);
177 friend SelectionSet operator&(const SelectionSet& bs1,
178 const SelectionSet& bs2);
179 friend SelectionSet operator^(const SelectionSet& bs1,
180 const SelectionSet& bs2);
181 friend SelectionSet operator-(const SelectionSet& bs1,
182 const SelectionSet& bs2);
183
184 friend bool operator==(const SelectionSet& bs1, const SelectionSet& bs2);
185
186 // friend std::istream& operator>> ( std::istream&, const SelectionSet& bs);
187 friend std::ostream& operator<<(std::ostream&, const SelectionSet& bs);
188
189 std::vector<OpenMDBitSet> bitsets_;
190
191 private:
192 /** Sets the bit at the specified index to the specified value. */
193 // void setBit(std::vector<int> bitIndex, bool value);
194
195 /** Sets the bits from the specified fromIndex(inclusive) to the specified
196 * toIndex(exclusive) to the specified value. */
197 // void setBits(std::vector<int> fromIndex, std::vector<int> toIndex, bool
198 // value);
199 };
200} // namespace OpenMD
201
202#endif
std::vector< int > size() const
Returns the number of bits of space actually in use by this SelectionSet to represent bit values.
std::vector< int > nextOffBit(std::vector< int > fromIndex) const
Returns the index of the first bit that is set to false that occurs on or after the specified startin...
std::vector< bool > get(std::vector< int > bitIndex)
Returns the value of the bit with the specified index.
void clearAll()
Sets all of the bits in this SelectionSet to false.
void xorOperator(const SelectionSet &bs)
Performs a logical XOR of this bit set with the bit set argument.
void flip()
Sets each bit to the complement of its current value.
std::vector< int > countBits()
Returns the number of bits set to true in this SelectionSet.
std::vector< bool > none()
Returns true if no bits are set to true.
std::vector< int > nextOnBit(std::vector< int > fromIndex) const
Returns the index of the first bit that is set to true that occurs on or after the specified starting...
void andOperator(const SelectionSet &bs)
Performs a logical AND of this target bit set with the argument bit set.
void resize(std::vector< int > nbits)
Changes the size of SelectionSet.
void orOperator(const SelectionSet &bs)
Performs a logical OR of this bit set with the bit set argument.
std::vector< bool > any()
Returns true if any bits are set to true.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
SelectionType
The SelectionType enum.
@ INVERSION
Inversions.
@ STUNTDOUBLE
StuntDoubles (Atoms & RigidBodies)
@ TORSION
Torsions.
@ BEND
Bends.
@ BOND
Bonds.
@ MOLECULE
Molecules.