Skip to content

Commit e65849b

Browse files
committed
Enable selecting to show driv force, m3h plot in notebook.
1 parent f806b44 commit e65849b

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +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, scaling_plot=True,
19-
cond_dens_plot=True, driving_force_plot=True,
18+
injected_current_plot=True, gating_plot=True, cond_scaling_plot=False,
19+
cond_dens_plot=True, driving_force_plot=False,
2020
current_plot=True, memb_pot_plot=True):
2121

2222
self.C_m = C_m
@@ -79,14 +79,14 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
7979
# plotting conditionals
8080
self.injected_current_plot = injected_current_plot
8181
self.gating_plot = gating_plot
82-
self.scaling_plot = scaling_plot
82+
self.cond_scaling_plot = cond_scaling_plot
8383
self.cond_dens_plot = cond_dens_plot
8484
self.driving_force_plot = driving_force_plot
8585
self.current_plot = current_plot
8686
self.memb_pot_plot = memb_pot_plot
8787

8888
self.num_plots = (int(self.injected_current_plot) +
89-
int(self.gating_plot)+ int(self.scaling_plot) +
89+
int(self.gating_plot)+ int(self.cond_scaling_plot) +
9090
int(self.cond_dens_plot) + int(self.driving_force_plot) +
9191
int(self.current_plot) + int(self.memb_pot_plot))
9292

@@ -321,7 +321,7 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
321321
plt.legend()
322322
self.plot_count += 1
323323

324-
if self.scaling_plot:
324+
if self.cond_scaling_plot:
325325
try:
326326
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
327327
except NameError:
@@ -364,8 +364,8 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
364364
ax_here.fill_between(self.t, dna, color='c', alpha=0.5)
365365
ax_here.fill_between(self.t, dk, color='y', alpha=0.5)
366366

367-
plt.plot(self.t, dna, 'c', label='$V - E_{Na}$', linewidth=0.8)
368-
plt.plot(self.t, dk, 'y', label='$V - E_{K}$', linewidth=0.8)
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)
369369
plt.plot(self.t, zero, 'k', linestyle='dashed', linewidth=0.5)
370370
plt.ylabel('Driving force (mV)')
371371
plt.legend()

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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,15 @@ def highlight_slider():
206206
button_row=ipywidgets.HBox([reset_button,showValue_togglebtn])
207207

208208
#plot selectors
209-
header_plotting = ipywidgets.HTMLMath(value=r"<b> Select plots</b>")
210-
injected_current_plot_value = ipywidgets.Checkbox(value=True, description="Current injection", disabled=False,)
211-
gating_plot_value = ipywidgets.Checkbox(value=True, description="Gating variables", disabled=False,)
212-
cond_dens_plot_value = ipywidgets.Checkbox(value=True, description="Conductance densities", disabled=False,)
213-
current_plot_value = ipywidgets.Checkbox(value=True, description="Current densities", disabled=False,)
214-
memb_pot_plot_value = ipywidgets.Checkbox(value=True, description="Membrane potential", disabled=False,)
215-
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])])
216218

217219
#layout vertically all the widgets defined above
218220
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues,plot_selection_row])
@@ -230,7 +232,7 @@ def launch_interactive_widget():
230232
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
231233
I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration,
232234
vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode,
233-
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):
234236

235237
highlight_slider()
236238
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L,
@@ -241,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,
241243
runMode,
242244
injected_current_plot=injected_current_plot,
243245
gating_plot=gating_plot,
246+
cond_scaling_plot=cond_scaling_plot,
244247
cond_dens_plot=cond_dens_plot,
248+
driving_force_plot=driving_force_plot,
245249
current_plot=current_plot,
246250
memb_pot_plot=memb_pot_plot)
247251
# init_values are the steady state values for v,m,h,n at zero current injection
@@ -257,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,
257261
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,
258262
'runMode':runMode_togglebtns, 'injected_current_plot': injected_current_plot_value,
259263
'gating_plot':gating_plot_value,
264+
'cond_scaling_plot':cond_scaling_value,
260265
'cond_dens_plot':cond_dens_plot_value,
266+
'driving_force_plot':driving_force_value,
261267
'current_plot':current_plot_value,
262268
'memb_pot_plot':memb_pot_plot_value})
263269

0 commit comments

Comments
 (0)