IMP  2.2.1
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-2014 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/kernel/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 kernel::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<kernel::ParticleIndexKey, Bonded>
83  VertexVertexPropertyMap;
84 
85  typedef internal::AttributeEdgePropertyMap<FloatKey, Float>
86  EdgeFloatPropertyMap;
87  typedef internal::AttributeEdgePropertyMap<IntKey, Int> EdgeIntPropertyMap;
88 
89  VertexIntPropertyMap get_vertex_index_map() const;
90 #else
91  /** @name Property maps
92  Boost.Graph makes extensive use of property maps. We define a few maps
93  which use the particle attributes to store their data. Each map is
94  constructed by passing an appropriate attribute key, to specify the
95  attribute used to store the data. Attempt to store to an attribute
96  which the particle does not already have adds the attribute to the
97  particle. More information about property maps can be found in
98 \external{http://www.boost.org/doc/libs/1_39_0/libs/property_map/property_map.html,
99  the Boost.PropertyMap documentation}.
100  @{
101  */
102  //! Provide boost access to a Float attribute each vertex
104  //! Provide boost access to an Int attribute each vertex
106  //! Provide boost access to a kernel::Particle attribute each vertex
107  /** The particles in question must be Bonded particles. */
109  //! Provide boost access to a Float attribute on the edges such as length
111  //! Provide boost access to an Int attribute on each edge.
113 
114  VertexIntPropertyMap get_vertex_index_map() const;
115 /** @} */
116 #endif
117 
118 #ifndef IMP_DOXYGEN
119  typedef std::pair<Bonded, Bonded> edge_descriptor;
120 #endif
121 
122  Bond get_bond(edge_descriptor d) const {
123  return IMP::atom::get_bond(d.first, d.second);
124  }
125 
126 #ifndef IMP_DOXYGEN
127  struct traversal_category : public virtual boost::adjacency_graph_tag,
128  public virtual boost::vertex_list_graph_tag,
129  public virtual boost::edge_list_graph_tag,
130  // public virtual boost::incidence_graph_tag
131  public virtual boost::bidirectional_graph_tag {};
132  typedef Bonded vertex_descriptor;
133  // typedef undirected_tag directed_category;
134  typedef int vertices_size_type;
135  typedef int edges_size_type;
136  typedef int degree_size_type;
137 
138  typedef boost::transform_iterator<internal::MakeOutEdgeDescriptor,
139  vertex_descriptor::BondIterator>
140  out_edge_iterator;
141  typedef vertex_descriptor::BondedIterator adjacency_iterator;
142  typedef boost::transform_iterator<
143  internal::MakeBonded, IMP::kernel::Particles::iterator> vertex_iterator;
144  typedef boost::disallow_parallel_edge_tag edge_parallel_category;
145  typedef boost::undirected_tag directed_category;
146 
147  typedef boost::transform_iterator<internal::MakeInEdgeDescriptor,
148  vertex_descriptor::BondIterator>
149  in_edge_iterator;
150 
151  typedef IMP::internal::NestedIterator<internal::NestedTraits> edge_iterator;
152 
153  struct graph_tag {};
154  typedef Int vertex_property_type;
155 #endif
156 };
157 
158 IMPATOM_END_NAMESPACE
159 
160 #include "internal/bond_graph_boost_functions.h"
161 
162 #endif // IMP_SWIG
163 
164 #endif /* IMPATOM_BOND_GRAPH_H */
EdgeFloatPropertyMap
Provide boost access to a Float attribute on the edges such as length.
Definition: bond_graph.h:110
A base class for Keys.
Definition: kernel/Key.h:46
Store a list of kernel::ParticlesTemp.
VertexFloatPropertyMap
Provide boost access to a Float attribute each vertex.
Definition: bond_graph.h:103
EdgeIntPropertyMap
Provide boost access to an Int attribute on each edge.
Definition: bond_graph.h:112
Contains decorators for a bond.
Decorator for helping deal with a hierarchy of molecules.
VertexIntPropertyMap
Provide boost access to an Int attribute each vertex.
Definition: bond_graph.h:105
The standard decorator for manipulating molecular structures.
A decorator for wrapping a particle representing a molecular bond.
#define IMP_NO_DOXYGEN(x)
Hide something from doxygen.
Represent a bond graph as a boost graph.
Definition: bond_graph.h:58
Bond get_bond(Bonded a, Bonded b)
Get the bond between two particles.
int Int
Basic integer value.
Definition: base/types.h:35
VertexVertexPropertyMap
Provide boost access to a kernel::Particle attribute each vertex.
Definition: bond_graph.h:108