Skip to content

Commit

Permalink
Merge pull request #74 from openworm/development
Browse files Browse the repository at this point in the history
Fix vclamp duration/dt issue
  • Loading branch information
pgleeson authored Oct 23, 2023
2 parents b63ba99 + d5756c9 commit 71aaa50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
28 changes: 11 additions & 17 deletions Tutorial/Source/HodgkinHuxley.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class HodgkinHuxley():
""" when no argument is passed default values are used """

def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
E_K=-77, E_L=-54.387, t_0=0, t_n=450, delta_t=0.01,
E_K=-77, E_L=-54.387, t_n=450, delta_t=0.01,
I_inj_amplitude=0, I_inj_duration=0, I_inj_delay=0,
vc_delay=10, vc_duration=30, vc_condVoltage=-65,
vc_testVoltage=10, vc_returnVoltage=-65, runMode='iclamp',
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self, C_m=1, gmax_Na=120, gmax_K=36, gmax_L=0.3, E_Na=50,
self.E_L = E_L
""" Leak Nernst reversal potentials, in mV """

self.t = np.arange(t_0, t_n, delta_t)
self.t = np.arange(0, t_n, delta_t)
""" The time to integrate over """

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

def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
def simulate(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]):
"""
Main demo for the Hodgkin Huxley neuron model
Main simulate method for the Hodgkin Huxley neuron model
"""
if __name__ == '__main__':

self.run_mode='iclamp'

if '-iclamp' in sys.argv: #default mode
self.run_mode='iclamp'
elif '-vclamp' in sys.argv:
self.run_mode='vclamp'

if self.is_vclamp():
self.t = np.arange(0, 50, 0.001) #update default time array for python script (notebook can be controlled through widgets)

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

if __name__ == '__main__':
runner = HodgkinHuxley()
runner.Main()

if '-vclamp' in sys.argv:
runner = HodgkinHuxley(runMode='vclamp', t_n=50, delta_t=0.0005)
else: #default mode
runner = HodgkinHuxley(runMode='iclamp', t_n=450, delta_t=0.01)

runner.simulate()
14 changes: 6 additions & 8 deletions notebooks/Python_HH_version/ui_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
default_testVoltage = 10
default_returnVoltage = -65
default_tn_vclamp = 50
default_deltat_vclamp = 0.001
default_deltat_vclamp = 0.0005

#function to reset input values to default on button click
def resetTodefault(_):
Expand All @@ -39,7 +39,6 @@ def resetTodefault(_):
slider_E_Na.value = default_E_Na
slider_E_K.value = default_E_K
slider_E_L.value = default_E_L
time_start.value = default_t0
time_end.value = default_tn
time_step.value = default_deltat
slider_amplitude.value = default_ic_amplitude
Expand Down Expand Up @@ -122,7 +121,6 @@ def highlight_slider():
slider_returnVoltage = ipywidgets.FloatSlider(value=default_returnVoltage ,min=-120,max=100,step=1,description='Returning',readout=False,continuous_update=False)

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

Expand Down Expand Up @@ -188,7 +186,7 @@ def highlight_slider():
h5=ipywidgets.HBox([header_potential])
h6=ipywidgets.HBox([slider_E_Na,textBox_E_Na,slider_E_K,textBox_E_K,slider_E_L,textBox_E_L])
h7=ipywidgets.HBox([header_simTime])
h8=ipywidgets.HBox([time_start,time_end,time_step])
h8=ipywidgets.HBox([time_end,time_step])
h9=ipywidgets.HBox([header_runMode])
h10=ipywidgets.HBox([runMode_togglebtns])

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

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

highlight_slider()
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,
t_n, delta_t, I_inj_max,
I_inj_width, I_inj_trans, vc_delay,
vc_duration, vc_condVoltage,
vc_testVoltage, vc_returnVoltage,
Expand All @@ -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,
current_plot=current_plot,
memb_pot_plot=memb_pot_plot)
# init_values are the steady state values for v,m,h,n at zero current injection
runner.Main(init_values=[-63.8, 0.0609, 0.5538, 0.3361])
runner.simulate(init_values=[-63.8, 0.0609, 0.5538, 0.3361])

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

0 comments on commit 71aaa50

Please sign in to comment.