|
| 1 | +import os |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +from bmtk.builder import NetworkBuilder |
| 5 | +from bmtk.utils.io.spike_trains import PoissonSpikesGenerator |
| 6 | +from bmtk.builder.auxi.node_params import positions_columinar, xiter_random |
| 7 | +from bmtk.analyzer import nodes_table |
| 8 | + |
| 9 | +# Brunel network parameters ------------------------------------------------------------------------- |
| 10 | +N_exc = 10000 # number of excitatory LIF neurons 80% |
| 11 | +N_inh = 2500 # number of inhibitory LIF neurons 20% |
| 12 | +n_cells = N_exc + N_inh # total number of internal neurons |
| 13 | +N_ext = 100 # number of neurons in the external network |
| 14 | + |
| 15 | +JE = 0.1 # excitatory synaptic strength (mV) |
| 16 | +g = 5. # ratio of inhibitory synpatic strength to excitatory synaptic strength (unitless)************* |
| 17 | +JI = g*JE # inhibitory synpatic strength (mv) |
| 18 | +eps = 0.1 # percentage of all possible target neurons that are connected to any given source |
| 19 | +CE = int(eps*N_exc) # number of internal connections with excitatory source neurons |
| 20 | +C_ext = CE # number of connections to each internal cell from the input network |
| 21 | +n_syn = int(C_ext/N_ext) # number of synapses per neuron in the input network |
| 22 | +CI = int(eps*N_inh) # number of internal connections with inhibitory source neurons |
| 23 | +C = CE + CI # number of internal connections |
| 24 | +tau_e = 20. # membrane time constant of excitatory neurons (ms) |
| 25 | +theta = 20. # neuron firing threshold (mV) |
| 26 | +Vr = 10. # neuron rest potential (mV) |
| 27 | +tau_rp = 2. # refractory period (ms) |
| 28 | +D = 1.5 # transmission delay (ms) |
| 29 | +v_ext_v_thr_ratio = 100. # ratio of v_ext to v_thr (unitless)*************** |
| 30 | +eps_ext = C_ext/float(n_cells) # external connection probability |
| 31 | +v_thr = theta/(JE*CE*tau_e) # frequency needed for a neuron to reach threshold in absence of feedback |
| 32 | +v_ext = v_ext_v_thr_ratio*v_thr # external firing frequency |
| 33 | + |
| 34 | +#----------------------------------------------------------------------------------------------- |
| 35 | + |
| 36 | +def generate_random_positions(N): |
| 37 | + ''' |
| 38 | + Generate N random positions. |
| 39 | + N: number of positions to generate |
| 40 | + ''' |
| 41 | + |
| 42 | + x = np.random.random(N) # x-axis location |
| 43 | + y = np.random.random(N) # y-axis location |
| 44 | + z = np.random.random(N) # z-axis location |
| 45 | + |
| 46 | + positions = np.column_stack((x, y, z)) |
| 47 | + |
| 48 | + return positions |
| 49 | + |
| 50 | +build_recurrent_edges = True |
| 51 | + |
| 52 | +bio_models = { |
| 53 | + "Internal_exc": { |
| 54 | + 'N': N_exc, |
| 55 | + 'model_type' :'biophysical', |
| 56 | + 'model_name': 'Scnn1a', 'ei': 'e', |
| 57 | + 'morphology': 'Scnn1a_473845048_m.swc', |
| 58 | + 'model_template': 'nml:Cell_472363762.cell.nml' |
| 59 | + }, |
| 60 | + |
| 61 | + "Internal_inh": { |
| 62 | + 'N': N_inh, |
| 63 | + 'model_type' :'biophysical', |
| 64 | + 'model_name': 'PV1', 'ei': 'i', |
| 65 | + 'morphology': 'Pvalb_470522102_m.swc', |
| 66 | + 'model_template': 'nml:Cell_472912177.cell.nml' |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +internal = NetworkBuilder("internal") |
| 72 | + |
| 73 | +for model in bio_models: |
| 74 | + params = bio_models[model].copy() |
| 75 | + internal.add_nodes(**params) |
| 76 | + |
| 77 | +#internal.save_nodes(nodes_file_name='internal_nodes.h5', node_types_file_name='internal_node_types.csv',output_dir='network') |
| 78 | + |
| 79 | +def random_connections(source,target, p = 0.1 ): |
| 80 | + |
| 81 | + sid = source['node_id'] # Get source id |
| 82 | + tid = target['node_id'] # Get target id |
| 83 | + |
| 84 | + # Avoid self-connections. |
| 85 | + if (sid == tid): |
| 86 | + if sid % 1000 == 0: |
| 87 | + print(sid) |
| 88 | + return None |
| 89 | + return np.random.binomial(1,p) #nsyns |
| 90 | + |
| 91 | +if build_recurrent_edges: |
| 92 | + # exc --> exc connections |
| 93 | + internal.add_edges(source={'ei': 'e'}, target={'ei': 'e'}, |
| 94 | + connection_rule=random_connections, |
| 95 | + connection_params={'p': eps}, |
| 96 | + dynamics_params='brunel_excitatory.json', |
| 97 | + model_template='Exp2Syn', |
| 98 | + syn_weight=7.0e-5, |
| 99 | + delay=D, |
| 100 | + target_sections=['basal','apical'], |
| 101 | + distance_range=[0.0, 1e+20]) |
| 102 | + |
| 103 | + # exc --> inh connections |
| 104 | + internal.add_edges(source={'ei': 'e'}, target={'ei': 'i'}, |
| 105 | + connection_rule=random_connections, |
| 106 | + connection_params={'p': eps}, |
| 107 | + dynamics_params='brunel_excitatory.json', |
| 108 | + model_template='Exp2Syn', |
| 109 | + syn_weight=7.0e-5, |
| 110 | + delay=D, |
| 111 | + target_sections=['somatic','basal'], |
| 112 | + distance_range=[0.0, 1e+20]) |
| 113 | + # inh --> exc connections |
| 114 | + internal.add_edges(source={'ei': 'i'}, target={'ei': 'e', 'model_type': 'biophysical'}, |
| 115 | + connection_rule=random_connections, |
| 116 | + connection_params={'p': eps}, |
| 117 | + dynamics_params='brunel_inhibitory.json', |
| 118 | + model_template='Exp2Syn', |
| 119 | + syn_weight=17.5e-5, |
| 120 | + delay=D, |
| 121 | + target_sections=['somatic','basal','apical'], |
| 122 | + distance_range=[0.0, 200]) |
| 123 | + |
| 124 | + # inh --> inh connections |
| 125 | + internal.add_edges(source={'ei': 'i'}, target={'ei': 'i', 'model_type': 'biophysical'}, |
| 126 | + connection_rule=random_connections, |
| 127 | + connection_params={'p': eps}, |
| 128 | + dynamics_params='brunel_inhibitory.json', |
| 129 | + model_template='Exp2Syn', |
| 130 | + syn_weight=17.5e-5, |
| 131 | + delay=D, |
| 132 | + target_sections=['somatic','basal'], |
| 133 | + distance_range=[0.0, 1e+20]) |
| 134 | + |
| 135 | +internal.build() |
| 136 | + |
| 137 | +print('Saving internal') |
| 138 | +internal.save(output_dir='network') |
| 139 | +print('Building external connections') |
| 140 | +external = NetworkBuilder("external") |
| 141 | +external.add_nodes(N=N_ext, model_type='virtual', ei='e') |
| 142 | + |
| 143 | +cm = external.add_edges(source=external.nodes(), |
| 144 | + target=internal.nodes(), |
| 145 | + connection_rule=random_connections, |
| 146 | + connection_params={'p': 0.1}, |
| 147 | + dynamics_params='AMPA_ExcToExc.json', |
| 148 | + model_template='Exp2Syn', |
| 149 | + syn_weight = 7.0e-3, |
| 150 | + delay=D, |
| 151 | + target_sections = ['somatic','basal'], |
| 152 | + distance_range=[0.0, 1e+20]) |
| 153 | + |
| 154 | +external.build() |
| 155 | +print('Saving external') |
| 156 | +external.save(output_dir='network') |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
0 commit comments