Hi!
I'm quite new to C++ and as it goes I have problem of which I think is quite trivial. However I'm completely stuck.
What I want to do is create a simulation of a Hodgkin & Huxley Neuron. For all non-biologitsts, this is a very old and classic model derived from empirical data.
It consists of 4 differential equations and 6 regular equations.
I've already searched for examples, and actually found some using nearly the same values but mine doesn't work. This is quite frustrating since I don't know where to look anymore. The given values are all correct, they were taken from a working model. The equations were all triple checked. So my guess is I'm making a stupid beginners mistake on which I can't quite put my finger....
Any help/suggestion would be greatly appreciated. If you need any further information just ask.
So what the model should do is, come to a resting potential around -65mV that is Vi should become -65. However I'm stuck at around -7.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
#include <math.h>
#include <fstream>
#include <iostream>
using namespace std;
//define functions --------------------------
double i_Na();
double i_K();
double i_L();
double val_n(double ni);
double val_m(double mi);
double val_h(double hi);
double val_V(double Vi);
//begin variables ------------------------------
//time
double ti,t0,tn;
//iteration
int i;
int n;
double s;
//potential
double V0,Vi;
//membrane permeability
double n0,ni;
double m0,mi;
double h0,hi;
//---permeability
double alpha_n;
double beta_n;
double alpha_m;
double beta_m;
double alpha_h;
double beta_h;
//------constants
double C;
double VNa;
double VK;
double VL;
double gNa;
double gK;
double gL;
int main(){
//begin initialising variables ----------------------
t0 = 0; //Intervall - START
tn = 400; //Intervall - STOP
n = 200000; //SAMPLES
i = 0; //Sample-count
s = (tn - t0) / n; //step range (increment)
//constants declaration
C = 1; //Capacity in uF*cm^-2
VNa = 50; //Sodium equilibrium potential in mV 50
VK = -77; //Potassium equilibrium potential in mV -77
VL = -54.387; //Leak potential in mV -54.387
gNa = 120; //Sodium conductance in mS * cm^-2
gK = 36; //Potassium conductance in mS * cm^-2
gL = 0.3; //Leakage 'conductance' in mS * cm^-2
//initialising starting variables
V0 = 0; //0
n0 = 0.31768; //0.31768
h0 = 0.59612; //0.59612
m0 = 0.052932; //0.052932
Vi = V0;
ni = n0;
mi = m0;
hi = h0;
//end initialising variables --------------------
ofstream daten;
daten.open ("werte.txt");
for (i; i <= n; i++)
{
ti = t0 + s * i;
//---data-log
daten << ti;
daten << "\t";
daten << Vi;
daten << "\n";
//mi ------------
mi = val_m(mi);
//ni ------------
ni = val_n(ni);
//hi ------------
hi = val_h(hi);
//constrain m,n,h ------------
if(mi <= 0.000001){
mi = 0.000001;
}
if(mi >= 1){
mi = 1;
}
if(ni <= 0.000001){
ni = 0.000001;
}
if(ni >= 1){
ni = 1;
}
if(hi <= 0.000001){
hi = 0.000001;
}
if(hi >= 1){
hi = 1;
}
//Membrane Potential --------------
Vi = val_V(Vi);
//--------------------------
}
daten.close();
cout << "done!";
return 0;
}
//begin formulae -----------------------
//individual currents ******************
//i_Na sodium current
double i_Na()
{
return (gNa * pow(mi,3) * hi * (Vi - VNa));
}
//i_K potassium current
double i_K()
{
return (gK * pow(ni,4) * (Vi - VK));
}
//i_L leakage current
double i_L()
{
return (gL * (Vi - VL));
}
//conductance activation and inhibition ****************************
//potassium channel activation factor
double val_n(double ni)
{
alpha_n = (0.01 * (Vi + 10)) / exp(((Vi +10) / 10) -1);
beta_n = 0.125 * exp(Vi / 80);
return (ni + s * (alpha_n * (1 - ni) - beta_n * ni));
}
//sodium channel activation factor
double val_m(double mi)
{
alpha_m = (0.1 * (Vi + 25)) / exp(((Vi + 25) / 10) -1);
beta_m = 4 * exp(Vi / 18);
return (mi + s * (alpha_m * (1 - mi) - beta_m * mi));
}
//sodium channel inhibition factor
double val_h(double hi)
{
alpha_h = 0.07 * exp(Vi / 20);
beta_h = 1 / (exp((Vi + 30) / 10) +1);
return (hi + s * (alpha_h * (1 - hi) - beta_h * hi));
}
//membrane potential **************************
double val_V(double Vi)
{
return (Vi + s * ((0 - (i_Na() + i_K() + i_L())) / C));
}
|
All the equations and values can be found here:
http://www.ebi.ac.uk/biomodels-main/BIOMD0000000020
I know it looks quite complicated, it might be easyiest to start looking at the values of m,n and h because they're the first three differential equations depending on Vi (Volt at step i), from there on Vi directly depends on m,n,h the rest is all constants.
cheers!
Horst
(and my eternal gratitude should someone be able to help me :-))