IMP  2.0.0
The Integrative Modeling Platform
bond_graph.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/bond_graph.h \brief Contains decorators for a bond
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPATOM_BOND_GRAPH_H
9 #define IMPATOM_BOND_GRAPH_H
10 
11 #include "bond_decorators.h"
12 #include "Hierarchy.h"
13 #include "internal/bond_graph_functors.h"
15 #include <IMP/internal/NestedIterator.h>
16 #include <boost/graph/graph_traits.hpp>
17 #include <boost/graph/properties.hpp>
18 #include <boost/iterator/transform_iterator.hpp>
19 
20 #ifndef SWIG
21 
22 IMPATOM_BEGIN_NAMESPACE
23 
24 //! Represent a bond graph as a boost graph
25 /** The BondGraph class implements the following boost graph concepts
26  - bidirectional_graph
27  - adjacency_graph
28  - vertex_list_graph
29  - edge_list_graph.
30 
31  See the
32 \external{http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/table_of_contents.html,
33  Boost.Graph manual} for more details and a list of algorithms.
34 
35  The vertices are Bondeds. The type of the edge_descriptors
36  is internal. You can use the get_bond() method to get the corresponding
37  Bond.
38 
39  And all vertices can be assumed to have internal boost vertex indices.
40  The Boost.PropertyMap to access these can be accessed using the
41  get_vertex_index_map() function.
42 
43  Some usage examples
44  \code
45  boost::isomorphism(a,b,
46  boost::isomorphism_map(BondGraph::VertexVertexPropertyMap(pk))
47  .vertex_index1_map(a.get_vertex_index_map())
48  .vertex_index2_map(b.get_vertex_index_map()));
49 boost::dijkstra_shortest_paths(a, Bonded(),
50  boost::predecessor_map(BondGraph::VertexVertexPropertyMap(pk))
51  .weight_map(BondGraph::EdgeFloatPropertyMap(Bond::get_legnth_key()))
52  .distance_map(BondGraph::VertexFloatPropertyMap(FloatKey("graph distance")))
53  .vertex_index_map(a.get_vertex_index_map()));
54  \endcode
55 
56  \untested{BondGraph}
57  */
58 class IMPATOMEXPORT BondGraph{
59 
60  mutable IntKey index_key_;
61 
62 public:
63  IMP_NO_DOXYGEN(mutable Particles sc_);
64 
65  //! The graph is on the leaves of the atom::Hierarchy
66  /** All the leaves will be made Bonded particles if they are not already.
67  \note The hierarchy must not have any bonds to particles not in the
68  hierarchy.
69  */
70  BondGraph(Hierarchy bd);
71 
72  BondGraph(){}
73 
74  ~BondGraph();
75 
76 #ifndef IMP_DOXYGEN
77 
78  typedef internal::AttributeVertexPropertyMap<FloatKey, Float>
79  VertexFloatPropertyMap;
80  typedef internal::AttributeVertexPropertyMap<IntKey, Int>
81  VertexIntPropertyMap;
82  typedef internal::AttributeVertexPropertyMap<ParticleIndexKey, Bonded>
83  VertexVertexPropertyMap;
84 
85 
86 
87  typedef internal::AttributeEdgePropertyMap<FloatKey, Float>
88  EdgeFloatPropertyMap;
89  typedef internal::AttributeEdgePropertyMap<IntKey, Int> EdgeIntPropertyMap;
90 
91  VertexIntPropertyMap get_vertex_index_map() const;
92 #else
93  /** @name Property maps
94  Boost.Graph makes extensive use of property maps. We define a few maps
95  which use the particle attributes to store their data. Each map is
96  constructed by passing an appropriate attribute key, to specify the
97  attribute used to store the data. Attempt to store to an attribute
98  which the particle does not already have adds the attribute to the
99  particle. More information about property maps can be found in
100 \external{http://www.boost.org/doc/libs/1_39_0/libs/property_map/property_map.html,
101  the Boost.PropertyMap documentation}.
102  @{
103  */
104  //! Provide boost access to a Float attribute each vertex
106  //! Provide boost access to an Int attribute each vertex
108  //! Provide boost access to a Particle attribute each vertex
109  /** The particles in question must be Bonded particles. */
111  //! Provide boost access to a Float attribute on the edges such as length
113  //! Provide boost access to an Int attribute on each edge.
115 
116  VertexIntPropertyMap get_vertex_index_map() const;
117  /** @} */
118 #endif
119 
120 
121 #ifndef IMP_DOXYGEN
122  typedef std::pair<Bonded,
123  Bonded> edge_descriptor;
124 #endif
125 
126  Bond get_bond(edge_descriptor d) const {
127  return IMP::atom::get_bond(d.first, d.second);
128  }
129 
130 #ifndef IMP_DOXYGEN
131  struct traversal_category: public virtual boost::adjacency_graph_tag,
132  public virtual boost::vertex_list_graph_tag,
133  public virtual boost::edge_list_graph_tag,
134  //public virtual boost::incidence_graph_tag
135  public virtual boost::bidirectional_graph_tag
136  {};
137  typedef Bonded vertex_descriptor;
138  //typedef undirected_tag directed_category;
139  typedef int vertices_size_type;
140  typedef int edges_size_type;
141  typedef int degree_size_type;
142 
143  typedef boost::transform_iterator<internal::MakeOutEdgeDescriptor,
144  vertex_descriptor::BondIterator> out_edge_iterator;
145  typedef vertex_descriptor::BondedIterator adjacency_iterator;
146  typedef boost::transform_iterator<internal::MakeBonded,
147  IMP::Particles::iterator>
148  vertex_iterator;
149  typedef boost::disallow_parallel_edge_tag edge_parallel_category;
150  typedef boost::undirected_tag directed_category;
151 
152  typedef boost::transform_iterator<internal::MakeInEdgeDescriptor,
153  vertex_descriptor::BondIterator> in_edge_iterator;
154 
155 
156 
157 
158 
159  typedef IMP::internal::NestedIterator<internal::NestedTraits> edge_iterator;
160 
161  struct graph_tag{};
162  typedef Int vertex_property_type;
163 #endif
164 
165 };
166 
167 
168 
169 
170 IMPATOM_END_NAMESPACE
171 
172 #include "internal/bond_graph_boost_functions.h"
173 
174 #endif // IMP_SWIG
175 
176 #endif /* IMPATOM_BOND_GRAPH_H */