Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
AP_NSPDK.hh
Go to the documentation of this file.
1 
2 #ifndef GGL_CHEM_AP_NSPDK_HH_
3 #define GGL_CHEM_AP_NSPDK_HH_
4 
5 #include <cassert>
6 #include <vector>
7 #include <set>
8 #include <algorithm>
9 #include <limits>
10 
11 #include "sgd/svmmodel.h"
12 
13 #include "nspdk/GraphClass.h"
14 
15 #include "sgm/Graph_Interface.hh"
16 #include "sgm/NSPDK_port.hh"
17 
20 
21 namespace ggl {
22 namespace chem {
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////
26 
27 
28  /*! @brief NSPDK-based aromaticity prediction
29  *
30  * Implementation of an AromaticityPerception based on the NSPDK graph
31  * kernel and linear SVM models derived from chemical databases. The graph
32  * kernel features are derived are all anchored within the according ring
33  * of interest.
34  *
35  * @author Martin Mann (c) 2011 http://www.bioinf.uni-freiburg.de/~mmann/
36  *
37  */
38  class AP_NSPDK
39  : public AromaticityPerception
40  {
41  public :
42 
43  //! ring describing class
45 
46  //! Vector that holds ( index, weight ) pairs
47  typedef std::vector< std::pair<size_t,double> > RingWeightVec;
48 
49 
50  protected:
51 
52  //! defines an edge; NOTE: use as ordered pairs, i.e. first <= second
54  //! defines an aromatic ring via the set of aromatic edges
56  //! defines a list of view points for NSPDK feature generation
58 
59  //! the aromatic ring container to fill
61 
62  //! container that will hold all rings of the current molecule
63  //! -> this list is later pruned to the rings of interest
65 
66  //! the NSPDK graph instance used for feature generation and testing
67  nspdk::GraphClass nspdkGraph;
68 
69  //! the SVM model used to predict the aromaticity of a ring
71 
72 
73  public:
74 
75  /*!
76  * Construction
77  * @param modelID the identifier of the aromaticity model to be used
78  * (check ggl::chem::AP_NSPDK_Model)
79  */
80  AP_NSPDK( const std::string & modelID );
81 
82  /*!
83  * Construction
84  * @param model the aromaticity model to be used
85  */
86  AP_NSPDK( const AP_NSPDK_Model * const model );
87 
88  /*!
89  * Copy construction
90  * @param toCopy the object to make this a copy of
91  */
92  AP_NSPDK( const AP_NSPDK & toCopy );
93 
94  /*!
95  * destruction
96  */
97  virtual ~AP_NSPDK();
98 
99 
100  /*!
101  * Identifies all rings up to the maximally predictable size of the
102  * used NSPDK model and stores them within the allRings container.
103  *
104  * @param mol the molecule to check for rings
105  */
106  virtual
107  void
108  findAllRings( const Molecule & mol );
109 
110  /*!
111  * Identifies aromatic rings and stores their edges within the
112  * aromaticEdges container.
113  *
114  * To this end, each ring is classified using an linear NSPDK SVM
115  * model of aromaticity.
116  *
117  * @param mol the molecule to check for aromatic rings
118  */
119  void
120  identifyAromaticEdges( const Molecule & mol );
121 
122 
123  /*!
124  * Access to the aromaticity model used.
125  */
126  const AP_NSPDK_Model* const
127  getModel( void ) const;
128 
129  /*!
130  * Creates a heap copy of this instance that has to be deleted by the
131  * calling methods later on.
132  * @return a new instance that is a copy of this object
133  */
134  virtual
135  AP_NSPDK *
136  clone() const;
137 
138 
139  /*!
140  * Identifies all rings and returns for each a RingList representation
141  * as well as the according NSPDK features.
142  *
143  * Note: if the used model is ringCentered, only ring nodes are
144  * viewpoints (ring.ring.begin()..(ring.ring.end()-1)))
145  * and thus returned; otherwise a weight for each node is
146  * returned.
147  *
148  * @param mol the molecule to check for rings
149  * @return a ring representation and the features of each ring
150  */
151  virtual
152  std::vector< std::pair< RingList, nspdk::SVector > >
153  getFeatures( const Molecule & mol );
154 
155  /*!
156  * Identifies all rings and returns for each a RingDescriptor
157  * as well as the normalized feature weight for each viewpoint node.
158  *
159  * Note: if the used model is ringCentered, only ring nodes are
160  * viewpoints (ring.ring.begin()..(ring.ring.end()-1)))
161  * and thus returned; otherwise a weight for each node is
162  * returned.
163  *
164  * @param mol the molecule to check for rings
165  * @return a ring representation and the weights for each ring node
166  */
167  virtual
168  std::vector< std::pair< RingDescriptor, RingWeightVec > >
169  getNodeWeights( const Molecule & mol );
170 
171  protected: // member functions
172 
173  /*!
174  * Computes the NSPDK feature vector for a given ring within a
175  * molecule. Note, the molecule graph has to show already the
176  * according ring relabeling.
177  *
178  * Note: if the used model is ringCentered, only ring nodes are
179  * viewpoints (ring.ring.begin()..(ring.ring.end()-1)))
180  * and thus returned; otherwise a weight for each node is
181  * returned.
182  *
183  * @param molGraph the molecule graph containing the ring
184  * @param ring the ring to be described
185  * @param aromaticityModel the model to use
186  */
187  virtual
188  nspdk::SVector
189  getFeaturesOfRing( nspdk::GraphClass &molGraph
190  , const RingDescriptor & ring
192 
193  /*!
194  * Computes the normalized NSPDK feature weights for each viewpoint
195  * node in the graph for a ring within a molecule.
196  * Note, the molecule graph has to show already the
197  * according ring relabeling.
198  *
199  * Note further: if the model is ringCentered, only ring nodes are
200  * viewpoints (ring.ring.begin()..(ring.ring.end()-1)))
201  * and thus returned; otherwise a weight for each node is
202  * returned.
203  *
204  * @param molGraph the molecule graph containing the ring
205  * @param ring the ring to be described
206  * @param aromaticityModel the model to use
207  * @return the feature vector for each viewpoint (see above)
208  */
209  virtual
211  getWeightsOfRing( nspdk::GraphClass &molGraph
212  , const RingDescriptor & ring
213  , const AP_NSPDK_Model& aromaticityModel );
214 
215  /*!
216  * Does an aromaticity prediction for the given ring.
217  *
218  * @param ring the ring to predict
219  * @return true if the ring is aromatic; false otherwise
220  */
221  virtual
222  bool
223  isAromaticRing( const RingDescriptor & ring );
224 
225  /*!
226  * Decides on an aromaticity prediction value if it means aromatic
227  * or not.
228  *
229  * @param predictionValue the prediction value to decide on
230  * @return true if the ring is aromatic; false otherwise
231  */
232  virtual
233  bool
234  isAromaticRing( const double predictionValue );
235 
236  /*!
237  * Computes the classification prediction value for this ring.
238  * This value can be given to "isAromaticRing()"
239  * in order to decide if it is aromatic or not.
240  *
241  * @param ring the ring to predict
242  * @return the prediction value for this ring
243  */
244  virtual
245  double
246  getPredictionValue( const RingDescriptor & ring );
247 
248  protected: // member classes
249 
250 
251  /*!
252  * Generates the set of view point nodes for a given ring in the
253  * molecule graph that anchor the feature generation for the NSPDK
254  * graph kernel. The view point set depends on the aromaticity model
255  * setup, ie. if its covering all nodes or only the ring nodes and
256  * their surrounding.
257  *
258  * @param molGraph the graph of interest
259  * @param ring the ring of interest
260  * @param model the model defining what view points to choose
261  */
262  virtual
264  getViewPoints( nspdk::GraphClass & molGraph
265  , const RingDescriptor & ring
266  , const AP_NSPDK_Model & model ) const;
267 
268 
269  /*!
270  * Initializes the nspdkGraph and relabels all nodes and edges
271  * of the nspdkGraph involved within rings.
272  *
273  * NOTE: rings that contain edges with valence > 2 or < 1 are
274  * ignored!
275  *
276  * @param mol the molecule graph to be used for initialization
277  * @param edgeLabel the edge label to set for all rings
278  * @param ringFlag the flag that is added to the beginning of
279  * each node label of nodes involved in a ring
280  */
281  virtual
282  void
283  initializeGraph( const Molecule mol
284  , const std::string edgeLabel
285  , const std::string ringFlag );
286 
287 
288  //////////////////////////////////////////////////////////////////////
289  //////////////////////////////////////////////////////////////////////
290  };
291 
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 ////////////////////////////////////////////////////////////////////////////////
295 
296 }} // namespace
297 
298 #include "ggl/chem/AP_NSPDK.icc"
299 
300 #endif /* GGL_CHEM_AP_NSPDK_HH_ */