66class HodgkinHuxley ():
77 """Full Hodgkin-Huxley Model implemented in Python"""
88
9- C_m = 1.0
10- """membrane capacitance, in uF/cm^2"""
11-
12- g_Na = 120.0
13- """Sodium (Na) maximum conductances, in mS/cm^2"""
14-
15- g_K = 36.0
16- """Postassium (K) maximum conductances, in mS/cm^2"""
17-
18- g_L = 0.3
19- """Leak maximum conductances, in mS/cm^2"""
20-
21- E_Na = 50.0
22- """Sodium (Na) Nernst reversal potentials, in mV"""
23-
24- E_K = - 77.0
25- """Postassium (K) Nernst reversal potentials, in mV"""
26-
27- E_L = - 54.387
28- """Leak Nernst reversal potentials, in mV"""
29-
30- t = np .arange (0.0 , 450.0 , 0.01 )
31- """ The time to integrate over """
9+ """ __init__ uses optional arguments """
10+ """ when no argument is passed default values are used """
11+
12+ def __init__ (self , C_m = 1 , g_Na = 120 , g_K = 36 , g_L = 0.3 , E_Na = 50 , E_K = - 77 , E_L = - 54.387 , t_0 = 0 , t_n = 450 , delta_t = 0.01 , I_inj_max = 0 , I_inj_width = 0 , I_inj_trans = 0 ):
13+
14+ self .C_m = C_m
15+ """ membrane capacitance, in uF/cm^2 """
16+
17+ self .g_Na = g_Na
18+ """ Sodium (Na) maximum conductances, in mS/cm^2 """
19+
20+ self .g_K = g_K
21+ """ Postassium (K) maximum conductances, in mS/cm^2 """
22+
23+ self .g_L = g_L
24+ """ Leak maximum conductances, in mS/cm^2 """
25+
26+ self .E_Na = E_Na
27+ """ Sodium (Na) Nernst reversal potentials, in mV """
28+
29+ self .E_K = E_K
30+ """ Postassium (K) Nernst reversal potentials, in mV """
31+
32+ self .E_L = E_L
33+ """ Leak Nernst reversal potentials, in mV """
34+
35+ self .t = np .arange (t_0 , t_n , delta_t )
36+ """ The time to integrate over """
37+
38+ """ Advanced input - injection current (single rectangular pulse only) """
39+
40+ self .I_inj_max = I_inj_max
41+ """ maximum value or amplitude of injection pulse """
42+
43+ self .I_inj_width = I_inj_width
44+ """ duration or width of injection pulse """
45+
46+ self .I_inj_trans = I_inj_trans
47+ """ strart time of injection pulse or tranlation about time axis """
3248
3349 def alpha_m (self , V ):
3450 """Channel gating kinetics. Functions of membrane voltage"""
@@ -98,7 +114,14 @@ def I_inj(self, t):
98114 | step up to 35 uA/cm^2 at t>300
99115 | step down to 0 uA/cm^2 at t>400
100116 """
101- return 10 * (t > 100 ) - 10 * (t > 200 ) + 35 * (t > 300 ) - 35 * (t > 400 )
117+
118+ """ running standalone python script """
119+ if __name__ == '__main__' :
120+ return 10 * (t > 100 ) - 10 * (t > 200 ) + 35 * (t > 300 ) - 35 * (t > 400 )
121+
122+ #""" running jupyterLab notebook """
123+ else :
124+ return self .I_inj_max * (t > self .I_inj_trans ) - self .I_inj_max * (t > self .I_inj_trans + self .I_inj_width )
102125
103126 @staticmethod
104127 def dALLdt (X , t , self ):
@@ -130,13 +153,22 @@ def Main(self):
130153 ina = self .I_Na (V , m , h )
131154 ik = self .I_K (V , n )
132155 il = self .I_L (V )
133-
134- plt .figure ()
135-
156+
157+ #increase figure and font size for display in jupyter notebook
158+ if __name__ != '__main__' :
159+ plt .rcParams ['figure.figsize' ] = [12 , 8 ]
160+ plt .rcParams ['font.size' ] = 15
161+ plt .rcParams ['legend.fontsize' ] = 12
162+ plt .rcParams ['legend.loc' ] = "upper right"
163+
164+ fig = plt .figure ()
165+
136166 ax1 = plt .subplot (4 ,1 ,1 )
167+ plt .xlim ([np .min (self .t ),np .max (self .t )]) #for all subplots
137168 plt .title ('Hodgkin-Huxley Neuron' )
138- plt .plot (self .t , V , 'k' )
139- plt .ylabel ('V (mV)' )
169+ i_inj_values = [self .I_inj (t ) for t in self .t ]
170+ plt .plot (self .t , i_inj_values , 'k' )
171+ plt .ylabel ('$I_{inj}$ ($\\ mu{A}/cm^2$)' )
140172
141173 plt .subplot (4 ,1 ,2 , sharex = ax1 )
142174 plt .plot (self .t , ina , 'c' , label = '$I_{Na}$' )
@@ -153,11 +185,10 @@ def Main(self):
153185 plt .legend ()
154186
155187 plt .subplot (4 ,1 ,4 , sharex = ax1 )
156- i_inj_values = [ self . I_inj ( t ) for t in self .t ]
157- plt .plot ( self . t , i_inj_values , 'k ' )
188+ plt . plot ( self .t , V , 'k' )
189+ plt .ylabel ( 'V (mV) ' )
158190 plt .xlabel ('t (ms)' )
159- plt .ylabel ('$I_{inj}$ ($\\ mu{A}/cm^2$)' )
160- plt .ylim (- 1 , 40 )
191+ #plt.ylim(-1, 40)
161192
162193 plt .tight_layout ()
163194 plt .show ()
0 commit comments