-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsingle_olive_iclamp_nrn.py
218 lines (161 loc) · 7.65 KB
/
single_olive_iclamp_nrn.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
'''
Neuron simulator export for:
Components:
null (Type: include)
na_s (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
null (Type: annotation)
kdr (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
null (Type: annotation)
k (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
null (Type: annotation)
cal (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
leak (Type: ionChannelPassive: conductance=1.0E-11 (SI conductance))
null (Type: annotation)
cah (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
kca (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
null (Type: annotation)
h (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
ca_conc (Type: fixedFactorConcentrationModel: restingConc=0.0 (SI concentration) decayConstant=0.013333333333333 (SI time) rho=300000.0 (SI rho_factor))
null (Type: include)
na_a (Type: ionChannelHH: conductance=1.0E-11 (SI conductance))
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
null (Type: include)
cell (Type: cell)
null (Type: include)
iclamp0 (Type: pulseGenerator: delay=0.5 (SI time) duration=0.2 (SI time) amplitude=-3.0E-10 (SI current))
net (Type: networkWithTemperature: temperature=300.15 (SI temperature))
sim1 (Type: Simulation: length=2.0 (SI time) step=2.5E-5 (SI time))
This NEURON file has been generated by org.neuroml.export (see https://github.com/NeuroML/org.neuroml.export)
org.neuroml.export v1.4.6
org.neuroml.model v1.4.6
jLEMS v0.9.8.6
'''
import neuron
import time
h = neuron.h
h.load_file("nrngui.hoc")
h("objref p")
h("p = new PythonObject()")
class NeuronSimulation():
def __init__(self, tstop, dt):
print("\n Starting simulation in NEURON generated from NeuroML2 model...\n")
# Adding simulation Component(id=sim1 type=Simulation) of network/component: net (Type: networkWithTemperature: temperature=300.15 (SI temperature))
# Temperature used for network: 300.15 K
h.celsius = 300.15 - 273.15
print("Population pop contains 1 instance(s) of component: cell of type: cell")
print("Setting the default initial concentrations for ca (used in cell) to 3.7152 mM (internal), 3.0 mM (external)")
h("cai0_ca_ion = 3.7152")
h("cao0_ca_ion = 3.0")
h.load_file("cell.hoc")
a_pop = []
h("{ n_pop = 1 }")
h("objectvar a_pop[n_pop]")
for i in range(int(h.n_pop)):
h("a_pop[%i] = new cell()"%i)
h("access a_pop[%i].soma"%i)
h("{ a_pop[0].position(0, 0, 0) }")
h("proc initialiseV_pop() { for i = 0, n_pop-1 { a_pop[i].set_initial_v() } }")
h("objref fih_pop")
h('{fih_pop = new FInitializeHandler(0, "initialiseV_pop()")}')
h("proc initialiseIons_pop() { for i = 0, n_pop-1 { a_pop[i].set_initial_ion_properties() } }")
h("objref fih_ion_pop")
h('{fih_ion_pop = new FInitializeHandler(1, "initialiseIons_pop()")}')
# Adding input: Component(id=0 type=input)
h("objref Clamps_0")
h("a_pop[0].soma { Clamps_0 = new iclamp0(0.500000) } ")
trec = h.Vector()
trec.record(h._ref_t)
h.tstop = tstop
h.dt = dt
h.steps_per_ms = 1/h.dt
# Display: self.display_d1
self.display_d1 = h.Graph(0)
self.display_d1.size(0,h.tstop,-80.0,50.0)
self.display_d1.view(0, -80.0, h.tstop, 130.0, 80, 330, 330, 250)
h.graphList[0].append(self.display_d1)
# Line, plotting: pop/0/cell/0/v
self.display_d1.addexpr("a_pop[0].soma.v(0.5)", "a_pop[0].soma.v(0.5)", 1, 1, 0.8, 0.9, 2)
# Line, plotting: pop/0/cell/1/v
self.display_d1.addexpr("a_pop[0].dend.v(0.5)", "a_pop[0].dend.v(0.5)", 2, 1, 0.8, 0.9, 2)
# Line, plotting: pop/0/cell/2/v
self.display_d1.addexpr("a_pop[0].axon.v(0.5)", "a_pop[0].axon.v(0.5)", 3, 1, 0.8, 0.9, 2)
# File to save: time
# Column: time
h(' objectvar v_time ')
h(' { v_time = new Vector() } ')
h(' { v_time.record(&t) } ')
h.v_time.resize((h.tstop * h.steps_per_ms) + 1)
# File to save: outf
# Column: pop/0/cell/0/v
h(' objectvar v_v_outf ')
h(' { v_v_outf = new Vector() } ')
h(' { v_v_outf.record(&a_pop[0].soma.v(0.5)) } ')
h.v_v_outf.resize((h.tstop * h.steps_per_ms) + 1)
# Column: pop/0/cell/1/v
h(' objectvar v_v_outf_ ')
h(' { v_v_outf_ = new Vector() } ')
h(' { v_v_outf_.record(&a_pop[0].dend.v(0.5)) } ')
h.v_v_outf_.resize((h.tstop * h.steps_per_ms) + 1)
# Column: pop/0/cell/2/v
h(' objectvar v_v_outf__ ')
h(' { v_v_outf__ = new Vector() } ')
h(' { v_v_outf__.record(&a_pop[0].axon.v(0.5)) } ')
h.v_v_outf__.resize((h.tstop * h.steps_per_ms) + 1)
# Column: pop/0/cell/1/caConc
h(' objectvar v_v_outf___ ')
h(' { v_v_outf___ = new Vector() } ')
h(' { v_v_outf___.record(&a_pop[0].dend.cai(0.5)) } ')
h.v_v_outf___.resize((h.tstop * h.steps_per_ms) + 1)
self.initialized = False
self.sim_end = -1 # will be overwritten
h.nrncontrolmenu()
def run(self):
self.initialized = True
sim_start = time.time()
print("Running a simulation of %sms (dt = %sms)" % (h.tstop, h.dt))
h.run()
self.sim_end = time.time()
sim_time = self.sim_end - sim_start
print("Finished NEURON simulation in %f seconds (%f mins)..."%(sim_time, sim_time/60.0))
self.save_results()
def advance(self):
if not self.initialized:
h.finitialize()
self.initialized = True
h.fadvance()
def save_results(self):
print("Saving results at t=%s..."%h.t)
if self.sim_end < 0: self.sim_end = time.time()
self.display_d1.exec_menu("View = plot")
# File to save: time
py_v_time = [ t/1000 for t in h.v_time.to_python() ] # Convert to Python list for speed...
f_time_f2 = open('time.dat', 'w')
for i in range(int(h.tstop * h.steps_per_ms) + 1):
f_time_f2.write('%f'% py_v_time[i]) # Save in SI units...+ '\n')
f_time_f2.close()
print("Saved data to: time.dat")
# File to save: outf
py_v_v_outf = [ float(x / 1000.0) for x in h.v_v_outf.to_python() ] # Convert to Python list for speed, variable has dim: voltage
py_v_v_outf_ = [ float(x / 1000.0) for x in h.v_v_outf_.to_python() ] # Convert to Python list for speed, variable has dim: voltage
py_v_v_outf__ = [ float(x / 1000.0) for x in h.v_v_outf__.to_python() ] # Convert to Python list for speed, variable has dim: voltage
py_v_v_outf___ = [ float(x ) for x in h.v_v_outf___.to_python() ] # Convert to Python list for speed, variable has dim: concentration
f_outf_f2 = open('single_olive_iclamp.dat', 'w')
for i in range(int(h.tstop * h.steps_per_ms) + 1):
f_outf_f2.write('%e\t'% py_v_time[i] + '%e\t'%(py_v_v_outf[i]) + '%e\t'%(py_v_v_outf_[i]) + '%e\t'%(py_v_v_outf__[i]) + '%e\t'%(py_v_v_outf___[i]) + '\n')
f_outf_f2.close()
print("Saved data to: single_olive_iclamp.dat")
save_end = time.time()
save_time = save_end - self.sim_end
print("Finished saving results in %f seconds"%(save_time))
print("Done")
if __name__ == '__main__':
ns = NeuronSimulation(tstop=2000 , dt=0.025)
ns.run()