File: build_network.py

package info (click to toggle)
bmtk 0.0%2Bgit20210109.8572664%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 74,876 kB
  • sloc: python: 24,853; javascript: 1,998; makefile: 34; sh: 16
file content (369 lines) | stat: -rw-r--r-- 16,355 bytes parent folder | download | duplicates (2)
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import os
import numpy as np

from bmtk.builder.networks import NetworkBuilder


# Step 1: Create a v1 mock network of 14 cells (nodes) with across 7 different cell "types"
net = NetworkBuilder("v1")
net.add_nodes(N=2,  # specifiy the number of cells belong to said group.
              pop_name='Scnn1a', location='VisL4', ei='e',  # pop_name, location, and ei are optional parameters that help's identifies properties of the cells. The modeler can choose whatever key-value pairs as they deem appropiate.
              positions=[(28.753, -364.868, -161.705),  # The following properties we are passing in lists
                         (48.753, -344.868, -141.705)], # of size N. Doing so will uniquely assign different
              tuning_angle=[0.0, 25.0],                 #  values to each individual cell
              rotation_angle_yaxis=[3.55501, 3.81531],
              rotation_angle_zaxis=-3.646878266, # Note that the y-axis rotation is differnt for each cell (ie. given a list of size N), but with z-axis rotation all cells have the same value
              model_type='biophysical',  # The type of cell we are using
              model_template='ctdb:Biophys1.hoc',  # Tells the simulator that when building cells models use a hoc_template specially created for parsing Allen Cell-types file models. Value would be different if we were using NeuronML or different model files
              model_processing='aibs_perisomatic',  # further instructions for how to processes a cell model. In this case aibs_perisomatic is a built-in directive to cut the axon in a specific way
              dynamics_params='472363762_fit.json',  # Name of file (downloaded from Allen Cell-Types) used to set model parameters and channels
              morphology='Scnn1a-Tg3-Cre_Ai14_IVSCC_-177300.01.02.01_473845048_m.swc')  # Name of morphology file downloaded

net.add_nodes(N=2, pop_name='Rorb', location='VisL4', ei='e',
              positions=[(241.092, -349.263, 146.916), (201.092, -399.263, 126.916)],
              tuning_angle=[50.0, 75.0],
              rotation_angle_yaxis=[3.50934, 3.50934],
              model_type='biophysical',
              model_template='ctdb:Biophys1.hoc',
              model_processing='aibs_perisomatic',
              dynamics_params='473863510_fit.json',
              morphology='Rorb-IRES2-Cre-D_Ai14_IVSCC_-168053.05.01.01_325404214_m.swc',
              rotation_angle_zaxis=-4.159763785)

net.add_nodes(N=2, pop_name='Nr5a1', location='VisL4', ei='e',
              positions=[(320.498, -351.259, 20.273), (310.498, -371.259, 10.273)],
              tuning_angle=[100.0, 125.0],
              rotation_angle_yaxis=[0.72202, 0.72202],
              model_type='biophysical',
              model_template='ctdb:Biophys1.hoc',
              model_processing='aibs_perisomatic',
              dynamics_params='473863035_fit.json',
              morphology='Nr5a1-Cre_Ai14_IVSCC_-169250.03.02.01_471087815_m.swc',
              rotation_angle_zaxis=-2.639275277)

# Note that in the previous cells we set the tuning_angle, but for PV1 and PV2 such parameter is absent (as it is not
# applicable for inhibitory cells). The BMTK builder allows heterogeneous cell properties as dictated by the model
net.add_nodes(N=2, pop_name='PV1', location='VisL4', ei='i',
              positions=[(122.373, -352.417, -216.748), (102.373, -342.417, -206.748)],
              rotation_angle_yaxis=[2.92043, 2.92043],
              model_type='biophysical',
              model_template='ctdb:Biophys1.hoc',
              model_processing='aibs_perisomatic',
              dynamics_params='472912177_fit.json',
              morphology='Pvalb-IRES-Cre_Ai14_IVSCC_-176847.04.02.01_470522102_m.swc',
              rotation_angle_zaxis=-2.539551891)

net.add_nodes(N=2, pop_name='PV2', location='VisL4', ei='i',
              positions=[(350.321, -372.535, -18.282), (360.321, -371.535, -12.282)],
              rotation_angle_yaxis=[5.043336, 5.043336],
              model_type='biophysical',
              model_template='ctdb:Biophys1.hoc',
              model_processing='aibs_perisomatic',
              dynamics_params='473862421_fit.json',
              morphology='Pvalb-IRES-Cre_Ai14_IVSCC_-169125.03.01.01_469628681_m.swc',
              rotation_angle_zaxis=-3.684439949)


# Along with our biophysical cells our network will also include integate-and-fire point cells
net.add_nodes(N=2, pop_name='LIF_exc', location='VisL4', ei='e',
              positions=[(-243.04, -342.352, -665.666), (-233.04, -332.352, -675.666)],
              tuning_angle=[150.0, 175.0],
              model_type='point_process',  # use point_process to indicate were are using point model cells
              model_template='nrn:IntFire1',  # Tell the simulator to use the NEURON built-in IntFire1 type cell
              dynamics_params='IntFire1_exc_1.json')

net.add_nodes(N=2, pop_name='LIF_inh', location='VisL4', ei='i',
              positions=[(211.04, -321.333, -631.593), (218.04, -327.333, -635.593)],
              model_type='point_process',
              model_template='nrn:IntFire1',
              dynamics_params='IntFire1_inh_1.json')


# Step 2: We want to connect our network. Just like how we have node-types concept we group our connections into
# "edge-types" that share rules and properties
net.add_edges(source={'ei': 'i'},  # For our synaptic source cells we select all inhibitory cells (ei==i), incl. both biophys and point
              target={'ei': 'i', 'model_type': 'biophysical'},  # For our synaptic target we select all inhibitory biophysically detailed cells
              connection_rule=5,  # All matching source/target pairs will have
              syn_weight=0.0002,  # synaptic weight
              target_sections=['somatic', 'basal'],  # Gives the simulator the target sections and
              distance_range=[0.0, 1e+20],           # distances (from soma) when creating connections
              delay=2.0,
              dynamics_params='GABA_InhToInh.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'i'}, target={'ei': 'i', 'model_type': 'point_process'},
              connection_rule=5,
              syn_weight=0.00225,
              weight_function='wmax',
              delay=2.0,
              dynamics_params='instanteneousInh.json')

net.add_edges(source={'ei': 'i'}, target={'ei': 'e', 'model_type': 'biophysical'},
              connection_rule=lambda trg, src: 5,
              syn_weight=0.00018,
              weight_function='wmax',
              distance_range=[0.0, 50.0],
              target_sections=['somatic', 'basal', 'apical'],
              delay=2.0,
              dynamics_params='GABA_InhToExc.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'i'}, target={'ei': 'e', 'model_type': 'point_process'},
              connection_rule=5,
              syn_weight=0.009,
              weight_function='wmax',
              delay=2.0,
              dynamics_params='instanteneousInh.json')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'PV1'},
              connection_rule=5,
              syn_weight=0.00035,
              weight_function='wmax',
              distance_range=[0.0, 1e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              dynamics_params='AMPA_ExcToInh.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'PV2'},
              connection_rule=5,
              syn_weight=0.00027,
              weight_function='wmax',
              distance_range=[0.0, 1e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              dynamics_params='AMPA_ExcToInh.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_inh'},
              connection_rule=5,
              syn_weight=0.0043,
              weight_function='wmax',
              delay=2.0,
              dynamics_params='instanteneousExc.json')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Scnn1a'},
              connection_rule=5,
              syn_weight=6.4e-05,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              distance_range=[30.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Rorb'},
              connection_rule=5,
              syn_weight=5.5e-05,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              distance_range=[30.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Nr5a1'},
              connection_rule=5,
              syn_weight=7.2e-05,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              distance_range=[30.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_exc'},
              connection_rule=5,
              syn_weight=0.0019,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              delay=2.0,
              dynamics_params='instanteneousExc.json')


net.build()
net.save(output_dir='network')


def generate_positions(N, x0=0.0, x1=300.0, y0=0.0, y1=100.0):
    X = np.random.uniform(x0, x1, N)
    Y = np.random.uniform(y0, y1, N)
    return np.column_stack((X, Y))


def select_source_cells(src_cells, trg_cell, n_syns):
    if 'tuning_angle' in trg_cell:
        synapses = [n_syns if src['pop_name'] == 'tON' or src['pop_name'] == 'tOFF' else 0 for src in src_cells]
    else:
        synapses = [n_syns if src['pop_name'] == 'tONOFF' else 0 for src in src_cells]

    return synapses


lgn = NetworkBuilder("lgn")
lgn.add_nodes(N=30, pop_name='tON', ei='e', location='LGN',
              positions=generate_positions(30),
              model_type='virtual')

lgn.add_nodes(N=30, pop_name='tOFF', ei='e', location='LGN',
              positions=generate_positions(30),
              model_type='virtual')

lgn.add_nodes(N=30, pop_name='tONOFF', ei='e', location='LGN',
              positions=generate_positions(30),
              model_type='virtual')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='Rorb'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=5e-05,
              weight_function='wmax',
              distance_range=[0.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='Nr5a1'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=5e-05,
              weight_function='wmax',
              distance_range=[0.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='Scnn1a'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=4e-05,
              weight_function='wmax',
              distance_range=[0.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='PV1'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=0.0001,
              weight_function='wmax',
              distance_range=[0.0, 1.0e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              dynamics_params='AMPA_ExcToInh.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='PV2'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=9e-05,
              weight_function='wmax',
              distance_range=[0.0, 1.0e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              dynamics_params='AMPA_ExcToInh.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='LIF_exc'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=0.0045,
              weight_function='wmax',
              delay=2.0,
              dynamics_params='instanteneousExc.json')

lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='LIF_inh'),
              iterator='all_to_one',
              connection_rule=select_source_cells,
              connection_params={'n_syns': 10},
              syn_weight=0.002,
              weight_function='wmax',
              delay=2.0,
              dynamics_params='instanteneousExc.json')

lgn.build()
lgn.save(output_dir='network')


tw = NetworkBuilder("tw")
tw.add_nodes(N=30, pop_name='TW', ei='e', location='TW', model_type='virtual')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='Rorb'),
             connection_rule=5,
             syn_weight=0.00015,
             weight_function='wmax',
             distance_range=[30.0, 150.0],
             target_sections=['basal', 'apical'],
             delay=2.0,
             dynamics_params='AMPA_ExcToExc.json',
             model_template='exp2syn')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='Scnn1a'),
             connection_rule=5,
             syn_weight=0.00019,
             weight_function='wmax',
             distance_range=[30.0, 150.0],
             target_sections=['basal', 'apical'],
             delay=2.0,
             dynamics_params='AMPA_ExcToExc.json',
             model_template='exp2syn')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='Nr5a1'),
             connection_rule=5,
             syn_weight=0.00019,
             weight_function='wmax',
             distance_range=[30.0, 150.0],
             target_sections=['basal', 'apical'],
             delay=2.0,
             dynamics_params='AMPA_ExcToExc.json',
             model_template='exp2syn')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='PV1'),
             connection_rule=5,
             syn_weight=0.0022,
             weight_function='wmax',
             distance_range=[0.0, 1.0e+20],
             target_sections=['basal', 'somatic'],
             delay=2.0,
             dynamics_params='AMPA_ExcToInh.json',
             model_template='exp2syn')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='PV2'),
             connection_rule = 5,
             syn_weight = 0.0013,
             weight_function = 'wmax',
             distance_range = [0.0, 1.0e+20],
             target_sections = ['basal', 'somatic'],
             delay = 2.0,
             dynamics_params = 'AMPA_ExcToInh.json',
             model_template = 'exp2syn')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='LIF_exc'),
             connection_rule=5,
             syn_weight=0.015,
             weight_function='wmax',
             delay=2.0,
             dynamics_params='instanteneousExc.json')

tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='LIF_inh'),
             connection_rule=5,
             syn_weight=0.05,
             weight_function='wmax',
             delay=2.0,
             dynamics_params='instanteneousExc.json')

tw.build()
tw.save(output_dir='network')