Skip to content

Commit 2b399e6

Browse files
committed
suggested changes
1 parent 7445d9f commit 2b399e6

3 files changed

Lines changed: 57 additions & 54 deletions

File tree

Tutorial/Source/HodgkinHuxley.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,42 @@ def Main(self):
158158
ina = self.I_Na(V, m, h)
159159
ik = self.I_K(V, n)
160160
il = self.I_L(V)
161-
162-
plt.figure(figsize=[15,10])
161+
162+
#increase figure and font size for display in jupyter notebook
163+
if __name__ != '__main__':
164+
plt.rcParams['figure.figsize'] = [12, 8]
165+
plt.rcParams['font.size'] = 15
166+
plt.rcParams['legend.fontsize'] = 12
167+
168+
fig=plt.figure()
163169

164170
ax1 = plt.subplot(4,1,1)
165171
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
166-
plt.title('Hodgkin-Huxley Neuron', fontsize = 20)
172+
plt.title('Hodgkin-Huxley Neuron')
167173
plt.plot(self.t, V, 'k')
168-
plt.ylabel('V (mV)', fontsize = 15)
174+
plt.ylabel('V (mV)')
169175

170176

171177
plt.subplot(4,1,2, sharex = ax1)
172178
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
173179
plt.plot(self.t, ik, 'y', label='$I_{K}$')
174180
plt.plot(self.t, il, 'm', label='$I_{L}$')
175-
plt.ylabel('Current', fontsize = 15)
176-
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
181+
plt.ylabel('Current')
182+
plt.legend()
177183

178184
plt.subplot(4,1,3, sharex = ax1)
179185
plt.plot(self.t, m, 'r', label='m')
180186
plt.plot(self.t, h, 'g', label='h')
181187
plt.plot(self.t, n, 'b', label='n')
182-
plt.ylabel('Gating Value', fontsize = 15)
183-
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
188+
plt.ylabel('Gating Value')
189+
plt.legend()
184190

185191
plt.subplot(4,1,4, sharex = ax1)
186192
i_inj_values = [self.I_inj(t) for t in self.t]
187193
plt.plot(self.t, i_inj_values, 'k')
188-
plt.xlabel('t (ms)', fontsize = 15)
189-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)', fontsize = 15)
190-
plt.ylim(-1, 40)
194+
plt.xlabel('t (ms)')
195+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
196+
#plt.ylim(-1, 40)
191197

192198
plt.tight_layout()
193199
plt.show()

notebook/notebook.ipynb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
{
4848
"data": {
4949
"application/vnd.jupyter.widget-view+json": {
50-
"model_id": "0069befeceae4a93a70e238bd4db6770",
50+
"model_id": "d24a25dd35ff467282b98da9124b4cfd",
5151
"version_major": 2,
5252
"version_minor": 0
5353
},
5454
"text/plain": [
55-
"VBox(children=(HBox(children=(HTML(value=\"<b><font color='blue'>Membrane Capacitance, uF/cm^2</b>\"),)), HBox(c"
55+
"VBox(children=(HBox(children=(HTMLMath(value=\"<b><font color='blue'>Membrane Capacitance, \\\\(\\\\mu{F}/cm^2\\\\)</"
5656
]
5757
},
5858
"metadata": {},
@@ -61,12 +61,12 @@
6161
{
6262
"data": {
6363
"application/vnd.jupyter.widget-view+json": {
64-
"model_id": "f778c8dc95a342e3a889af3c1ce47463",
64+
"model_id": "1ba19affdea04156a454e03ae6e62490",
6565
"version_major": 2,
6666
"version_minor": 0
6767
},
6868
"text/plain": [
69-
"interactive(children=(Checkbox(value=False, description=\"<b><font color='blue'>Advanced Input - Incjection Cur…"
69+
"Output()"
7070
]
7171
},
7272
"metadata": {},
@@ -85,28 +85,18 @@
8585
"\n",
8686
"#function to call python script as a module\n",
8787
"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):\n",
88+
" ui_widget.highlight_slider()\n",
8889
" 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)\n",
8990
" runner.Main()\n",
9091
"\n",
91-
"#function to handle checkbox event\n",
92-
"def checkboxEvent(checkboxStatus):\n",
93-
" if checkboxStatus:\n",
94-
" wid_inj=ipywidgets.interact(ui_widget.injectorCurrent,amplidute=ui_widget.slider_amplitude,t_width=ui_widget.slider_width,t_translation=ui_widget.slider_translation);\n",
95-
" display(wid_plotArea)\n",
96-
" else:\n",
97-
" display(wid_plotArea)\n",
98-
"\n",
99-
"#create checkbox widget\n",
100-
"wid_checkbox=ipywidgets.interactive(checkboxEvent,checkboxStatus=ui_widget.cb);\n",
101-
"\n",
10292
"#create plot area widget and interact with HHmodel\n",
10393
"wid_plotArea=ipywidgets.interactive_output(runHH,{'C_m':ui_widget.slider_capacitance,\n",
10494
" 'g_Na':ui_widget.slider_cond_Na, 'g_K':ui_widget.slider_cond_K, 'g_L':ui_widget.slider_cond_L, \n",
10595
" 'E_Na':ui_widget.slider_pot_Na, 'E_K':ui_widget.slider_pot_K, 'E_L':ui_widget.slider_pot_L,\n",
10696
" 't_0':ui_widget.time_start, 't_n':ui_widget.time_end, 'delta_t':ui_widget.time_step, \n",
10797
" 'I_inj_max':ui_widget.slider_amplitude,'I_inj_width':ui_widget.slider_width,'I_inj_trans':ui_widget.slider_translation})\n",
10898
" \n",
109-
"display(ui_widget.basicInputs,wid_checkbox)"
99+
"display(ui_widget.modelInputs,wid_plotArea)"
110100
]
111101
},
112102
{
@@ -120,7 +110,7 @@
120110
"cell_type": "markdown",
121111
"metadata": {},
122112
"source": [
123-
"1) Starting from the bottom, the first (bottom-most) plot shows two currents injected into the cell membrane at times 100ms and 300ms.\n",
113+
"1) Starting from the bottom, the first (bottom-most) plot shows two currents injected into the cell membrane at times 100ms and 300ms for default values. If injection current is changed from above slider then it will be a single rectangular pulse based on user input.\n",
124114
"2) The second plot from the bottom shows the activation/inactivation parameters of the ion channels in the neuron. \n",
125115
"3) Third plot from the bottom (the current/time plot) makes this more concrete, showing the influx (negative y-axis) and outflux (positive y-axis) of ions passing through each type of ion channel being modeled.\n",
126116
"4) The top plot, which shows neural membrane voltage activity. The spikes here are called “action potentials” and correspond directly to the current/time plot. "

notebook/ui_widget.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,33 @@ def resetTodefault(_):
1616
slider_amplitude.value = 50
1717
slider_width.value = 0
1818
slider_translation.value = 50
19-
cb.value = False
20-
21-
#function to define injector current parameters and plot
22-
def injectorCurrent(amplidute=10, t_width=100, t_translation=100):
23-
t = np.arange(0, 450, 5) #range for plotting only not used in simulation
24-
for i in t:
25-
I_inj = amplidute*(t>t_translation) - amplidute*(t>t_translation+t_width)
26-
plt.figure()
27-
plt.plot(t, I_inj)
28-
plt.xlabel('t (ms)', fontsize = 15)
29-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
30-
plt.show()
31-
#display(plt.show(),wid_plotArea)
3219

33-
header_capacitance = ipywidgets.HTML(value=f"<b><font color='blue'>Membrane Capacitance, uF/cm^2</b>")
34-
header_conductance = ipywidgets.HTML(value=f"<b><font color='blue'>Maximum Conductances, mS/cm^2</b>")
35-
header_potential = ipywidgets.HTML(value=f"<b><font color='blue'>Nernst Reverasal Potentials, mV</b>")
36-
header_simTime = ipywidgets.HTML(value=f"<b><font color='blue'>Simulation Time, ms</b>")
20+
#function to change slider handle colour when move from default
21+
def highlight_slider():
22+
inputList = [slider_capacitance, slider_cond_Na, slider_cond_K, slider_cond_L, slider_pot_Na, slider_pot_K, slider_pot_L]
23+
inputDefault = [1.0, 120, 36, 0.3, 50, -77, -54.387]
24+
for l, d in zip(inputList,inputDefault):
25+
if l.value == d:
26+
l.style.handle_color = 'white'
27+
else:
28+
l.style.handle_color = 'orange'
29+
if slider_width.value == 0.0:
30+
slider_amplitude.style.handle_color = 'white'
31+
slider_width.style.handle_color = 'white'
32+
slider_translation.style.handle_color = 'white'
33+
else:
34+
slider_amplitude.style.handle_color = 'orange'
35+
slider_width.style.handle_color = 'orange'
36+
slider_translation.style.handle_color = 'orange'
37+
38+
header_capacitance = ipywidgets.HTMLMath(value=r"<b><font color='blue'>Membrane Capacitance, \(\mu{F}/cm^2\)</b>")
39+
header_conductance = ipywidgets.HTMLMath(value=r"<b><font color='blue'>Maximum Conductances, \(mS/cm^2\)</b>")
40+
header_potential = ipywidgets.HTMLMath(value=r"<b><font color='blue'>Nernst Reverasal Potentials, \(mV\)</b>")
41+
header_simTime = ipywidgets.HTMLMath(value=r"<b><font color='blue'>Simulation Time, \(ms\)</b>")
42+
header_injCurrent = ipywidgets.HTMLMath(value=r"<b><font color='blue'>Injection Current, \(\mu{A}/cm^2\)</b>")
43+
injCurrent_note = ipywidgets.HTML(value=f"<i>*For injection current width = 0, the model uses default two pulse signal from tutorial</i>")
3744
slider_capacitance = ipywidgets.FloatSlider(value=1,min=0,max=3,step=0.1,description='Capacitance',readout_format='.1f',continuous_update=False)
38-
slider_cond_Na = ipywidgets.FloatSlider(value=120,min=80,max=160,step=0.1,description='Sodium',readout_format='.1f',continuous_update=False)
45+
slider_cond_Na = ipywidgets.FloatSlider(value=120,min=0,max=160,step=0.1,description='Sodium',readout_format='.1f',continuous_update=False)
3946
slider_cond_K = ipywidgets.FloatSlider(value=36,min=0,max=80,step=0.1,description='Potassium',readout_format='.1f',continuous_update=False)
4047
slider_cond_L = ipywidgets.FloatSlider(value=0.3,min=0,max=1,step=0.1,description='Leak',readout_format='.1f',continuous_update=False)
4148
slider_pot_Na = ipywidgets.FloatSlider(value=50,min=-100,max=100,step=0.1,description='Sodium',readout_format='.1f',continuous_update=False)
@@ -44,6 +51,9 @@ def injectorCurrent(amplidute=10, t_width=100, t_translation=100):
4451
time_start = ipywidgets.FloatText(value=0,description='Start Time',disabled=True)
4552
time_end = ipywidgets.FloatText(value=450,description='Total Time',disabled=False)
4653
time_step = ipywidgets.FloatText(value=0.01,description='Time Step',disabled=False)
54+
slider_amplitude = ipywidgets.FloatSlider(value=50,min=-20,max=200,step=0.1,description='Amplitude',readout_format='.1f',continuous_update=False)
55+
slider_width = ipywidgets.FloatSlider(value=0,min=0,max=500,step=0.1,description='Width',readout_format='.1f',continuous_update=False)
56+
slider_translation = ipywidgets.FloatSlider(value=50,min=0,max=250,step=0.1,description='Start at',readout_format='.1f',continuous_update=False)
4757

4858
reset_button = ipywidgets.Button(description="Reset All")
4959
reset_button.on_click(resetTodefault)
@@ -56,11 +66,8 @@ def injectorCurrent(amplidute=10, t_width=100, t_translation=100):
5666
h6=ipywidgets.HBox([slider_pot_Na,slider_pot_K,slider_pot_L])
5767
h7=ipywidgets.HBox([header_simTime])
5868
h8=ipywidgets.HBox([time_start,time_end,time_step])
59-
h9=ipywidgets.HBox([reset_button])
60-
basicInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9])
61-
62-
#Advanced Inputs
63-
cb=ipywidgets.Checkbox(value=False,description=f"<b><font color='blue'>Advanced Input - Incjection Current</b>",indent=False)
64-
slider_amplitude = ipywidgets.FloatSlider(value=50,min=-100,max=100,step=1,description='Amplitude',readout_format='d',continuous_update=False)
65-
slider_width = ipywidgets.FloatSlider(value=0,min=0,max=500,step=1,description='Width',readout_format='d',continuous_update=False)
66-
slider_translation = ipywidgets.FloatSlider(value=50,min=0,max=250,step=1,description='Start at',readout_format='d',continuous_update=False)
69+
h9=ipywidgets.HBox([header_injCurrent])
70+
h10=ipywidgets.HBox([injCurrent_note])
71+
h11=ipywidgets.HBox([slider_amplitude,slider_width,slider_translation])
72+
h12=ipywidgets.HBox([reset_button])
73+
modelInputs=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12])

0 commit comments

Comments
 (0)