| 1 |
import os |
| 2 |
import numpy as np |
| 3 |
|
| 4 |
from bmtk.builder import NetworkBuilder |
| 5 |
from bmtk.builder.auxi.node_params import positions_columinar, xiter_random |
| 6 |
|
| 7 |
|
| 8 |
# List of non-virtual cell models |
| 9 |
bio_models = [ |
| 10 |
{ |
| 11 |
'model_name': 'Scnn1a', 'ei': 'e', |
| 12 |
'morphology': 'Scnn1a_473845048_m.swc', |
| 13 |
'model_template': 'ctdb:Biophys1.hoc', |
| 14 |
'dynamics_params': '472363762_fit.json' |
| 15 |
}, |
| 16 |
{ |
| 17 |
'model_name': 'Rorb', 'ei': 'e', |
| 18 |
'morphology': 'Rorb_325404214_m.swc', |
| 19 |
'model_template': 'ctdb:Biophys1.hoc', |
| 20 |
'dynamics_params': '473863510_fit.json' |
| 21 |
}, |
| 22 |
{ |
| 23 |
'model_name': 'Nr5a1', 'ei': 'e', |
| 24 |
'morphology': 'Nr5a1_471087815_m.swc', |
| 25 |
'model_template': 'ctdb:Biophys1.hoc', |
| 26 |
'dynamics_params': '473863035_fit.json' |
| 27 |
}, |
| 28 |
{ |
| 29 |
'model_name': 'PV1', 'ei': 'i', |
| 30 |
'morphology': 'Pvalb_470522102_m.swc', |
| 31 |
'model_template': 'ctdb:Biophys1.hoc', |
| 32 |
'dynamics_params': '472912177_fit.json' |
| 33 |
}, |
| 34 |
{ |
| 35 |
'model_name': 'PV2', 'ei': 'i', |
| 36 |
'morphology': 'Pvalb_469628681_m.swc', |
| 37 |
'model_template': 'ctdb:Biophys1.hoc', |
| 38 |
'dynamics_params': '473862421_fit.json' |
| 39 |
} |
| 40 |
] |
| 41 |
|
| 42 |
point_models = [ |
| 43 |
{ |
| 44 |
'model_name': 'LIF_exc', 'ei': 'e', |
| 45 |
'dynamics_params': 'IntFire1_exc_1.json' |
| 46 |
}, |
| 47 |
{ |
| 48 |
'model_name': 'LIF_inh', 'ei': 'i', |
| 49 |
'dynamics_params': 'IntFire1_inh_1.json' |
| 50 |
} |
| 51 |
] |
| 52 |
|
| 53 |
|
| 54 |
def build_v1_network(): |
| 55 |
print('Building v1 connections') |
| 56 |
v1 = NetworkBuilder('v1') |
| 57 |
for i, model_props in enumerate(bio_models): |
| 58 |
n_cells = 80 if model_props['ei'] == 'e' else 30 # 80% excitatory, 20% inhib |
| 59 |
|
| 60 |
# Randomly get positions uniformly distributed in a column |
| 61 |
positions = positions_columinar(N=n_cells, center=[0, 10.0, 0], max_radius=50.0, height=200.0) |
| 62 |
|
| 63 |
v1.add_nodes( |
| 64 |
N=n_cells, |
| 65 |
x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], |
| 66 |
rotation_angle_yaxis=xiter_random(N=n_cells, min_x=0.0, max_x=2 * np.pi), # randomly rotate y axis |
| 67 |
rotation_angle_zaxis=xiter_random(N=n_cells, min_x=0.0, max_x=2 * np.pi), # randomly rotate z axis |
| 68 |
model_type='biophysical', |
| 69 |
model_processing='aibs_perisomatic', |
| 70 |
**model_props |
| 71 |
) |
| 72 |
|
| 73 |
# Build intfire type cells |
| 74 |
for model_props in point_models: |
| 75 |
n_cells = 75 # Just assume 75 cells for both point inhibitory and point excitatory |
| 76 |
positions = positions_columinar(N=n_cells, center=[0, 10.0, 0], max_radius=50.0, height=200.0) |
| 77 |
v1.add_nodes( |
| 78 |
N=n_cells, |
| 79 |
x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], |
| 80 |
model_type='point_process', |
| 81 |
model_template='nrn:IntFire1', |
| 82 |
**model_props |
| 83 |
) |
| 84 |
|
| 85 |
def n_connections(src, trg, prob=0.1, min_syns=1, max_syns=5): |
| 86 |
"""Referenced by add_edges() and called by build() for every source/target pair. For every given target/source |
| 87 |
pair will connect the two with a probability prob (excludes self-connections)""" |
| 88 |
if src.node_id == trg.node_id: |
| 89 |
return 0 |
| 90 |
|
| 91 |
return 0 if np.random.uniform() > prob else np.random.randint(min_syns, max_syns) |
| 92 |
|
| 93 |
# Connections onto biophysical components, use the connection map to save section and position of every synapse |
| 94 |
# exc --> exc connections |
| 95 |
v1.add_edges( |
| 96 |
source={'ei': 'e'}, target={'ei': 'e', 'model_type': 'biophysical'}, |
| 97 |
connection_rule=n_connections, |
| 98 |
connection_params={'prob': 0.2}, |
| 99 |
dynamics_params='AMPA_ExcToExc.json', |
| 100 |
model_template='Exp2Syn', |
| 101 |
syn_weight=6.0e-05, |
| 102 |
delay=2.0, |
| 103 |
target_sections=['basal', 'apical'], |
| 104 |
distance_range=[30.0, 150.0] |
| 105 |
) |
| 106 |
|
| 107 |
# exc --> inh connections |
| 108 |
v1.add_edges( |
| 109 |
source={'ei': 'e'}, target={'ei': 'i', 'model_type': 'biophysical'}, |
| 110 |
connection_rule=n_connections, |
| 111 |
dynamics_params='AMPA_ExcToInh.json', |
| 112 |
model_template='Exp2Syn', |
| 113 |
syn_weight=0.0006, |
| 114 |
delay=2.0, |
| 115 |
target_sections=['somatic', 'basal'], |
| 116 |
distance_range=[0.0, 1.0e+20] |
| 117 |
) |
| 118 |
|
| 119 |
# inh --> exc connections |
| 120 |
v1.add_edges( |
| 121 |
source={'ei': 'i'}, target={'ei': 'e', 'model_type': 'biophysical'}, |
| 122 |
connection_rule=n_connections, |
| 123 |
dynamics_params='GABA_InhToExc.json', |
| 124 |
model_template='Exp2Syn', |
| 125 |
syn_weight=0.002, |
| 126 |
delay=2.0, |
| 127 |
target_sections=['somatic', 'basal', 'apical'], |
| 128 |
distance_range=[0.0, 50.0] |
| 129 |
) |
| 130 |
|
| 131 |
# inh --> inh connections |
| 132 |
v1.add_edges( |
| 133 |
source={'ei': 'i'}, target={'ei': 'i', 'model_type': 'biophysical'}, |
| 134 |
connection_rule=n_connections, |
| 135 |
connection_params={'prob': 0.2}, |
| 136 |
dynamics_params='GABA_InhToInh.json', |
| 137 |
model_template='Exp2Syn', |
| 138 |
syn_weight=0.00015, |
| 139 |
delay=2.0, |
| 140 |
target_sections=['somatic', 'basal'], |
| 141 |
distance_range=[0.0, 1.0e+20] |
| 142 |
) |
| 143 |
|
| 144 |
# For connections on point neurons it doesn't make sense to save syanpatic location |
| 145 |
v1.add_edges( |
| 146 |
source={'ei': 'e'}, target={'model_type': 'point_process'}, |
| 147 |
connection_rule=n_connections, |
| 148 |
dynamics_params='instanteneousExc.json', |
| 149 |
syn_weight=0.0019, |
| 150 |
delay=2.0 |
| 151 |
) |
| 152 |
|
| 153 |
v1.add_edges( |
| 154 |
source={'ei': 'i'}, target={'model_type': 'point_process'}, |
| 155 |
connection_rule=n_connections, |
| 156 |
dynamics_params='instanteneousInh.json', |
| 157 |
syn_weight=0.0019, |
| 158 |
delay=2.0 |
| 159 |
) |
| 160 |
|
| 161 |
# Build and save v1 network |
| 162 |
print(' Saving network') |
| 163 |
v1.build() |
| 164 |
v1.save(output_dir='network') |
| 165 |
print(' done.') |
| 166 |
|
| 167 |
return v1 |
| 168 |
|
| 169 |
|
| 170 |
def build_lgn_network(v1): |
| 171 |
print('Building lgn network') |
| 172 |
lgn = NetworkBuilder("lgn") |
| 173 |
|
| 174 |
lgn.add_nodes(N=100, model_type='virtual', ei='e') |
| 175 |
|
| 176 |
# Targets all biophysical excitatory cells |
| 177 |
lgn.add_edges( |
| 178 |
target=v1.nodes(ei='e', model_type='biophysical'), source=lgn.nodes(), |
| 179 |
connection_rule=lambda *_: np.random.randint(0, 5), |
| 180 |
dynamics_params='AMPA_ExcToExc.json', |
| 181 |
model_template='Exp2Syn', |
| 182 |
delay=2.0, |
| 183 |
syn_weight=0.00041, |
| 184 |
target_sections=['basal', 'apical', 'somatic'], |
| 185 |
distance_range=[0.0, 50.0] |
| 186 |
) |
| 187 |
|
| 188 |
# Targets all biophysical inhibitory cells |
| 189 |
lgn.add_edges( |
| 190 |
target=v1.nodes(ei='i', model_type='biophysical'), source=lgn.nodes(), |
| 191 |
connection_rule=lambda *_: np.random.randint(0, 5), |
| 192 |
dynamics_params='AMPA_ExcToInh.json', |
| 193 |
model_template='Exp2Syn', |
| 194 |
delay=2.0, |
| 195 |
syn_weight=0.00095, |
| 196 |
target_sections=['basal', 'apical'], |
| 197 |
distance_range=[0.0, 1e+20] |
| 198 |
) |
| 199 |
|
| 200 |
# Targets all intfire1 cells (exc and inh) |
| 201 |
lgn.add_edges( |
| 202 |
target=v1.nodes(model_type='point_process'), source=lgn.nodes(), |
| 203 |
connection_rule=lambda *_: np.random.randint(0, 5), |
| 204 |
dynamics_params='instanteneousExc.json', |
| 205 |
delay=2.0, |
| 206 |
syn_weight=0.045 |
| 207 |
) |
| 208 |
|
| 209 |
print(' Saving network') |
| 210 |
lgn.build() |
| 211 |
lgn.save(output_dir='network') |
| 212 |
print(' done.') |
| 213 |
|
| 214 |
return lgn |
| 215 |
|
| 216 |
|
| 217 |
if __name__ == '__main__': |
| 218 |
v1 = build_v1_network() |
| 219 |
lgn = build_lgn_network(v1) |