MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HHChannel.cpp
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-2007 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 #include "header.h"
11 #include "ElementValueFinfo.h"
12 #include "HHGate.h"
13 #include "ChanBase.h"
14 #include "ChanCommon.h"
15 #include "HHChannelBase.h"
16 #include "HHChannel.h"
17 #include "../shell/Shell.h"
18 
19 const double HHChannel::EPSILON = 1.0e-10;
20 const int HHChannel::INSTANT_X = 1;
21 const int HHChannel::INSTANT_Y = 2;
22 const int HHChannel::INSTANT_Z = 4;
23 
25 {
27  static string doc[] =
28  {
29  "Name", "HHChannel",
30  "Author", "Upinder S. Bhalla, 2007, NCBS",
31  "Description", "HHChannel: Hodgkin-Huxley type voltage-gated Ion channel. Something "
32  "like the old tabchannel from GENESIS, but also presents "
33  "a similar interface as hhchan from GENESIS. ",
34  };
35 
36  static Dinfo< HHChannel > dinfo;
37 
38  static Cinfo HHChannelCinfo(
39  "HHChannel",
41  0,
42  0,
43  &dinfo,
44  doc,
45  sizeof(doc)/sizeof(string)
46  );
47 
48  return &HHChannelCinfo;
49 }
50 
53 
54 
56 // Constructor
59  :
60  conc_( 0.0 ),
61  instant_( 0 ),
62  X_( 0.0 ), Y_( 0.0 ), Z_( 0.0 ),
63  xInited_( false ), yInited_( false ), zInited_( false ),
64  g_( 0.0 ),
65  xGate_( 0 ),
66  yGate_( 0 ),
67  zGate_( 0 ),
68  myId_()
69 {
70  ;
71 }
72 
74 {
75  // if ( xGate_ && reinterpret_cast< char* >( this ) ==
76  // ObjId( xGate_->originalChannelId(), 0 ).data() )
77  // delete xGate_;
78  // if ( yGate_ && reinterpret_cast< char* >( this ) ==
79  // ObjId( yGate_->originalChannelId(), 0 ).data() )
80  // delete yGate_;
81  // if ( zGate_ && reinterpret_cast< char* >( this ) ==
82  // ObjId( zGate_->originalChannelId(), 0 ).data() )
83  // delete zGate_;
84 }
85 
86 bool HHChannel::setGatePower( const Eref& e, double power,
87  double *assignee, const string& gateType )
88 {
89  if ( doubleEq( power, *assignee ) )
90  return false;
91 
92  if ( doubleEq( *assignee, 0.0 ) && power > 0 ) {
93  createGate( e, gateType );
94  } else if ( doubleEq( power, 0.0 ) ) {
95  // destroyGate( e, gateType );
96  }
97  *assignee = power;
98 
99  return true;
100 }
101 
108 void HHChannel::vSetXpower( const Eref& e, double power )
109 {
110  if ( setGatePower( e, power, &Xpower_, "X" ) )
111  takeXpower_ = selectPower( power );
112 }
113 
114 void HHChannel::vSetYpower( const Eref& e, double power )
115 {
116  if ( setGatePower( e, power, &Ypower_, "Y" ) )
117  takeYpower_ = selectPower( power );
118 }
119 
120 void HHChannel::vSetZpower( const Eref& e, double power )
121 {
122  if ( setGatePower( e, power, &Zpower_, "Z" ) ) {
123  takeZpower_ = selectPower( power );
124  useConcentration_ = 1; // Not sure about this.
125  }
126 }
127 
143 // Assuming that the elements are simple elements. Use Eref for
144 // general case
145 
146 bool HHChannel::checkOriginal( Id chanId ) const
147 {
148  bool isOriginal = 1;
149  if ( xGate_ ) {
150  isOriginal = xGate_->isOriginalChannel( chanId );
151  } else if ( yGate_ ) {
152  isOriginal = yGate_->isOriginalChannel( chanId );
153  } else if ( zGate_ ) {
154  isOriginal = zGate_->isOriginalChannel( chanId );
155  }
156  return isOriginal;
157 }
158 
159 void HHChannel::innerCreateGate( const string& gateName,
160  HHGate** gatePtr, Id chanId, Id gateId )
161 {
162  //Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() );
163  if ( *gatePtr ) {
164  cout << "Warning: HHChannel::createGate: '" << gateName <<
165  "' on Element '" << chanId.path() << "' already present\n";
166  return;
167  }
168  *gatePtr = new HHGate( chanId, gateId );
169 }
170 
172  string gateType )
173 {
174  if ( !checkOriginal( e.id() ) ) {
175  cout << "Warning: HHChannel::createGate: Not allowed from copied channel:\n" << e.id().path() << "\n";
176  return;
177  }
178 
179  if ( gateType == "X" )
180  innerCreateGate( "xGate", &xGate_, e.id(), Id(e.id().value() + 1) );
181  else if ( gateType == "Y" )
182  innerCreateGate( "yGate", &yGate_, e.id(), Id(e.id().value() + 2) );
183  else if ( gateType == "Z" )
184  innerCreateGate( "zGate", &zGate_, e.id(), Id(e.id().value() + 3) );
185  else
186  cout << "Warning: HHChannel::createGate: Unknown gate type '" <<
187  gateType << "'. Ignored\n";
188 }
189 
190 void HHChannel::innerDestroyGate( const string& gateName,
191  HHGate** gatePtr, Id chanId )
192 {
193  if ( *gatePtr == 0 ) {
194  cout << "Warning: HHChannel::destroyGate: '" << gateName <<
195  "' on Element '" << chanId.path() << "' not present\n";
196  return;
197  }
198  delete (*gatePtr);
199  *gatePtr = 0;
200 }
201 
203  string gateType )
204 {
205  if ( !checkOriginal( e.id() ) ) {
206  cout << "Warning: HHChannel::destroyGate: Not allowed from copied channel:\n" << e.id().path() << "\n";
207  return;
208  }
209 
210  if ( gateType == "X" )
211  innerDestroyGate( "xGate", &xGate_, e.id() );
212  else if ( gateType == "Y" )
213  innerDestroyGate( "yGate", &yGate_, e.id() );
214  else if ( gateType == "Z" )
215  innerDestroyGate( "zGate", &zGate_, e.id() );
216  else
217  cout << "Warning: HHChannel::destroyGate: Unknown gate type '" <<
218  gateType << "'. Ignored\n";
219 }
220 
222 // Field function definitions
224 
225 void HHChannel::vSetInstant( const Eref& e, int instant )
226 {
227  instant_ = instant;
228 }
229 
230 int HHChannel::vGetInstant( const Eref& e ) const
231 {
232  return instant_;
233 }
234 
235 void HHChannel::vSetX( const Eref& e, double X )
236 {
237  X_ = X;
238  xInited_ = true;
239 }
240 double HHChannel::vGetX( const Eref& e ) const
241 {
242  return X_;
243 }
244 
245 void HHChannel::vSetY( const Eref& e, double Y )
246 {
247  Y_ = Y;
248  yInited_ = true;
249 }
250 double HHChannel::vGetY( const Eref& e ) const
251 {
252  return Y_;
253 }
254 
255 void HHChannel::vSetZ( const Eref& e, double Z )
256 {
257  Z_ = Z;
258  zInited_ = true;
259 }
260 double HHChannel::vGetZ( const Eref& e ) const
261 {
262  return Z_;
263 }
264 
266 {
268 }
269 
271 // Dest function definitions
273 
278 double HHChannel::integrate( double state, double dt, double A, double B )
279 {
280  if ( B > EPSILON ) {
281  double x = exp( -B * dt );
282  return state * x + ( A / B ) * ( 1 - x );
283  }
284  return state + A * dt ;
285 }
286 
288 {
289  g_ += ChanCommon::vGetGbar( e );
290  double A = 0;
291  double B = 0;
292  if ( Xpower_ > 0 ) {
293  xGate_->lookupBoth( Vm_, &A, &B );
294  if ( instant_ & INSTANT_X )
295  X_ = A/B;
296  else
297  X_ = integrate( X_, info->dt, A, B );
298  g_ *= takeXpower_( X_, Xpower_ );
299  }
300 
301  if ( Ypower_ > 0 ) {
302  yGate_->lookupBoth( Vm_, &A, &B );
303  if ( instant_ & INSTANT_Y )
304  Y_ = A/B;
305  else
306  Y_ = integrate( Y_, info->dt, A, B );
307 
308  g_ *= takeYpower_( Y_, Ypower_ );
309  }
310 
311  if ( Zpower_ > 0 ) {
312  if ( useConcentration_ )
313  zGate_->lookupBoth( conc_, &A, &B );
314  else
315  zGate_->lookupBoth( Vm_, &A, &B );
316  if ( instant_ & INSTANT_Z )
317  Z_ = A/B;
318  else
319  Z_ = integrate( Z_, info->dt, A, B );
320 
321  g_ *= takeZpower_( Z_, Zpower_ );
322  }
323 
326  // Gk_ = g_;
327  // Ik_ = ( Ek_ - Vm_ ) * g_;
328 
329  // Send out the relevant channel messages.
330  ChanCommon::sendProcessMsgs( e, info );
331 
332  g_ = 0.0;
333 }
334 
340 {
341  g_ = ChanCommon::vGetGbar( er );
342  Element* e = er.element();
343 
344  double A = 0.0;
345  double B = 0.0;
346  if ( Xpower_ > 0 ) {
347  assert( xGate_ );
348  xGate_->lookupBoth( Vm_, &A, &B );
349  if ( B < EPSILON ) {
350  cout << "Warning: B_ value for " << e->getName() <<
351  " is ~0. Check X table\n";
352  return;
353  }
354  if (!xInited_)
355  X_ = A/B;
356  g_ *= takeXpower_( X_, Xpower_ );
357  }
358 
359  if ( Ypower_ > 0 ) {
360  assert( yGate_ );
361  yGate_->lookupBoth( Vm_, &A, &B );
362  if ( B < EPSILON ) {
363  cout << "Warning: B value for " << e->getName() <<
364  " is ~0. Check Y table\n";
365  return;
366  }
367  if (!yInited_)
368  Y_ = A/B;
369  g_ *= takeYpower_( Y_, Ypower_ );
370  }
371 
372  if ( Zpower_ > 0 ) {
373  assert( zGate_ );
374  if ( useConcentration_ )
375  zGate_->lookupBoth( conc_, &A, &B );
376  else
377  zGate_->lookupBoth( Vm_, &A, &B );
378  if ( B < EPSILON ) {
379  cout << "Warning: B value for " << e->getName() <<
380  " is ~0. Check Z table\n";
381  return;
382  }
383  if (!zInited_)
384  Z_ = A/B;
385  g_ *= takeZpower_( Z_, Zpower_ );
386  }
387 
390  // Gk_ = g_;
391  // Ik_ = ( Ek_ - Vm_ ) * g_;
392 
393  // Send out the relevant channel messages.
394  // Same for reinit as for process.
395  ChanCommon::sendReinitMsgs( er, info );
396 
397  g_ = 0.0;
398 }
399 
400 void HHChannel::vHandleConc( const Eref& e, double conc )
401 {
402  conc_ = conc;
403 }
404 
405 void HHChannel::vSetModulation( const Eref& e, double modulation )
406 {
407  if ( modulation > 0.0 )
408  HHChannelBase::modulation_ = modulation;
409 }
410 
411 double HHChannel::vGetModulation( const Eref& e ) const
412 {
414 }
415 
416 
418 // HHGate functions
420 
421 
422 HHGate* HHChannel::vGetXgate( unsigned int i ) const
423 {
424  return xGate_;
425 }
426 
427 HHGate* HHChannel::vGetYgate( unsigned int i ) const
428 {
429  return yGate_;
430 }
431 
432 HHGate* HHChannel::vGetZgate( unsigned int i ) const
433 {
434  return zGate_;
435 }
double vGetZ(const Eref &e) const
Definition: HHChannel.cpp:260
Id id() const
Definition: Eref.cpp:62
HHGate * zGate_
HHGate data structure for the yGate.
Definition: HHChannel.h:206
uint32_t value
Definition: moosemodule.h:42
Definition: HHGate.h:31
double modulation_
Value used to scale channel conductance up or down.
void vCreateGate(const Eref &e, string gateType)
Definition: HHChannel.cpp:171
static const int INSTANT_Y
Definition: HHChannel.h:212
double conc_
Conc_ is input variable for Ca-dependent channels.
Definition: HHChannel.h:173
double X_
Definition: HHChannel.h:183
void vReinit(const Eref &e, ProcPtr p)
Definition: HHChannel.cpp:339
bool zInited_
Definition: HHChannel.h:189
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
HHGate * vGetYgate(unsigned int i) const
Definition: HHChannel.cpp:427
unsigned int value() const
Definition: Id.cpp:197
void vSetModulation(const Eref &e, double modulation)
Definition: HHChannel.cpp:405
Definition: Dinfo.h:60
HHGate * vGetXgate(unsigned int i) const
Definition: HHChannel.cpp:422
bool checkOriginal(Id chanId) const
Returns true if channel is original, false if copy.
Definition: HHChannel.cpp:146
double Zpower_
Exponent for Z gate.
static PFDD selectPower(double power)
double Z_
State variable for Z gate.
Definition: HHChannel.h:187
Element * element() const
Definition: Eref.h:42
double(* takeXpower_)(double, double)
Definition: HHChannel.h:175
void updateIk()
Definition: ChanCommon.cpp:119
void destroyGate(const Eref &e, string gateType)
Definition: HHChannel.cpp:202
static const int INSTANT_Z
Definition: HHChannel.h:213
double g_
Definition: HHChannel.h:191
int instant_
bitmapped flag for X, Y, Z, to do equil calculation for gate
Definition: HHChannel.h:180
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
void lookupBoth(double v, double *A, double *B) const
Definition: HHGate.cpp:275
void vSetUseConcentration(const Eref &e, int value)
Definition: HHChannel.cpp:265
double(* takeZpower_)(double, double)
Definition: HHChannel.h:177
static const Cinfo * initCinfo()
Definition: HHChannel.cpp:24
double Vm_
Vm_ is input variable from compartment, used for most rates.
Definition: ChanCommon.h:80
static const double EPSILON
Definition: HHChannel.h:210
bool useConcentration_
Flag for use of conc for input to Z gate calculations.
static const Cinfo * initCinfo()
double Y_
State variable for Y gate.
Definition: HHChannel.h:185
void vSetXpower(const Eref &e, double Xpower)
Definition: HHChannel.cpp:108
double dt
Definition: ProcInfo.h:18
void vSetGk(const Eref &e, double Gk)
Definition: ChanCommon.cpp:68
void createGate(const Eref &e, string gateType)
int vGetInstant(const Eref &e) const
Definition: HHChannel.cpp:230
HHGate * yGate_
HHGate data structure for the yGate.
Definition: HHChannel.h:203
bool yInited_
Definition: HHChannel.h:189
Definition: Eref.h:26
void vSetX(const Eref &e, double X)
Definition: HHChannel.cpp:235
void vHandleConc(const Eref &e, double conc)
Definition: HHChannel.cpp:400
double vGetGbar(const Eref &e) const
Definition: ChanCommon.cpp:39
void vSetZ(const Eref &e, double Z)
Definition: HHChannel.cpp:255
double integrate(double state, double dt, double A, double B)
Internal variable used to calculate conductance.
Definition: HHChannel.cpp:278
void innerCreateGate(const string &gateName, HHGate **gatePtr, Id chanId, Id gateId)
Inner utility function for creating the gate.
Definition: HHChannel.cpp:159
HHGate * xGate_
Definition: HHChannel.h:200
double Ypower_
Exponent for Y gate.
void vSetY(const Eref &e, double Y)
Definition: HHChannel.cpp:245
void vSetInstant(const Eref &e, int Instant)
Definition: HHChannel.cpp:225
static const Cinfo * hhChannelCinfo
Definition: HHChannel.cpp:51
double vGetY(const Eref &e) const
Definition: HHChannel.cpp:250
void sendReinitMsgs(const Eref &e, const ProcPtr info)
Definition: ChanCommon.cpp:111
void innerDestroyGate(const string &gateName, HHGate **gatePtr, Id chanId)
Definition: HHChannel.cpp:190
Definition: Id.h:17
double(* takeYpower_)(double, double)
Definition: HHChannel.h:176
double vGetX(const Eref &e) const
Definition: HHChannel.cpp:240
bool xInited_
Definition: HHChannel.h:189
static const int INSTANT_X
Definition: HHChannel.h:211
void vSetZpower(const Eref &e, double Zpower)
Definition: HHChannel.cpp:120
void vSetYpower(const Eref &e, double Ypower)
Definition: HHChannel.cpp:114
void sendProcessMsgs(const Eref &e, const ProcPtr info)
Definition: ChanCommon.cpp:100
double vGetModulation(const Eref &e) const
Definition: HHChannel.cpp:411
const string & getName() const
Definition: Element.cpp:56
bool setGatePower(const Eref &e, double power, double *assignee, const string &gateType)
Definition: HHChannel.cpp:86
Definition: Cinfo.h:18
double Xpower_
Exponent for X gate.
HHGate * vGetZgate(unsigned int i) const
Definition: HHChannel.cpp:432
void vProcess(const Eref &e, ProcPtr p)
Definition: HHChannel.cpp:287
bool isOriginalChannel(Id id) const
Definition: HHGate.cpp:786