AnimatLab  2
Test
IonChannel.cpp
Go to the documentation of this file.
1 
7 #include "stdafx.h"
8 #include "IonChannel.h"
9 #include "SynapseType.h"
10 #include "Connexion.h"
11 #include "CaActivation.h"
12 #include "Neuron.h"
13 #include "ElectricalSynapse.h"
15 #include "SpikingChemicalSynapse.h"
16 #include "IntegrateFireModule.h"
17 #include "ClassFactory.h"
18 
19 
20 namespace IntegrateFireSim
21 {
22 
30 {
31  m_bEnabled = true;
32  m_fltGmax = 0;
33  m_fltG = 0;
34  m_fltMPower = 0;
35  m_fltHPower = 0;
37 
38  m_fltM = 0;
39  m_fltNm = 1;
40  m_lpMinf = NULL;
41  m_lpTm = NULL;
42 
43  m_fltH = 0;
44  m_fltNh = 1;
45  m_lpHinf = NULL;
46  m_lpTh = NULL;
47 
48  m_fltGInit = 0;
49  m_fltMInit = 0;
50  m_fltHInit = 0;
51 
52  m_fltTotalAct = 0;
53  m_fltI = 0;
54  m_fltMinf = 0;
55  m_fltHinf = 0;
56  m_fltTm = 0;
57  m_fltTh = 0;
58 }
59 
67 {
68 
69 try
70 {
71  if(m_lpMinf) delete m_lpMinf;
72  if(m_lpTm) delete m_lpTm;
73  if(m_lpHinf) delete m_lpHinf;
74  if(m_lpTh) delete m_lpTh;
75 }
76 catch(...)
77 {Std_TraceMsg(0, "Caught Error in desctructor of IonChannel\r\n", "", -1, false, true);}
78 }
79 
80 
81 #pragma region Accessor-Mutators
82 
91 void IonChannel::Enabled(bool bVal) {m_bEnabled = bVal;}
92 
102 
111 void IonChannel::Gmax(float fltVal) {m_fltGmax = fltVal;}
112 
121 float IonChannel::Gmax() {return m_fltGmax;}
122 
131 void IonChannel::Ginit(float fltVal)
132 {
133  //The mempot variables are calculated, so we do not want to just re-set them to the new value.
134  //instead lets adjust them by the difference between the old and new resting potential.
135  float fltDiff = fltVal - m_fltGInit;
136  m_fltG += fltDiff;
137  m_fltGInit = fltVal;
138 };
139 
148 float IonChannel::Ginit() {return m_fltGInit;}
149 
158 void IonChannel::Hinit(float fltVal)
159 {
160  //The mempot variables are calculated, so we do not want to just re-set them to the new value.
161  //instead lets adjust them by the difference between the old and new resting potential.
162  float fltDiff = fltVal - m_fltHInit;
163  m_fltH += fltDiff;
164  m_fltHInit = fltVal;
165 };
166 
175 float IonChannel::Hinit() {return m_fltHInit;}
176 
185 void IonChannel::Minit(float fltVal)
186 {
187  //The mempot variables are calculated, so we do not want to just re-set them to the new value.
188  //instead lets adjust them by the difference between the old and new resting potential.
189  float fltDiff = fltVal - m_fltMInit;
190  m_fltM += fltDiff;
191  m_fltMInit = fltVal;
192 };
193 
202 float IonChannel::Minit() {return m_fltMInit;}
203 
212 void IonChannel::MPower(float fltVal) {m_fltMPower = fltVal;}
213 
223 
232 void IonChannel::HPower(float fltVal) {m_fltHPower = fltVal;}
233 
243 
253 
263 
272 void IonChannel::Nm(float fltVal) {m_fltNm = fltVal;}
273 
282 float IonChannel::Nm() {return m_fltNm;}
283 
292 void IonChannel::Nh(float fltVal) {m_fltNh = fltVal;}
293 
302 float IonChannel::Nh() {return m_fltNh;}
303 
313 
323 {
324  if(m_lpMinf)
325  {
326  if(m_lpMinf)
327  {delete m_lpMinf; m_lpMinf = NULL;}
328  m_lpMinf = lpGain;
329  }
330 }
331 
340 void IonChannel::Minf(std::string strXml)
341 {
342  CStdXml oXml;
343  oXml.Deserialize(strXml);
344  oXml.FindElement("Root");
345  oXml.FindChildElement("Gain");
346  Minf(AnimatSim::Gains::LoadGain(m_lpSim, "Gain", oXml));
347 }
348 
349 
359 
369 {
370  if(m_lpTm)
371  {
372  if(m_lpTm)
373  {delete m_lpTm; m_lpTm = NULL;}
374  m_lpTm = lpGain;
375  }
376 }
377 
386 void IonChannel::Tm(std::string strXml)
387 {
388  CStdXml oXml;
389  oXml.Deserialize(strXml);
390  oXml.FindElement("Root");
391  oXml.FindChildElement("Gain");
392  Tm(AnimatSim::Gains::LoadGain(m_lpSim, "Gain", oXml));
393 }
394 
395 
405 
415 {
416  if(m_lpHinf)
417  {
418  if(m_lpHinf)
419  {delete m_lpHinf; m_lpHinf = NULL;}
420  m_lpHinf = lpGain;
421  }
422 }
423 
432 void IonChannel::Hinf(std::string strXml)
433 {
434  CStdXml oXml;
435  oXml.Deserialize(strXml);
436  oXml.FindElement("Root");
437  oXml.FindChildElement("Gain");
438  Hinf(AnimatSim::Gains::LoadGain(m_lpSim, "Gain", oXml));
439 }
440 
441 
451 
461 {
462  if(m_lpTh)
463  {
464  if(m_lpTh)
465  {delete m_lpTh; m_lpTh = NULL;}
466  m_lpTh = lpGain;
467  }
468 }
469 
478 void IonChannel::Th(std::string strXml)
479 {
480  CStdXml oXml;
481  oXml.Deserialize(strXml);
482  oXml.FindElement("Root");
483  oXml.FindChildElement("Gain");
484  Th(AnimatSim::Gains::LoadGain(m_lpSim, "Gain", oXml));
485 }
486 
487 #pragma endregion
488 
500 float IonChannel::CalculateCurrent(float fltStep, float fltVm)
501 {
502  if(m_bEnabled)
503  {
504  if(m_fltMPower > 0)
505  {
506  m_fltMinf = m_lpMinf->CalculateGain(fltVm);
507  m_fltTm = m_lpTm->CalculateGain(fltVm);
508  m_fltM = m_fltM + fltStep*((m_fltMinf- m_fltM)/(m_fltNm*m_fltTm));
509  }
510 
511  if(m_fltHPower > 0)
512  {
513  m_fltHinf = m_lpHinf->CalculateGain(fltVm);
514  m_fltTh = m_lpTh->CalculateGain(fltVm);
515  m_fltH = m_fltH + fltStep*((m_fltHinf- m_fltH)/(m_fltNh*m_fltTh));
516  }
517 
521  }
522  else
523  m_fltI = 0;
524 
525  return m_fltI;
526 }
527 
528 
530 {
531  m_fltMinf = 0;
532  m_fltTm = 0;
533  m_fltM = m_fltMInit;
534  m_fltHinf = 0;
535  m_fltTh = 0;
536  m_fltH = m_fltHInit;
537  m_fltI = 0;
538  m_fltTotalAct = 0;
539  m_fltG = 0;
540 }
541 
542 #pragma region DataAccesMethods
543 
544 float *IonChannel::GetDataPointer(const std::string &strDataType)
545 {
546  std::string strType = Std_CheckString(strDataType);
547 
548  if(strType == "G")
549  return &m_fltG;
550 
551  if(strType == "M")
552  return &m_fltM;
553 
554  if(strType == "H")
555  return &m_fltH;
556 
557  if(strType == "I")
558  return &m_fltI;
559 
560  if(strType == "ACT")
561  return &m_fltTotalAct;
562 
563  if(strType == "TM")
564  return &m_fltTm;
565 
566  if(strType == "TH")
567  return &m_fltTh;
568 
569  if(strType == "MINF")
570  return &m_fltMinf;
571 
572  if(strType == "HINF")
573  return &m_fltHinf;
574 
575  //If it was not one of those above then we have a problem.
576  THROW_PARAM_ERROR(Rn_Err_lInvalidNeuronDataType, Rn_Err_strInvalidNeuronDataType, "Ion Channel Data Type", strDataType);
577 
578  return NULL;
579 }
580 
581 bool IonChannel::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
582 {
583  std::string strType = Std_CheckString(strDataType);
584 
585  if(AnimatBase::SetData(strDataType, strValue, false))
586  return true;
587 
588  if(strType == "ENABLED")
589  {
590  Enabled(Std_ToBool(strValue));
591  return true;
592  }
593 
594  if(strType == "GMAX")
595  {
596  Gmax(atof(strValue.c_str()));
597  return true;
598  }
599 
600  if(strType == "GINIT")
601  {
602  Ginit(atof(strValue.c_str()));
603  return true;
604  }
605 
606  if(strType == "MINIT")
607  {
608  Minit(atof(strValue.c_str()));
609  return true;
610  }
611 
612  if(strType == "HINIT")
613  {
614  Hinit(atof(strValue.c_str()));
615  return true;
616  }
617 
618  if(strType == "MPOWER")
619  {
620  MPower(atof(strValue.c_str()));
621  return true;
622  }
623 
624  if(strType == "HPOWER")
625  {
626  HPower(atof(strValue.c_str()));
627  return true;
628  }
629 
630  if(strType == "EQUILIBRIUMPOTENTIAL")
631  {
632  EquilibriumPotential(atof(strValue.c_str()));
633  return true;
634  }
635 
636  if(strType == "NM")
637  {
638  Nm(atof(strValue.c_str()));
639  return true;
640  }
641 
642  if(strType == "NH")
643  {
644  Nh(atof(strValue.c_str()));
645  return true;
646  }
647 
648  if(strType == "MINF")
649  {
650  Minf(strValue);
651  return true;
652  }
653 
654  if(strType == "TM")
655  {
656  Tm(strValue);
657  return true;
658  }
659 
660  if(strType == "HINF")
661  {
662  Hinf(strValue);
663  return true;
664  }
665 
666  if(strType == "TH")
667  {
668  Th(strValue);
669  return true;
670  }
671 
672  //If it was not one of those above then we have a problem.
673  if(bThrowError)
674  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
675 
676  return false;
677 }
678 
679 void IonChannel::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
680 {
681  AnimatBase::QueryProperties(aryProperties);
682 
683  aryProperties.Add(new TypeProperty("G", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
684  aryProperties.Add(new TypeProperty("M", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
685  aryProperties.Add(new TypeProperty("H", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
686  aryProperties.Add(new TypeProperty("I", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
687  aryProperties.Add(new TypeProperty("Act", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
688  aryProperties.Add(new TypeProperty("Tm", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
689  aryProperties.Add(new TypeProperty("Th", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
690  aryProperties.Add(new TypeProperty("Tinf", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
691  aryProperties.Add(new TypeProperty("Hinf", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
692 
693  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
694  aryProperties.Add(new TypeProperty("Gmax", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
695  aryProperties.Add(new TypeProperty("Ginit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
696  aryProperties.Add(new TypeProperty("Minit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
697  aryProperties.Add(new TypeProperty("Hinit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
698  aryProperties.Add(new TypeProperty("MPower", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
699  aryProperties.Add(new TypeProperty("HPower", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
700  aryProperties.Add(new TypeProperty("EquilibriumPotential", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
701  aryProperties.Add(new TypeProperty("Nm", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
702  aryProperties.Add(new TypeProperty("Nh", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
703  aryProperties.Add(new TypeProperty("Minf", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
704  aryProperties.Add(new TypeProperty("Tm", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
705  aryProperties.Add(new TypeProperty("Hinf", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
706  aryProperties.Add(new TypeProperty("Th", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
707 }
708 
709 #pragma endregion
710 
711 
712 void IonChannel::Load(CStdXml &oXml)
713 {
714  AnimatBase::Load(oXml);
715 
716  oXml.IntoElem(); //Into IonChannel Element
717 
718  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
719 
720  Gmax(oXml.GetChildFloat("Gmax"));
721  MPower(oXml.GetChildFloat("MPower"));
722  HPower(oXml.GetChildFloat("HPower"));
723  EquilibriumPotential(oXml.GetChildFloat("EqPot"));
724 
725  Minit(oXml.GetChildFloat("Minit"));
726  Nm(oXml.GetChildFloat("Nm"));
727 
728  //Load Minf
729  oXml.IntoChildElement("Minf");
730  std::string strModuleName = oXml.GetChildString("ModuleName", "");
731  std::string strType = oXml.GetChildString("Type");
732  oXml.OutOfElem(); //OutOf Gain Element
733 
734  m_lpMinf = dynamic_cast<AnimatSim::Gains::Gain *>(m_lpSim->CreateObject(strModuleName, "Gain", strType));
735  if(!m_lpMinf)
736  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Gain");
737 
739  m_lpMinf->Load(oXml);
740 
741  //Load Tm
742  oXml.IntoChildElement("Tm");
743  strModuleName = oXml.GetChildString("ModuleName", "");
744  strType = oXml.GetChildString("Type");
745  oXml.OutOfElem(); //OutOf Gain Element
746 
747  m_lpTm = dynamic_cast<AnimatSim::Gains::Gain *>(m_lpSim->CreateObject(strModuleName, "Gain", strType));
748  if(!m_lpTm)
749  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Gain");
750 
752  m_lpTm->Load(oXml);
753 
754  Hinit(oXml.GetChildFloat("Hinit"));
755  Nh(oXml.GetChildFloat("Nh"));
756 
757  //Load Hinf
758  oXml.IntoChildElement("Hinf");
759  strModuleName = oXml.GetChildString("ModuleName", "");
760  strType = oXml.GetChildString("Type");
761  oXml.OutOfElem(); //OutOf Gain Element
762 
763  m_lpHinf = dynamic_cast<AnimatSim::Gains::Gain *>(m_lpSim->CreateObject(strModuleName, "Gain", strType));
764  if(!m_lpHinf)
765  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Gain");
766 
768  m_lpHinf->Load(oXml);
769 
770  //Load Th
771  oXml.IntoChildElement("Th");
772  strModuleName = oXml.GetChildString("ModuleName", "");
773  strType = oXml.GetChildString("Type");
774  oXml.OutOfElem(); //OutOf Gain Element
775 
776  m_lpTh = dynamic_cast<AnimatSim::Gains::Gain *>(m_lpSim->CreateObject(strModuleName, "Gain", strType));
777  if(!m_lpTh)
778  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Gain");
779 
781  m_lpTh->Load(oXml);
782 
783  oXml.OutOfElem(); //OutOf IonChannel Element
784 }
785 
786 
787 } //IntegrateFireSim
float m_fltGmax
The maximum conductance.
Definition: IonChannel.h:27
float m_fltGInit
The initial conductance.
Definition: IonChannel.h:18
float Ginit()
Sets initial conductance.
Definition: IonChannel.cpp:148
float m_fltM
The current activation level.
Definition: IonChannel.h:42
Declares the integrate fire module class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
float m_fltH
The current inactivation level.
Definition: IonChannel.h:54
AnimatSim::Behavior::NeuralModule * m_lpModule
The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NU...
Definition: AnimatBase.h:49
virtual bool Enabled()
Gets whether this channel is enabled.
Definition: IonChannel.cpp:101
AnimatSim::Gains::Gain * Hinf()
Gets the Hinf.
Definition: IonChannel.cpp:404
AnimatSim::Gains::Gain * m_lpTm
The Tm gain function.
Definition: IonChannel.h:51
Declares the connexion class.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
AnimatSim::Gains::Gain * Minf()
Gets the minf.
Definition: IonChannel.cpp:312
float m_fltEquilibriumPotential
The equilibrium potential.
Definition: IonChannel.h:39
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: IonChannel.cpp:529
The Gain base class.
Definition: Gain.h:35
AnimatSim::Gains::Gain * Th()
Gets the Th.
Definition: IonChannel.cpp:450
float m_fltMPower
The activation exponent in the equation.
Definition: IonChannel.h:33
float Minit()
Gets Minit.
Definition: IonChannel.cpp:202
AnimatSim::Gains::Gain * m_lpHinf
The Hinf gain function.
Definition: IonChannel.h:60
Declares the spiking chemical synapse class.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
IonChannel()
Default constructor.
Definition: IonChannel.cpp:29
float Hinit()
Gets Hinit.
Definition: IonChannel.cpp:175
AnimatSim::Gains::Gain * m_lpTh
The Th gain function.
Definition: IonChannel.h:63
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
Definition: Simulator.cpp:3440
float m_fltI
The current.
Definition: IonChannel.h:70
Declares the ca activation class.
float HPower()
Gets HPower.
Definition: IonChannel.cpp:242
float MPower()
Gets MPower.
Definition: IonChannel.cpp:222
float m_fltTm
The Tm value.
Definition: IonChannel.h:79
float m_fltMinf
The Minf value.
Definition: IonChannel.h:73
virtual ~IonChannel()
Destructor.
Definition: IonChannel.cpp:66
float m_fltHPower
The inactivation exponent in the equation.
Definition: IonChannel.h:36
bool Std_ToBool(int iVal)
Converts a value toa bool.
float m_fltMInit
The initial activation.
Definition: IonChannel.h:21
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
AnimatSim::Gains::Gain * Tm()
Gets the Tm.
Definition: IonChannel.cpp:358
Declares the synapse type class.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Definition: IonChannel.cpp:544
float Gmax()
Gets maximum conductance.
Definition: IonChannel.cpp:121
Declares the electrical synapse class.
AnimatSim::Gains::Gain * m_lpMinf
The Minf gain function.
Definition: IonChannel.h:48
float m_fltHinf
The Hinf value.
Definition: IonChannel.h:76
virtual float CalculateGain(float fltInput)=0
Calculates the gain.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
float m_fltHInit
The initial inactivation.
Definition: IonChannel.h:24
float m_fltG
The active conductance.
Definition: IonChannel.h:30
virtual float CalculateCurrent(float fltStep, float fltVm)
Calculates the current.
Definition: IonChannel.cpp:500
float EquilibriumPotential()
Gets the equilibrium potential.
Definition: IonChannel.cpp:262
float m_fltTh
The Th value.
Definition: IonChannel.h:82
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: IonChannel.cpp:581
float m_fltTotalAct
The total activation level.
Definition: IonChannel.h:67
Contains all of the classes to implement a basic integrate and fire neural model. ...
Gain * LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
Loads a gain object.
Definition: Gain.cpp:287
Declares the non spiking chemical synapse class.
Declares the neuron class.