Skip to content

Instantly share code, notes, and snippets.

@coderforlife
Created September 7, 2013 08:53
Show Gist options
  • Save coderforlife/6473989 to your computer and use it in GitHub Desktop.
Save coderforlife/6473989 to your computer and use it in GitHub Desktop.
Hodgkin-Huxley Neuron Model
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "Hodgkin-Huxley"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from scipy.integrate import odeint\n",
"\n",
"C_m = 1.0 # uF / cm^2\n",
"I_ext = 10.0 # uA / cm^2\n",
"\n",
"g_Na = 120.0 # in mS/cm^2\n",
"g_K = 36.0\n",
"g_L = 0.3\n",
"\n",
"E_Na = + 45.0 # in mV\n",
"E_K = - 82.0\n",
"E_L = - 59.387\n",
"\n",
"def alpha_n(V): return 0.01 * (V + 60.0) / (1.0 - exp(-(V+60.0)/10.0)) # in msec^-1\n",
"def beta_n (V): return 0.125 * exp(-(V+70.0) / 80.0)\n",
"def alpha_m(V): return 0.1 * (V + 45.0) / (1.0 - exp(-(V+45.0)/10.0))\n",
"def beta_m (V): return 4.0 * exp(-(V+70)/18.0)\n",
"def alpha_h(V): return 0.07 * exp(-(V+70)/20.0)\n",
"def beta_h (V): return 1.0 / (1.0 + exp(-(V+40.0)/10.0))\n",
"\n",
"def I_K (V, n): return g_K * n**4 * (V - E_K ) # uA / cm^2\n",
"def I_Na(V, m, h): return g_Na * m**3 * h * (V - E_Na)\n",
"def I_L(V): return g_L * (V - E_L)\n",
"\n",
"def HH(X, t):\n",
" V, n, m, h = X\n",
" dV_dt = (I_ext - I_K(V, n) - I_Na(V, m, h) - I_L(V)) / C_m\n",
" dn_dt = alpha_n(V) * (1.0 - n) - beta_n(V) * n\n",
" dm_dt = alpha_m(V) * (1.0 - m) - beta_m(V) * m\n",
" dh_dt = alpha_h(V) * (1.0 - h) - beta_h(V) * h\n",
" return dV_dt, dn_dt, dm_dt, dh_dt\n",
"\n",
"t = arange(0.0, 500.0, 0.1) # in msec\n",
"X = odeint(HH, (-70.0, 0.32, 0.05, 0.6), t)\n",
"\n",
"V = X[:, 0]\n",
"n = X[:, 1]\n",
"m = X[:, 2]\n",
"h = X[:, 3]\n",
"\n",
"figure()\n",
"xlabel('Time (sec)')\n",
"ylabel('Membrane Potential (mV)')\n",
"plot(t, V)\n",
"\n",
"figure()\n",
"xlabel('Time (sec)')\n",
"ylabel('Gating Variable')\n",
"plot(t, n)\n",
"plot(t, m)\n",
"plot(t, h)"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment