-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanced.py
More file actions
217 lines (159 loc) · 7.56 KB
/
Copy pathBalanced.py
File metadata and controls
217 lines (159 loc) · 7.56 KB
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
'''
Generates a NeuroML 2 file with many types of cells, populations and inputs
for testing purposes
'''
import opencortex.core as oc
import sys
min_pop_size = 3
def scale_pop_size(baseline, scale):
return max(min_pop_size, int(baseline*scale))
def generate(reference = "Balanced",
num_bbp =1,
scalePops = 1,
scalex=1,
scaley=1,
scalez=1,
connections=True,
duration = 1000,
input_rate = 150,
global_delay = 0,
max_in_pop_to_plot_and_save = 5,
gen_spike_saves_for_all_somas = True,
format='xml'):
num_exc = scale_pop_size(80,scalePops)
num_inh = scale_pop_size(40,scalePops)
nml_doc, network = oc.generate_network(reference)
oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml')
oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml')
if num_bbp>0:
oc.include_opencortex_cell(nml_doc, 'BlueBrainProject_NMC/cADpyr229_L23_PC_5ecbf9b163_0_0.cell.nml')
xDim = 400*scalex
yDim = 500*scaley
zDim = 300*scalez
xs = -200
ys = -150
zs = 100
##### Synapses
synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="1nS",
erev="0mV", tau_rise="0.5ms", tau_decay="5ms")
synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="2nS",
erev="-80mV", tau_rise="1ms", tau_decay="20ms")
##### Input types
pfs1 = oc.add_poisson_firing_synapse(nml_doc,
id="psf1",
average_rate="%s Hz"%input_rate,
synapse_id=synAmpa1.id)
##### Populations
popExc = oc.add_population_in_rectangular_region(network,
'popExc',
'HH_477127614',
num_exc,
xs,ys,zs,
xDim,yDim,zDim)
popInh = oc.add_population_in_rectangular_region(network,
'popInh',
'HH_476686112',
num_inh,
xs,ys,zs,
xDim,yDim,zDim)
if num_bbp == 1:
popBBP = oc.add_single_cell_population(network,
'popBBP',
'cADpyr229_L23_PC_5ecbf9b163_0_0',
z=200)
elif num_bbp > 1:
popBBP = oc.add_population_in_rectangular_region(network,
'popBBP',
'cADpyr229_L23_PC_5ecbf9b163_0_0',
num_bbp,
xs,ys,zs,
xDim,yDim,zDim)
##### Projections
total_conns = 0
if connections:
proj = oc.add_probabilistic_projection(network, "proj0",
popExc, popExc,
synAmpa1.id, 0.5, delay = global_delay)
total_conns += len(proj.connection_wds)
proj = oc.add_probabilistic_projection(network, "proj1",
popExc, popInh,
synAmpa1.id, 0.7, delay = global_delay)
total_conns += len(proj.connection_wds)
proj = oc.add_probabilistic_projection(network, "proj3",
popInh, popExc,
synGaba1.id, 0.7, delay = global_delay)
total_conns += len(proj.connection_wds)
proj = oc.add_probabilistic_projection(network, "proj4",
popInh, popInh,
synGaba1.id, 0.5, delay = global_delay)
total_conns += len(proj.connection_wds)
if num_bbp>0:
proj = oc.add_probabilistic_projection(network, "proj5",
popExc, popBBP,
synAmpa1.id, 0.5, delay = global_delay)
total_conns += len(proj.connection_wds)
##### Inputs
oc.add_inputs_to_population(network, "Stim0",
popExc, pfs1.id,
all_cells=True)
##### Save NeuroML and LEMS Simulation files
nml_file_name = '%s.net.%s'%(network.id,'nml.h5' if format == 'hdf5' else 'nml')
oc.save_network(nml_doc,
nml_file_name,
validate=(format=='xml'),
format = format)
if format=='xml':
plot_v = {popExc.id:[],popInh.id:[]}
save_v = {'%s_v.dat'%popExc.id:[],'%s_v.dat'%popInh.id:[]}
if num_bbp>0:
plot_v[popBBP.id]=[]
save_v['%s_v.dat'%popBBP.id]=[]
for i in range(min(max_in_pop_to_plot_and_save,num_exc)):
plot_v[popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component))
save_v['%s_v.dat'%popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component))
for i in range(min(max_in_pop_to_plot_and_save,num_inh)):
plot_v[popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component))
save_v['%s_v.dat'%popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component))
for i in range(min(max_in_pop_to_plot_and_save,num_bbp)):
plot_v[popBBP.id].append("%s/%i/%s/v"%(popBBP.id,i,popBBP.component))
save_v['%s_v.dat'%popBBP.id].append("%s/%i/%s/v"%(popBBP.id,i,popBBP.component))
lems_file_name = oc.generate_lems_simulation(nml_doc, network,
nml_file_name,
duration = duration,
dt = 0.025,
gen_plots_for_all_v = False,
gen_plots_for_quantities = plot_v,
gen_saves_for_all_v = False,
gen_saves_for_quantities = save_v,
gen_spike_saves_for_all_somas = gen_spike_saves_for_all_somas)
else:
lems_file_name = None
return nml_doc, nml_file_name, lems_file_name
if __name__ == '__main__':
if '-all' in sys.argv:
generate()
generate(num_bbp =10,
scalePops = 5,
scalex=2,
scalez=2,
connections=False)
generate(num_bbp =10,
scalePops = 5,
scalex=2,
scalez=2,
global_delay = 2)
generate(num_bbp =0,
scalePops = 2,
scalex=2,
scalez=2,
duration = 2000,
global_delay = 2)
else:
generate(num_bbp = 1,
scalePops = 3,
scalex=2,
scalez=2,
duration = 1000,
max_in_pop_to_plot_and_save = 5,
global_delay = 2,
input_rate=250)