MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Stoich.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2014 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #ifndef _STOICH_H
11 #define _STOICH_H
12 
49 class Stoich
50 {
51  public:
52  Stoich();
53  ~Stoich();
54 
56  // Field assignment stuff
58 
59  void setOneWay( bool v );
60  bool getOneWay() const;
61 
62  // Flag that defines permission for pool values to go negative.
63  void setAllowNegative( bool v );
64  bool getAllowNegative() const;
65 
67  unsigned int getNumVarPools() const;
68 
70  unsigned int getNumBufPools() const;
71 
77  unsigned int getNumAllPools() const;
78 
83  unsigned int getNumProxyPools() const;
84 
92  vector< unsigned int > getPoolIdMap() const;
93 
94  Id getPoolByIndex( unsigned int index ) const;
95 
100  void setPath( const Eref& e, string path );
101  string getPath( const Eref& e ) const;
102 
104  void setKsolve( Id v );
105  Id getKsolve() const;
106 
108  void setDsolve( Id v );
109  Id getDsolve() const;
110 
112  void setCompartment( Id v );
113  Id getCompartment() const;
114 
119  unsigned int getNumRates() const;
120 
125  unsigned int getNumCoreRates() const;
126 
128  const RateTerm* rates( unsigned int i ) const;
129 
131  const vector< RateTerm* >& getRateTerms() const;
132 
133  unsigned int getNumFuncs() const;
134  const FuncTerm* funcs( unsigned int i ) const;
136  bool isFuncTarget( unsigned int poolIndex ) const;
137 
138  vector< int > getMatrixEntry() const;
139  vector< unsigned int > getColIndex() const;
140  vector< unsigned int > getRowStart() const;
141 
142  vector< Id > getProxyPools( Id i ) const;
143 
154  int getStatus() const;
156  // Model traversal and building functions
158 
162  void setElist( const Eref& e, const vector< ObjId >& elist );
163 
170  void locateOffSolverReacs( Id myCompt, vector< Id >& elist );
171 
180  void resizeArrays();
183  void allocateModelObject( Id id );
185  void allocateModel( const vector< Id >& elist );
186 
188  void buildPoolLookup();
189  void buildRateTermLookup();
190  void buildFuncLookup();
191 
202 
204  void scaleBufsAndRates( unsigned int index, double volScale );
205 
207  // Zombification functions.
209 
215  void zombifyModel( const Eref& e, const vector< Id >& elist );
216 
220  void unZombifyModel();
221 
223  void unZombifyPools();
224 
225  void zombifyChemCompt( Id compt );
226 
233 
234  unsigned int convertIdToReacIndex( Id id ) const;
235  unsigned int convertIdToPoolIndex( Id id ) const;
236  unsigned int convertIdToFuncIndex( Id id ) const;
237 
240  double rate, const vector< Id >& reactants );
241 
242  /*
243  * This takes the specified Reac and its substrate and product
244  * list, and installs them into the Stoich. It also builds up the
245  * vectors to store which compartment each substrate/product
246  * belongs to, needed for cross-reaction computations.
247  * This is the high-level interface function.
248  */
249  void installReaction( Id reacId,
250  const vector< Id >& subs, const vector< Id >& prds );
251  /*
252  * This takes the specified subs and prds belonging
253  * to the specified Reac, and builds them into the Stoich.
254  * It is a low-level function used internally.
255  */
256  unsigned int innerInstallReaction( Id reacId,
257  const vector< Id >& subs, const vector< Id >& prds );
258 
263  void installMMenz( Id enzId, const vector< Id >& enzMolId,
264  const vector< Id >& subs, const vector< Id >& prds );
268  void installMMenz( MMEnzymeBase* meb, unsigned int rateIndex,
269  const vector< Id >& subs, const vector< Id >& prds );
270 
271  /*
272  * This takes the specified Reac and its substrate and product
273  * list, and installs them into the Stoich. This is the high-level
274  * interface function.
275  */
276  void installEnzyme( Id enzId, Id enzMolId, Id cplxId,
277  const vector< Id >& subs, const vector< Id >& prds );
283  void installEnzyme( ZeroOrder* r1, ZeroOrder* r2, ZeroOrder* r3,
284  Id enzId, Id enzMolId, const vector< Id >& prds );
285 
287  void installDummyEnzyme( Id enzId, Id enzMolId);
288 
293  void installAndUnschedFunc( Id func, Id pool, double volScale );
294 
300  void installAndUnschedFuncRate( Id func, Id pool );
301 
306  void installAndUnschedFuncReac( Id func, Id reac );
307 
309 
313  unsigned int getSpecies( unsigned int poolIndex ) const;
314 
318  void setSpecies( unsigned int poolIndex, unsigned int s );
319 
327  void setReacKf( const Eref& e, double v ) const;
328 
336  void setReacKb( const Eref& e, double v ) const;
337 
344  void setMMenzKm( const Eref& e, double v ) const;
345  double getMMenzNumKm( const Eref& e ) const;
346 
350  void setMMenzKcat( const Eref& e, double v ) const;
351  double getMMenzKcat( const Eref& e ) const;
352 
361  void setEnzK1( const Eref& e, double v ) const;
362  double getEnzNumK1( const Eref& e ) const;
363 
365  void setEnzK2( const Eref& e, double v ) const;
367  double getEnzK2( const Eref& e ) const;
368 
370  void setEnzK3( const Eref& e, double v ) const;
372  double getEnzK3( const Eref& e ) const;
373 
378  double getR1( const Eref& e ) const;
385  double getR1offset1( const Eref& e ) const;
392  double getR1offset2( const Eref& e ) const;
393 
399  double getR2( const Eref& e ) const;
400 
404  void setFunctionExpr( const Eref& e, string expr );
405 
411  void updateRatesAfterRemesh();
412 
414  void print() const;
415 
417  void printRates() const;
419  // Utility funcs for numeric calculations
421 
436  void updateReacVelocities( const double* s, vector< double >& vel,
437  unsigned int volIndex ) const;
438 
440  void updateFuncs( double* s, double t ) const;
441 
443  /*
444  void updateJunctionRates( const double* s,
445  const vector< unsigned int >& reacTerms, double* yprime );
446  */
447 
458  // Access functions for cross-node reactions.
460  const vector< Id >& getOffSolverPools() const;
461 
466  vector< Id > getOffSolverCompts() const;
467 
472  const vector< Id >& offSolverPoolMap( Id compt ) const;
473 
480  static const unsigned int PoolIsNotOnSolver;
482  static const Cinfo* initCinfo();
483  private:
489 
497 
498  string path_;
499 
502 
505 
508 
513 
518  vector< unsigned int > species_;
519 
531  vector< RateTerm* > rates_;
532 
539  unsigned int numVoxels_;
541 
543  vector< FuncTerm* > funcs_;
544 
547 
557  // vector< unsigned int > objMap_;
563  // unsigned int objMapStart_;
564  //
566  // Here we have the vectors of the different kinds of objects
567  // managed by the Stoich
569 
573  vector< Id > varPoolVec_;
574 
578  vector< Id > bufPoolVec_;
579 
585  vector< Id > offSolverPoolVec_;
586 
590  vector< Id > reacVec_;
591  vector< Id > offSolverReacVec_;
592 
596  vector< Id > enzVec_;
597  vector< Id > offSolverEnzVec_;
598 
602  vector< Id > mmEnzVec_;
603  vector< Id > offSolverMMenzVec_;
604 
608  vector< Id > poolFuncVec_;
609 
615  vector< unsigned int > funcTarget_;
616 
621  vector< Id > incrementFuncVec_;
622 
627  vector< Id > reacFuncVec_;
628 
630  // Here we have maps to look up objects from their ids.
632  map< Id, unsigned int > poolLookup_;
633  map< Id, unsigned int > rateTermLookup_;
634  map< Id, unsigned int > funcLookup_;
635 
641  // unsigned int numVarPools_;
642 
653  // unsigned int numBufPools_;
654 
684  int status_;
685 
687  // Off-solver stuff
689 
697  map< Id, vector< Id > > offSolverPoolMap_;
698 
708  vector< pair< Id, Id > > offSolverReacCompts_;
709  vector< pair< Id, Id > > offSolverEnzCompts_;
710  vector< pair< Id, Id > > offSolverMMenzCompts_;
711 
717  vector< vector< Id > > subComptVec_;
718 
724  vector< vector< Id > > prdComptVec_;
725 };
726 
727 #endif // _STOICH_H
unsigned int innerInstallReaction(Id reacId, const vector< Id > &subs, const vector< Id > &prds)
Definition: Stoich.cpp:1562
void updateFuncs(double *s, double t) const
Updates the function values, within s.
Definition: Stoich.cpp:2118
double getEnzNumK1(const Eref &e) const
Definition: Stoich.cpp:1981
void updateReacVelocities(const double *s, vector< double > &vel, unsigned int volIndex) const
vector< vector< Id > > prdComptVec_
Definition: Stoich.h:724
Id zombifyPoolFuncWithScaling(Id pool)
Definition: Stoich.cpp:1244
void setMMenzKm(const Eref &e, double v) const
Definition: Stoich.cpp:1895
double getEnzK2(const Eref &e) const
Get rate k2 (1/sec) for enzyme.
Definition: Stoich.cpp:1986
vector< Id > offSolverMMenzVec_
Definition: Stoich.h:603
Id getCompartment() const
Definition: Stoich.cpp:505
void installAndUnschedFunc(Id func, Id pool, double volScale)
Definition: Stoich.cpp:1067
void setEnzK3(const Eref &e, double v) const
Set rate k3 (1/sec) for enzyme.
Definition: Stoich.cpp:1966
void setReacKf(const Eref &e, double v) const
Definition: Stoich.cpp:1860
void installAndUnschedFuncRate(Id func, Id pool)
Definition: Stoich.cpp:1113
Id compartment_
Contains Id of compartment holding reac system. Optional.
Definition: Stoich.h:507
map< Id, vector< Id > > offSolverPoolMap_
Definition: Stoich.h:697
void setAllowNegative(bool v)
Definition: Stoich.cpp:310
vector< unsigned int > species_
Definition: Stoich.h:518
double getR1(const Eref &e) const
Definition: Stoich.cpp:2006
vector< pair< Id, Id > > offSolverMMenzCompts_
Definition: Stoich.h:710
void installAndUnschedFuncReac(Id func, Id reac)
Definition: Stoich.cpp:1158
map< Id, unsigned int > rateTermLookup_
Definition: Stoich.h:633
vector< Id > offSolverPoolVec_
Definition: Stoich.h:585
void setEnzK1(const Eref &e, double v) const
Later handle all the volumes when this conversion is done.
Definition: Stoich.cpp:1943
string path_
Definition: Stoich.h:498
void resizeArrays()
Using the computed array sizes, now allocate space for them.
Definition: Stoich.cpp:932
void setMMenzKcat(const Eref &e, double v) const
Definition: Stoich.cpp:1926
Id getKsolve() const
Definition: Stoich.cpp:446
void zombifyChemCompt(Id compt)
~Stoich()
Definition: Stoich.cpp:273
int status_
Definition: Stoich.h:684
Stoich()
Definition: Stoich.cpp:255
bool useOneWay_
Definition: Stoich.h:488
const KinSparseMatrix & getStoichiometryMatrix() const
Updates the rates for cross-compartment reactions.
Definition: Stoich.cpp:1221
ZombiePoolInterface * dinterface_
Pointer for dsolve.
Definition: Stoich.h:512
vector< Id > poolFuncVec_
Definition: Stoich.h:608
unsigned int convertIdToFuncIndex(Id id) const
Definition: Stoich.cpp:1484
bool allowNegative_
Definition: Stoich.h:496
void installReaction(Id reacId, const vector< Id > &subs, const vector< Id > &prds)
Definition: Stoich.cpp:1525
vector< Id > getOffSolverCompts() const
Definition: Stoich.cpp:2092
void installEnzyme(Id enzId, Id enzMolId, Id cplxId, const vector< Id > &subs, const vector< Id > &prds)
Definition: Stoich.cpp:1732
vector< Id > reacVec_
Definition: Stoich.h:590
void allocateModelObject(Id id)
Identifies and allocates objects in the Stoich.
Definition: Stoich.cpp:844
void setFunctionExpr(const Eref &e, string expr)
Definition: Stoich.cpp:2028
void setOneWay(bool v)
Definition: Stoich.cpp:300
void buildPoolLookup()
Functions to build the maps between Ids and internal indices.
Definition: Stoich.cpp:997
Definition: Stoich.h:49
vector< Id > reacFuncVec_
Definition: Stoich.h:627
const vector< Id > & getOffSolverPools() const
Definition: Stoich.cpp:2087
void scaleBufsAndRates(unsigned int index, double volScale)
Used to handle run-time size updates for spines.
Definition: Stoich.cpp:2212
void setReacKb(const Eref &e, double v) const
Definition: Stoich.cpp:1874
void unZombifyModel()
Definition: Stoich.cpp:1402
void buildRateTermLookup()
Definition: Stoich.cpp:1011
double getR1offset1(const Eref &e) const
Definition: Stoich.cpp:2010
vector< Id > incrementFuncVec_
Definition: Stoich.h:621
void locateOffSolverReacs(Id myCompt, vector< Id > &elist)
Definition: Stoich.cpp:725
void allocateModel(const vector< Id > &elist)
Calculate sizes of all arrays, and allocate them.
Definition: Stoich.cpp:968
map< Id, unsigned int > funcLookup_
Definition: Stoich.h:634
bool getAllowNegative() const
Definition: Stoich.cpp:315
vector< RateTerm * > rates_
Definition: Stoich.h:531
vector< pair< Id, Id > > offSolverEnzCompts_
Definition: Stoich.h:709
unsigned int convertIdToPoolIndex(Id id) const
Definition: Stoich.cpp:1464
vector< unsigned int > getColIndex() const
Definition: Stoich.cpp:617
const vector< Id > & offSolverPoolMap(Id compt) const
Definition: Stoich.cpp:2102
KinSparseMatrix N_
N_ is the stoichiometry matrix. All pools * all reac terms.
Definition: Stoich.h:546
void setEnzK2(const Eref &e, double v) const
Set rate k2 (1/sec) for enzyme.
Definition: Stoich.cpp:1951
vector< Id > getProxyPools(Id i) const
Definition: Stoich.cpp:627
void unZombifyPools()
unZombifies Pools. Helper for unZombifyModel.
Definition: Stoich.cpp:1376
vector< vector< Id > > subComptVec_
Definition: Stoich.h:717
unsigned int getNumFuncs() const
Definition: Stoich.cpp:594
const FuncTerm * funcs(unsigned int i) const
Definition: Stoich.cpp:599
vector< pair< Id, Id > > offSolverReacCompts_
Definition: Stoich.h:708
Id dsolve_
This contains the Id of the Diffusion solver. Optional.
Definition: Stoich.h:504
Definition: Eref.h:26
void setDsolve(Id v)
assigns diffusion solver: Dsovle or a Gillespie voxel stepper
Definition: Stoich.cpp:451
vector< int > getMatrixEntry() const
Definition: Stoich.cpp:612
Id getDsolve() const
Definition: Stoich.cpp:469
unsigned int getNumBufPools() const
Returns number of local buffered pools.
Definition: Stoich.cpp:515
vector< unsigned int > funcTarget_
Definition: Stoich.h:615
unsigned int getNumRates() const
Definition: Stoich.cpp:568
void installDummyEnzyme(Id enzId, Id enzMolId)
This is used when the enzyme lacks sub or prd.
Definition: Stoich.cpp:1711
unsigned int getNumVarPools() const
Returns number of local pools that are updated by solver.
Definition: Stoich.cpp:510
void setElist(const Eref &e, const vector< ObjId > &elist)
Definition: Stoich.cpp:363
static const Cinfo * initCinfo()
Definition: Stoich.cpp:34
ZeroOrder * makeHalfReaction(double rate, const vector< Id > &reactants)
Utility function to make a half reac and return the rate term.
Definition: Stoich.cpp:1494
void convertRatesToStochasticForm()
Definition: Stoich.cpp:1196
const RateTerm * rates(unsigned int i) const
Utility function to return a rates_ entry.
Definition: Stoich.cpp:583
void printRates() const
Another utility function, prints out all Kf, kf, Kb, kb.
Definition: Stoich.cpp:2072
void buildFuncLookup()
Definition: Stoich.cpp:1054
double getEnzK3(const Eref &e) const
Get rate k3, aka kcat, for enzyme.
Definition: Stoich.cpp:1994
vector< unsigned int > getPoolIdMap() const
Definition: Stoich.cpp:530
static const unsigned int PoolIsNotOnSolver
Definition: Stoich.h:481
bool isFuncTarget(unsigned int poolIndex) const
Returns true if the specified pool is controlled by a func.
Definition: Stoich.cpp:606
void setKsolve(Id v)
assigns kinetic solver: Ksovle or GSSAsolve.
Definition: Stoich.cpp:421
double getMMenzKcat(const Eref &e) const
Definition: Stoich.cpp:1937
unsigned int convertIdToReacIndex(Id id) const
Definition: Stoich.cpp:1474
void zombifyModel(const Eref &e, const vector< Id > &elist)
Definition: Stoich.cpp:1270
void updateRatesAfterRemesh()
Definition: Stoich.cpp:2148
Definition: Id.h:17
void setCompartment(Id v)
assigns compartment occupied by Stoich.
Definition: Stoich.cpp:474
unsigned int getNumCoreRates() const
Number of rate terms for reactions purely on this compartment.
Definition: Stoich.cpp:574
Id ksolve_
This contains the Id of the Kinetic solver.
Definition: Stoich.h:501
vector< Id > varPoolVec_
Definition: Stoich.h:573
vector< FuncTerm * > funcs_
The FuncTerms handle mathematical ops on mol levels.
Definition: Stoich.h:543
unsigned int getNumAllPools() const
Definition: Stoich.cpp:520
const vector< RateTerm * > & getRateTerms() const
Returns a reference to the entire rates_ vector.
Definition: Stoich.cpp:589
void setSpecies(unsigned int poolIndex, unsigned int s)
Definition: Stoich.cpp:2060
double getR2(const Eref &e) const
Definition: Stoich.cpp:2023
vector< unsigned int > getRowStart() const
Definition: Stoich.cpp:622
int getStatus() const
Definition: Stoich.cpp:644
string getPath(const Eref &e) const
Definition: Stoich.cpp:416
ZombiePoolInterface * kinterface_
Pointer for ksolve.
Definition: Stoich.h:510
vector< Id > bufPoolVec_
Definition: Stoich.h:578
bool getOneWay() const
Definition: Stoich.cpp:305
unsigned int getNumProxyPools() const
Definition: Stoich.cpp:525
double getR1offset2(const Eref &e) const
Definition: Stoich.cpp:2014
void installMMenz(Id enzId, const vector< Id > &enzMolId, const vector< Id > &subs, const vector< Id > &prds)
Definition: Stoich.cpp:1636
void print() const
Utility function, prints out N_, used for debugging.
Definition: Stoich.cpp:2066
Definition: Cinfo.h:18
static char path[]
Definition: mfield.cpp:403
double getMMenzNumKm(const Eref &e) const
Definition: Stoich.cpp:1921
void setPath(const Eref &e, string path)
Definition: Stoich.cpp:320
map< Id, unsigned int > poolLookup_
Definition: Stoich.h:632
vector< Id > enzVec_
Definition: Stoich.h:596
Id getPoolByIndex(unsigned int index) const
Definition: Stoich.cpp:557
vector< Id > mmEnzVec_
Definition: Stoich.h:602
unsigned int numVoxels_
Number of voxels in reac system.
Definition: Stoich.h:540
vector< Id > offSolverReacVec_
Definition: Stoich.h:591
vector< Id > offSolverEnzVec_
Definition: Stoich.h:597
unsigned int getSpecies(unsigned int poolIndex) const
Definition: Stoich.cpp:2055