From 55f5a7e444741e750b6858185ba80735510fbff9 Mon Sep 17 00:00:00 2001 From: pgleeson Date: Mon, 23 Oct 2023 10:58:17 +0100 Subject: [PATCH 1/2] Improved handling of times in vclamp Renames Main() method to simulate() Removes unused start time Fixes #71 Fixes #72 --- Tutorial/Source/HodgkinHuxley.py | 30 ++++++++++-------------- notebooks/Python_HH_version/ui_widget.py | 12 ++++------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Tutorial/Source/HodgkinHuxley.py b/Tutorial/Source/HodgkinHuxley.py index 7bdc657..2e56ea5 100644 --- a/Tutorial/Source/HodgkinHuxley.py +++ b/Tutorial/Source/HodgkinHuxley.py @@ -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', @@ -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) """ @@ -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,)) @@ -290,7 +279,7 @@ def Main(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]): fig=plt.figure(figsize=(7, self.num_plots * 2)) fig.canvas.header_visible = False - plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots + #plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots if self.injected_current_plot: ax1 = plt.subplot(self.num_plots,1,self.plot_count + 1) @@ -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.001) + else: #default mode + runner = HodgkinHuxley(runMode='iclamp', t_n=450, delta_t=0.01) + + runner.simulate() diff --git a/notebooks/Python_HH_version/ui_widget.py b/notebooks/Python_HH_version/ui_widget.py index 9c5d351..9bd29e5 100644 --- a/notebooks/Python_HH_version/ui_widget.py +++ b/notebooks/Python_HH_version/ui_widget.py @@ -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 @@ -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) @@ -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]) @@ -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, @@ -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, From d5756c97ef78c557b9ab490ba8fbf4b76c08d85a Mon Sep 17 00:00:00 2001 From: pgleeson Date: Mon, 23 Oct 2023 12:11:09 +0100 Subject: [PATCH 2/2] Reduce default timestep for vclamp so clamp current at end of testing phase more obvious --- Tutorial/Source/HodgkinHuxley.py | 2 +- notebooks/Python_HH_version/ui_widget.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tutorial/Source/HodgkinHuxley.py b/Tutorial/Source/HodgkinHuxley.py index 71b882e..8eb99de 100644 --- a/Tutorial/Source/HodgkinHuxley.py +++ b/Tutorial/Source/HodgkinHuxley.py @@ -394,7 +394,7 @@ def simulate(self, init_values=[-64.99584, 0.05296, 0.59590, 0.31773]): if __name__ == '__main__': if '-vclamp' in sys.argv: - runner = HodgkinHuxley(runMode='vclamp', t_n=50, delta_t=0.001) + 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) diff --git a/notebooks/Python_HH_version/ui_widget.py b/notebooks/Python_HH_version/ui_widget.py index 9bd29e5..409353f 100644 --- a/notebooks/Python_HH_version/ui_widget.py +++ b/notebooks/Python_HH_version/ui_widget.py @@ -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(_):