Skip to content

Commit caffb17

Browse files
committed
notebook files cleanup and updating HodgkinHuxley.py in tutorial to use same scrpit for python and jupyter calls
1 parent e222ba4 commit caffb17

8 files changed

Lines changed: 133 additions & 276 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Tutorial/Source/*json
3535
/Tutorial/Source/*_brian.py
3636
*code.gen.*
3737
*_eden.py
38-
.ipynb_*
38+
/notebook/.ipynb_checkpoints

notebook/.ipynb_checkpoints/HodgkinHuxley-checkpoint.py renamed to Tutorial/Source/.ipynb_checkpoints/HodgkinHuxley-checkpoint.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,34 @@
66
class 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):
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 """
3237

3338
def alpha_m(self, V):
3439
"""Channel gating kinetics. Functions of membrane voltage"""
@@ -131,32 +136,34 @@ def Main(self):
131136
ik = self.I_K(V, n)
132137
il = self.I_L(V)
133138

134-
plt.figure()
135-
139+
plt.figure(figsize=[15,10])
140+
136141
ax1 = plt.subplot(4,1,1)
137-
plt.title('Hodgkin-Huxley Neuron')
142+
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
143+
plt.title('Hodgkin-Huxley Neuron', fontsize = 20)
138144
plt.plot(self.t, V, 'k')
139-
plt.ylabel('V (mV)')
145+
plt.ylabel('V (mV)', fontsize = 15)
146+
140147

141148
plt.subplot(4,1,2, sharex = ax1)
142149
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
143150
plt.plot(self.t, ik, 'y', label='$I_{K}$')
144151
plt.plot(self.t, il, 'm', label='$I_{L}$')
145-
plt.ylabel('Current')
146-
plt.legend()
152+
plt.ylabel('Current', fontsize = 15)
153+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
147154

148155
plt.subplot(4,1,3, sharex = ax1)
149156
plt.plot(self.t, m, 'r', label='m')
150157
plt.plot(self.t, h, 'g', label='h')
151158
plt.plot(self.t, n, 'b', label='n')
152-
plt.ylabel('Gating Value')
153-
plt.legend()
159+
plt.ylabel('Gating Value', fontsize = 15)
160+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
154161

155162
plt.subplot(4,1,4, sharex = ax1)
156163
i_inj_values = [self.I_inj(t) for t in self.t]
157164
plt.plot(self.t, i_inj_values, 'k')
158-
plt.xlabel('t (ms)')
159-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
165+
plt.xlabel('t (ms)', fontsize = 15)
166+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)', fontsize = 15)
160167
plt.ylim(-1, 40)
161168

162169
plt.tight_layout()

Tutorial/Source/HodgkinHuxley.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,34 @@
66
class 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):
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 """
3237

3338
def alpha_m(self, V):
3439
"""Channel gating kinetics. Functions of membrane voltage"""
@@ -131,32 +136,34 @@ def Main(self):
131136
ik = self.I_K(V, n)
132137
il = self.I_L(V)
133138

134-
plt.figure()
135-
139+
plt.figure(figsize=[15,10])
140+
136141
ax1 = plt.subplot(4,1,1)
137-
plt.title('Hodgkin-Huxley Neuron')
142+
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
143+
plt.title('Hodgkin-Huxley Neuron', fontsize = 20)
138144
plt.plot(self.t, V, 'k')
139-
plt.ylabel('V (mV)')
145+
plt.ylabel('V (mV)', fontsize = 15)
146+
140147

141148
plt.subplot(4,1,2, sharex = ax1)
142149
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
143150
plt.plot(self.t, ik, 'y', label='$I_{K}$')
144151
plt.plot(self.t, il, 'm', label='$I_{L}$')
145-
plt.ylabel('Current')
146-
plt.legend()
152+
plt.ylabel('Current', fontsize = 15)
153+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
147154

148155
plt.subplot(4,1,3, sharex = ax1)
149156
plt.plot(self.t, m, 'r', label='m')
150157
plt.plot(self.t, h, 'g', label='h')
151158
plt.plot(self.t, n, 'b', label='n')
152-
plt.ylabel('Gating Value')
153-
plt.legend()
159+
plt.ylabel('Gating Value', fontsize = 15)
160+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
154161

155162
plt.subplot(4,1,4, sharex = ax1)
156163
i_inj_values = [self.I_inj(t) for t in self.t]
157164
plt.plot(self.t, i_inj_values, 'k')
158-
plt.xlabel('t (ms)')
159-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
165+
plt.xlabel('t (ms)', fontsize = 15)
166+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)', fontsize = 15)
160167
plt.ylim(-1, 40)
161168

162169
plt.tight_layout()

notebook/.ipynb_checkpoints/HHmodel-checkpoint.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
import pylab as plt
44
from scipy.integrate import odeint
55

6-
class HodgkinHuxley:
7-
def __init__(self, C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t):
6+
class HodgkinHuxley():
7+
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):
88
self.C_m = C_m
99
self.g_Na = g_Na
1010
self.g_K = g_K
1111
self.g_L = g_L
1212
self.E_Na = E_Na
1313
self.E_K = E_K
1414
self.E_L = E_L
15-
self.t = t
16-
#self.tn = tn
17-
#self.delta_t = delta_t
18-
#t = np.arange(t0, tn, delta_t)
19-
#print(t)
20-
15+
self.t = np.arange(t_0, t_n, delta_t)
16+
2117
def alpha_m(self, V):
2218
"""Channel gating kinetics. Functions of membrane voltage"""
2319
return 0.1*(V+40.0)/(1.0 - np.exp(-(V+40.0) / 10.0))

notebook/.ipynb_checkpoints/notebook-checkpoint.ipynb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 1,
44+
"execution_count": 11,
4545
"metadata": {},
4646
"outputs": [
4747
{
4848
"data": {
4949
"application/vnd.jupyter.widget-view+json": {
50-
"model_id": "ad6a061177c04f0699acea9767f2345b",
50+
"model_id": "544d4e30f0e54eeda92d4fb7a3c53d7a",
5151
"version_major": 2,
5252
"version_minor": 0
5353
},
@@ -61,7 +61,7 @@
6161
{
6262
"data": {
6363
"application/vnd.jupyter.widget-view+json": {
64-
"model_id": "4932cb960e094cc18913bbf2f918930f",
64+
"model_id": "0261eb17cf364d8998d2f37d974812a3",
6565
"version_major": 2,
6666
"version_minor": 0
6767
},
@@ -74,14 +74,16 @@
7474
}
7575
],
7676
"source": [
77-
"import ui_widget\n",
78-
"import HHmodel\n",
7977
"import ipywidgets\n",
80-
"import numpy as np\n",
78+
"import ui_widget\n",
79+
"from importlib.machinery import SourceFileLoader\n",
80+
" \n",
81+
"# imports the module from the given path\n",
82+
"HHmodel = SourceFileLoader(\"HodgkinHuxley.py\",\"../Tutorial/Source/HodgkinHuxley.py\").load_module()\n",
8183
"\n",
8284
"def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t):\n",
83-
" t = np.arange(t_0, t_n, delta_t)\n",
84-
" runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t)\n",
85+
" #t = np.arange(t_0, t_n, delta_t)\n",
86+
" runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t)\n",
8587
" runner.Main()\n",
8688
" \n",
8789
"w1=ipywidgets.interactive_output(runHH,{'C_m':ui_widget.slider_capacitance,\n",
@@ -114,23 +116,23 @@
114116
"cell_type": "markdown",
115117
"metadata": {},
116118
"source": [
117-
"<font size=\"5\">Advanced Inputs</font>"
119+
"<font size=\"5\">Advanced Inputs - Injection Current</font>"
118120
]
119121
},
120122
{
121123
"cell_type": "code",
122-
"execution_count": 4,
124+
"execution_count": 2,
123125
"metadata": {},
124126
"outputs": [
125127
{
126128
"data": {
127129
"application/vnd.jupyter.widget-view+json": {
128-
"model_id": "ac8ae0e37ce54981916660fa626b1991",
130+
"model_id": "f9ab28397cb244dbab2085294792dc4b",
129131
"version_major": 2,
130132
"version_minor": 0
131133
},
132134
"text/plain": [
133-
"interactive(children=(IntSlider(value=10, description='amplidute'), IntSlider(value=100, description='t_width'"
135+
"interactive(children=(IntSlider(value=10, description='amplidute', min=-100), IntSlider(value=100, description…"
134136
]
135137
},
136138
"metadata": {},
@@ -154,10 +156,17 @@
154156
" sympy.plot(I_inj, (t, 0, 450, 0.01))\n",
155157
" \n",
156158
"w=interact(injectorCurrent,\n",
157-
" amplidute=(0,100),\n",
159+
" amplidute=(-100,100),\n",
158160
" t_width=(0,100),\n",
159161
" t_translation=(0,450));"
160162
]
163+
},
164+
{
165+
"cell_type": "code",
166+
"execution_count": null,
167+
"metadata": {},
168+
"outputs": [],
169+
"source": []
161170
}
162171
],
163172
"metadata": {

notebook/HHmodel.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
import pylab as plt
44
from scipy.integrate import odeint
55

6-
class HodgkinHuxley:
7-
def __init__(self, C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t):
6+
class HodgkinHuxley():
7+
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):
88
self.C_m = C_m
99
self.g_Na = g_Na
1010
self.g_K = g_K
1111
self.g_L = g_L
1212
self.E_Na = E_Na
1313
self.E_K = E_K
1414
self.E_L = E_L
15-
self.t = t
16-
#self.tn = tn
17-
#self.delta_t = delta_t
18-
#t = np.arange(t0, tn, delta_t)
19-
#print(t)
20-
15+
self.t = np.arange(t_0, t_n, delta_t)
16+
2117
def alpha_m(self, V):
2218
"""Channel gating kinetics. Functions of membrane voltage"""
2319
return 0.1*(V+40.0)/(1.0 - np.exp(-(V+40.0) / 10.0))

0 commit comments

Comments
 (0)