COPASI API  4.16.103
CTrajectoryMethodDsaLsodar.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/trajectory/CTrajectoryMethodDsaLsodar.h,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:34:14 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 /**
15  * CTrajectoryMethodDsaLsodar
16  *
17  * This class implements an hybrid algorithm to simulate a biochemical
18  * system over time.
19  *
20  * File name: CTrajectoryMethodDsaLsodar.h
21  * Author: Stefan Hoops
22  *
23  */
24 
25 /**
26  * Partition the system into a deterministic part and a stochastic part.
27  * That is, every reaction is either classified deterministic or
28  * stochastic. Deterministic reactions involve only those metabolites (on
29  * substrate and product side), which have a high particle number.
30  * Therefore it is legal to integrate this part of the system with e.g. a
31  * numerical integrator. The concentration and relative particle number
32  * change should be low enough, so that the probabilities of all the
33  * reactions in the system show only little changes. The stochastic
34  * reactions must be simulated with an exact stochastic method (e.g. next
35  * reaction method (Gibson)), because their firing changes the reaction
36  * probabilities in the system significantly.
37  */
38 #ifndef COPASI_CTrajectoryMethodDsaLsodar
39 #define COPASI_CTrajectoryMethodDsaLsodar
40 
41 /* INCLUDES ******************************************************************/
42 
44 
46 #include "copasi/model/CState.h"
47 
48 class CReaction;
49 class CMetab;
50 class CRandom;
51 
53 {
54  friend CTrajectoryMethod *
56 
57  /* PUBLIC METHODS **********************************************************/
59  {
60  public:
61  // Operations
62  /**
63  * Default constructor
64  */
66 
67  /**
68  * Copy constructor
69  * @param const CReactionDependencies & src
70  */
72 
73  /**
74  * Destructor
75  */
77 
78  /**
79  * Assignment operator
80  * @param const CReactionDependencies & rhs
81  * @return CReactionDependencies &
82  */
84 
85  // Attributes
86 
87  /**
88  * Vector of multiplier to calculate the new state
89  */
91 
92  /**
93  * Vector of pointers to method internal species values to calculate the new state.
94  */
96 
97  /**
98  * Vector of pointers to model species values to calculate the new state.
99  */
101 
102  /**
103  * Vector of refresh methods which need to be executed to update all values required for simulation
104  */
105  std::vector< Refresh * > mCalculations;
106 
107  /**
108  * A vector of indexes of reaction which propensities have to be recalculated.
109  */
111 
112  /**
113  * Vector of multiplier to calculate the new propensity.
114  */
116 
117  /**
118  * Vector of pointers to method internal species values to calculate the new propensity.
119  */
121 
122  /**
123  * Vector of pointers to model species values to calculate the new propensity.
124  */
126 
127  /**
128  * A pointer to the particle flux of the reaction.
129  */
131 
132  /**
133  * A vector containing the index of each species participating in the reaction as
134  * a substrate and/or product.
135  */
137  };
138 
140  {
141  public:
142  typedef std::multimap< size_t, size_t > speciesToReactionsMap;
143 
144  // Operations
145  /**
146  * Default constructor
147  */
148  CPartition();
149 
150  /**
151  * Copy constructor
152  * @param const CPartition & src
153  */
154  CPartition(const CPartition & src);
155 
156  /**
157  * Destructor
158  */
159  ~CPartition();
160 
161  void intialize(std::vector< CReactionDependencies > & reactions,
162  const speciesToReactionsMap & speciesToReactions,
163  const C_FLOAT64 & lowerThreshold,
164  const C_FLOAT64 & upperThreshold,
165  const CState & state);
166 
167  bool rePartition(const CState & state);
168 
170 
171  private:
172  // Attributes
173  /**
174  * A map from a species index to the indexes of the reactions it participates in
175  */
177 
178  /**
179  * The threshold for switching to stochastic treatment
180  */
182 
183  /**
184  * The threshold for switching to deterministic treatment
185  */
187 
188  /**
189  * The index of the first species determined by reactions in the state
190  */
192 
193  /**
194  * The number of species determined by reactions
195  */
197 
198  public:
199  /**
200  * A vector containing pointers to stochastic reaction dependencies
201  */
203 
204  /**
205  * A vector containing pointers to stochastic reaction dependencies
206  */
208 
209  /**
210  * A vector indicating whether a species is treated stochastically or not.
211  */
213 
214  /**
215  * A Boolean flag indicating whether the system has stochastic reactions
216  */
218 
219  /**
220  * A Boolean flag indicating whether the system has deterministic reactions
221  */
223 
224  private:
225  /**
226  * A vector containing the number of low species for each reaction
227  */
229 
230  /**
231  * A vector containing the current treatment of the species
232  */
234  };
235 
236 protected:
237  /**
238  * Default constructor.
239  * @param const CCopasiMethod::SubType & subType (default: DsaLsodar)
240  * @param const CCopasiContainer * pParent (default: NULL)
241  */
243  const CCopasiContainer * pParent = NULL);
244 
245 public:
246  /**
247  * Copy constructor
248  * @param const CTrajectoryMethodDsaLsodar & src
249  * @param const CCopasiContainer * pParent (default: NULL)
250  */
252  const CCopasiContainer * pParent = NULL);
253 
254  /**
255  * Destructor.
256  */
258 
259  /**
260  * This methods must be called to elevate subgroups to
261  * derived objects. The default implementation does nothing.
262  * @return bool success
263  */
264  virtual bool elevateChildren();
265 
266  /**
267  * Inform the trajectory method that the state has changed outside
268  * its control
269  */
270  virtual void stateChanged();
271 
272  /**
273  * This instructs the method to calculate a time step of deltaT
274  * starting with the current state, i.e., the result of the previous
275  * step.
276  * The new state (after deltaT) is expected in the current state.
277  * The return value is the actual time step taken.
278  * @param "const double &" deltaT
279  * @return Status status
280  */
281  virtual Status step(const double & deltaT);
282 
283  /**
284  * This instructs the method to prepare for integration
285  * starting with the initialState given.
286  * @param "const CState *" initialState
287  */
288  virtual void start(const CState * initialState);
289 
290  /**
291  * This evaluates the derivatives
292  */
293  virtual void evalF(const C_FLOAT64 * t, const C_FLOAT64 * y, C_FLOAT64 * ydot);
294 
295  /**
296  * This evaluates the roots
297  */
298  virtual void evalR(const C_FLOAT64 * t, const C_FLOAT64 * y, const C_INT * nr, C_FLOAT64 * r);
299 
300  /**
301  * Check if the method is suitable for this problem
302  * @return bool suitability of the method
303  */
304  virtual bool isValidProblem(const CCopasiProblem * pProblem);
305 
306  /* PROTECTED METHODS *******************************************************/
307 
308  /**
309  * Cleans up memory, etc.
310  */
311  void cleanup();
312 
313  /* VIRTUAL METHODS *********************************************************/
314 
315  /**
316  * Simulates the system over the next interval of time. The current time
317  * and the end time of the current step() are given as arguments.
318  *
319  * @param currentTime A C_FLOAT64 specifying the current time
320  * @param endTime A C_FLOAT64 specifying the end time of the step()
321  * @return A C_FLOAT giving the new time
322  */
323  virtual C_FLOAT64 doSingleStep(C_FLOAT64 currentTime, C_FLOAT64 endTime);
324 
325  /* DETERMINISTIC STUFF *****************************************************/
326 
327  /**
328  * Integrates the deterministic reactions of the system over the
329  * specified time interval.
330  * @param const C_FLOAT64 & deltaT.
331  */
332  void integrateDeterministicPart(const C_FLOAT64 & deltaT);
333 
334  /* STOCHASTIC STUFF ********************************************************/
335 
336  /**
337  * Executes the specified reaction in the system once.
338  * @param const size_t & index
339  */
340  void fireReaction(const size_t & index);
341 
342  /**
343  * Calculates an amu value for a given reaction.
344  * @param const size_t & index
345  */
346  void calculateAmu(const size_t & index);
347 
348  /**
349  * Calculate the propensities of all stochastic reactions
350  */
351  void calculatePropensities();
352 
353  /* PRIVATE METHODS *********************************************************/
354 
355 private:
356  /**
357  * Initialize the method parameter
358  */
359  void initializeParameter();
360 
361  /* VARIABLES ***************************************************************/
362 protected:
363  /**
364  * Pointer to the method parameter "Max Internal Steps"
365  */
366  unsigned C_INT32 * mpMaxSteps;
367 
368  /**
369  * Pointer to the method parameter "Lower Limit"
370  */
372 
373  /**
374  * Pointer to the method parameter "Upper Limit"
375  */
377 
378  /**
379  * Pointer to the method parameter "Partitioning Interval"
380  */
382 
383  /**
384  * Pointer to the method parameter "Partitioning Stepsize"
385  */
387 
388  /**
389  * The random number generator.
390  */
392 
393  /**
394  * Index of the first species determined by reactions in CState
395  */
397 
398 
400 
401  /**
402  * Number of elementary steps after the last partitioning.
403  */
405 
406  /**
407  * The particle and reaction numbers
408  */
410 
411  /**
412  * The time the next reaction fires
413  */
415 
416  /**
417  * The index of the next reaction which fires
418  */
420 
421  /**
422  * A boolean flag indicating whether correction for higher order reactions need to be applied
423  */
425 
426  /**
427  * A vector of reaction propensities
428  */
430 
431  /**
432  * Total propensity (sum over mAmu[i])
433  */
435 
436  /**
437  * A vector containing dependency information to minimize the required updates.
438  */
439  std::vector< CReactionDependencies > mReactionDependencies;
440 
441  /**
442  * The partition of the system
443  */
445 };
446 
448 
449 #endif // COPASI_CTrajectoryMethodDsaLsodar
CTrajectoryMethodDsaLsodar(const CCopasiMethod::SubType &subType=DsaLsodar, const CCopasiContainer *pParent=NULL)
void calculateAmu(const size_t &index)
#define C_INT
Definition: copasi.h:115
virtual void evalR(const C_FLOAT64 *t, const C_FLOAT64 *y, const C_INT *nr, C_FLOAT64 *r)
virtual Status step(const double &deltaT)
Definition: CState.h:305
CVector< CReactionDependencies * > mStochasticReactions
virtual void evalF(const C_FLOAT64 *t, const C_FLOAT64 *y, C_FLOAT64 *ydot)
#define C_INT32
Definition: copasi.h:90
Definition: CMetab.h:178
virtual C_FLOAT64 doSingleStep(C_FLOAT64 currentTime, C_FLOAT64 endTime)
CReactionDependencies & operator=(const CReactionDependencies &rhs)
virtual bool isValidProblem(const CCopasiProblem *pProblem)
std::vector< CReactionDependencies > mReactionDependencies
void integrateDeterministicPart(const C_FLOAT64 &deltaT)
void intialize(std::vector< CReactionDependencies > &reactions, const speciesToReactionsMap &speciesToReactions, const C_FLOAT64 &lowerThreshold, const C_FLOAT64 &upperThreshold, const CState &state)
static CTrajectoryMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::deterministic)
#define C_FLOAT64
Definition: copasi.h:92
std::multimap< size_t, size_t > speciesToReactionsMap
void fireReaction(const size_t &index)
CVector< CReactionDependencies * > mDeterministicReactions
virtual void start(const CState *initialState)