Skip to content

Commit 5377b14

Browse files
authored
Merge pull request #61 from sanjayankur31/feat/allow-plot-toggling
Feat/allow plot toggling
2 parents 6aa465a + 1f6f868 commit 5377b14

2 files changed

Lines changed: 114 additions & 47 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')
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')
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 (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/ui_widget.py

Lines changed: 30 additions & 4 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 plot", 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 density", disabled=False,)
212+
current_plot_value = ipywidgets.Checkbox(value=True, description="Current", disabled=False,)
213+
memb_pot_plot_value = ipywidgets.Checkbox(value=True, description="Memb pot", 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,10 +226,23 @@ 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

@@ -232,7 +254,11 @@ 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_i
232254
'I_inj_max':textBox_amplitude,'I_inj_width':textBox_width,'I_inj_trans':textBox_translation,
233255
'vc_delay':textBox_delay,'vc_duration':textBox_duration,'vc_condVoltage':textBox_condVoltage,
234256
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,
235-
'runMode':runMode_togglebtns})
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)