votca 2024.2-dev
Loading...
Searching...
No Matches
exclusionlist.cc
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// Standard includes
19#include <algorithm>
20
21// Local VOTCA includes
23#include "votca/csg/topology.h"
24
25namespace votca {
26namespace csg {
27
28using namespace std;
29
31
32 for (auto &exclusion_ : exclusions_) {
33 delete exclusion_;
34 }
35 exclusions_.clear();
36}
37
40
41 for (auto &ia : ic) {
42 Index beads_in_int = ia->BeadCount();
43 std::vector<Bead *> l;
44
45 for (Index ibead = 0; ibead < beads_in_int; ibead++) {
46 Index ii = ia->getBeadId(ibead);
47 l.push_back(top->getBead(ii));
48 }
49 ExcludeList(l);
50 }
51}
52
54 Bead *bead) const {
55 std::map<Bead *, exclusion_t *>::const_iterator iter =
56 excl_by_bead_.find(bead);
57 if (iter == excl_by_bead_.end()) {
58 return nullptr;
59 }
60
61 return (*iter).second;
62}
63
65 std::map<Bead *, exclusion_t *>::iterator iter = excl_by_bead_.find(bead);
66 if (iter == excl_by_bead_.end()) {
67 return nullptr;
68 }
69
70 return (*iter).second;
71}
72
73bool ExclusionList::IsExcluded(Bead *bead1, Bead *bead2) const {
74 if (bead1->getMoleculeId() != bead2->getMoleculeId()) {
75 return false;
76 }
77 if (bead2->getId() < bead1->getId()) {
78 swap(bead1, bead2);
79 }
80
81 const exclusion_t *excl = GetExclusions(bead1);
82 if (excl != nullptr) {
83 if (find(excl->exclude_.begin(), excl->exclude_.end(), bead2) !=
84 excl->exclude_.end()) {
85 return true;
86 }
87 }
88 return false;
89}
90
92 if (bead2->getId() < bead1->getId()) {
93 std::swap(bead1, bead2);
94 }
95
96 if (bead1 == bead2) {
97 return;
98 }
99
100 if (IsExcluded(bead1, bead2)) {
101 return;
102 }
103
104 exclusion_t *e;
105 if ((e = GetExclusions(bead1)) == nullptr) {
106 e = new exclusion_t;
107 e->atom_ = bead1;
108 exclusions_.push_back(e);
109 excl_by_bead_[bead1] = e;
110 }
111 e->exclude_.push_back(bead2);
112}
113
115 if (bead2->getId() < bead1->getId()) {
116 std::swap(bead1, bead2);
117 }
118
119 if (bead1 == bead2) {
120 return;
121 }
122
123 if (!IsExcluded(bead1, bead2)) {
124 return;
125 }
126
127 std::list<exclusion_t *>::iterator ex =
128 std::find_if(exclusions_.begin(), exclusions_.end(),
129 [&bead1](exclusion_t *e) { return e->atom_ == bead1; });
130
131 if (ex == exclusions_.end()) {
132 return;
133 }
134
135 (*ex)->exclude_.remove(bead2);
136 if ((*ex)->exclude_.empty()) {
137 (*ex) = nullptr;
138 exclusions_.erase(ex);
139 }
140 exclusions_.remove(nullptr);
141}
142
145 return a->atom_->getId() < b->atom_->getId();
146}
147
148bool compareAtomIdBeadList(const Bead *a, const Bead *b) {
149 return a->getId() < b->getId();
150}
151
152std::ostream &operator<<(std::ostream &out, ExclusionList &exl) {
154
155 for (auto &exclusion_ : exl.exclusions_) {
156 exclusion_->exclude_.sort(compareAtomIdBeadList);
157 out << (Index)(exclusion_->atom_->getId()) + 1;
158 for (Bead *bead : exclusion_->exclude_) {
159 out << " " << (bead->getId() + 1);
160 }
161 out << endl;
162 }
163 return out;
164}
165
166} // namespace csg
167} // namespace votca
Index getMoleculeId() const noexcept
Get the id of the molecule the bead is a part of, if the molecule id has not been set return topology...
Definition basebead.h:78
Index getId() const noexcept
Gets the id of the bead.
Definition basebead.h:52
information about a bead
Definition bead.h:50
void RemoveExclusion(Bead *bead1, Bead *bead2)
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
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
InteractionContainer & BondedInteractions()
Definition topology.h:189
STL namespace.
std::vector< Interaction * > InteractionContainer
Definition topology.h:72
bool compareAtomIdiExclusionList(const ExclusionList::exclusion_t *a, const ExclusionList::exclusion_t *b)
std::ostream & operator<<(std::ostream &out, ExclusionList &exl)
bool compareAtomIdBeadList(const Bead *a, const Bead *b)
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26