11 while (end-- > last) {
12 std::iter_swap(first++, end);
16 template <
class T>
struct IterRange : std::pair<T, T>
18 using std::pair<T, T>::pair;
20 T& begin() {
return this->first; }
22 T& end() {
return this->second; }
24 [[nodiscard]]
const T& begin()
const {
return this->first; }
26 [[nodiscard]]
const T& end()
const {
return this->second; }
28 [[nodiscard]]
size_t size()
const {
return std::distance(this->first, this->second); }
36 [[nodiscard]]
bool empty()
const {
return this->first == this->second; }
40 this->second = this->first;
44 [[nodiscard]] std::pair<int, int>
to_index(
T reference)
const 46 return {std::distance(reference, begin()), std::distance(reference, end() - 1)};
63 using Titer =
typename std::vector<T>::iterator;
64 using const_iterator =
typename std::vector<T>::const_iterator;
77 [[nodiscard]]
size_t capacity()
const;
78 [[nodiscard]]
auto inactive()
const;
80 deactivate(Titer first,
82 void activate(Titer first, Titer last);
84 [[nodiscard]]
const Titer& trueend()
const;
85 void relocate(const_iterator oldorigin,
87 [[nodiscard]] [[nodiscard]]
virtual bool isFull()
const;
89 [[maybe_unused]] [[nodiscard]]
auto numInactive()
const;
94 [[maybe_unused]] [[nodiscard]]
inline bool 95 resizeIsPossible(
int number_to_insert_or_delete)
const 97 auto new_size =
static_cast<int>(size()) + number_to_insert_or_delete;
98 return (new_size >= 0 && new_size <= capacity());
103 return std::ranges::subrange(begin(), trueend());
106 [[nodiscard]]
inline auto all()
const 108 return std::ranges::subrange(begin(), trueend());
114 return end() == trueend();
126 return std::distance(begin(), _trueend);
131 return base({end(), _trueend});
137 size_t n = std::distance(first, last);
138 assert(first >= begin() && last <= end());
139 std::rotate(begin(), last, end());
141 assert(size() + inactive().size() == capacity());
147 size_t n = std::distance(first, last);
148 std::rotate(end(), first, _trueend);
150 assert(size() + inactive().size() == capacity());
165 ElasticRange::Titer neworigin)
167 begin() = neworigin + std::distance(oldorigin, const_iterator(begin()));
168 end() = neworigin + std::distance(oldorigin, const_iterator(end()));
169 trueend() = neworigin + std::distance(oldorigin, const_iterator(trueend()));
174 return inactive().size();
180 ~
Group()
override =
default;
182 using iter =
typename base::Titer;
184 int conformation_id = 0;
185 Point mass_center = {0.0, 0.0, 0.0};
189 return traits().atomic;
194 return !traits().atomic;
197 [[nodiscard]]
bool isFull()
const override;
199 std::optional<std::reference_wrapper<Point>>
201 [[nodiscard]] std::optional<std::reference_wrapper<const Point>>
209 INACTIVE = (1U << 3U),
210 NEUTRAL = (1U << 4U),
212 MOLECULAR = (1U << 6U),
224 #pragma clang diagnostic push 225 #pragma clang diagnostic ignored "-Wc++11-narrowing" 227 template <
unsigned int mask> [[nodiscard]]
bool match()
const 229 static_assert(mask >= ANY && mask <= FULL);
230 if constexpr (mask & ANY) {
231 static_assert(mask == ANY,
"don't mix ANY with other flags");
234 if constexpr (mask & ACTIVE) {
235 static_assert(!(mask & INACTIVE),
"don't mix ACTIVE and INACTIVE");
240 else if constexpr (mask & INACTIVE) {
245 if constexpr (mask & FULL) {
246 if (end() != trueend()) {
250 if constexpr (mask & ATOMIC) {
251 static_assert(!(mask & MOLECULAR),
"don't mix ATOMIC and MOLECULAR");
256 else if constexpr (mask & MOLECULAR) {
261 if constexpr (mask & NEUTRAL) {
262 auto _end = (mask & INACTIVE) ? trueend() : end();
263 auto _charge = std::accumulate(begin(), _end, 0.0, [](
auto sum,
const auto& particle) {
264 return sum + particle.charge;
266 if (std::fabs(_charge) > pc::epsilon_dbl) {
273 #pragma clang diagnostic pop 283 Group(MoleculeData::index_type molid, iter begin, iter end);
286 [[nodiscard]]
bool contains(
const Particle& particle,
287 bool include_inactive =
false)
const;
288 [[nodiscard]]
double mass()
const;
292 return std::ranges::subrange(begin(), end()) |
293 std::views::transform([&](
Particle& particle) ->
Point& {
return particle.
pos; });
298 return std::ranges::subrange(begin(), end()) |
299 std::views::transform(
303 [[nodiscard]] AtomData::index_type getParticleIndex(
const Particle& particle,
304 bool include_inactive =
false)
307 [[nodiscard]]
auto findAtomID(AtomData::index_type atomid)
const 310 std::views::filter([atomid](
auto& particle) {
return (particle.
id == atomid); });
319 inline auto&
operator[](
size_t index) {
return *(begin() + index); }
321 inline const auto& operator[](
size_t index)
const {
return *(begin() + index); }
324 [[nodiscard]]
const Particle& at(
size_t index)
const;
331 template <std::
integral T
int =
size_t>
auto operator[](std::vector<Tint>& indices)
334 if (not indices.empty()) {
335 assert(*std::max_element(indices.begin(), indices.end()) < size());
339 std::views::transform([
this](
auto i) ->
Particle& {
return *(begin() + i); });
349 template <
typename TdistanceFunc>
void unwrap(
const TdistanceFunc& vector_distance)
352 for (
auto& particle : *
this) {
353 particle.
pos = mass_center + vector_distance(particle.
pos, mass_center);
358 [[maybe_unused]]
void 365 void rotate(
const Eigen::Quaterniond& quaternion,
370 const Point& approximate_mass_center);
376 void to_json(
json& j,
const Group& group);
377 void from_json(
const json& j,
Group& group);
382 return [](
const Group& group) {
return group.
match<mask>(); };
386 template <
typename T>
388 std::ranges::range<T> && std::is_convertible_v<std::ranges::range_value_t<T>,
Group>;
auto inactive() const
Range of inactive elements.
Definition: group.h:129
nlohmann::json json
JSON object.
Definition: json_support.h:10
Eigen::Vector3d Point
3D vector used for positions, velocities, forces etc.
Definition: coordinates.h:7
Point pos
Particle position vector.
Definition: particle.h:227
void relocate(const_iterator oldorigin, Titer neworigin)
Shift all iterators to new underlying container; useful when resizing vectors.
Definition: group.h:164
double T
floating point size
Definition: units.h:73
auto operator[](std::vector< Tint > &indices)
Reference to subset of given indices, where 0 is the start of the group.
Definition: group.h:331
auto findAtomID(AtomData::index_type atomid) const
Range of all (active) elements with matching particle id.
Definition: group.h:307
auto all() const
Active and inactive elements.
Definition: group.h:106
void unwrap(const TdistanceFunc &vector_distance)
Remove PBC for molecular groups w.
Definition: group.h:349
auto & operator[](size_t index)
Returns i'th element in group.
Definition: group.h:319
void activate(Titer first, Titer last)
Activate previously deactivated elements.
Definition: group.h:145
Turns a pair of iterators into an elastic range.
Definition: group.h:60
void deactivate(Titer first, Titer last)
Deactivate particles by moving to end, reducing the effective size.
Definition: group.h:135
void swap_to_back(T first, T last, T end)
Move range [first:last] to [end] by swapping elements.
Definition: group.h:9
auto numInactive() const
Number of inactive elements.
Definition: group.h:172
Turns a pair of iterators into a range.
Definition: group.h:16
Selectors
Selections to filter groups using getSelectionFilter()
Definition: group.h:205
int id
Particle id/type.
Definition: particle.h:225
std::function< void(Point &)> BoundaryFunction
Function to apply PBC to a position.
Definition: core.h:30
General properties for molecules.
Definition: molecule.h:211
bool isAtomic() const
Is it an atomic group?
Definition: group.h:187
Particle class for storing positions, id, and other properties.
Definition: particle.h:220
Cell list class templates.
Definition: actions.cpp:11
End of Group class.
Definition: group.h:177
concept RequireGroups
Concept for a range of groups.
Definition: group.h:387
std::vector< MoleculeData > molecules
List of molecule types.
Definition: molecule.cpp:22
auto all()
Active and inactive elements.
Definition: group.h:101
bool isMolecular() const
is it a molecular group?
Definition: group.h:192
std::pair< int, int > to_index(T reference) const
Returns particle index pair relative to given reference.
Definition: group.h:44
const MoleculeData & traits() const
Convenient access to molecule properties.
Definition: group.h:275
bool match() const
Determines if given Selectors bitmask matches group.
Definition: group.h:227
std::function< bool(const Group &)> getGroupFilter()
Get lambda function matching given enum Select mask.
Definition: group.h:380
auto positions()
Range of positions of active particles.
Definition: group.h:290
auto positions() const
Range of positions of active particles.
Definition: group.h:296