votca 2024.1-dev
Loading...
Searching...
No Matches
beadmotif.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// VOTCA includes
20
21// Local VOTCA includes
22#include "votca/csg/beadmotif.h"
23
24namespace votca {
25namespace csg {
26class BaseBead;
27} // namespace csg
28} // namespace votca
29
30using namespace votca::tools;
31using namespace std;
32
33namespace votca {
34namespace csg {
35
36/**********************
37 * Internal Functions *
38 **********************/
39
44
46 if (!junctionsUpToDate_) {
48 junctionsUpToDate_ = true;
49 }
50 return junctions_.size() != 0;
51}
52
54 if (BeadCount() == 0) {
56 } else if (isSingle_()) {
60 } else if (isLine_()) {
62 } else if (isLoop_()) {
64 } else if (isFusedRing_()) {
66 } else {
68 }
69 type_up_to_date_ = true;
70}
71
72bool BeadMotif::isSingle_() const noexcept {
73 if (BeadCount() == 1) {
74 return true;
75 }
76 return false;
77}
78
80 if (junctionExist_()) {
81 return false;
82 }
83 // Ensure that the degree of two of the vertices is 1
84 // all other vertices must be 2
85 Index num_vertices_degree_1 = 0;
86
87 vector<Index> vertices = reduced_graph_.getVertices();
88 for (Index& vertex : vertices) {
89 Index degree = reduced_graph_.getDegree(vertex);
90 if (degree == 1) {
91 ++num_vertices_degree_1;
92 } else if (degree == 0) {
93 return false;
94 } else if (degree > 2) {
95 return false;
96 }
97 }
98 if (num_vertices_degree_1 != 2) {
99 return false;
100 }
101 return true;
102}
103
105 if (junctionExist_()) {
106 return false;
107 }
108
109 // Ensure that the degree of every vertex is 2
110 vector<Index> vertices = graph_.getVertices();
111 for (Index& vertex : vertices) {
112 if (graph_.getDegree(vertex) != 2) {
113 return false;
114 }
115 }
116 return true;
117}
118
154 if (!junctionExist_()) {
155 return false;
156 }
157 // Ensure that the degree of every vertex is 2 or greater
158 vector<Index> vertices = graph_.getVertices();
159 for (Index& vertex : vertices) {
160 if (graph_.getDegree(vertex) < 2) {
161 return false;
162 }
163 }
164 // If exploring from one branch of a junction lets you explore every
165 // edge than it is a fused ring.
167
168 for (Index junction : junctions_) {
169 vector<Edge> edges = reduced_graph_.getNeighEdges(junction);
170 set<Edge> all_edges_explored =
171 exploreBranch(reduced_graph_, junction, edges.at(0));
172 for (const Edge& edge_next_to_junction : edges) {
173 if (!all_edges_explored.count(edge_next_to_junction)) {
174 return false;
175 }
176 }
177 }
178 return true;
179}
180
186
187/***************************
188 * Public Facing Functions *
189 ***************************/
190
198
200 MotifType motif_type = getType();
201 if (motif_type == single_structure || motif_type == multiple_structures ||
202 motif_type == undefined) {
203 return false;
204 }
205 return true;
206}
207
208void BeadMotif::ConnectBeads(const Index& bead1_id, const Index& bead2_id) {
209 BeadStructure::ConnectBeads(bead1_id, bead2_id);
210 junctionsUpToDate_ = false;
211 type_up_to_date_ = false;
212}
213
214} // namespace csg
215} // namespace votca
bool isSingle_() const noexcept
Definition beadmotif.cc:72
void ConnectBeads(const Index &bead1_id, const Index &bead2_id) final
Adds a new connection to the motif.
Definition beadmotif.cc:208
MotifType getType()
Gets the motif type, calculates it first if it is not yet known.
Definition beadmotif.cc:191
bool isMotifSimple()
Determines if the motif type is a simple type.
Definition beadmotif.cc:199
tools::ReducedGraph reduced_graph_
Definition beadmotif.h:158
void UpdateOnBeadAddition_() final
Definition beadmotif.cc:181
std::vector< Index > junctions_
Definition beadmotif.h:157
size_t BeadCount() const noexcept
returns the number of beads in the bead structure
virtual void ConnectBeads(const Index &bead1_id, const Index &bead2_id)
Create a connection between two beads in the structure.
bool isSingleStructure()
Determine if the bead structure consists of a single connected structure.
Connects to vertices.
Definition edge.h:42
std::vector< Index > getJunctions() const
Gets all vertices with degree of 3 or greater.
Definition graph.cc:110
std::vector< Index > getVertices() const
Returns all the vertices in the graph.
Definition graph.cc:166
std::vector< Edge > getNeighEdges(Index vertex) const
Returns all the edges in the graph connected to vertex vertex
Definition graph.h:106
Index getDegree(Index vertex) const
Calcualtes the degree, or number of edges connected to vertex vertex
Definition graph.cc:140
STL namespace.
ReducedGraph reduceGraph(Graph graph)
Will take a graph and reduce it, by removing all vertices with degree of 2.
std::set< Edge > exploreBranch(Graph g, Index starting_vertex, const Edge &edge)
Explore one of the branches if exploration is initiated at vertex starting_vertex.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26