Code: Select all
import numpy as np
from scipy.integrate import solve_ivp
# Define the Hodgkin-Huxley model parameters
Cm = 1.0 # membrane capacitance (uF/cm^2)
gNa = 120.0 # maximum sodium conductance (mS/cm^2)
ENa = 50.0 # sodium reversal potential (mV)
gK = 36.0 # maximum potassium conductance (mS/cm^2)
EK = -77.0 # potassium reversal potential (mV)
gL = 0.3 # maximum leak conductance (mS/cm^2)
EL = -54.387 # leak reversal potential (mV)
# Define the Hodgkin-Huxley model equations
def hh_model(t, y, I):
V, m, h, n = y
# Calculate the gating variable time constants
alpha_m = 0.1 * (V + 40.0) / (1.0 - np.exp(-0.1 * (V + 40.0)))
beta_m = 4.0 * np.exp(-0.0556 * (V + 65.0))
alpha_h = 0.07 * np.exp(-0.05 * (V + 65.0))
beta_h = 1.0 / (1.0 + np.exp(-0.1 * (V + 35.0)))
alpha_n = 0.01 * (V + 55.0) / (1.0 - np.exp(-0.1 * (V + 55.0)))
beta_n = 0.125 * np.exp(-0.0125 * (V + 65.0))
# Calculate the membrane currents
INa = gNa * m**3 * h * (V - ENa)
IK = gK * n**4 * (V - EK)
IL = gL * (V - EL)
dVdt = (I - INa - IK - IL) / Cm
# Calculate the gating variable changes
dmdt = alpha_m * (1.0 - m) - beta_m * m
dhdt = alpha_h * (1.0 - h) - beta_h * h
dndt = alpha_n * (1.0 - n) - beta_n * n
return [dVdt, dmdt, dhdt, dndt]
# Set the initial conditions and input current
y0 = [-65.0, 0.05, 0.6, 0.32]
I = 10.0 # input current (uA/cm^2)
# Set the time range for the simulation
t_start = 0.0
t_end = 100.0
dt = 0.01
t_span = np.arange(t_start, t_end+dt, dt)
# Solve the differential equations using solve_ivp
sol = solve_ivp(fun=lambda t, y: hh_model(t, y, I),
t_span=[t_start, t_end],
y0=y0,
method='RK45',
t_eval=t_span)
# Plot the results
import matplotlib.pyplot as plt
plt.plot(sol.t, sol.y[0], color='k')
plt.show()
Code: Select all
from neuron import h, gui
# Create a new point neuron
soma = h.Section()
soma.L = 20.0 # length (um)
soma.diam = 20.0 # diameter (um)
# Define the Hodgkin-Huxley model parameters
soma.insert("hh") # insert the HH mechanism
soma(0.5).hh.gnabar = 0.12 # sodium conductance (S/cm^2)
soma(0.5).hh.gkbar = 0.036 # potassium conductance (S/cm^2)
soma(0.5).hh.gl = 0.0003 # leak conductance (S/cm^2)
soma(0.5).hh.el = -54.3 # reversal potential for the leak current (mV)
# Create a current clamp to stimulate the neuron
stim = h.IClamp(soma(0.5))
stim.delay = 100.0 # delay before the stimulus (ms)
stim.dur = 500.0 # duration of the stimulus (ms)
stim.amp = 0.1885 # amplitude of the stimulus (nA)
# Create a vector to record the membrane potential
time = h.Vector()
voltage = h.Vector()
time.record(h._ref_t)
voltage.record(soma(0.5)._ref_v)
# Run the simulation
h.finitialize(-65.0)
h.continuerun(700.0)
# Plot the results
import matplotlib.pyplot as plt
plt.plot(time, voltage)
plt.xlabel('Time (ms)')
plt.ylabel('Voltage (mV)')
plt.show()
Any help would be greatly appreciated.