Skip to content

Commit c2c88b4

Browse files
authored
Merge pull request #65 from openworm/development
Option to show extra plots of driving force and m3h etc.
2 parents 1cc93f6 + e65849b commit c2c88b4

4 files changed

Lines changed: 84 additions & 28 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
1515
I_inj_amplitude=0, I_inj_duration=0, I_inj_delay=0,
1616
vc_delay=10, vc_duration=30, vc_condVoltage=-65,
1717
vc_testVoltage=10, vc_returnVoltage=-65, runMode='iclamp',
18-
injected_current_plot=True, gating_plot=True, cond_dens_plot=True,
18+
injected_current_plot=True, gating_plot=True, cond_scaling_plot=False,
19+
cond_dens_plot=True, driving_force_plot=False,
1920
current_plot=True, memb_pot_plot=True):
2021

2122
self.C_m = C_m
@@ -78,12 +79,15 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
7879
# plotting conditionals
7980
self.injected_current_plot = injected_current_plot
8081
self.gating_plot = gating_plot
82+
self.cond_scaling_plot = cond_scaling_plot
8183
self.cond_dens_plot = cond_dens_plot
84+
self.driving_force_plot = driving_force_plot
8285
self.current_plot = current_plot
8386
self.memb_pot_plot = memb_pot_plot
8487

8588
self.num_plots = (int(self.injected_current_plot) +
86-
int(self.gating_plot) + int(self.cond_dens_plot) +
89+
int(self.gating_plot)+ int(self.cond_scaling_plot) +
90+
int(self.cond_dens_plot) + int(self.driving_force_plot) +
8791
int(self.current_plot) + int(self.memb_pot_plot))
8892

8993
self.plot_count = 0
@@ -310,10 +314,24 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
310314
except NameError:
311315
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
312316
plt.title('Simulation of Hodgkin Huxley model neuron')
313-
plt.plot(self.t, m, 'r', label='m')
314-
plt.plot(self.t, h, 'g', label='h')
315-
plt.plot(self.t, n, 'b', label='n')
316-
plt.ylabel('Gating Variable')
317+
plt.plot(self.t, m, 'r', label='$m$')
318+
plt.plot(self.t, h, 'g', label='$h$')
319+
plt.plot(self.t, n, 'b', label='$n$')
320+
plt.ylabel('Gating variable')
321+
plt.legend()
322+
self.plot_count += 1
323+
324+
if self.cond_scaling_plot:
325+
try:
326+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
327+
except NameError:
328+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
329+
plt.title('Simulation of Hodgkin Huxley model neuron')
330+
scale_na = m*m*m*h
331+
scale_k = n*n*n*n
332+
plt.plot(self.t, scale_na, 'c', label='$m^{3}h$')
333+
plt.plot(self.t, scale_k, 'y', label='$n^{4}$')
334+
plt.ylabel('Cond scaling')
317335
plt.legend()
318336
self.plot_count += 1
319337

@@ -325,8 +343,34 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
325343
plt.title('Simulation of Hodgkin Huxley model neuron')
326344
plt.plot(self.t, gna, 'c', label='$g_{Na}$')
327345
plt.plot(self.t, gk, 'y', label='$g_{K}$')
328-
plt.ylabel('Cond. dens ($mS/cm^2$)')
346+
plt.ylabel('Cond dens ($mS/cm^2$)')
347+
plt.legend()
348+
self.plot_count += 1
349+
350+
351+
if self.driving_force_plot:
352+
try:
353+
ax_here = plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
354+
except NameError:
355+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
356+
plt.title('Simulation of Hodgkin Huxley model neuron')
357+
ax_here = ax1
358+
359+
dna = V - self.E_Na
360+
dk = V - self.E_K
361+
zero = [0 for v in V]
362+
363+
#plt.plot(self.t, dna, 'c', label='$V - E_{Na}$')
364+
ax_here.fill_between(self.t, dna, color='c', alpha=0.5)
365+
ax_here.fill_between(self.t, dk, color='y', alpha=0.5)
366+
367+
plt.plot(self.t, dna, 'c', label='$V_{m} - E_{Na}$', linewidth=0.8)
368+
plt.plot(self.t, dk, 'y', label='$V_{m} - E_{K}$', linewidth=0.8)
369+
plt.plot(self.t, zero, 'k', linestyle='dashed', linewidth=0.5)
370+
plt.ylabel('Driving force (mV)')
329371
plt.legend()
372+
#if not self.is_vclamp(): plt.ylim(-85,60)
373+
#plt.ylim(-1, 40)
330374
self.plot_count += 1
331375

332376
if self.current_plot:
@@ -338,7 +382,7 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
338382
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
339383
plt.plot(self.t, ik, 'y', label='$I_{K}$')
340384
plt.plot(self.t, il, 'm', label='$I_{L}$')
341-
plt.ylabel('Current ($\\mu{A}/cm^2$)')
385+
plt.ylabel('Curr dens ($\\mu{A}/cm^2$)')
342386
plt.legend()
343387
self.plot_count += 1
344388

@@ -350,7 +394,7 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
350394
plt.title('Simulation of Hodgkin Huxley model neuron')
351395
plt.plot(self.t, V, 'k')
352396
plt.ylabel('$V_{m}$ (mV)')
353-
plt.xlabel('t (ms)')
397+
plt.xlabel('Time (ms)')
354398
if not self.is_vclamp(): plt.ylim(-85,60)
355399
#plt.ylim(-1, 40)
356400
self.plot_count += 1

Tutorial/Source/hhcell.cell.nml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.githubusercontent.com/NeuroML/NeuroML2/master/Schemas/NeuroML2/NeuroML_v2beta3.xsd"
5+
xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.githubusercontent.com/NeuroML/NeuroML2/master/Schemas/NeuroML2/NeuroML_v2.2.xsd"
66
id="hhcell">
77

88
<include href="passiveChan.channel.nml"/> <!-- Include the channel definitions -->
99
<include href="naChan.channel.nml"/>
1010
<include href="kChan.channel.nml"/>
1111

1212
<cell id="hhcell">
13-
13+
1414
<notes>Conductance based cell model NeuroML2 format: standard Hodgkin Huxley model cell with Na, K and passive conductances</notes>
1515

1616
<morphology id="morphology">
@@ -28,7 +28,7 @@
2828
<biophysicalProperties id="bioPhys1">
2929

3030
<membraneProperties>
31-
31+
3232
<channelDensity id="leak" ionChannel="passiveChan" condDensity="0.3 mS_per_cm2" erev="-54.387mV" ion="non_specific"/>
3333
<channelDensity id="naChans" ionChannel="naChan" condDensity="120.0 mS_per_cm2" erev="50.0 mV" ion="na"/>
3434
<channelDensity id="kChans" ionChannel="kChan" condDensity="36 mS_per_cm2" erev="-77mV" ion="k"/>
@@ -49,4 +49,3 @@
4949

5050

5151
</neuroml>
52-

notebooks/Python_HH_version/Python_Notebook_HH.ipynb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{
3838
"data": {
3939
"application/vnd.jupyter.widget-view+json": {
40-
"model_id": "012cf4db99d64e63b2aba86949411ced",
40+
"model_id": "c131ca61e49a441e95dff9c74a0b29f9",
4141
"version_major": 2,
4242
"version_minor": 0
4343
},
@@ -51,7 +51,7 @@
5151
{
5252
"data": {
5353
"application/vnd.jupyter.widget-view+json": {
54-
"model_id": "76a0b6d59696460dbbf15f755c87eee9",
54+
"model_id": "3080e0df7a9645299d1e6f2f7992ef53",
5555
"version_major": 2,
5656
"version_minor": 0
5757
},
@@ -88,11 +88,15 @@
8888
"\n",
8989
"2) The second plot shows the **activation/inactivation variables** of the ion channels in the neuron: activation variable **m** and inactivation variable **h** for *Na*, and activation variable **n** for *K*. Activation variables increase as the cell becomes depolarised (**V<sub>m</sub>** increases) and the inactivation variable decreases. **m** responds to these changes quicker than **h** or **n**.\n",
9090
"\n",
91-
"3) The third plot shows the **conductance densities** for Sodium (**g<sub>Na</sub> = gmax<sub>Na</sub> m<sup>3</sup> h**) and Potassium (**g<sub>K</sub> = gmax<sub>K</sub> n<sup>4</sup>**). Note, the leak conductance density value, **g<sub>L</sub>** is not voltage dependent, and so does not vary with time. The maximum conductance densities for the 3 conductances can be changed or set to zero.\n",
91+
"3) The third (optional) plot shows the **conductance scaling factors** for Sodium (**m<sup>3</sup> * h**) and Potassium (**n<sup>4</sup>**). Note: these only ever have a value between 0 and 1. \n",
9292
"\n",
93-
"4) The fourth plot shows the influx (negative y-axis) and outflux (positive y-axis) of **ionic currents (I<sub>Na</sub> = g<sub>Na</sub> (V<sub>m</sub> - E<sub>Na</sub>), I<sub>K</sub> = g<sub>K</sub> (V<sub>m</sub> - E<sub>K</sub>) and I<sub>L</sub> = g<sub>L</sub> (V<sub>m</sub> - E<sub>L</sub>**) passing through each type of ion channel being modeled. The reversal potentials of each of these (**E<sub>X</sub>**) can be altered above. \n",
93+
"4) The fourth plot shows the **conductance densities** for Sodium (**g<sub>Na</sub> = gmax<sub>Na</sub> m<sup>3</sup> h**) and Potassium (**g<sub>K</sub> = gmax<sub>K</sub> n<sup>4</sup>**). Note, the leak conductance density value, **g<sub>L</sub>** is not voltage dependent, and so does not vary with time. The maximum conductance densities for the 3 conductances can be changed or set to zero.\n",
9494
"\n",
95-
"5) The bottom plot shows the **neural membrane potential activity, V<sub>m</sub>**. The spikes here are called \"action potentials\". This variable is governed by the expression: **dV<sub>m</sub>/dt = (I<sub>inj</sub> - I<sub>Na</sub> - I<sub>K</sub> - I<sub>L</sub>)/C<sub>m</sub>**\n",
95+
"5) The fifth (optional) plot shows the **driving force** for the Sodium (**V<sub>m</sub> - E<sub>Na</sub>**) and Potassium (**V<sub>m</sub> - E<sub>K</sub>**) currents. Note, the important value here is how different these are from the zero line, i.e. the magnitude of the force driving ions in or out of the cell. \n",
96+
"\n",
97+
"6) The sixth plot shows the influx (negative y-axis) and outflux (positive y-axis) of **ionic currents** (**I<sub>Na</sub> = g<sub>Na</sub> (V<sub>m</sub> - E<sub>Na</sub>), I<sub>K</sub> = g<sub>K</sub> (V<sub>m</sub> - E<sub>K</sub>)** and **I<sub>L</sub> = g<sub>L</sub> (V<sub>m</sub> - E<sub>L</sub>)**) passing through each type of ion channel being modeled. The reversal potentials of each of these (**E<sub>X</sub>**) can be altered above. \n",
98+
"\n",
99+
"7) The bottom plot shows the **neural membrane potential activity, V<sub>m</sub>**. The spikes here are called \"action potentials\". This variable is governed by the expression: **dV<sub>m</sub>/dt = (I<sub>inj</sub> - I<sub>Na</sub> - I<sub>K</sub> - I<sub>L</sub>)/C<sub>m</sub>**\n",
96100
"\n",
97101
"\n",
98102
"![hh](../../Tutorial/_media/equivalentCircuit.png)\n"
@@ -104,7 +108,9 @@
104108
"source": [
105109
"<font size=\"5\">Notes</font>\n",
106110
"\n",
107-
">**Note: Sign of channel current $I_{Na}$, $I_{K}$ and $I_{L}$ are opposite to NeuroML tutorial<br />**\n",
111+
">**Note 1: Python source of the HH model<br />** The source of the HH model in Python as used in this notebook can be found [here](https://github.com/openworm/hodgkin_huxley_tutorial/blob/master/Tutorial/Source/HodgkinHuxley.py).\n",
112+
"\n",
113+
">**Note 2: Sign of channel current $I_{Na}$, $I_{K}$ and $I_{L}$ are opposite to NeuroML tutorial<br />**\n",
108114
"The Python code is interested in the current coming through the channel (so positive if flowing \"out\" like K, negative if flowing \"in\", like Na), whereas for the NeuroML channels (more specifically the channel density element) is what's flowing into the cell (so positive for Na)."
109115
]
110116
},

notebooks/Python_HH_version/ui_widget.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def highlight_slider():
171171
#define toggle button for default values and connect to fucntion call
172172
showValue_togglebtn = ipywidgets.ToggleButton(value=False,description='Default Values',disabled=False,button_style='info',tooltip='Show/Hide default value below') # 'success', 'info', 'warning', 'danger' or ''
173173
showValue_togglebtn.observe(showDefault)
174-
defalultValues = ipywidgets.HTMLMath(value=r"\(C = 1.0\)<br>\(G_{Na} = 120, G_{K} = 36, G_{L} = 0.3\)<br>\(V_{Na} = 50, V_{K} = -77, G_{L} = -54.387\)")
174+
defalultValues = ipywidgets.HTMLMath(value=r"\(C = %s\)<br>\(G_{Na} = %s, G_{K} = %s, G_{L} = %s\)<br>\(E_{Na} = %s, E_{K} = %s, E_{L} = %s\)" % \
175+
(default_capacitance, default_cond_Na, default_cond_K, default_cond_L, default_E_Na, default_E_K, default_E_L))
175176
defalultValues.layout.display = 'none'
176177

177178
#define toggle buttons for iclamp/vclamp run mode
@@ -205,13 +206,15 @@ def highlight_slider():
205206
button_row=ipywidgets.HBox([reset_button,showValue_togglebtn])
206207

207208
#plot selectors
208-
header_plotting = ipywidgets.HTMLMath(value=r"<b> Select plots</b>")
209-
injected_current_plot_value = ipywidgets.Checkbox(value=True, description="Current injection", disabled=False,)
210-
gating_plot_value = ipywidgets.Checkbox(value=True, description="Gating variables", disabled=False,)
211-
cond_dens_plot_value = ipywidgets.Checkbox(value=True, description="Conductance densities", disabled=False,)
212-
current_plot_value = ipywidgets.Checkbox(value=True, description="Current densities", disabled=False,)
213-
memb_pot_plot_value = ipywidgets.Checkbox(value=True, description="Membrane potential", disabled=False,)
214-
plot_selection_row=ipywidgets.VBox([header_plotting, ipywidgets.HBox([injected_current_plot_value, gating_plot_value, cond_dens_plot_value]), ipywidgets.HBox([current_plot_value, memb_pot_plot_value])])
209+
header_plotting = ipywidgets.HTMLMath(value=r"<b> Select plots to show</b>")
210+
injected_current_plot_value = ipywidgets.Checkbox(value=True, description="1) Current injection", disabled=False,)
211+
gating_plot_value = ipywidgets.Checkbox(value=True, description="2) Gating variables", disabled=False,)
212+
cond_scaling_value = ipywidgets.Checkbox(value=False, description="3) Conductance scaling", disabled=False,)
213+
cond_dens_plot_value = ipywidgets.Checkbox(value=True, description="4) Conductance densities", disabled=False,)
214+
driving_force_value = ipywidgets.Checkbox(value=False, description="5) Driving force", disabled=False,)
215+
current_plot_value = ipywidgets.Checkbox(value=True, description="6) Current densities", disabled=False,)
216+
memb_pot_plot_value = ipywidgets.Checkbox(value=True, description="7) Membrane potential", disabled=False,)
217+
plot_selection_row=ipywidgets.VBox([header_plotting, ipywidgets.HBox([injected_current_plot_value, gating_plot_value, cond_scaling_value, cond_dens_plot_value]), ipywidgets.HBox([driving_force_value, current_plot_value, memb_pot_plot_value])])
215218

216219
#layout vertically all the widgets defined above
217220
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues,plot_selection_row])
@@ -229,7 +232,7 @@ def launch_interactive_widget():
229232
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
230233
I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration,
231234
vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode,
232-
injected_current_plot, gating_plot, cond_dens_plot, current_plot, memb_pot_plot):
235+
injected_current_plot, gating_plot, cond_scaling_plot, cond_dens_plot, driving_force_plot, current_plot, memb_pot_plot):
233236

234237
highlight_slider()
235238
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L,
@@ -240,7 +243,9 @@ def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
240243
runMode,
241244
injected_current_plot=injected_current_plot,
242245
gating_plot=gating_plot,
246+
cond_scaling_plot=cond_scaling_plot,
243247
cond_dens_plot=cond_dens_plot,
248+
driving_force_plot=driving_force_plot,
244249
current_plot=current_plot,
245250
memb_pot_plot=memb_pot_plot)
246251
# init_values are the steady state values for v,m,h,n at zero current injection
@@ -256,7 +261,9 @@ def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
256261
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,
257262
'runMode':runMode_togglebtns, 'injected_current_plot': injected_current_plot_value,
258263
'gating_plot':gating_plot_value,
264+
'cond_scaling_plot':cond_scaling_value,
259265
'cond_dens_plot':cond_dens_plot_value,
266+
'driving_force_plot':driving_force_value,
260267
'current_plot':current_plot_value,
261268
'memb_pot_plot':memb_pot_plot_value})
262269

0 commit comments

Comments
 (0)