Debian Codegraph @

examples/compartmental/infinite_cable.py

raw
1 """
2 An (almost) infinite cable with pulse injection in the middle.
3 """
4 from brian2 import *
5
6 defaultclock.dt = 0.001*ms
7
8 # Morphology
9 diameter = 1*um
10 Cm = 1*uF/cm**2
11 Ri = 100*ohm*cm
12 N = 500
13 morpho = Cylinder(diameter=diameter, length=3*mm, n=N)
14
15 # Passive channels
16 gL = 1e-4*siemens/cm**2
17 EL = -70*mV
18 eqs = '''
19 Im = gL * (EL-v) : amp/meter**2
20 I : amp (point current)
21 '''
22
23 neuron = SpatialNeuron(morphology=morpho, model=eqs, Cm=Cm, Ri=Ri,
24 method = 'exponential_euler')
25 neuron.v = EL
26
27 taum = Cm /gL # membrane time constant
28 print("Time constant: %s" % taum)
29 la = neuron.space_constant[0]
30 print("Characteristic length: %s" % la)
31
32 # Monitors
33 mon = StateMonitor(neuron, 'v', record=range(0, N//2, 20))
34
35 neuron.I[len(neuron) // 2] = 1*nA # injecting in the middle
36 run(0.02*ms)
37 neuron.I = 0*amp
38 run(10*ms, report='text')
39
40 t = mon.t
41 plot(t/ms, mon.v.T/mV, 'k')
42 # Theory (incorrect near cable ends)
43 for i in range(0, len(neuron)//2, 20):
44 x = (len(neuron)/2 - i) * morpho.length[0]
45 theory = (1/(la*Cm*pi*diameter) * sqrt(taum / (4*pi*(t + defaultclock.dt))) *
46 exp(-(t+defaultclock.dt)/taum -
47 taum / (4*(t+defaultclock.dt))*(x/la)**2))
48 theory = EL + theory * 1*nA * 0.02*ms
49 plot(t/ms, theory/mV, 'r')
50 xlabel('Time (ms)')
51 ylabel('v (mV')
52 show()