Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
ClassIDGraph.hh
Go to the documentation of this file.
1 #ifndef GGL_CHEM_CLASSIDGRAPH_HH_
2 #define GGL_CHEM_CLASSIDGRAPH_HH_
3 
4 #include "sgm/Graph_Interface.hh"
5 
6 #include <sstream>
7 
8 namespace ggl {
9 namespace chem {
10 
11  /**
12  * Graph wrapper that adds the atom node ID as class information to each
13  * atom node label. The class ID string length is the length of the node
14  * number string plus a given number of leading zeros. For instance a graph
15  * with 12 atoms nodes and two leading zeros will have class ID '0001' to
16  * '0012'.
17  *
18  * NOTE: existing class information is extended with the generated class ID
19  * string.
20  *
21  * @author Martin Mann - 2013
22  */
24  protected:
25 
27 
28  size_t classIdLength;
29 
30  public:
31 
32  /**
33  * Construction
34  * @param molGraph the molecule graph to wrap
35  * @param leadingZeros the number of leading zeros in the class ID
36  */
37  ClassIDGraph( const sgm::Graph_Interface & molGraph, const size_t leadingZeros )
38  : oriGraph(molGraph)
39  , classIdLength(0)
40  {
41  // with positions for leading zeros
42  classIdLength = 1 + leadingZeros;
43  size_t divisor = 10;
44  const size_t nodeNumber = oriGraph.getNodeNumber();
45  while( nodeNumber / divisor > 0 ) {
46  divisor *= 10;
47  ++classIdLength;
48  }
49  }
50 
51  /**
52  * Destruction
53  */
54  virtual ~ClassIDGraph()
55  {}
56 
57 
58  //! Access to the number of nodes of the graph
59  //! @return the overall node number
60  virtual
61  size_t
62  getNodeNumber(void) const {
63  return oriGraph.getNodeNumber();
64  }
65 
66  //! Access to iteration begin for the edge in the adjacency list of
67  //! a specified node
68  //! @param i the index of the node of interest
69  //! @return the iterator to the first edge within the adjacency of i
70  virtual
71  OutEdge_iterator
72  getOutEdgesBegin( const IndexType & i ) const {
73  return oriGraph.getOutEdgesBegin(i);
74  }
75 
76  //! Access to iteration end for the edge in the adjacency list of
77  //! a specified node
78  //! @param i the index of the node of interest
79  //! @return the iterator the end of the adjacency iteration of i
80  virtual
81  OutEdge_iterator
82  getOutEdgesEnd( const IndexType & i ) const {
83  return oriGraph.getOutEdgesEnd(i);
84  }
85 
86  //! Access to the label of a specified node
87  //! @param i the index of the node of interest
88  //! @return a string representation of the node label
89  virtual
90  std::string
91  getNodeLabel(const IndexType & i) const {
92  // setup class ID generation
93  std::ostringstream classID;
94  classID.width(classIdLength);
95  classID.fill('0');
96  classID <<(i+1);
97 
98  // get atom label
99  const std::string oriLabel = oriGraph.getNodeLabel(i);
100  // check if class information already available
101  if ( oriLabel.find(':') != std::string::npos ) {
102  // class ID present -> just append
103  return oriLabel + classID.str();
104  } else {
105  // no class ID present -> generate
106  return oriLabel + std::string(":") + classID.str();
107  }
108 
109  }
110 
111  };
112 
113 }} // namespace
114 
115 #endif /* GGL_CHEM_CLASSIDGRAPH_HH_ */