Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
AromaticityPerception.hh
Go to the documentation of this file.
1 #ifndef GGL_CHEM_AROMATICITYPERCEPTION_HH_
2 #define GGL_CHEM_AROMATICITYPERCEPTION_HH_
3 
4 #include <utility>
5 #include <set>
6 #include <stdexcept>
7 
8 #include "sgm/RingReporter.hh"
9 
10 #include "ggl/chem/Molecule.hh"
11 
12 namespace ggl {
13 namespace chem {
14 
15 ////////////////////////////////////////////////////////////////////////////////
16 ////////////////////////////////////////////////////////////////////////////////
17 
18 
19 
20  /*! @brief Interface - aromaticity prediction
21  *
22  * Interface to identify aromatic rings in molecules and to relabel it
23  * accordingly.
24  *
25  * @author Martin Mann (c) 2011 http://www.bioinf.uni-freiburg.de/~mmann/
26  *
27  */
29 
30  public:
31 
32  //! defines an edge; NOTE: use as ordered pairs, i.e. first <= second
33  typedef std::pair< size_t, size_t > Edge;
34  //! container to maintain aromatic edges without duplicates
35  typedef std::set< Edge > EdgeSet;
36 
37 
38  /*!
39  * Describes a ring based on a sorted set of edges and the list of
40  * nodes to encode the ring direction.
41  */
43  public:
44 
46 
47  //! edges participating in the ring
49  //! nodes participating in the ring in ring order (note: the
50  //! reverse order is not stored but valid as well)
52 
53  //! the predicted aromaticity state of this ring
55 
56  //! a value >= 0 describing the certainty of the given predState.
57  //! the larger the value the more certain the prediction is.
58  double predCertainty;
59 
60  //! empty construction
62 
63  //! construction based on a ring list encoding
64  //! @ring the ring to be described
65  RingDescriptor( const RingList& ring );
66 
67  };
68 
69  protected:
70 
71  //! the list of edges part of aromatic rings to be identified
73 
74  //! container that will hold all rings of the current molecule
75  //! -> this list is later pruned to the rings of interest
76  std::vector< RingDescriptor* > allRings;
77 
78  /*! Describes the edge information of a node participating in a ring
79  * to enable the correct relabeling of ring edges.
80  *
81  */
82  struct AdjacencyData {
83  public:
84  //! ID of the node described
85  size_t nodeID;
86  //! the remaining valence of the node to be distributed among the
87  //! adjacent ring edges, i.e. the valence of the atom minus the
88  //! bonds valence of all labeled adjacent bonds
89  size_t remValence;
90  //! the number of non-labeled adjacent ring edges
91  size_t openEdges;
92  //! the number of adjacent labeled aromatic ring edges
93  size_t aromaticEdges;
94  /*! Construction
95  * @param nID node ID
96  * @param val remaining valence to be distributed
97  * @param openEdges number of adjacent non-labeled ring edges to relabel
98  * @param aromEdges number of adjacent labeled aromatic ring edges
99  */
100  AdjacencyData( const size_t nID = 0,
101  const size_t val = 0,
102  const size_t openEdges = 0,
103  const size_t aromEdges = 0 )
104  : nodeID(nID), remValence(val), openEdges(openEdges), aromaticEdges(aromEdges)
105  {}
106 
107 
108  };
109 
110  //! @brief Comparator for edge processing order
111  struct AdjacencyComp {
112  /*!
113  * Decides on the order of the edge processing when used to sort
114  * a container of AdjacencyData objects.
115  *
116  * @param e1 the first edge to be checked if to be processed first
117  * @param e2 the second edge that might be processed after e1
118  *
119  * @return whether or not the edge e1 should be processed before
120  * edge e2
121  */
122  bool operator() ( AdjacencyData* e1, AdjacencyData* e2);
123  };
124 
125 
126  /*!
127  * Comparison of ring descriptors based on the ring size and if equal
128  * on the pairwise order of its edge elements.
129  */
130  class RingSizeLess {
131  public:
132 
133  /*!
134  * less comparison of two ring descriptors.
135  * @param x the ring to be checked if smaller
136  * @param y the ring to compare to
137  * @return true if x.size < y.size
138  * || (x.size == y.size && x.edges < y.edges);
139  * false otherwise
140  */
142  , const RingDescriptor* y )
143  {
144  return x->edges.size() < y->edges.size()
145  || (x->edges.size() == y->edges.size() && x->edges < y->edges );
146  }
147  };
148 
149 
150  public:
151 
152  /*! construction
153  */
155 
156  /*! copy construction
157  */
159 
160  /*!
161  * destruction
162  */
163  virtual ~AromaticityPerception();
164 
165 
166  /*!
167  * Identifies aromatic rings within the molecule and relabels atoms
168  * and bonds accordingly. If rings are wrongly assigned aromatic, they
169  * are relabeled as well.
170  *
171  * @param mol the molecule to correct if needed (done inplace)
172  * @param checkValence whether or not the valence of nodes and bonds
173  * should be checked. In error case a std::runtime_error
174  * is thrown.
175  *
176  * @throw std::runtime_error if a canonical relabeling is not possible
177  * or the valence checks fail
178  */
179  virtual
180  void
181  correctAromaticity( Molecule & mol, const bool checkValence )
182  throw (std::runtime_error);
183 
184  /*!
185  * Creates a heap copy of this instance that has to be deleted by the
186  * calling methods later on.
187  * @return a new instance that is a copy of this object
188  */
189  virtual
191  clone() const = 0;
192 
193  /*!
194  * Is called to report a ring identified by a RingPerception instance.
195  *
196  * Here it is used to store each ring within the allRings container.
197  *
198  * @param graph the graph that contains the ring
199  * @param ringList the ring to report
200  */
201  virtual
202  void
203  reportRing( const sgm::Graph_Interface& graph
204  , const RingList & ringList );
205 
206 
207 
208  protected:
209 
210  /*!
211  * Resets internal temporary data structures.
212  */
213  void
214  clearData();
215 
216  /*!
217  * Identifies all rings and stores them within the allRings container.
218  *
219  * This function is abstract and has to be implemented by a
220  * specific subclass. An according RingReporter function is part of
221  * this class.
222  *
223  * @param mol the molecule to check for rings
224  */
225  virtual
226  void
227  findAllRings( const Molecule & mol ) = 0;
228 
229  /*!
230  * Identifies aromatic rings and stores their edges within the
231  * aromaticEdges container.
232  *
233  * This function is abstract and has to be implemented by a
234  * specific subclass.
235  *
236  * @param mol the molecule to check for aromatic rings
237  */
238  virtual
239  void
240  identifyAromaticEdges( const Molecule & mol ) = 0;
241 
242  /*!
243  * Relabels the given molecule according to the aromatic rings
244  * defined by the aromaticEdges container. All other nodes
245  * and edges are set non-aromatic.
246  *
247  * @param mol the molecule to relabel (done inplace)
248  * @param checkValence whether or not the valence of nodes and bonds
249  * should be checked. In error case a std::runtime_error
250  * is thrown.
251  *
252  * @throw std::runtime_error if a canonical relabeling is not possible
253  * or the valence checks fail
254  */
255  void
257  , const bool checkValence ) throw (std::runtime_error);
258 
259 
260  /*!
261  * Performs a pruning of rings (within the "allRings" container)
262  * that are fused versions of smaller rings sharing only one bond.
263  * @param rings the rings to be pruned
264  */
265  static
266  void
267  pruneFusedRings( std::vector< RingDescriptor* > & rings );
268 
269  /*!
270  * Performs a pruning of rings (within the "allRings" container)
271  * that are not composed of single and double bonds only.
272  * @param rings the rings to be pruned
273  * @param mol the molecule to relabel
274  */
275  static
276  void
277  pruneNonSingleDoubleBondRings( std::vector< RingDescriptor* > & rings
278  , const Molecule & mol );
279 
280  };
281 
282 
283 
284 ////////////////////////////////////////////////////////////////////////////////
285 ////////////////////////////////////////////////////////////////////////////////
286 
287 } } // namespace
288 
289 // include implementation
290 #include "ggl/chem/AromaticityPerception.icc"
291 
292 #endif /* GGL_CHEM_AROMATICITYPERCEPTION_HH_ */