22 "lookupA: Look up the A gate value from a double. Usually does"
23 "so by direct scaling and offset to an integer lookup, using"
24 "a fine enough table granularity that there is little error."
25 "Alternatively uses linear interpolation."
26 "The range of the double is predefined based on knowledge of"
27 "voltage or conc ranges, and the granularity is specified by"
28 "the xmin, xmax, and dV fields.",
31 "lookupB: Look up the B gate value from a double."
32 "Note that this looks up the raw tables, which are transformed"
33 "from the reference parameters.",
37 "Parameters for voltage-dependent rates, alpha:"
38 "Set up alpha term using 5 parameters, as follows:"
39 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
40 "The original HH equations can readily be cast into this form",
46 "Parameters for voltage-dependent rates, beta:"
47 "Set up beta term using 5 parameters, as follows:"
48 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
49 "The original HH equations can readily be cast into this form",
55 "Parameters for voltage-dependent rates, tau:"
56 "Set up tau curve using 5 parameters, as follows:"
57 "y(x) = (A + B * x) / (C + exp((x + D) / F))",
64 "Parameters for voltage-dependent rates, mInfinity:"
65 "Set up mInfinity curve using 5 parameters, as follows:"
66 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
67 "The original HH equations can readily be cast into this form",
73 "Minimum range for lookup",
79 "Minimum range for lookup",
85 "Divisions for lookup. Zero means to use linear interpolation",
99 "Table of alpha + beta entries",
106 "Flag: use linear interpolation if true, else direct lookup",
113 "Set up both gates using 13 parameters, as follows:"
114 "setupAlpha AA AB AC AD AF BA BB BC BD BF xdivs xmin xmax"
115 "Here AA-AF are Coefficients A to F of the alpha (forward) term"
116 "Here BA-BF are Coefficients A to F of the beta (reverse) term"
117 "Here xdivs is the number of entries in the table,"
118 "xmin and xmax define the range for lookup."
119 "Outside this range the returned value will be the low [high]"
120 "entry of the table."
121 "The equation describing each table is:"
122 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
123 "The original HH equations can readily be cast into this form",
132 "Set up both gates using 13 parameters, as follows:"
133 "setupAlpha AA AB AC AD AF BA BB BC BD BF xdivs xmin xmax"
134 "Here AA-AF are Coefficients A to F of the alpha (forward) term"
135 "Here BA-BF are Coefficients A to F of the beta (reverse) term"
136 "Here xdivs is the number of entries in the table,"
137 "xmin and xmax define the range for lookup."
138 "Outside this range the returned value will be the low [high]"
139 "entry of the table."
140 "The equation describing each table is:"
141 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
142 "The original HH equations can readily be cast into this form",
146 "Identical to setupAlpha, except that the forms specified by"
147 "the 13 parameters are for the tau and m-infinity curves rather"
148 "than the alpha and beta terms. So the parameters are:"
149 "setupTau TA TB TC TD TF MA MB MC MD MF xdivs xmin xmax"
150 "As before, the equation describing each curve is:"
151 "y(x) = (A + B * x) / (C + exp((x + D) / F))",
155 "Dummy function for backward compatibility. It used to convert"
156 "the tables from alpha, beta values to alpha, alpha+beta"
157 "because the internal calculations used these forms. Not"
158 "needed now, deprecated.",
162 "Dummy function for backward compatibility. It used to convert"
163 "the tables from tau, minf values to alpha, alpha+beta"
164 "because the internal calculations used these forms. Not"
165 "needed now, deprecated.",
169 "Sets up one gate at a time using the alpha/beta form."
170 "Has 9 parameters, as follows:"
171 "setupGate A B C D F xdivs xmin xmax is_beta"
172 "This sets up the gate using the equation:"
173 "y(x) = (A + B * x) / (C + exp((x + D) / F))"
177 static Finfo* HHGateFinfos[] =
199 static string doc[] =
202 "Author",
"Upinder S. Bhalla, 2011, NCBS",
203 "Description",
"HHGate: Gate for Hodkgin-Huxley type channels, equivalent to the "
204 "m and h terms on the Na squid channel and the n term on K. "
205 "This takes the voltage and state variable from the channel, "
206 "computes the new value of the state variable and a scaling, "
207 "depending on gate power, for the conductance.",
211 static Cinfo HHGateCinfo(
214 HHGateFinfos,
sizeof(HHGateFinfos)/
sizeof(
Finfo *),
217 sizeof(doc)/
sizeof(
string)
228 : xmin_(0), xmax_(1), invDx_(1),
231 lookupByInterpolation_(0),
239 xmin_(0), xmax_(1), invDx_(1),
240 originalChanId_( originalChanId ),
241 originalGateId_( originalGateId ),
242 lookupByInterpolation_(0),
252 if ( v <=
xmin_ )
return tab[0];
253 if ( v >=
xmax_ )
return tab.back();
256 static_cast< unsigned int >( ( v -
xmin_ ) *
invDx_ );
257 assert( tab.size() > index );
258 double frac = ( v -
xmin_ - index /
invDx_ ) * invDx_;
259 return tab[ index ] * ( 1 - frac ) + tab[ index + 1 ] * frac;
261 return tab[
static_cast< unsigned int >( (v -
xmin_) *
invDx_ ) ];
280 }
else if ( v >=
xmax_ ) {
285 static_cast< unsigned int >( ( v -
xmin_ ) *
invDx_ );
286 assert(
A_.size() > index &&
B_.size() > index );
288 double frac = ( v -
xmin_ - index /
invDx_ ) * invDx_;
289 *A =
A_[ index ] * ( 1 - frac ) +
A_[ index + 1 ] * frac;
290 *B =
B_[ index ] * ( 1 - frac ) +
B_[ index + 1 ] * frac;
305 if ( val.size() != 5 ) {
306 cout <<
"Error: HHGate::setAlpha on " << e.
id().
path() <<
307 ": Number of entries on argument vector should be 5, was " <<
325 if ( val.size() != 5 ) {
326 cout <<
"Error: HHGate::setBeta on " << e.
id().
path() <<
327 ": Number of entries on argument vector should be 5, was " <<
345 if ( val.size() != 5 ) {
346 cout <<
"Error: HHGate::setTau on " << e.
id().
path() <<
347 ": Number of entries on argument vector should be 5, was " <<
365 if ( val.size() != 5 ) {
366 cout <<
"Error: HHGate::setMinfinity on " << e.
id().
path() <<
367 ": Number of entries on argument vector should be 5, was " <<
387 unsigned int xdivs =
A_.size() - 1;
390 invDx_ =
static_cast< double >( xdivs ) / (
xmax_ - val );
408 unsigned int xdivs =
A_.size() - 1;
411 invDx_ =
static_cast< double >( xdivs ) / ( val -
xmin_ );
423 return A_.size() - 1;
435 A_.resize( val + 1 );
436 B_.resize( val + 1 );
450 if ( v.size() < 2 ) {
451 cout <<
"Warning: HHGate::setTableA: size must be >= 2 entries on "
458 unsigned int xdivs =
A_.size() - 1;
472 if (
A_.size() != v.size() ) {
473 cout <<
"Warning: HHGate::setTableB: size should be same as table A: " << v.size() <<
" != " <<
A_.size() <<
". Ignoring.\n";
492 vector< double > parms )
495 if ( parms.size() != 13 ) {
496 cout <<
"HHGate::setupAlpha: Error: parms.size() != 13\n";
501 beta_.resize( 5, 0 );
502 for (
unsigned int i = 0; i < 5; ++i )
504 for (
unsigned int i = 5; i < 10; ++i )
505 beta_[i - 5] = parms[i];
511 vector< double > ret =
alpha_;
512 ret.insert( ret.end(),
beta_.begin(),
beta_.end() );
513 ret.push_back(
A_.size() );
514 ret.push_back(
xmin_ );
515 ret.push_back(
xmax_ );
525 vector< double > parms )
528 if ( parms.size() != 13 ) {
529 cout <<
"HHGate::setupTau: Error: parms.size() != 13\n";
553 assert( parms.size() == 13 );
554 static const int XDIVS = 10;
555 static const int XMIN = 11;
556 static const int XMAX = 12;
557 if ( parms[XDIVS] < 1 )
return;
558 unsigned int xdivs =
static_cast< unsigned int >( parms[XDIVS] );
560 A_.resize( xdivs + 1 );
561 B_.resize( xdivs + 1 );
569 double prevAentry = 0.0;
570 double prevBentry = 0.0;
575 for( i = 0; i <= xdivs; i++ ) {
580 temp2 = parms[2] + exp( ( x + parms[3] ) / parms[4] );
582 temp2 = parms[2] + exp( ( x + dx/10.0 + parms[3] ) / parms[4] );
583 temp = ( parms[0] + parms[1] * (x + dx/10 ) ) / temp2;
585 temp2 = parms[2] + exp( ( x - dx/10.0 + parms[3] ) / parms[4] );
586 temp += ( parms[0] + parms[1] * (x - dx/10 ) ) / temp2;
593 temp = ( parms[0] + parms[1] * x) / temp2;
600 temp2 = parms[7] + exp( ( x + parms[8] ) / parms[9] );
602 temp2 = parms[7] + exp( ( x + dx/10.0 + parms[8] ) / parms[9] );
603 temp = (parms[5] + parms[6] * (x + dx/10) ) / temp2;
604 temp2 = parms[7] + exp( ( x - dx/10.0 + parms[8] ) / parms[9] );
605 temp += (parms[5] + parms[6] * (x - dx/10) ) / temp2;
610 B_[i] = (parms[5] + parms[6] * x ) / temp2;
629 for( i = 0; i <= xdivs; i++ ) {
636 A_[i] = temp2 / temp;
653 unsigned int size =
A_.size();
654 assert( size ==
B_.size() );
656 for ( i = 0; i < size; i++ ) {
657 double temp =
A_[ i ];
658 double temp2 =
B_[ i ];
665 A_[ i ] = temp2 / temp;
666 B_[ i ] = 1.0 / temp;
669 for ( i = 0; i < size; i++ )
675 vector< double > parms )
687 if ( parms.size() != 9 ) {
688 cout <<
"HHGate::setupGate: Error: parms.size() != 9\n";
697 int size =
static_cast< int > (parms[5] );
698 double min = parms[6];
699 double max = parms[7];
700 bool isBeta =
static_cast< bool >( parms[8] );
702 vector< double >& ip = ( isBeta ) ?
B_ :
A_;
705 size = ip.size() - 1;
707 cout <<
"Error: setupGate has zero size\n";
711 ip.resize( size + 1 );
714 double dx = ( max - min ) / static_cast< double >( size );
715 double x = min + dx / 2.0;
716 for (
int i = 0; i <= size; i++ ) {
720 double temp2 = C + exp( ( x + D ) / F );
724 ip[i] = ( A + B * x ) / temp2;
729 assert(
A_.size() > 0 );
731 if (
A_.size() !=
B_.size() ) {
732 if (
A_.size() >
B_.size() ) {
756 unsigned int newXdivs,
double newXmin,
double newXmax )
758 if ( newXdivs < 3 ) {
759 cout <<
"Error: tabFill: # divs must be >= 3. Not filling table.\n";
763 vector< double > old = table;
764 double newDx = ( newXmax - newXmin ) / newXdivs;
765 table.resize( newXdivs + 1 );
769 for(
unsigned int i = 0; i <= newXdivs; ++i ) {
770 table[i] =
lookupTable( table, newXmin + i * newDx );
781 cout <<
"Warning: HHGate: attempt to set field '" << field <<
"' on " <<
782 id.path() <<
"\nwhich is not the original Gate element. Ignored.\n";
818 vector< double > parms =
alpha_;
819 parms.insert( parms.end(),
beta_.begin(),
beta_.end() );
820 parms.push_back(
A_.size() );
821 parms.push_back(
xmin_ );
822 parms.push_back(
xmax_ );
vector< double > getTableB(const Eref &e) const
vector< double > beta_
5 parameters for beta
double getMin(const Eref &e) const
void setBeta(const Eref &e, vector< double > val)
std::string path(const std::string &separator="/") const
static const Cinfo * hhGateCinfo
void setTableA(const Eref &e, vector< double > v)
Id originalGateId() const
void setUseInterpolation(const Eref &e, bool val)
static const double SINGULARITY
vector< double > getAlpha(const Eref &e) const
double lookupA(double v) const
double lookupB(double v) const
vector< double > tau_
5 parameters for tau
void tabFill(vector< double > &table, unsigned int newXdivs, double newXmin, double newXmax)
void setTau(const Eref &e, vector< double > val)
void setupTau(const Eref &e, vector< double > parms)
vector< double > A_
The actual lookup table for calculations. Holds alpha(V).
vector< double > getTau(const Eref &e) const
vector< double > B_
The lookup table for calculations. Holds alpha(V) + beta(V).
vector< double > getBeta(const Eref &e) const
double lookupTable(const vector< double > &tab, double v) const
void lookupBoth(double v, double *A, double *B) const
unsigned int getDivs(const Eref &e) const
vector< double > getMinfinity(const Eref &e) const
vector< double > mInfinity_
5 parameters for mInfinity
static const Cinfo * initCinfo()
void setMax(const Eref &e, double val)
bool isOriginalGate(Id id) const
void tweakTables(bool doTau)
void setMin(const Eref &e, double val)
vector< double > getAlphaParms(const Eref &e) const
void setDivs(const Eref &e, unsigned int val)
void setupAlpha(const Eref &e, vector< double > parms)
vector< double > getTableA(const Eref &e) const
double xmax_
Max of the voltage (or conc) range.
void setupGate(const Eref &e, vector< double > parms)
bool checkOriginal(Id id, const string &field) const
void setTableB(const Eref &e, vector< double > v)
Id originalChannelId() const
bool getUseInterpolation(const Eref &e) const
void setAlpha(const Eref &e, vector< double > val)
bool lookupByInterpolation_
void setMinfinity(const Eref &e, vector< double > val)
static const Cinfo * initCinfo()
double xmin_
Minimum of the voltage (or conc) range.
double invDx_
increment of the range.
vector< double > alpha_
5 parameters for alpha
void setupTables(const vector< double > &parms, bool doTau)
double getMax(const Eref &e) const
bool isOriginalChannel(Id id) const