Skip to content

Commit e222ba4

Browse files
committed
Issue #19 resolved draft
1 parent 3726832 commit e222ba4

7 files changed

Lines changed: 220 additions & 440 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Tutorial/Source/*json
3535
/Tutorial/Source/*_brian.py
3636
*code.gen.*
3737
*_eden.py
38+
.ipynb_*

notebook/.ipynb_checkpoints/HHmodel-checkpoint.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from scipy.integrate import odeint
55

66
class HodgkinHuxley:
7-
t = np.arange(0.0, 450.0, 0.01)
87
def __init__(self, C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t):
98
self.C_m = C_m
109
self.g_Na = g_Na
@@ -16,8 +15,8 @@ def __init__(self, C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t):
1615
self.t = t
1716
#self.tn = tn
1817
#self.delta_t = delta_t
19-
#self.t = np.arange(t0, tn, delta_t)
20-
#print(self.t)
18+
#t = np.arange(t0, tn, delta_t)
19+
#print(t)
2120

2221
def alpha_m(self, V):
2322
"""Channel gating kinetics. Functions of membrane voltage"""
@@ -115,36 +114,35 @@ def Main(self):
115114
ik = self.I_K(V, n)
116115
il = self.I_L(V)
117116

118-
plt.figure(figsize=[4,2])
119-
117+
plt.figure(figsize=[15,10])
118+
120119
ax1 = plt.subplot(4,1,1)
121-
plt.title('Hodgkin-Huxley Neuron')
120+
plt.xlim([np.min(self.t),np.max(self.t)]) #for all subplots
121+
plt.title('Hodgkin-Huxley Neuron', fontsize = 20)
122122
plt.plot(self.t, V, 'k')
123-
plt.ylabel('V (mV)')
123+
plt.ylabel('V (mV)', fontsize = 15)
124+
124125

125126
plt.subplot(4,1,2, sharex = ax1)
126127
plt.plot(self.t, ina, 'c', label='$I_{Na}$')
127128
plt.plot(self.t, ik, 'y', label='$I_{K}$')
128129
plt.plot(self.t, il, 'm', label='$I_{L}$')
129-
plt.ylabel('Current')
130-
plt.legend()
130+
plt.ylabel('Current', fontsize = 15)
131+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
131132

132133
plt.subplot(4,1,3, sharex = ax1)
133134
plt.plot(self.t, m, 'r', label='m')
134135
plt.plot(self.t, h, 'g', label='h')
135136
plt.plot(self.t, n, 'b', label='n')
136-
plt.ylabel('Gating Value')
137-
plt.legend()
137+
plt.ylabel('Gating Value', fontsize = 15)
138+
plt.legend(bbox_to_anchor=(1.1, 0.5),loc='center right', fontsize = 15, borderaxespad=0)
138139

139140
plt.subplot(4,1,4, sharex = ax1)
140141
i_inj_values = [self.I_inj(t) for t in self.t]
141142
plt.plot(self.t, i_inj_values, 'k')
142-
plt.xlabel('t (ms)')
143-
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
143+
plt.xlabel('t (ms)', fontsize = 15)
144+
plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)', fontsize = 15)
144145
plt.ylim(-1, 40)
145146

146147
plt.tight_layout()
147-
plt.show()
148-
149-
#plt.rcParams["figure.figsize"]=200,100
150-
#plt.show()
148+
plt.show()

notebook/.ipynb_checkpoints/notebook-checkpoint.ipynb

Lines changed: 64 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,16 @@
2222
"source": [
2323
"This model relies on a basic equivalence between a biological membrane plus embedded ion channels, and an electrical circuit.\n",
2424
"\n",
25+
"<font size=\"5\">Basic inputs to the Model</font>\n",
26+
"\n",
27+
"1) Membrane capacitance, uF/cm^2\n",
28+
"2) Maximum Conductances, mS/cm^2\n",
29+
"3) Nernst Reverasal Potentials, mV\n",
30+
"4) Simulation Parameters (time), ms\n",
31+
"\n",
2532
"<img src=\"equivalentCircuit.PNG\" width=\"500\"/>\n"
2633
]
2734
},
28-
{
29-
"cell_type": "markdown",
30-
"metadata": {},
31-
"source": [
32-
"<font size=\"5\">Inputs to the Model</font>"
33-
]
34-
},
35-
{
36-
"cell_type": "markdown",
37-
"metadata": {},
38-
"source": [
39-
"<font size=\"3\">1) Membrane capacitance, uF/cm^2</font>"
40-
]
41-
},
42-
{
43-
"cell_type": "markdown",
44-
"metadata": {},
45-
"source": [
46-
"<font size=\"3\">2) Maximum Conductances, mS/cm^2</font>"
47-
]
48-
},
49-
{
50-
"cell_type": "markdown",
51-
"metadata": {},
52-
"source": [
53-
"<font size=\"3\">3) Nernst Reverasal Potentials, mV</font>"
54-
]
55-
},
56-
{
57-
"cell_type": "markdown",
58-
"metadata": {},
59-
"source": [
60-
"<font size=\"3\">4) Simulation Parameters (time), s</font>"
61-
]
62-
},
6335
{
6436
"cell_type": "markdown",
6537
"metadata": {},
@@ -75,12 +47,12 @@
7547
{
7648
"data": {
7749
"application/vnd.jupyter.widget-view+json": {
78-
"model_id": "e851f9fc076c4a64a36657cd04c67824",
50+
"model_id": "ad6a061177c04f0699acea9767f2345b",
7951
"version_major": 2,
8052
"version_minor": 0
8153
},
8254
"text/plain": [
83-
"interactive(children=(FloatSlider(value=1.0, description='C_m', max=3.0, min=-1.0), IntSlider(value=120, descr"
55+
"VBox(children=(HBox(children=(HTML(value=\"<b><font color='blue'>Membrane Capacitance, uF/cm^2</b>\"),)), HBox(c"
8456
]
8557
},
8658
"metadata": {},
@@ -89,12 +61,12 @@
8961
{
9062
"data": {
9163
"application/vnd.jupyter.widget-view+json": {
92-
"model_id": "2fffcdd416f543289755b6567288ba86",
64+
"model_id": "4932cb960e094cc18913bbf2f918930f",
9365
"version_major": 2,
9466
"version_minor": 0
9567
},
9668
"text/plain": [
97-
"VBox(children=(HBox(children=(HTML(value=\"<b><font color='blue'>Membrane Capacitance, uF/cm^2</b>\"),)), HBox(c…"
69+
"Output()"
9870
]
9971
},
10072
"metadata": {},
@@ -107,93 +79,25 @@
10779
"import ipywidgets\n",
10880
"import numpy as np\n",
10981
"\n",
110-
"def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L):\n",
111-
" t = np.arange(0.0, 450.0, 0.01)\n",
82+
"def runHH(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t_0, t_n, delta_t):\n",
83+
" t = np.arange(t_0, t_n, delta_t)\n",
11284
" runner = HHmodel.HodgkinHuxley(C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, t)\n",
11385
" runner.Main()\n",
11486
" \n",
115-
"w1=ipywidgets.interact(runHH,C_m=1.0,g_Na=120, g_K=36, g_L=0.3, E_Na=50, E_K=-77, E_L=-54.387)\n",
116-
"ui_widget.v1"
117-
]
118-
},
119-
{
120-
"cell_type": "code",
121-
"execution_count": null,
122-
"metadata": {},
123-
"outputs": [],
124-
"source": [
125-
"from ipywidgets import Button, GridBox, Layout, ButtonStyle\n",
126-
"\n",
127-
"\n",
128-
"header = Button(description='Header',\n",
129-
" layout=Layout(width='auto', grid_area='header'),\n",
130-
" style=ButtonStyle(button_color='lightblue'))\n",
131-
"main = Button(description='Main',\n",
132-
" layout=Layout(width='auto', grid_area='main'),\n",
133-
" style=ButtonStyle(button_color='moccasin'))\n",
134-
"sidebar = Button(description='Sidebar',\n",
135-
" layout=Layout(width='auto', grid_area='sidebar'),\n",
136-
" style=ButtonStyle(button_color='salmon'))\n",
137-
"footer = Button(description='Footer',\n",
138-
" layout=Layout(width='auto', grid_area='footer'),\n",
139-
" style=ButtonStyle(button_color='olive'))\n",
87+
"w1=ipywidgets.interactive_output(runHH,{'C_m':ui_widget.slider_capacitance,\n",
88+
" 'g_Na':ui_widget.slider_cond_Na, 'g_K':ui_widget.slider_cond_K, 'g_L':ui_widget.slider_cond_L, \n",
89+
" 'E_Na':ui_widget.slider_pot_Na, 'E_K':ui_widget.slider_pot_K, 'E_L':ui_widget.slider_pot_L,\n",
90+
" 't_0':ui_widget.time_start, 't_n':ui_widget.time_end, 'delta_t':ui_widget.time_step})\n",
14091
"\n",
141-
"GridBox(children=[header, main, sidebar, footer],\n",
142-
" layout=Layout(\n",
143-
" width='50%',\n",
144-
" grid_template_rows='auto auto auto',\n",
145-
" grid_template_columns='25% 25% 25% 25%',\n",
146-
" grid_template_areas='''\n",
147-
" \"header header header header\"\n",
148-
" \"main main . sidebar \"\n",
149-
" \"footer footer footer footer\"\n",
150-
" ''')\n",
151-
" )"
152-
]
153-
},
154-
{
155-
"cell_type": "code",
156-
"execution_count": null,
157-
"metadata": {},
158-
"outputs": [],
159-
"source": [
160-
"from ipywidgets import AppLayout, Button, Layout\n",
161-
"\n",
162-
"def create_expanded_button(description, button_style):\n",
163-
" return Button(description=description, button_style=button_style, layout=Layout(height='auto', width='auto'))\n",
164-
"\n",
165-
"header_button = create_expanded_button('Header', 'success')\n",
166-
"left_button = create_expanded_button('Left', 'info')\n",
167-
"center_button = create_expanded_button('Center', 'warning')\n",
168-
"right_button = create_expanded_button('Right', 'info')\n",
169-
"footer_button = create_expanded_button('Footer', 'success')\n",
170-
"\n",
171-
"AppLayout(header=header_button,\n",
172-
" left_sidebar=left_button,\n",
173-
" center=None,\n",
174-
" right_sidebar=right_button,\n",
175-
" footer=footer_button)\n",
176-
"\n",
177-
"from ipywidgets import GridspecLayout\n",
178-
"\n",
179-
"\n",
180-
"grid = GridspecLayout(4, 3)\n",
181-
"\n",
182-
"grid[0, 0] = create_expanded_button('Button {} - {}', 'warning')\n",
183-
"grid[0, 1] = create_expanded_button('Button {} - {}', 'success')\n",
184-
"grid\n",
185-
"\n",
186-
"\n"
92+
"ui_widget.v1\n",
93+
"display(ui_widget.v1,w1)"
18794
]
18895
},
18996
{
19097
"cell_type": "markdown",
191-
"metadata": {
192-
"jp-MarkdownHeadingCollapsed": true,
193-
"tags": []
194-
},
98+
"metadata": {},
19599
"source": [
196-
"<font size=\"5\">Description of each plot</font>"
100+
"<font size=\"5\">Description of the Plots</font>"
197101
]
198102
},
199103
{
@@ -210,7 +114,49 @@
210114
"cell_type": "markdown",
211115
"metadata": {},
212116
"source": [
213-
"![CircuitDiagram](equivalentCircuit.JPG)"
117+
"<font size=\"5\">Advanced Inputs</font>"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 4,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"data": {
127+
"application/vnd.jupyter.widget-view+json": {
128+
"model_id": "ac8ae0e37ce54981916660fa626b1991",
129+
"version_major": 2,
130+
"version_minor": 0
131+
},
132+
"text/plain": [
133+
"interactive(children=(IntSlider(value=10, description='amplidute'), IntSlider(value=100, description='t_width'…"
134+
]
135+
},
136+
"metadata": {},
137+
"output_type": "display_data"
138+
}
139+
],
140+
"source": [
141+
"import sympy\n",
142+
"import matplotlib.pyplot as plt\n",
143+
"from ipywidgets import interact\n",
144+
"sympy.init_printing()\n",
145+
"%matplotlib inline\n",
146+
"\n",
147+
"t = sympy.symbols('t')\n",
148+
"S = sympy.Heaviside\n",
149+
"\n",
150+
"def injectorCurrent(amplidute=10, t_width=100, t_translation=100):\n",
151+
" s1 = amplidute*S(t - 0 - t_translation)\n",
152+
" s2 = amplidute*S(t - t_width - t_translation) \n",
153+
" I_inj = (s1 - s2)\n",
154+
" sympy.plot(I_inj, (t, 0, 450, 0.01))\n",
155+
" \n",
156+
"w=interact(injectorCurrent,\n",
157+
" amplidute=(0,100),\n",
158+
" t_width=(0,100),\n",
159+
" t_translation=(0,450));"
214160
]
215161
}
216162
],

notebook/.ipynb_checkpoints/ui_widget-checkpoint.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,40 @@
33
header_capacitance = ipywidgets.HTML(value=f"<b><font color='blue'>Membrane Capacitance, uF/cm^2</b>")
44
header_conductance = ipywidgets.HTML(value=f"<b><font color='blue'>Maximum Conductances, mS/cm^2</b>")
55
header_potential = ipywidgets.HTML(value=f"<b><font color='blue'>Nernst Reverasal Potentials, mV</b>")
6-
slider_capacitance = ipywidgets.FloatSlider(value=1,min=0,max=3,step=0.1,description='Capacitance',readout_format='.1f')
7-
slider_cond_Na = ipywidgets.FloatSlider(value=120,min=80,max=160,step=0.1,description='Sodium',readout_format='.1f')
8-
slider_cond_K = ipywidgets.FloatSlider(value=36,min=0,max=80,step=0.1,description='Potassium',readout_format='.1f')
9-
slider_cond_L = ipywidgets.FloatSlider(value=0.3,min=0,max=1,step=0.1,description='Leak',readout_format='.1f')
10-
slider_pot_Na = ipywidgets.FloatSlider(value=50,min=-100,max=100,step=0.1,description='Sodium',readout_format='.1f')
11-
slider_pot_K = ipywidgets.FloatSlider(value=-77,min=-100,max=100,step=0.1,description='Potassium',readout_format='.1f')
12-
slider_pot_L = ipywidgets.FloatSlider(value=-54.387,min=-100,max=100,step=0.1,description='Leak',readout_format='.1f')
6+
header_simTime = ipywidgets.HTML(value=f"<b><font color='blue'>Simulation Time, ms</b>")
7+
slider_capacitance = ipywidgets.FloatSlider(value=1,min=0,max=3,step=0.1,description='Capacitance',readout_format='.1f',continuous_update=False)
8+
slider_cond_Na = ipywidgets.FloatSlider(value=120,min=80,max=160,step=0.1,description='Sodium',readout_format='.1f',continuous_update=False)
9+
slider_cond_K = ipywidgets.FloatSlider(value=36,min=0,max=80,step=0.1,description='Potassium',readout_format='.1f',continuous_update=False)
10+
slider_cond_L = ipywidgets.FloatSlider(value=0.3,min=0,max=1,step=0.1,description='Leak',readout_format='.1f',continuous_update=False)
11+
slider_pot_Na = ipywidgets.FloatSlider(value=50,min=-100,max=100,step=0.1,description='Sodium',readout_format='.1f',continuous_update=False)
12+
slider_pot_K = ipywidgets.FloatSlider(value=-77,min=-100,max=100,step=0.1,description='Potassium',readout_format='.1f',continuous_update=False)
13+
slider_pot_L = ipywidgets.FloatSlider(value=-54.387,min=-100,max=100,step=0.1,description='Leak',readout_format='.1f',continuous_update=False)
14+
time_start = ipywidgets.FloatText(value=0,description='Start Time',disabled=True)
15+
time_end = ipywidgets.FloatText(value=450,description='Total Time',disabled=False)
16+
time_step = ipywidgets.FloatText(value=0.01,description='Time Step',disabled=False)
17+
18+
def resetTodefault(_):
19+
slider_capacitance.value = 1
20+
slider_cond_Na.value = 120
21+
slider_cond_K.value = 36
22+
slider_cond_L.value = 0.3
23+
slider_pot_Na.value = 50
24+
slider_pot_K.value = -77
25+
slider_pot_L.value = -54.387
26+
time_start.value = 0
27+
time_end.value = 450
28+
time_step.value = 0.01
29+
30+
reset_button = ipywidgets.Button(description="Reset All")
31+
reset_button.on_click(resetTodefault)
1332

1433
h1=ipywidgets.HBox([header_capacitance])
1534
h2=ipywidgets.HBox([slider_capacitance])
1635
h3=ipywidgets.HBox([header_conductance])
1736
h4=ipywidgets.HBox([slider_cond_Na,slider_cond_K,slider_cond_L])
1837
h5=ipywidgets.HBox([header_potential])
1938
h6=ipywidgets.HBox([slider_pot_Na,slider_pot_K,slider_pot_L])
20-
v1=ipywidgets.VBox([h1,h2,h3,h4,h5,h6])
39+
h7=ipywidgets.HBox([header_simTime])
40+
h8=ipywidgets.HBox([time_start,time_end,time_step])
41+
h9=ipywidgets.HBox([reset_button])
42+
v1=ipywidgets.VBox([h1,h2,h3,h4,h5,h6,h7,h8,h9])

0 commit comments

Comments
 (0)