daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jan 16th, 2018 84 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. import scipy as sp
  2. import pylab as plt
  3. from scipy.integrate import odeint
  4. from scipy import stats
  5. import scipy.linalg as lin
  6.  
  7. ## Full Hodgkin-Huxley Model (copied from Computational Lab 2)
  8.  
  9. # Constants
  10. C_m  =   1.0 # membrane capacitance, in uF/cm^2
  11. g_Na = 5.0 # maximum conducances, in mS/cm^2
  12. g_K  =  30.0
  13. g_L  =   0.2
  14. E_Na =  50.0 # Nernst reversal potentials, in mV
  15. E_K  = -80.0
  16. E_L  = -70.0
  17.  
  18. # Channel gating kinetics
  19. # Functions of membrane voltage
  20. def alpha_m(V): return 0.4 * (V + 66.0) / (1.0 - sp.exp(-(V + 66.0)/5.0))
  21. def beta_m(V): return 0.4 * (-(V + 32.0)) / (1.0 - sp.exp((V + 32.0)/5.0))
  22. def h_inf(V): return 1.0 / (1.0 + sp.exp((V + 65.0)/7.0))
  23. def h_tau(V): return 30.0 / (sp.exp((V + 60.0)/15.0) + sp.exp(-(V + 60.0)/16.0))
  24. def n_inf(V): return 1.0 / (1.0 + sp.exp(-(V + 38.0)/15.0))
  25. def n_tau(V): return 5.0/ (sp.exp((V + 50.0)/40.0) + sp.exp(-(V + 50.0)/50.0))
  26.  
  27. # Membrane currents (in uA/cm^2)
  28. #  Sodium (Na = element name)
  29. def I_Na(V,m,h):return g_Na * m**3 * h * (V - E_Na)
  30. #  Potassium (K = element name)
  31. def I_K(V, n):  return g_K  * n**4     * (V - E_K)
  32. #  Leak
  33. def I_L(V):     return g_L             * (V - E_L)
  34.  
  35. # External current
  36. def I_inj(t):
  37.     return 7.0 # 7 uA/cm^2
  38.  
  39. # The time to integrate over
  40. t = sp.arange(0.0, 150.0, 0.1)
  41.  
  42. # Integrate!
  43. def dALLdt(X, t):
  44.     V, m, h, n = X
  45.  
  46.     #calculate membrane potential & activation variables
  47.     dVdt = (I_inj(t) - I_Na(V, m, h) - I_K(V, n) - I_L(V)) / C_m
  48.     dmdt = alpha_m(V)*(1.0-m) - beta_m(V)*m
  49.     dhdt = (h_inf(V) - h) / h_tau(V)
  50.     dndt = (n_inf(V) - n) / n_tau(V)
  51.     return dVdt, dmdt, dhdt, dndt
  52.  
  53. # X = odeint(dALLdt, [-65, 0.05, 0.6, 0.32], t)
  54. X = odeint(dALLdt, [-65, alpha_m(-65)/(alpha_m(-65) + beta_m(-65)), h_inf(-65), n_inf(-65)], t)
  55. V = X[:,0]
  56. m = X[:,1]
  57. h = X[:,2]
  58. n = X[:,3]
  59. ina = I_Na(V,m,h)
  60. ik = I_K(V, n)
  61. il = I_L(V)
  62.  
  63. plt.figure()
  64.  
  65. plt.subplot(4,1,1)
  66. plt.title('Hodgkin-Huxley Neuron')
  67. plt.plot(t, V, 'k')
  68. plt.ylabel('V (mV)')
  69.  
  70. plt.subplot(4,1,2)
  71. plt.plot(t, ina, 'c', label='$I_{Na}$')
  72. plt.plot(t, ik, 'y', label='$I_{K}$')
  73. plt.plot(t, il, 'm', label='$I_{L}$')
  74. plt.ylabel('Current')
  75. plt.legend()
  76.  
  77. plt.subplot(4,1,3)
  78. plt.plot(t, m, 'r', label='m')
  79. plt.plot(t, h, 'g', label='h')
  80. plt.plot(t, n, 'b', label='n')
  81. plt.ylabel('Gating Value')
  82. plt.legend()
  83.  
  84. # plt.subplot(4,1,4)
  85. # plt.plot(t, I_inj(t), 'k')
  86. # plt.xlabel('t (ms)')
  87. # plt.ylabel('$I_{inj}$ ($\\mu{A}/cm^2$)')
  88. # plt.ylim(-1, 31)
  89.  
  90. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top