Skip to content

Commit e75853f

Browse files
authored
Merge pull request #28 from openworm/development
Jupyter notebook with HH example & updated docs
2 parents 6c9d4b5 + 95a2821 commit e75853f

24 files changed

Lines changed: 1490 additions & 1160 deletions

.github/workflows/non-omv.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Non OMV tests
22

33
on:
44
push:
5-
branches: [ master, development, experimental ]
5+
branches: [ master, development, experimental, test* ]
66
pull_request:
7-
branches: [ master, development, experimental ]
7+
branches: [ master, development, experimental, test* ]
88

99
jobs:
1010
build:
@@ -16,14 +16,14 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v2
19-
19+
2020
- name: Set up Python ${{ matrix.python-version }}
2121
uses: actions/setup-python@v2
2222
with:
2323
python-version: ${{ matrix.python-version }}
24-
24+
2525
- name: Test python HH
2626
run: |
2727
pip install scipy matplotlib
2828
cd Tutorial/Source
29-
python HodgkinHuxley.py
29+
python HodgkinHuxley.py

.github/workflows/omv-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Continuous build using OMV
33

44
on:
55
push:
6-
branches: [ master, development, experimental ]
6+
branches: [ master, development, experimental, test* ]
77
pull_request:
8-
branches: [ master, development, experimental ]
8+
branches: [ master, development, experimental, test* ]
99

1010
jobs:
1111
build:

.gitignore

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

Tutorial/Source/HodgkinHuxley.py

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,45 @@
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, 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()
18.9 KB
Loading

Tutorial/_media/figure_1.png

5.48 KB
Loading

0 commit comments

Comments
 (0)