Skip to content

Commit

Permalink
Merge pull request #28 from openworm/development
Browse files Browse the repository at this point in the history
Jupyter notebook with HH example & updated docs
  • Loading branch information
pgleeson authored Jul 26, 2022
2 parents 6c9d4b5 + 95a2821 commit e75853f
Show file tree
Hide file tree
Showing 24 changed files with 1,490 additions and 1,160 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/non-omv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Non OMV tests

on:
push:
branches: [ master, development, experimental ]
branches: [ master, development, experimental, test* ]
pull_request:
branches: [ master, development, experimental ]
branches: [ master, development, experimental, test* ]

jobs:
build:
Expand All @@ -16,14 +16,14 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Test python HH
run: |
pip install scipy matplotlib
cd Tutorial/Source
python HodgkinHuxley.py
python HodgkinHuxley.py
4 changes: 2 additions & 2 deletions .github/workflows/omv-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Continuous build using OMV

on:
push:
branches: [ master, development, experimental ]
branches: [ master, development, experimental, test* ]
pull_request:
branches: [ master, development, experimental ]
branches: [ master, development, experimental, test* ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Tutorial/Source/*json
/Tutorial/Source/*_brian.py
*code.gen.*
*_eden.py
**/.ipynb_checkpoints/
97 changes: 64 additions & 33 deletions Tutorial/Source/HodgkinHuxley.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,45 @@
class HodgkinHuxley():
"""Full Hodgkin-Huxley Model implemented in Python"""

C_m = 1.0
"""membrane capacitance, in uF/cm^2"""

g_Na = 120.0
"""Sodium (Na) maximum conductances, in mS/cm^2"""

g_K = 36.0
"""Postassium (K) maximum conductances, in mS/cm^2"""

g_L = 0.3
"""Leak maximum conductances, in mS/cm^2"""

E_Na = 50.0
"""Sodium (Na) Nernst reversal potentials, in mV"""

E_K = -77.0
"""Postassium (K) Nernst reversal potentials, in mV"""

E_L = -54.387
"""Leak Nernst reversal potentials, in mV"""

t = np.arange(0.0, 450.0, 0.01)
""" The time to integrate over """
""" __init__ uses optional arguments """
""" when no argument is passed default values are used """

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):

self.C_m = C_m
""" membrane capacitance, in uF/cm^2 """

self.g_Na = g_Na
""" Sodium (Na) maximum conductances, in mS/cm^2 """

self.g_K = g_K
""" Postassium (K) maximum conductances, in mS/cm^2 """

self.g_L = g_L
""" Leak maximum conductances, in mS/cm^2 """

self.E_Na = E_Na
""" Sodium (Na) Nernst reversal potentials, in mV """

self.E_K = E_K
""" Postassium (K) Nernst reversal potentials, in mV """

self.E_L = E_L
""" Leak Nernst reversal potentials, in mV """

self.t = np.arange(t_0, t_n, delta_t)
""" The time to integrate over """

""" Advanced input - injection current (single rectangular pulse only) """

self.I_inj_max = I_inj_max
""" maximum value or amplitude of injection pulse """

self.I_inj_width = I_inj_width
""" duration or width of injection pulse """

self.I_inj_trans = I_inj_trans
""" strart time of injection pulse or tranlation about time axis """

def alpha_m(self, V):
"""Channel gating kinetics. Functions of membrane voltage"""
Expand Down Expand Up @@ -98,7 +114,14 @@ def I_inj(self, t):
| step up to 35 uA/cm^2 at t>300
| step down to 0 uA/cm^2 at t>400
"""
return 10*(t>100) - 10*(t>200) + 35*(t>300) - 35*(t>400)

""" running standalone python script """
if __name__ == '__main__':
return 10*(t>100) - 10*(t>200) + 35*(t>300) - 35*(t>400)

#""" running jupyterLab notebook """
else:
return self.I_inj_max*(t>self.I_inj_trans) - self.I_inj_max*(t>self.I_inj_trans+self.I_inj_width)

@staticmethod
def dALLdt(X, t, self):
Expand Down Expand Up @@ -130,13 +153,22 @@ def Main(self):
ina = self.I_Na(V, m, h)
ik = self.I_K(V, n)
il = self.I_L(V)

plt.figure()


#increase figure and font size for display in jupyter notebook
if __name__ != '__main__':
plt.rcParams['figure.figsize'] = [12, 8]
plt.rcParams['font.size'] = 15
plt.rcParams['legend.fontsize'] = 12
plt.rcParams['legend.loc'] = "upper right"

fig=plt.figure()

ax1 = plt.subplot(4,1,1)
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
plt.title('Hodgkin-Huxley Neuron')
plt.plot(self.t, V, 'k')
plt.ylabel('V (mV)')
i_inj_values = [self.I_inj(t) for t in self.t]
plt.plot(self.t, i_inj_values, 'k')
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')

plt.subplot(4,1,2, sharex = ax1)
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
Expand All @@ -153,11 +185,10 @@ def Main(self):
plt.legend()

plt.subplot(4,1,4, sharex = ax1)
i_inj_values = [self.I_inj(t) for t in self.t]
plt.plot(self.t, i_inj_values, 'k')
plt.plot(self.t, V, 'k')
plt.ylabel('V (mV)')
plt.xlabel('t (ms)')
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
plt.ylim(-1, 40)
#plt.ylim(-1, 40)

plt.tight_layout()
plt.show()
Expand Down
Binary file added Tutorial/_media/equivalentCircuit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tutorial/_media/figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e75853f

Please sign in to comment.