Skip to content

Commit 4432301

Browse files
committed
wip
1 parent 8d6d04e commit 4432301

2 files changed

Lines changed: 84 additions & 45 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 55 additions & 41 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,13 @@ 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+
7685
def alpha_m(self, V):
7786
"""Channel gating kinetics. Functions of membrane voltage"""
7887
return 0.1*(V+40.0)/(1.0 - np.exp(-(V+40.0) / 10.0))
@@ -271,46 +280,51 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
271280
fig=plt.figure()
272281
fig.canvas.header_visible = False
273282

274-
ax1 = plt.subplot(5,1,1)
275-
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
276-
plt.title('Simulation of Hodgkin Huxley model neuron')
277-
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)
283+
if self.injected_current_plot:
284+
ax1 = plt.subplot(5,1,1)
285+
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
286+
plt.title('Simulation of Hodgkin Huxley model neuron')
287+
288+
if self.is_vclamp():
289+
i_inj_values = [self.I_inj_vclamp(t,v) for t,v in zip(self.t,V)]
290+
else:
291+
i_inj_values = [self.I_inj(t) for t in self.t]
292+
293+
plt.plot(self.t, i_inj_values, 'k')
294+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
295+
if self.is_vclamp(): plt.ylim(-2000,3000)
296+
297+
298+
if self.gating_plot:
299+
plt.subplot(5,1,2, sharex = ax1)
300+
plt.plot(self.t, m, 'r', label='m')
301+
plt.plot(self.t, h, 'g', label='h')
302+
plt.plot(self.t, n, 'b', label='n')
303+
plt.ylabel('Gating Variable')
304+
plt.legend()
305+
306+
if self.cond_dens_plot:
307+
plt.subplot(5,1,3, sharex = ax1)
308+
plt.plot(self.t, gna, 'c', label='$g_{Na}$')
309+
plt.plot(self.t, gk, 'y', label='$g_{K}$')
310+
plt.ylabel('Cond. dens')
311+
plt.legend()
312+
313+
if self.current_plot:
314+
plt.subplot(5,1,4, sharex = ax1)
315+
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
316+
plt.plot(self.t, ik, 'y', label='$I_{K}$')
317+
plt.plot(self.t, il, 'm', label='$I_{L}$')
318+
plt.ylabel('Current')
319+
plt.legend()
320+
321+
if self.memb_pot_plot:
322+
plt.subplot(5,1,5, sharex = ax1)
323+
plt.plot(self.t, V, 'k')
324+
plt.ylabel('V (mV)')
325+
plt.xlabel('t (ms)')
326+
if not self.is_vclamp(): plt.ylim(-85,60)
327+
#plt.ylim(-1, 40)
314328

315329
plt.tight_layout()
316330

notebooks/Python_HH_version/ui_widget.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,16 @@ 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+
injected_current_plot_value = ipywidgets.ToggleButton(value=True, description="Current injection plot", disabled=True,)
209+
gating_plot_value = ipywidgets.ToggleButton(value=False, description="Gating variables", disabled=False,)
210+
cond_dens_plot_value = ipywidgets.ToggleButton(value=False, description="Conductance density", disabled=False,)
211+
current_plot_value = ipywidgets.ToggleButton(value=False, description="Current", disabled=False,)
212+
memb_pot_plot_value = ipywidgets.ToggleButton(value=False, description="Memb pot", disabled=False,)
213+
plot_selection_row=ipywidgets.HBox([injected_current_plot_value, gating_plot_value, cond_dens_plot_value, current_plot_value, memb_pot_plot_value])
214+
207215
#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])
216+
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,runMode_iclamp,runMode_vclamp,button_row,defalultValues,plot_selection_row])
209217

210218
# Main method to create interactive widget
211219
def launch_interactive_widget():
@@ -217,10 +225,23 @@ def launch_interactive_widget():
217225
HHmodel = SourceFileLoader("HodgkinHuxley.py","../../Tutorial/Source/HodgkinHuxley.py").load_module()
218226

219227
#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):
228+
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
229+
I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration,
230+
vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode,
231+
injected_current_plot, gating_plot, cond_dens_plot, current_plot, memb_pot_plot):
221232

222233
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)
234+
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L,
235+
t_0, t_n, delta_t, I_inj_max,
236+
I_inj_width, I_inj_trans, vc_delay,
237+
vc_duration, vc_condVoltage,
238+
vc_testVoltage, vc_returnVoltage,
239+
runMode,
240+
injected_current_plot=injected_current_plot,
241+
gating_plot=gating_plot,
242+
cond_dens_plot=cond_dens_plot,
243+
current_plot=current_plot,
244+
memb_pot_plot=memb_pot_plot)
224245
# init_values are the steady state values for v,m,h,n at zero current injection
225246
runner.Main(init_values=[-63.8, 0.0609, 0.5538, 0.3361])
226247

@@ -232,7 +253,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
232253
'I_inj_max':textBox_amplitude,'I_inj_width':textBox_width,'I_inj_trans':textBox_translation,
233254
'vc_delay':textBox_delay,'vc_duration':textBox_duration,'vc_condVoltage':textBox_condVoltage,
234255
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,
235-
'runMode':runMode_togglebtns})
256+
'runMode':runMode_togglebtns, 'injected_current_plot': injected_current_plot_value,
257+
'gating_plot':gating_plot_value,
258+
'cond_dens_plot':cond_dens_plot_value,
259+
'current_plot':current_plot_value,
260+
'memb_pot_plot':memb_pot_plot_value})
236261

237262
#display the widgets and plot area
238263
display(modelInputs,wid_plotArea)

0 commit comments

Comments
 (0)