MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MarkovRateTable.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-2011 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 _MARKOVRATETABLE_H
11 #define _MARKOVRATETABLE_H
12 
14 //Class : MarkovRateTable
15 //Author : Vishaka Datta S, 2011, NCBS
16 //
17 //Presents a unified interface to deal with transition rates that are dependent
18 //on one or two parameters, or are constant.
19 //Ther Interpol2D class is used for carrying out 2-D rate lookups. The one
20 //parameter lookup functions are based on the lookup tables used in the HHGate
21 //class.
22 //
23 //The class consists of a table of pointers to the VectorTable class and the
24 //Interpol2D class. Since these classes are user-defined and possess
25 //constructors, destructors, etc., using a union is not possible (but would've
26 //been more efficient).
27 //
28 //For a given rate entry (i,j) either one of these pointers may be set, but not
29 //both. If both pointers are null, the rate is assumed to be zero i.e. there
30 //is no transition from state i to state j.
31 //
32 //In case a rate is constant, it is stored in a VectorTable class whose lookup
33 //table is of size 1.
34 //
36 
37 template <class T>
38 vector< vector< T > > resize( vector< vector< T > >table, unsigned int n, T init )
39 {
40  table.resize( n );
41 
42  for ( unsigned int i = 0; i < n; ++i )
43  table[i].resize( n, init );
44 
45  return table;
46 }
47 
49  public :
51 
53 
54  //One parameter rate table set and get functions.
55  VectorTable* getVtChildTable( unsigned int, unsigned int ) const;
56  void innerSetVtChildTable( unsigned int, unsigned int, VectorTable, unsigned int );
57  //Two parameter rate table set and get functions.
58  Interpol2D* getInt2dChildTable( unsigned int, unsigned int ) const;
59  void innerSetInt2dChildTable( unsigned int, unsigned int, Interpol2D );
60 
61  //Lookup functions.
62  double lookup1dValue( unsigned int, unsigned int, double );
63  double lookup1dIndex( unsigned int, unsigned int, unsigned int );
64  double lookup2dValue( unsigned int, unsigned int, double, double );
65  double lookup2dIndex( unsigned int, unsigned int, unsigned int, unsigned int );
66 
67  //Rate update and initialization functions.
68  void updateRates();
69  void initConstantRates();
70 
71  vector< unsigned int > getListOf1dRates();
72  vector< unsigned int > getListOf2dRates();
73  vector< unsigned int > getListOfLigandRates();
74  vector< unsigned int > getListOfVoltageRates();
75  vector< unsigned int > getListOfConstantRates();
76 
77  //Overloading the >> operator. This is done so that VectorTable and
78  //Interpol2D classes can be used to declare OpFuncs.
79  friend istream& operator>>( istream&, MarkovRateTable& );
80 
82  //*ValueFinfo related functions.
84  vector< vector< double > > getQ() const;
85  unsigned int getSize() const;
86 
87  double getVm( ) const;
88  void setVm( double );
89 
90  double getLigandConc( ) const;
91  void setLigandConc( double );
92 
94  //Helper functions
96 
97  //Returns true if the (i,j)'th rate is zero i.e. no transitions between states
98  //i and j. When this is the case, both the (i,j)'th pointers in vtTables_
99  // and int2dTables_ are not set i.e. both are zero.
100  bool isRateZero( unsigned int, unsigned int ) const ;
101 
102  //Returns true if the (i,j)'th rate is a constant. This is true when the
103  //vtTables_[i][j] pointer points to a 1D lookup table of size 1.
104  bool isRateConstant( unsigned int, unsigned int ) const ;
105 
106  //Returns true if the (i,j)'th rate is varies with only one parameter.
107  bool isRate1d( unsigned int, unsigned int ) const ;
108 
109  //Returns true if the (i,j)'th rate is dependent on ligand concentration and
110  //not membrane voltage, and is set with a 1D lookup table.
111  bool isRateLigandDep( unsigned int, unsigned int) const;
112 
113  //Returns true if the (i,j)'th rate varies with two parameters.
114  bool isRate2d( unsigned int, unsigned int ) const ;
115 
116  //Returns true if a table is being accessed at an invalid address.
117  bool areIndicesOutOfBounds( unsigned int, unsigned int ) const ;
118 
120  //These functions return general information about the whole rate table
121  //itself. Useful for the MarkovSolver class.
123 
124  //Returns true if all the rates in the transition matrix are constant.
125  bool areAllRatesConstant();
126 
127  //Returns true if at least one of the rates are 1D i.e. vary with only
128  //one parameter.
129  bool areAnyRates1d();
130  bool areAllRates1d();
131 
132  //Returns true if at least one of the rates are 2D i.e. vary with two
133  //parameters.
134  bool areAnyRates2d();
135  bool areAllRates2d();
136 
137  //Returns true if at least one of the rates are ligand dependent.
138  bool areAnyRatesLigandDep();
139  bool areAllRatesLigandDep();
140 
141  //Returns true if at least one of the rates are voltage dependent.
142  bool areAnyRatesVoltageDep();
143  bool areAllRatesVoltageDep();
144 
145  static const Cinfo* initCinfo();
146 
148  //MsgDest functions.
150  void process( const Eref&, ProcPtr );
151  void reinit( const Eref&, ProcPtr );
152 
153  //Initialization of object.
154  void init( unsigned int );
155 
156  //Handling incoming messages containing voltage and concentration information.
157  void handleVm( double );
158  void handleLigandConc( double );
159 
160  //Setting rate tables for 1-D and 2-D rate transitions.
161  void setVtChildTable( unsigned int, unsigned int, Id, unsigned int );
162  void setInt2dChildTable( unsigned int, unsigned int, Id );
163 
164  //Setting a constant rate.
165  void setConstantRate( unsigned int, unsigned int, double );
166 
167  private :
168  //Family of 1D lookup table pointers. Each entry is a pointer to a 1-D
169  //lookup table (VectorTable type) that contains the values of the rates of
170  //transition at a given voltage or ligand concentration.
171  vector< vector< VectorTable* > > vtTables_;
172 
173  //Family of 2D lookup table pointers. Each entry is a pointer to a 2-D
174  //lookup table of type Interpol2D. These lookup tables deal with rates that
175  //vary with voltage and ligand concentration.
176  vector< vector< Interpol2D* > > int2dTables_;
177 
178  //In the case of 1-D lookup tables, this matrix determines which rates are
179  //ligand dependent. When the (i,j)'th value is "true", the ligand
180  //concentration is used instead of voltage for rate lookups.
181  vector< vector< unsigned int > > useLigandConc_;
182 
183  //Maintains a list of the indices of 1D,2D,constant rates, voltage and
184  //ligand dependent rates. Makes updating rates a whole lot easier and
185  //more elegant than blindly scanning through the entire rate matrix
186  //each time.
187  vector< unsigned int > listOf1dRates_;
188  vector< unsigned int > listOf2dRates_;
189  vector< unsigned int > listOfConstantRates_;
190  vector< unsigned int > listOfLigandRates_;
191  vector< unsigned int > listOfVoltageRates_;
192 
193  //The instantaneous rate matrix.
194  vector< vector< double > > Q_;
195 
196  //Membrane voltage and ligand concentration. Needed for rate lookups.
197  //Admittedly, this is a bit of a deviation from the usual scheme where
198  //channels are the only destinations for Vm and conc.
199  double Vm_;
200  double ligandConc_;
201 
202  //Time step of simulation. The rates are specified in sec^(-1). All the rates
203  //have to be proportionally scaled for an arbitrary time step.
204  //Is not a MOOSE field, and does not need an explicit setup call either.
205  //It is set during the call to reinit.
206 
207  unsigned int size_;
208 
209  //Check to see if the table has been initialized.
210  bool isInitialized() const;
211 };
212 #endif
vector< unsigned int > listOfConstantRates_
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
vector< vector< Interpol2D * > > int2dTables_
vector< unsigned int > getListOf2dRates()
bool areIndicesOutOfBounds(unsigned int, unsigned int) const
void process(const Eref &, ProcPtr)
Interpol2D * getInt2dChildTable(unsigned int, unsigned int) const
void reinit(const Eref &, ProcPtr)
bool isRateConstant(unsigned int, unsigned int) const
vector< vector< double > > getQ() const
void setVtChildTable(unsigned int, unsigned int, Id, unsigned int)
vector< unsigned int > listOf2dRates_
VectorTable * getVtChildTable(unsigned int, unsigned int) const
vector< unsigned int > getListOfConstantRates()
vector< unsigned int > listOfLigandRates_
static const Cinfo * initCinfo()
unsigned int size_
void handleVm(double)
friend istream & operator>>(istream &, MarkovRateTable &)
vector< unsigned int > getListOf1dRates()
void setVm(double)
bool isRateLigandDep(unsigned int, unsigned int) const
vector< unsigned int > getListOfVoltageRates()
void init(unsigned int)
bool isRate1d(unsigned int, unsigned int) const
bool isInitialized() const
vector< vector< VectorTable * > > vtTables_
Definition: Eref.h:26
bool isRate2d(unsigned int, unsigned int) const
bool isRateZero(unsigned int, unsigned int) const
vector< vector< T > > resize(vector< vector< T > >table, unsigned int n, T init)
vector< vector< unsigned int > > useLigandConc_
void innerSetVtChildTable(unsigned int, unsigned int, VectorTable, unsigned int)
double lookup2dValue(unsigned int, unsigned int, double, double)
void setConstantRate(unsigned int, unsigned int, double)
unsigned int getSize() const
Definition: Id.h:17
vector< unsigned int > listOfVoltageRates_
void setLigandConc(double)
vector< unsigned int > getListOfLigandRates()
void handleLigandConc(double)
void setInt2dChildTable(unsigned int, unsigned int, Id)
double lookup2dIndex(unsigned int, unsigned int, unsigned int, unsigned int)
vector< unsigned int > listOf1dRates_
double getLigandConc() const
Definition: Cinfo.h:18
double lookup1dValue(unsigned int, unsigned int, double)
double lookup1dIndex(unsigned int, unsigned int, unsigned int)
void innerSetInt2dChildTable(unsigned int, unsigned int, Interpol2D)
double getVm() const
vector< vector< double > > Q_