Debian Codegraph @

examples/compartmental/hh_with_spikes.py

raw
1 """
2 Hodgkin-Huxley equations (1952).
3
4 Spikes are recorded along the axon, and then velocity is calculated.
5 """
6 from brian2 import *
7 from scipy import stats
8
9 defaultclock.dt = 0.01*ms
10
11 morpho = Cylinder(length=10*cm, diameter=2*238*um, n=1000, type='axon')
12
13 El = 10.613*mV
14 ENa = 115*mV
15 EK = -12*mV
16 gl = 0.3*msiemens/cm**2
17 gNa0 = 120*msiemens/cm**2
18 gK = 36*msiemens/cm**2
19
20 # Typical equations
21 eqs = '''
22 # The same equations for the whole neuron, but possibly different parameter values
23 # distributed transmembrane current
24 Im = gl * (El-v) + gNa * m**3 * h * (ENa-v) + gK * n**4 * (EK-v) : amp/meter**2
25 I : amp (point current) # applied current
26 dm/dt = alpham * (1-m) - betam * m : 1
27 dn/dt = alphan * (1-n) - betan * n : 1
28 dh/dt = alphah * (1-h) - betah * h : 1
29 alpham = (0.1/mV) * 10*mV/exprel((-v+25*mV)/(10*mV))/ms : Hz
30 betam = 4 * exp(-v/(18*mV))/ms : Hz
31 alphah = 0.07 * exp(-v/(20*mV))/ms : Hz
32 betah = 1/(exp((-v+30*mV) / (10*mV)) + 1)/ms : Hz
33 alphan = (0.01/mV) * 10*mV/exprel((-v+10*mV)/(10*mV))/ms : Hz
34 betan = 0.125*exp(-v/(80*mV))/ms : Hz
35 gNa : siemens/meter**2
36 '''
37
38 neuron = SpatialNeuron(morphology=morpho, model=eqs, method="exponential_euler",
39 refractory="m > 0.4", threshold="m > 0.5",
40 Cm=1*uF/cm**2, Ri=35.4*ohm*cm)
41 neuron.v = 0*mV
42 neuron.h = 1
43 neuron.m = 0
44 neuron.n = .5
45 neuron.I = 0*amp
46 neuron.gNa = gNa0
47 M = StateMonitor(neuron, 'v', record=True)
48 spikes = SpikeMonitor(neuron)
49
50 run(50*ms, report='text')
51 neuron.I[0] = 1*uA # current injection at one end
52 run(3*ms)
53 neuron.I = 0*amp
54 run(50*ms, report='text')
55
56 # Calculation of velocity
57 slope, intercept, r_value, p_value, std_err = stats.linregress(spikes.t/second,
58 neuron.distance[spikes.i]/meter)
59 print("Velocity = %.2f m/s" % slope)
60
61 subplot(211)
62 for i in range(10):
63 plot(M.t/ms, M.v.T[:, i*100]/mV)
64 ylabel('v')
65 subplot(212)
66 plot(spikes.t/ms, spikes.i*neuron.length[0]/cm, '.k')
67 plot(spikes.t/ms, (intercept+slope*(spikes.t/second))/cm, 'r')
68 xlabel('Time (ms)')
69 ylabel('Position (cm)')
70 show()