Skip to content

Commit 71aaa50

Browse files
authored
Merge pull request #74 from openworm/development
Fix vclamp duration/dt issue
2 parents b63ba99 + d5756c9 commit 71aaa50

2 files changed

Lines changed: 17 additions & 25 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class HodgkinHuxley():
1111
""" when no argument is passed default values are used """
1212

1313
def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
14-
E_K=-77, E_L=-54.387, t_0=0, t_n=450, delta_t=0.01,
14+
E_K=-77, E_L=-54.387, 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,
1717
vc_testVoltage=10, vc_returnVoltage=-65, runMode='iclamp',
@@ -40,7 +40,7 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
4040
self.E_L = E_L
4141
""" Leak Nernst reversal potentials, in mV """
4242

43-
self.t = np.arange(t_0, t_n, delta_t)
43+
self.t = np.arange(0, t_n, delta_t)
4444
""" The time to integrate over """
4545

4646
""" Advanced input - injection current (single rectangular pulse only) """
@@ -240,21 +240,10 @@ def dALLdt(X, t, self):
240240
def is_vclamp(self):
241241
return self.run_mode=='vclamp' or self.run_mode=='Voltage Clamp'
242242

243-
def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
243+
def simulate(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
244244
"""
245-
Main demo for the Hodgkin Huxley neuron model
245+
Main simulate method for the Hodgkin Huxley neuron model
246246
"""
247-
if __name__ == '__main__':
248-
249-
self.run_mode='iclamp'
250-
251-
if '-iclamp' in sys.argv: #default mode
252-
self.run_mode='iclamp'
253-
elif '-vclamp' in sys.argv:
254-
self.run_mode='vclamp'
255-
256-
if self.is_vclamp():
257-
self.t = np.arange(0, 50, 0.001) #update default time array for python script (notebook can be controlled through widgets)
258247

259248
# init_values are the steady state values for v,m,h,n at zero current injection
260249
X = odeint(self.dALLdt, init_values, self.t, args=(self,))
@@ -403,5 +392,10 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
403392
plt.show()
404393

405394
if __name__ == '__main__':
406-
runner = HodgkinHuxley()
407-
runner.Main()
395+
396+
if '-vclamp' in sys.argv:
397+
runner = HodgkinHuxley(runMode='vclamp', t_n=50, delta_t=0.0005)
398+
else: #default mode
399+
runner = HodgkinHuxley(runMode='iclamp', t_n=450, delta_t=0.01)
400+
401+
runner.simulate()

notebooks/Python_HH_version/ui_widget.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
default_testVoltage = 10
2929
default_returnVoltage = -65
3030
default_tn_vclamp = 50
31-
default_deltat_vclamp = 0.001
31+
default_deltat_vclamp = 0.0005
3232

3333
#function to reset input values to default on button click
3434
def resetTodefault(_):
@@ -39,7 +39,6 @@ def resetTodefault(_):
3939
slider_E_Na.value = default_E_Na
4040
slider_E_K.value = default_E_K
4141
slider_E_L.value = default_E_L
42-
time_start.value = default_t0
4342
time_end.value = default_tn
4443
time_step.value = default_deltat
4544
slider_amplitude.value = default_ic_amplitude
@@ -122,7 +121,6 @@ def highlight_slider():
122121
slider_returnVoltage = ipywidgets.FloatSlider(value=default_returnVoltage ,min=-120,max=100,step=1,description='Returning',readout=False,continuous_update=False)
123122

124123
#text box widgets
125-
time_start = ipywidgets.FloatText(value=default_t0,description='Start Time',disabled=True)
126124
time_end = ipywidgets.FloatText(value=default_tn,description='Total Time',disabled=False)
127125
time_step = ipywidgets.FloatText(value=default_deltat,description='Time Step',disabled=False)
128126

@@ -188,7 +186,7 @@ def highlight_slider():
188186
h5=ipywidgets.HBox([header_potential])
189187
h6=ipywidgets.HBox([slider_E_Na,textBox_E_Na,slider_E_K,textBox_E_K,slider_E_L,textBox_E_L])
190188
h7=ipywidgets.HBox([header_simTime])
191-
h8=ipywidgets.HBox([time_start,time_end,time_step])
189+
h8=ipywidgets.HBox([time_end,time_step])
192190
h9=ipywidgets.HBox([header_runMode])
193191
h10=ipywidgets.HBox([runMode_togglebtns])
194192

@@ -229,14 +227,14 @@ def launch_interactive_widget():
229227
HHmodel = SourceFileLoader("HodgkinHuxley.py","../../Tutorial/Source/HodgkinHuxley.py").load_module()
230228

231229
#function to call python script as a module
232-
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
230+
def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_n, delta_t,
233231
I_inj_max, I_inj_width, I_inj_trans, vc_delay, vc_duration,
234232
vc_condVoltage, vc_testVoltage, vc_returnVoltage, runMode,
235233
injected_current_plot, gating_plot, cond_scaling_plot, cond_dens_plot, driving_force_plot, current_plot, memb_pot_plot):
236234

237235
highlight_slider()
238236
runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L,
239-
t_0, t_n, delta_t, I_inj_max,
237+
t_n, delta_t, I_inj_max,
240238
I_inj_width, I_inj_trans, vc_delay,
241239
vc_duration, vc_condVoltage,
242240
vc_testVoltage, vc_returnVoltage,
@@ -249,13 +247,13 @@ def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t,
249247
current_plot=current_plot,
250248
memb_pot_plot=memb_pot_plot)
251249
# init_values are the steady state values for v,m,h,n at zero current injection
252-
runner.Main(init_values=[-63.8, 0.0609, 0.5538, 0.3361])
250+
runner.simulate(init_values=[-63.8, 0.0609, 0.5538, 0.3361])
253251

254252
#create plot area widget and interact with HHmodel
255253
wid_plotArea=ipywidgets.interactive_output(runHH,{'C_m':slider_capacitance,
256254
'g_Na':textBox_cond_Na, 'g_K':textBox_cond_K, 'g_L':textBox_cond_L,
257255
'E_Na':textBox_E_Na, 'E_K':textBox_E_K, 'E_L':textBox_E_L,
258-
't_0':time_start, 't_n':time_end, 'delta_t':time_step,
256+
't_n':time_end, 'delta_t':time_step,
259257
'I_inj_max':textBox_amplitude,'I_inj_width':textBox_width,'I_inj_trans':textBox_translation,
260258
'vc_delay':textBox_delay,'vc_duration':textBox_duration,'vc_condVoltage':textBox_condVoltage,
261259
'vc_testVoltage':textBox_testVoltage,'vc_returnVoltage':textBox_returnVoltage,

0 commit comments

Comments
 (0)