votca 2024.2-dev
Loading...
Searching...
No Matches
exclusionlist.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_CSG_EXCLUSIONLIST_H
19#define VOTCA_CSG_EXCLUSIONLIST_H
20
21// Standard includes
22#include <iostream>
23#include <list>
24#include <map>
25
26// Local VOTCA includes
27#include "bead.h"
28
29namespace votca {
30namespace csg {
31
34
35class Topology;
36class Bead;
37
39 public:
40 ExclusionList() = default;
42
43 void Clear(void);
44
45 template <typename iterable>
46 void Remove(iterable &l);
47
48 template <typename iterable>
49 void ExcludeList(iterable &l);
50
51 struct exclusion_t {
53 std::list<Bead *> exclude_;
54 };
55
56 void CreateExclusions(Topology *top);
58 const exclusion_t *GetExclusions(Bead *bead) const;
59
60 using iterator = std::list<exclusion_t *>::iterator;
61
62 iterator begin() { return exclusions_.begin(); }
63 iterator end() { return exclusions_.end(); }
64
65 bool IsExcluded(Bead *bead1, Bead *bead2) const;
66
67 template <typename iterable>
68 void InsertExclusion(Bead *bead, iterable &excluded);
69
70 void InsertExclusion(Bead *bead1, Bead *bead2);
71
72 void RemoveExclusion(Bead *bead1, Bead *bead2);
73
74 private:
75 std::list<exclusion_t *> exclusions_;
76 std::map<Bead *, exclusion_t *> excl_by_bead_;
77
78 friend std::ostream &operator<<(std::ostream &out, ExclusionList &exl);
79};
80
81template <typename iterable>
82inline void ExclusionList::Remove(iterable &l) {
83 typename iterable::iterator i, j;
84
85 for (i = l.begin(); i != l.end(); ++i) {
86 for (j = i; j != l.end(); ++j) {
87 RemoveExclusion(*i, *j);
88 }
89 }
90}
91
92template <typename iterable>
93inline void ExclusionList::ExcludeList(iterable &l) {
94 typename iterable::iterator i, j;
95
96 for (i = l.begin(); i != l.end(); ++i) {
97 for (j = i; j != l.end(); ++j) {
98 InsertExclusion(*i, *j);
99 }
100 }
101}
102
103template <typename iterable>
104inline void ExclusionList::InsertExclusion(Bead *beadA, iterable &l) {
105 for (Bead *beadB : l) {
106 Bead *bead1 = beadA;
107 Bead *bead2 = beadB;
108 if (bead2->getId() < bead1->getId()) {
109 std::swap(bead1, bead2);
110 }
111 if (bead1 == bead2) {
112 continue;
113 }
114 if (IsExcluded(bead1, bead2)) {
115 continue;
116 }
117
118 exclusion_t *e;
119 if ((e = GetExclusions(bead1)) == nullptr) {
120 e = new exclusion_t;
121 e->atom_ = bead1;
122 exclusions_.push_back(e);
123 excl_by_bead_[bead1] = e;
124 }
125 e->exclude_.push_back(bead2);
126 }
127}
128
129std::ostream &operator<<(std::ostream &out, ExclusionList &exl);
130
131} // namespace csg
132} // namespace votca
133
134#endif // VOTCA_CSG_EXCLUSIONLIST_H
Index getId() const noexcept
Gets the id of the bead.
Definition basebead.h:52
information about a bead
Definition bead.h:50
friend std::ostream & operator<<(std::ostream &out, ExclusionList &exl)
void RemoveExclusion(Bead *bead1, Bead *bead2)
void Remove(iterable &l)
std::list< exclusion_t * >::iterator iterator
std::list< exclusion_t * > exclusions_
void ExcludeList(iterable &l)
void CreateExclusions(Topology *top)
void InsertExclusion(Bead *bead, iterable &excluded)
exclusion_t * GetExclusions(Bead *bead)
bool IsExcluded(Bead *bead1, Bead *bead2) const
std::map< Bead *, exclusion_t * > excl_by_bead_
topology of the whole system
Definition topology.h:81
std::ostream & operator<<(std::ostream &out, ExclusionList &exl)
base class for all analysis tools
Definition basebead.h:33