-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrn.mustache
136 lines (103 loc) · 2.76 KB
/
nrn.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/ipython -i
from neuron import *
from nrn import *
def create_comp(name='soma'):
comp = h.Section(name)
comp.nseg = {{geometry.nseg}}
comp.L = {{geometry.L}}
comp.diam = {{geometry.diam}}
{{#mod_mechanisms}}
comp.insert('{{name}}')
{{#gbar.name}}
comp.{{gbar.name}} = {{gbar.val}}
{{/gbar.name}}
{{^gbar.name}}
comp.gbar_{{name}} = {{gbar}}
{{/gbar.name}}
{{#ion}}
comp.e{{ion}} = {{rev}}
{{/ion}}
{{^ion}}
comp.e{{name}} = {{rev}}
{{/ion}}
{{/mod_mechanisms}}
{{#nml_mechanisms}}
comp.insert('{{name}}')
{{#gbar.name}}
comp.{{gbar.name}} = {{gbar.val}}
{{/gbar.name}}
{{^gbar.name}}
comp.gbar_{{name}} = {{gbar}}
{{/gbar.name}}
{{#ion}}
comp.e{{ion}} = {{rev}}
{{/ion}}
{{^ion}}
comp.e{{name}} = {{rev}}
{{/ion}}
{{/nml_mechanisms}}
{{#passive}}
comp.insert('{{name}}')
comp.g{{ion}} = {{g}}
comp.e{{ion}} = {{rev}}
{{/passive}}
{{#reversals}}
{{/reversals}}
return comp
def get_next_hex_color():
from random import randint
return "#%06x" %randint(0,0xFFFFFF)
def plot_timeseries(vdict, varlist):
import matplotlib.pyplot as plt
t = vdict['t']
v = vdict['v']
fig = plt.figure(figsize=(10, 12))
ax = fig.add_subplot(2, 1, 1)
ax.plot(t, v, 'k-', linewidth=2)
ax.set_title('membrane potential')
ax.set_xlim([0, {{run.total}}])
ax2 = fig.add_subplot(2, 1, 2)
for n in range(1, len(varlist)):
ax2.plot(t, vdict[varlist[n]], label=varlist[n], color=get_next_hex_color(), linewidth=2)
ax2.set_title('recorded gating variables')
ax2.set_xlim([0, {{run.total}}])
ax2.set_xlabel('Time [ms]')
ax2.set_ylim([0, 1])
ax2.legend()
plt.show()
def create_dumps(section, varlist):
recordings = {n: h.Vector() for n in varlist}
for (vn, v) in recordings.iteritems():
v.record(section(0.5).__getattribute__('_ref_' + vn))
recordings['t'] = h.Vector()
recordings['t'].record(h._ref_t)
return recordings
def dump_to_file(vdict, varlist, fname='sccct.nrn.dat'):
from numpy import savetxt, array
vnames = ['t'] + varlist
X = array([vdict[x].to_python() for x in vnames]).T
savetxt(fname, X)
def run(tstop=10, dt=0.001):
h.dt = dt
h.finitialize({{run.v0}})
h.fcurrent()
h.frecord_init()
while h.t < tstop:
h.fadvance()
comp = create_comp('soma')
h.celsius = {{run.temp}}
inputs = []
{{#inputs}}
stim = h.IClamp(0.5, sec=comp)
stim.delay = {{delay}}
stim.dur = {{dur}}
stim.amp = {{amp}}
inputs.append(stim)
{{/inputs}}
varlist = {{record}}
ds = create_dumps(comp, varlist)
run({{run.total}}, {{run.dt}})
{{#plot}}
plot_timeseries(ds, varlist)
{{/plot}}
dump_to_file(ds, varlist)