Skip to content

Commit fc235ff

Browse files
authored
Merge pull request #62 from openworm/experimental
Select plots
2 parents cbf7f16 + c9908bf commit fc235ff

3 files changed

Lines changed: 123 additions & 56 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 84 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
1414
E_K=-77, E_L=-54.387, t_0=0, t_n=450, delta_t=0.01,
1515
I_inj_amplitude=0, I_inj_duration=0, I_inj_delay=0,
1616
vc_delay=10, vc_duration=30, vc_condVoltage=-65,
17-
vc_testVoltage=10, vc_returnVoltage=-65, runMode='iclamp'):
17+
vc_testVoltage=10, vc_returnVoltage=-65, runMode='iclamp',
18+
injected_current_plot=True, gating_plot=True, cond_dens_plot=True,
19+
current_plot=True, memb_pot_plot=True):
1820

1921
self.C_m = C_m
2022
""" membrane capacitance, in uF/cm^2 """
@@ -73,6 +75,19 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
7375
self.simpleSeriesResistance = 1e7
7476
"""Current will be calculated by the difference in voltage between the target and parent, divided by this value, in mOhm"""
7577

78+
# plotting conditionals
79+
self.injected_current_plot = injected_current_plot
80+
self.gating_plot = gating_plot
81+
self.cond_dens_plot = cond_dens_plot
82+
self.current_plot = current_plot
83+
self.memb_pot_plot = memb_pot_plot
84+
85+
self.num_plots = (int(self.injected_current_plot) +
86+
int(self.gating_plot) + int(self.cond_dens_plot) +
87+
int(self.current_plot) + int(self.memb_pot_plot))
88+
89+
self.plot_count = 0
90+
7691
def alpha_m(self, V):
7792
"""Channel gating kinetics. Functions of membrane voltage"""
7893
return 0.1*(V+40.0)/(1.0 - np.exp(-(V+40.0) / 10.0))
@@ -268,53 +283,79 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
268283
plt.rcParams['figure.figsize'] = [10, 7]
269284

270285
plt.close()
271-
fig=plt.figure()
272-
fig.canvas.header_visible = False
273286

274-
ax1 = plt.subplot(5,1,1)
287+
fig=plt.figure(figsize=(7, self.num_plots * 2))
288+
fig.canvas.header_visible = False
275289
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
276-
plt.title('Simulation of Hodgkin Huxley model neuron')
277290

278-
if self.is_vclamp():
279-
i_inj_values = [self.I_inj_vclamp(t,v) for t,v in zip(self.t,V)]
280-
else:
281-
i_inj_values = [self.I_inj(t) for t in self.t]
282-
283-
plt.plot(self.t, i_inj_values, 'k')
284-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
285-
if self.is_vclamp(): plt.ylim(-2000,3000)
286-
287-
288-
plt.subplot(5,1,2, sharex = ax1)
289-
plt.plot(self.t, m, 'r', label='m')
290-
plt.plot(self.t, h, 'g', label='h')
291-
plt.plot(self.t, n, 'b', label='n')
292-
plt.ylabel('Gating Variable')
293-
plt.legend()
294-
295-
plt.subplot(5,1,3, sharex = ax1)
296-
plt.plot(self.t, gna, 'c', label='$g_{Na}$')
297-
plt.plot(self.t, gk, 'y', label='$g_{K}$')
298-
plt.ylabel('Cond. dens')
299-
plt.legend()
300-
301-
plt.subplot(5,1,4, sharex = ax1)
302-
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
303-
plt.plot(self.t, ik, 'y', label='$I_{K}$')
304-
plt.plot(self.t, il, 'm', label='$I_{L}$')
305-
plt.ylabel('Current')
306-
plt.legend()
307-
308-
plt.subplot(5,1,5, sharex = ax1)
309-
plt.plot(self.t, V, 'k')
310-
plt.ylabel('V (mV)')
311-
plt.xlabel('t (ms)')
312-
if not self.is_vclamp(): plt.ylim(-85,60)
313-
#plt.ylim(-1, 40)
291+
if self.injected_current_plot:
292+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
293+
plt.title('Simulation of Hodgkin Huxley model neuron')
294+
if self.is_vclamp():
295+
i_inj_values = [self.I_inj_vclamp(t,v) for t,v in zip(self.t,V)]
296+
else:
297+
i_inj_values = [self.I_inj(t) for t in self.t]
298+
299+
if self.is_vclamp(): plt.ylim(-2000,3000)
300+
301+
plt.plot(self.t, i_inj_values, 'k')
302+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
303+
304+
self.plot_count += 1
305+
306+
307+
if self.gating_plot:
308+
try:
309+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
310+
except NameError:
311+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
312+
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.legend()
318+
self.plot_count += 1
319+
320+
if self.cond_dens_plot:
321+
try:
322+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
323+
except NameError:
324+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
325+
plt.title('Simulation of Hodgkin Huxley model neuron')
326+
plt.plot(self.t, gna, 'c', label='$g_{Na}$')
327+
plt.plot(self.t, gk, 'y', label='$g_{K}$')
328+
plt.ylabel('Cond. dens ($mS/cm^2$)')
329+
plt.legend()
330+
self.plot_count += 1
331+
332+
if self.current_plot:
333+
try:
334+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
335+
except NameError:
336+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
337+
plt.title('Simulation of Hodgkin Huxley model neuron')
338+
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
339+
plt.plot(self.t, ik, 'y', label='$I_{K}$')
340+
plt.plot(self.t, il, 'm', label='$I_{L}$')
341+
plt.ylabel('Current ($\\mu{A}/cm^2$)')
342+
plt.legend()
343+
self.plot_count += 1
344+
345+
if self.memb_pot_plot:
346+
try:
347+
plt.subplot(self.num_plots,1,self.plot_count+1, sharex = ax1)
348+
except NameError:
349+
ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1)
350+
plt.title('Simulation of Hodgkin Huxley model neuron')
351+
plt.plot(self.t, V, 'k')
352+
plt.ylabel('$V_{m}$ (mV)')
353+
plt.xlabel('t (ms)')
354+
if not self.is_vclamp(): plt.ylim(-85,60)
355+
#plt.ylim(-1, 40)
356+
self.plot_count += 1
314357

315358
plt.tight_layout()
316-
317-
318359
plt.show()
319360

320361
if __name__ == '__main__':

notebooks/Python_HH_version/Python_Notebook_HH.ipynb

Lines changed: 4 additions & 4 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": "3785f140f0394fd186765d0525cd0f1a",
40+
"model_id": "012cf4db99d64e63b2aba86949411ced",
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": "c5fc97be4b7f421fa15c5c60c6cb6b66",
54+
"model_id": "76a0b6d59696460dbbf15f755c87eee9",
5555
"version_major": 2,
5656
"version_minor": 0
5757
},
@@ -90,7 +90,7 @@
9090
"\n",
9191
"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",
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> = gmax<sub>Na</sub> (V<sub>m</sub> - E<sub>Na</sub>), I<sub>K</sub> = gmax<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 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",
9494
"\n",
9595
"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",
9696
"\n",
@@ -118,7 +118,7 @@
118118
],
119119
"metadata": {
120120
"kernelspec": {
121-
"display_name": "Python 3 (ipykernel)",
121+
"display_name": "Python 3",
122122
"language": "python",
123123
"name": "python3"
124124
},

notebooks/Python_HH_version/ui_widget.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,17 @@ def highlight_slider():
204204
#reset and defalult value buttons in single row
205205
button_row=ipywidgets.HBox([reset_button,showValue_togglebtn])
206206

207+
#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])])
215+
207216
#layout vertically all the widgets defined above
208-
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues])
217+
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues,plot_selection_row])
209218

210219
# Main method to create interactive widget
211220
def launch_interactive_widget():
@@ -217,22 +226,39 @@ def launch_interactive_widget():
217226
HHmodel = SourceFileLoader("HodgkinHuxley.py","../../Tutorial/Source/HodgkinHuxley.py").load_module()
218227

219228
#function to call python script as a module
220-
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t, I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration, vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode):
229+
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
230+
I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration,
231+
vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode,
232+
injected_current_plot, gating_plot, cond_dens_plot, current_plot, memb_pot_plot):
221233

222234
highlight_slider()
223-
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t, I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration, vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode)
235+
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L,
236+
t_0, t_n, delta_t, I_inj_max,
237+
I_inj_width, I_inj_trans, vc_delay,
238+
vc_duration, vc_condVoltage,
239+
vc_testVoltage, vc_returnVoltage,
240+
runMode,
241+
injected_current_plot=injected_current_plot,
242+
gating_plot=gating_plot,
243+
cond_dens_plot=cond_dens_plot,
244+
current_plot=current_plot,
245+
memb_pot_plot=memb_pot_plot)
224246
# init_values are the steady state values for v,m,h,n at zero current injection
225247
runner.Main(init_values=[-63.8, 0.0609, 0.5538, 0.3361])
226248

227249
#create plot area widget and interact with HHmodel
228250
wid_plotArea=ipywidgets.interactive_output(runHH,{'C_m':slider_capacitance,
229-
'g_Na':slider_cond_Na, 'g_K':slider_cond_K, 'g_L':slider_cond_L,
230-
'E_Na':slider_E_Na, 'E_K':slider_E_K, 'E_L':slider_E_L,
251+
'g_Na':textBox_cond_Na, 'g_K':textBox_cond_K, 'g_L':textBox_cond_L,
252+
'E_Na':textBox_E_Na, 'E_K':textBox_E_K, 'E_L':textBox_E_L,
231253
't_0':time_start, 't_n':time_end, 'delta_t':time_step,
232-
'I_inj_max':slider_amplitude,'I_inj_width':slider_width,'I_inj_trans':slider_translation,
233-
'vc_delay':slider_delay,'vc_duration':slider_duration,'vc_condVoltage':slider_condVoltage,
234-
'vc_testVoltage':slider_testVoltage,'vc_returnVoltage':slider_returnVoltage,
235-
'runMode':runMode_togglebtns})
254+
'I_inj_max':textBox_amplitude,'I_inj_width':textBox_width,'I_inj_trans':textBox_translation,
255+
'vc_delay':textBox_delay,'vc_duration':textBox_duration,'vc_condVoltage':textBox_condVoltage,
256+
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,
257+
'runMode':runMode_togglebtns, 'injected_current_plot': injected_current_plot_value,
258+
'gating_plot':gating_plot_value,
259+
'cond_dens_plot':cond_dens_plot_value,
260+
'current_plot':current_plot_value,
261+
'memb_pot_plot':memb_pot_plot_value})
236262

237263
#display the widgets and plot area
238264
display(modelInputs,wid_plotArea)

0 commit comments

Comments
 (0)