Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
MR_Reactions.hh
Go to the documentation of this file.
1 #ifndef GGL_CHEM_MR_REACTIONS_HH_
2 #define GGL_CHEM_MR_REACTIONS_HH_
3 
4 #include <vector>
5 #include <set>
6 #include <cassert>
7 
8 #include "sgm/Match_Reporter.hh"
9 #include "sgm/Graph_boostV_p.hh"
10 
11 #include "ggl/RuleGraph.hh"
12 #include "ggl/MR_ApplyRule.hh"
13 
14 #include "ggl/chem/Molecule.hh"
15 #include "ggl/chem/SMILESwriter.hh"
16 #include "ggl/chem/GS_MolCheck.hh"
17 #include "ggl/chem/GS_SMILES.hh"
18 #include "ggl/chem/Reaction.hh"
21 #include "ggl/chem/AP_NSPDK.hh"
22 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////
26 
27 #include "sgm/HashMap.hh"
28 
29 
30 #if HAVE_UNORDERED_MAP > 0
31  #include <unordered_map>
32 #elif HAVE_TR1_UNORDERED_MAP > 0
33  #include <tr1/unordered_map>
34 #elif HAVE_GNU_HASH_MAP > 0
35  #include <ext/hash_map>
36 #else
37  #include <map>
38 #endif
39 
40 
41 
42 namespace ggl {
43  namespace chem {
44 
45  //////////////////////////////////////////////////////////////////////////////
46  //! Type for mapping of SMILES strings to their graph
47  //! implementation
48 typedef
49 #if HAVE_UNORDERED_MAP > 0
50  std::unordered_map< std::string, ggl::chem::Molecule*>
51 #elif HAVE_TR1_UNORDERED_MAP > 0
52  std::tr1::unordered_map< std::string, ggl::chem::Molecule*>
53 #elif HAVE_GNU_HASH_MAP > 0
54  __gnu_cxx::hash_map< std::string, ggl::chem::Molecule*, sgm::hash_string >
55 #else
56  std::map< std::string, ggl::chem::Molecule* >
57 #endif
59  //////////////////////////////////////////////////////////////////////////////
60 
61 
62  //////////////////////////////////////////////////////////////////////////////
63  //! Type for mapping of graph implementations to SMILES strings
64 typedef
65 #if HAVE_UNORDERED_MAP > 0
66  std::unordered_map< const ggl::chem::Molecule*, std::string >
67 #elif HAVE_TR1_UNORDERED_MAP > 0
68  std::tr1::unordered_map< const ggl::chem::Molecule*, std::string >
69 #elif HAVE_GNU_HASH_MAP > 0
70  __gnu_cxx::hash_map< const ggl::chem::Molecule*, std::string >
71 #else
72  std::map< const ggl::chem::Molecule*, std::string >
73 #endif
75  //////////////////////////////////////////////////////////////////////////////
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 ////////////////////////////////////////////////////////////////////////////////
80 
81 
82  /*! @brief Reaction match reporter
83  *
84  * A Match_Reporter that generates a Reaction object from a rule
85  * application.
86  *
87  * NOTE : this class currently only works for target graphs that are an
88  * object of Molecule_GraphV !!! Furthermore, it assumes that the
89  * elements (pointer) from the covered target graph are from the here
90  * maintained storage, to enable a fast lookup of their SMILES !!!
91  * Finaly, SMILES are generated using an instance of SMILESwriter !!!
92  *
93  * @author Martin Mann (c) 2009 http://www.bioinf.uni-freiburg.de/~mmann/
94  *
95  */
97  : public sgm::Match_Reporter
98  , public GS_SMILES_MOLp< Smiles2GraphMap >
99  {
100 
101  public:
102 
103  //! a container that stores Reaction objects
104  typedef std::set< Reaction > Reaction_Container;
105 
106  protected:
107 
108  //! the SMILESwriter to use for target-to-smiles conversion
110 
111  //! access to the superclass of this class
113 
114  protected:
115 
116  //! The storage of known SMILES to the graph implementations.
118  //! An alternative second storage of known SMILES to the graph
119  //! implementations.
121  //! The storage of new SMILES to the graph implementations.
122  //! The pointer are 'new' allocated and have to be destroyed outside!
124  //! A vice versa lookup table for smiles2graph
126 
127  //! The container of Reaction objects to fill and extend
129 
130  //! the current Reaction to fill and to store later
132 
133  //! if set to true, than all components of the Rules LeftSidePattern
134  //! are matched to an own target graph copy if two components map to
135  //! the same target graph
136  const bool addEachComponent;
137 
138  //! the checker used to correct all molecules produced by the Ruler;
139  //! it will apply an AP_NSPDK aromaticity perception instance.
141 
142  //! the Match_Reporter utilized to apply the rule and to produce the
143  //! resulting molecules that will be stored in the reaction
145 
146  //! if != NULL, for each new reaction a rate is calculated
148 
149  public:
150 
151  /*! Construction
152  *
153  * @param smiles2graph the initial container that contains all
154  * molecules known so far and is fixed
155  * @param newSmiles2graph the container where all new molecules will
156  * be stored in
157  * @param reactions the Reaction container to fill
158  * @param addEachComponent if set to true, than all components of the
159  * Rules LeftSidePattern are matched to an own target graph
160  * copy if two components map to the same target graph
161  * @param rateCalculation The object to use to calculate a reaction
162  * rate for each new reaction created. If not present (==NULL)
163  * no reaction rate will be calculated.
164  * @param aromaticity the aromaticity perception class to be used to
165  * correct rings in the product molecules after the rule
166  * application was done.
167  */
168  MR_Reactions( const Smiles2GraphMap& smiles2graph
169  , Smiles2GraphMap& newSmiles2graph
171  , const bool addEachComponent = false
173  , const AromaticityPerception & aromaticity =
174  AP_NSPDK("Marvin:general:2013"));
175 
176 
177  /*! Construction
178  *
179  * @param smiles2graph the initial container that contains all
180  * molecules known so far and which is not changed
181  * @param smiles2graph2 second container of the initial
182  * molecules known so far
183  * @param newSmiles2graph the container where all new molecules will
184  * be stored in
185  * @param reactions the Reaction container to fill
186  * @param addEachComponent if set to true, than all components of the
187  * Rules LeftSidePattern are matched to an own target graph
188  * copy if two components map to the same target graph,
189  * @param rateCalculation The object to use to calculate a reaction
190  * rate for each new reaction created. If not present (==NULL)
191  * no reaction rate will be calculated.
192  * @param aromaticity the aromaticity perception class to be used to
193  * correct rings in the product molecules after the rule
194  * application was done.
195  */
196  MR_Reactions( const Smiles2GraphMap& smiles2graph
197  , const Smiles2GraphMap& smiles2graph2
198  , Smiles2GraphMap& newSmiles2graph
199  , Reaction_Container& reactions
200  , const bool addEachComponent = false
202  , const AromaticityPerception & aromaticity =
203  AP_NSPDK("Marvin:general:2013"));
204 
205  /*! Destruction
206  */
207  virtual
208  ~MR_Reactions();
209 
210 
211  ///////////// sgm::Match_Reporter interface //////////////////////////
212 
213  //! Reports a match. The match is encoded using a vector. The length
214  //! of the vector corresponds to the number of vertices in the pattern
215  //! and position i encodes the matched position of pattern node i in
216  //! the target graph (an instance of sgm::Graph_boostV_p).
217  //! @param pattern the pattern graph that was searched for. NOTE: HAS
218  //! TO BE AN INSTANCE OF ggl::chem::LeftSidePattern !!!
219  //! @param target the graph the pattern was found within. NOTE: HAS TO
220  //! BE AN INSTANCE OF sgm::Graph_boostV_p !!!
221  //! @param match contains the indices of the matched pattern nodes in
222  //! the target graph. match[i] corresponds to the mapping of the ith
223  //! vertex in the pattern graph.
224  virtual
225  void
226  reportHit ( const sgm::Pattern_Interface & pattern,
227  const sgm::Graph_Interface & target,
228  const sgm::Match & match );
229 
230 
231  protected:
232 
233  ///////////// GS_SMILES_MOLp interface //////////////////
234 
235  /*! Writes a given SMILES and the corresponding molecule graph to the
236  * global storage. Furthermore, the given SMILES is added to the
237  * products of the currently processed ggl::chem::Reaction.
238  *
239  * @param SMILES the SMILES string produced
240  * @param molGraph the molecule graph that corresponds to the given SMILES
241  * @return true it the SMILES was not seen so far; false otherwise
242  */
243  virtual
244  bool
245  insert2map(const std::string & SMILES, const Molecule& molGraph );
246 
247  }; // MR_Reactions
248 
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 ////////////////////////////////////////////////////////////////////////////////
252 
253  } // namespace chem
254 } // namespace ggl
255 
256  // include implementation
257 #include "ggl/chem/MR_Reactions.icc"
258 
259 #endif /*MR_REACTIONS_HH_*/