source: src/Graph/BoostGraphCreator.hpp@ d24ef58

Action_Thermostats Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since d24ef58 was d24ef58, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Extracted conversion to boost::graph into distinct struct.

  • BoostGraphCreator allows to convert sets of atoms into a boost::graph while using an additional predicate.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * BoostGraphCreator.hpp
3 *
4 * Created on: May 17, 2017
5 * Author: heber
6 */
7
8
9#ifndef GRAPH_BOOSTGRAPHCREATOR_HPP_
10#define GRAPH_BOOSTGRAPHCREATOR_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <vector>
18
19#include <boost/function.hpp>
20#include <boost/graph/adjacency_list.hpp>
21
22class atom;
23class bond;
24class molecule;
25
26/** This is a helper class that contains functions to create a boost::graph
27 * from the present bond graph of molecules.
28 */
29struct BoostGraphCreator
30{
31public:
32 //!> typedef for an undirected graph using boost::graph
33 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS,
34 boost::no_property, boost::no_property > UndirectedGraph;
35 //!> typedef for a map of graph node indices
36 typedef boost::property_map < boost::adjacency_list <>, boost::vertex_index_t >::type index_map_t;
37 //!> typedef for the predicate to evaluate for adding the current edge or not
38 typedef boost::function<bool (const bond &)> predicate_t;
39
40
41 /** Creates the boost::graph using all atoms and bonds in the given \a _mol.
42 *
43 * \param _mol molecule whose bond graph to construct
44 * \param _pred predicate to evaluate on adding each edge/bond
45 */
46 void createFromMolecule(
47 const molecule &_mol,
48 const predicate_t &_pred);
49
50 /** Creates the boost::graph using all atoms and bonds in the given vector
51 * of \a _atoms
52 *
53 * \param _atoms vector of _atoms whose bond graph to construct
54 * \param _pred predicate to evaluate on adding each edge/bond
55 */
56 void createFromAtoms(
57 const std::vector<atom *> &_atoms,
58 const predicate_t &_pred);
59
60 /** Getter for the created graph.
61 *
62 * \return graph
63 */
64 UndirectedGraph get() const
65 { return graph; }
66
67 /** Getter for the index map of the created graph.
68 *
69 * \return indexmap
70 */
71 index_map_t getIndexMap() const {
72 return boost::get(boost::vertex_index, graph);
73 }
74
75 /** Return the number of vertices contained in the created graph.
76 *
77 * \return number of vertices
78 */
79 size_t getNumVertices() const {
80 return boost::num_vertices(graph);
81 }
82
83 /** Return the number of edges contained in the created graph.
84 *
85 * \return number of edges
86 */
87 size_t getNumEdges() const {
88 return boost::num_edges(graph);
89 }
90
91private:
92 /** General purpose function that contains the internal logic of walking the
93 * bonds of a set of atoms given by \a _begin and \a _end iterators and
94 * adding its edges to a graph based on the evaluation of a given predicate
95 * \a _pred.
96 *
97 * \note We need \a _no_nodes because molecule::iterator does not work with
98 * std::distance.
99 *
100 * \param _begin begin iterator
101 * \param _end end iterator
102 * \param _no_nodes number of nodes
103 * \param _pred predicate
104 */
105 template <typename iterator>
106 void createFromRange(
107 const iterator &_begin,
108 const iterator &_end,
109 const size_t &_no_nodes,
110 const predicate_t &_pred
111 );
112
113private:
114 //!> internal graph that is created by creator functions
115 UndirectedGraph graph;
116};
117
118
119#endif /* GRAPH_BOOSTGRAPHCREATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.