votca 2024.1-dev
Loading...
Searching...
No Matches
beadstructure.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2019 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#pragma once
19#ifndef VOTCA_CSG_BEADSTRUCTURE_H
20#define VOTCA_CSG_BEADSTRUCTURE_H
21
22// Standard inlcudes
23#include <unordered_map>
24
25// VOTCA includes
26#include <votca/tools/graph.h>
27
28namespace votca {
29namespace csg {
30
52 public:
53 virtual ~BeadStructure() = default;
54
70 BeadStructure getSubStructure(const std::vector<Index> &idx,
71 const std::vector<tools::Edge> &edges) const;
72
82 bool isSingleStructure();
83
87 size_t BeadCount() const noexcept { return beads_.size(); }
88
94 template <class T>
95 void AddBead(const T &bead);
96
103 virtual void ConnectBeads(const Index &bead1_id, const Index &bead2_id);
104
108 std::vector<Index> getNeighBeadIds(const Index &index);
109
111
122 bool isStructureEquivalent(BeadStructure &beadstructure);
123
125 bool BeadExist(Index bead_id) const { return beads_.count(bead_id); }
126
132 std::vector<Index> getBeadIds() const;
133
134 protected:
136 struct BeadInfo {
137 double mass = 0.0;
138 std::string name = "";
139 };
142 virtual void UpdateOnBeadAddition_() {};
143 void InitializeGraph_();
144 void CalculateStructure_();
145 tools::GraphNode BeadInfoToGraphNode_(const BeadInfo &);
146
148 bool graphUpToDate = false;
150 bool single_structure_ = false;
151 std::string structure_id_ = "";
153 std::set<tools::Edge> connections_;
154 std::unordered_map<Index, BeadInfo> beads_;
155 std::unordered_map<Index, tools::GraphNode> graphnodes_;
156};
157
158template <class T>
159void BeadStructure::AddBead(const T &bead) {
160 if (beads_.count(bead.getId())) {
161 std::string err = "Cannot add bead with Id ";
162 err += std::to_string(bead.getId());
163 err += " because each bead must have a unique Id and a bead with that Id ";
164 err += "already exists within the beadstructure";
165 throw std::invalid_argument(err);
166 }
168 size_t numberOfBeads = beads_.size();
169 BeadInfo bead_info;
170 bead_info.mass = bead.getMass();
171 bead_info.name = bead.getName();
172
173 beads_[bead.getId()] = bead_info;
174
175 if (numberOfBeads != beads_.size()) {
177 graphUpToDate = false;
178 structureIdUpToDate = false;
179 }
180}
181
182} // namespace csg
183} // namespace votca
184
185#endif // VOTCA_CSG_BEADSTRUCTURE_H
Designed to determine if the structure beads passed in.
tools::GraphNode BeadInfoToGraphNode_(const BeadInfo &)
std::set< tools::Edge > connections_
size_t BeadCount() const noexcept
returns the number of beads in the bead structure
virtual void UpdateOnBeadAddition_()
bool BeadExist(Index bead_id) const
Determine if a bead exists in the structure.
std::vector< Index > getNeighBeadIds(const Index &index)
Return a vector of all the ids of the beads neighboring the index.
void AddBead(const T &bead)
add a bead to the bead structure
virtual void ConnectBeads(const Index &bead1_id, const Index &bead2_id)
Create a connection between two beads in the structure.
std::unordered_map< Index, tools::GraphNode > graphnodes_
std::unordered_map< Index, BeadInfo > beads_
bool isStructureEquivalent(BeadStructure &beadstructure)
Compare the topology of two bead structures.
virtual ~BeadStructure()=default
BeadStructure getSubStructure(const std::vector< Index > &idx, const std::vector< tools::Edge > &edges) const
Given indices and edges that exist are a subset of beadstructure, return the sub-beadstructure.
std::vector< Index > getBeadIds() const
Return the ids of the beads that are in the structure.
bool isSingleStructure()
Determine if the bead structure consists of a single connected structure.
A graph node that will take a variety of different values.
Definition graphnode.h:46
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Small structure to help store bead info relevant to the structure.