-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_simulation.py
347 lines (280 loc) · 9.46 KB
/
run_simulation.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/usr/bin/python
from neuron import h
from neuron import gui
import numpy as np
import os
import pickle
import cPickle
from scipy.stats.stats import pearsonr
import sys
sys.path.append(os.getcwd())
import itertools
print ('Setting cell model...')
neuron_num = 9
synaptic_map_file_name = 'synapse_location_for_neuron_{}.pickle'.format(neuron_num)
rate_E = 1.75
rate_I = 10
h.load_file('model_files/{}.hoc'.format(neuron_num))
h.v_init = -80
h.dt = 0.025
def set_cell(neuron_num):
h.load_file('model_files/{}.hoc'.format(neuron_num))
h('''
objref somatic, apical, axonal, basal
somatic = new SectionList()
basal = new SectionList()
apical = new SectionList()
axonal = new SectionList()
celsius=37
proc distribute(){local x localobj sl
strdef stmp,distfunc,mech
sl = $o1
mech = $s2
distfunc = $s3
sprint(distfunc,"%%s %s(%%f) = %s",mech, distfunc)
forsec sl for(x) {
sprint (stmp,distfunc,secname(),x,distance(x))
execute(stmp)
}
}
create axon[2]''')
h('''
access axon[0]
{
L = 30
diam = 0.66
nseg = 30
all.append()
axonal.append()
}
access axon[1]
{
L = 30
diam = 0.33
nseg = 30
all.append()
axonal.append()
}
nSecAxonal = 2
soma connect axon[0](0), 1
axon[0] connect axon[1](0), 1
''')
h("celsius = 37.0")
for sec in h.all:
if sec.name().startswith('soma') or sec.name().startswith('axon'): continue
h("{}.nseg = {}".format(sec.name(), max(eval('h.{}.L'.format(sec.name())), 1)))
for sec in h.all:
if sec.name().startswith('dend_5') or sec.name().startswith('apic'):
h('access {}'.format(sec.name()))
h('apical.append()')
h.pop_section()
elif sec.name().startswith('dend_7'):
h('access {}'.format(sec.name()))
h('basal.append()')
h.pop_section()
elif 'soma' in sec.name() or sec.name().startswith('dend_0'):
h('access {}'.format(sec.name()))
h('somatic.append()')
h.pop_section()
elif 'axon' in sec.name():
h('access {}'.format(sec.name()))
h('axonal.append()')
h.pop_section()
else:
print 'no section list for {}'.format(sec.name())
h('''
forsec all {
insert pas
}
forsec all {
e_pas = -75
}
forsec all {
Ra = 150
}
forsec all {
cm = 1
}
forsec all {
g_pas = 1.0 / 12000.0
}
forsec apical {
cm = 1
}
forsec basal {
cm = 1
}
''')
def active_soma():
h('''
forsec somatic {
insert Ca_HVA
insert SKv3_1
insert SK_E2
insert Ca_LVAst
insert Ih
insert NaTs2_t
insert CaDynamics_E2
}
forsec axonal {
insert Ca_HVA
insert SKv3_1
insert SK_E2
insert CaDynamics_E2
insert Nap_Et2
insert K_Pst
insert K_Tst
insert Ca_LVAst
insert NaTa_t
}
forsec axonal {
ena = 50
ek = -85
}
forsec somatic {
ena = 50
}
forsec somatic {
ek = -85
}
access soma
distance()
distribute(axonal,"gNaTa_tbar_NaTa_t","(0.0 * %g + 1.0)*3.429725")
distribute(axonal,"gK_Tstbar_K_Tst","(0.0 * %g + 1.0)*0.001035")
distribute(axonal,"gamma_CaDynamics_E2","(0.0 * %g + 1.0)*0.016713")
distribute(axonal,"gNap_Et2bar_Nap_Et2","(0.0 * %g + 1.0)*0.009803")
distribute(axonal,"gSK_E2bar_SK_E2","(0.0 * %g + 1.0)*0.008085")
distribute(axonal,"gCa_HVAbar_Ca_HVA","(0.0 * %g + 1.0)*0.000306")
distribute(axonal,"gK_Pstbar_K_Pst","(0.0 * %g + 1.0)*0.959296")
distribute(axonal,"gSKv3_1bar_SKv3_1","(0.0 * %g + 1.0)*0.094971")
distribute(axonal,"decay_CaDynamics_E2","(0.0 * %g + 1.0)*384.114655")
distribute(axonal,"gCa_LVAstbar_Ca_LVAst","(0.0 * %g + 1.0)*0.000050")
distribute(somatic,"gamma_CaDynamics_E2","(0.0 * %g + 1.0)*0.000533")
distribute(somatic,"gSKv3_1bar_SKv3_1","(0.0 * %g + 1.0)*0.102517")
distribute(somatic,"gSK_E2bar_SK_E2","(0.0 * %g + 1.0)*0.099433")
distribute(somatic,"gCa_HVAbar_Ca_HVA","(0.0 * %g + 1.0)*0.000374")
distribute(somatic,"gNaTs2_tbar_NaTs2_t","(0.0 * %g + 1.0)*0.926705")
distribute(somatic,"gIhbar_Ih","(0.0 * %g + 1.0)*0.000080")
distribute(somatic,"decay_CaDynamics_E2","(0.0 * %g + 1.0)*342.544232")
distribute(somatic,"gCa_LVAstbar_Ca_LVAst","(0.0 * %g + 1.0)*0.000778")
''')
def active_dendrites_tuned():
h('''
forsec basal {
insert Ih
}
forsec apical {
insert Im
insert NaTs2_t
insert SKv3_1
insert Ih
}
forsec apical {
ena = 50
ek = -85
}
access soma
distance()
distribute(basal,"gIhbar_Ih","(0.0 * %g + 1.0)*0.000080")
distribute(apical,"gNaTs2_tbar_NaTs2_t","(0.0 * %g + 1.0)*0.008009") // based on ttx comparison
// distribute(apical,"gNaTs2_tbar_NaTs2_t","(0.0 * %g + 1.0)*0.012009") // original
distribute(apical,"gSKv3_1bar_SKv3_1","(0.0 * %g + 1.0)*0.000513")
distribute(apical,"gIhbar_Ih","(-0.869600 + 2.087000*exp((%g-0.000000)*0.020100))*0.000080") // based on attenuation comparison
// distribute(apical,"gIhbar_Ih","(-0.869600 + 2.087000*exp((%g-0.000000)*0.003100))*0.000080") // original
distribute(apical,"gImbar_Im","(0.0 * %g + 1.0)*0.000740")
''')
set_cell(neuron_num)
active_soma()
active_dendrites_tuned()
print ('Setting parameters...')
duration_of_simulation = 1000
number_of_inhibitory_synapses_on_soma = 100
(spine_locations, full_IS_locations) = pickle.load(open('model_files/{}'.format(synaptic_map_file_name), 'rb'))
full_IS_locations = list(full_IS_locations)
for loc in np.linspace(0, 1, number_of_inhibitory_synapses_on_soma):
full_IS_locations.append(('soma', loc, 'soma',0,0))
h.tstop = duration_of_simulation
number_of_E_synapses = len(spine_locations)
number_of_I_synapses = len(full_IS_locations)
print ('Set recording...')
voltage_vectors = []
print ('Placing synapses...')
background_E_events = np.random.poisson(rate_E / 1000.0, size=(number_of_E_synapses, duration_of_simulation))
background_I_events = np.random.poisson(rate_I / 1000.0, size=(number_of_I_synapses, duration_of_simulation))
eSynlist = []
eNetconlist = []
iSynlist = []
iNetconlist = []
E_vcs = []
I_vcs = []
E_vcs_events = []
I_vcs_events = []
def placeNMDA(location, conductance):
eSynlist.append(h.ProbAMPANMDA2_RATIO(float(location)))
eSynlist[-1].gmax = conductance
eSynlist[-1].mgVoltageCoeff = 0.08
eNetconlist.append(h.NetCon(E_vcs[-1], eSynlist[-1]))
eNetconlist[-1].weight[0] = 1
eNetconlist[-1].delay = 0
def placeGABA(location, conductance):
iSynlist.append(h.ProbUDFsyn2_lark(float(location)))
iSynlist[-1].tau_r = 0.18
iSynlist[-1].tau_d = 5
iSynlist[-1].e = - 80
iSynlist[-1].gmax = conductance
iNetconlist.append(h.NetCon(I_vcs[-1], iSynlist[-1]))
iNetconlist[-1].weight[0] = 1
iNetconlist[-1].delay = 0
for sec in h.all:
if sec.name().startswith('soma') or sec.name().startswith('axon'): continue
h("{}.nseg = {}".format(sec.name(), max(eval('h.{}.L'.format(sec.name())), 1)))
for sec in h.all:
voltage_vectors.append(h.Vector())
voltage_vectors[-1].record(eval('h.{}({})._ref_v'.format(sec.name(), 0.5)))
spine_ind = 0
spine_firing_times = []
for sec, loc, branch_type, spine_head_width, spine_volume, spine_length in spine_locations:
h("access {}".format(sec))
h("nseg = {}".format(max(h.L, 1)))
E_vcs.append(h.VecStim())
E_vcs_events.append(h.Vector())
spine_firing_times.append([])
events = np.where(background_E_events[spine_ind, :].flatten())[0] + 100
for event in events:
E_vcs_events[-1].append(event)
spine_firing_times[-1].append(event)
E_vcs[-1].play(E_vcs_events[-1])
placeNMDA(loc, 0.0004)
spine_ind += 1
h.pop_section()
IS_ind = 0
IS_firing_times = []
for sec, loc, branch_type, IS_volume, on_spine in full_IS_locations:
h("access {}".format(sec))
h("nseg = {}".format(max(h.L, 1)))
I_vcs.append(h.VecStim())
I_vcs_events.append(h.Vector())
IS_firing_times.append([])
events = np.where(background_I_events[IS_ind, :].flatten())[0] + 100
for event in events:
I_vcs_events[-1].append(event)
IS_firing_times[-1].append(event)
I_vcs[-1].play(I_vcs_events[-1])
h("access {}".format(sec))
placeGABA(loc, 0.001)
h.pop_section()
IS_ind += 1
firing_times = np.zeros(shape=(int(number_of_E_synapses), int(h.tstop) + 100))
for ind in range(len(spine_firing_times)):
firing_times[ind, spine_firing_times[ind]] = 1
print ('Running...')
soma_voltageVector = h.Vector()
soma_voltageVector.record(h.soma(0.5)._ref_v)
timeVector = h.Vector()
timeVector.record(h._ref_t)
E_densities = []
I_densities = []
h.stdinit()
h.run()
voltage_vectors = np.array(voltage_vectors)
timeVector = np.array(timeVector)