def build_input_network(net, output_dir='network/source_input'): def select_source_cells(sources, target, N_syn=10): """ Note here that "sources" are given (not "source"). So the iterations occur through every target with all sources as potential inputs. Faster than before and better if will have common rules. """ target_id = target.node_id source_ids = [s.node_id for s in sources] nsyns_ret = [N_syn] * len(source_ids) return nsyns_ret filter_models = { 'inputFilter': { 'N': 25, 'ei': 'e', 'pop_name': 'input_filter', 'model_type': 'virtual' } } inputNetwork = NetworkBuilder("inputNetwork") inputNetwork.add_nodes(**filter_models['inputFilter']) inputNetwork.add_edges(target=net.nodes(pop_name='Scnn1a'), iterator='all_to_one', connection_rule=select_source_cells, syn_weight=0.0007, distance_range=[0.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') inputNetwork.add_edges(target=net.nodes(pop_name='LIF_exc'), iterator='all_to_one', connection_rule=select_source_cells, syn_weight=0.07, delay=2.0, dynamics_params='instanteneousExc.json') inputNetwork.add_edges(target=net.nodes(pop_name='PV1'), iterator='all_to_one', connection_rule=select_source_cells, syn_weight=0.002, distance_range=[0.0, 1.0e+20], target_sections=['basal', 'somatic'], delay=2.0, dynamics_params='AMPA_ExcToInh.json', model_template='exp2syn') inputNetwork.add_edges(target=net.nodes(pop_name='LIF_inh'), iterator='all_to_one', connection_rule=select_source_cells, syn_weight=0.01, delay=2.0, dynamics_params='instanteneousExc.json') inputNetwork.build() inputNetwork.save(output_dir=output_dir)
def build_hippocampus(): net = NetworkBuilder('CA3') net.add_nodes(N=1, pop_name='CA3e', model_type='biophysical', model_template='hoc:Spikingcell', morphology='blank.swc') inputnet = NetworkBuilder('input') inputnet.add_nodes(N=1, model_type='virtual', pat='pat1', pop_name='virt') conn = inputnet.add_edges( target=net.nodes(pop_name='CA3e'), source={'pat': 'pat1'}, connection_rule=1, dynamics_params='stsp.json', model_template='Exp2Syn1_STSP', delay=0, syn_weight=.5, target_sections=['soma'], # target soma distance_range=[0.0, 300]) conn.add_properties(['sec_id', 'sec_x'], rule=(0, 0.9), dtypes=[np.int32, np.float]) net.build() net.save_nodes(output_dir='network') net.save_edges(output_dir='network') inputnet.build() inputnet.save(output_dir='network')
'nedges': 140, 'nsyns_min': 2, 'nsyns_max': 5, 'divergence': 100 }, iterator='one_to_all', syn_weight=0.0016, weight_function='wmax', distance_range=[0.0, 50.0], target_sections=['somatic'], delay=0.85, model_template='exp2syn', dynamics_params='GABA_InhToExc_BC_GC.json') net.build() net.save(output_dir='network') # BASELINE EXTERNAL DRIVE TO THE GC population GC_external_input = NetworkBuilder("GC_external_input") GC_external_input.add_nodes(N=9000, pop_name='perforant_path', ei='e', positions=generate_positions(9000), model_type='virtual') # drive to the GC population GC_external_input.add_edges( source=GC_external_input.nodes(), target=net.nodes(ei='e'), connection_rule=select_random_srcs, connection_params={ 'nconns': 5,
# 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': 'e'}, target={'pop_name': ''}, connection_rule=5, syn_weight=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.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): synapses = [n_syns]*len(src_cells) #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]
def build_cortical_network(output_dir='network/recurrent_network'): def distance_connection_handler(source, target, d_max, nsyn_min, nsyn_max): """ Connect cells that are less than d_max apart with a random number of synapses in the interval [nsyn_min, nsyn_max) """ sid = source['node_id'] # Get source id tid = target['node_id'] # Get target id # Avoid self-connections. if (sid == tid): return None # first calculate euclidean distance between cells src_positions = np.array([source['x'], source['y'], source['z']]) trg_positions = np.array([target['x'], target['y'], target['z']]) separation = np.sqrt(np.sum(src_positions - trg_positions)**2) # drop the connection if nodes too far apart if separation >= d_max: return None # Add the number of synapses for every connection. tmp_nsyn = random.randint(nsyn_min, nsyn_max) return tmp_nsyn #### Step 1: Figure out what types, and number of, different cells to use in our network #### # Number of cell models desired N_Scnn1a = 2 N_PV1 = 2 N_LIF_exc = 2 N_LIF_inh = 2 # Define all the cell models in a dictionary (note dictionaries within a dictionary) biophysical_models = { 'Scnn1a': { 'N': N_Scnn1a, 'ei': 'e', 'pop_name': 'Scnn1a', 'model_type': 'biophysical', 'model_template': 'ctdb:Biophys1.hoc', 'model_processing': 'aibs_perisomatic', 'morphology_file': 'Scnn1a-Tg3-Cre_Ai14_IVSCC_-177300.01.02.01_473845048_m.swc', 'dynamics_params': '472363762_fit.json', 'rotation_angle_zaxis': -3.646878266 }, 'PV1': { 'N': N_PV1, 'ei': 'i', 'pop_name': 'PV1', 'model_type': 'biophysical', 'model_template': 'ctdb:Biophys1.hoc', 'model_processing': 'aibs_perisomatic', 'dynamics_params': '472912177_fit.json', 'morphology_file': 'Pvalb-IRES-Cre_Ai14_IVSCC_-176847.04.02.01_470522102_m.swc', 'rotation_angle_zaxis': -2.539551891 } } # Define all the cell models in a dictionary. LIF_models = { 'LIF_exc': { 'N': N_LIF_exc, 'ei': 'e', 'pop_name': 'LIF_exc', 'model_type': 'point_process', 'model_template': 'nrn:IntFire1', 'dynamics_params': 'IntFire1_exc_1.json' }, 'LIF_inh': { 'N': N_LIF_inh, 'ei': 'i', 'pop_name': 'LIF_inh', 'model_type': 'point_process', 'model_template': 'nrn:IntFire1', 'dynamics_params': 'IntFire1_inh_1.json' } } #### Step 2: Create NetworkBuidler object to build nodes and edges #### net = NetworkBuilder('Cortical') #### Step 3: Used add_nodes() method to add all our cells/cell-types for model in biophysical_models: # Build our biophysical cells params = biophysical_models[model] n_cells = params.pop('N') # We'll randomly assign positions positions = generate_random_positions(n_cells) # Use add_nodes to create a set of N cells for each cell-type net.add_nodes( N=n_cells, # Specify the numer of cells belonging to this set of nodes x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], rotation_angle_yaxis=np.random.uniform(0.0, 2 * np.pi, n_cells), # The other parameters are shared by all cells of this set in the dictionary **params) # python shortcut for unrolling a dictionary for model in LIF_models: # Same thing as above but for our LIF type cells params = LIF_models[model].copy() # Number of cells for this model type n_cells = params.pop('N') # Precacluate positions, rotation angles for each N neurons in the population positions = generate_random_positions(n_cells) # Adds node populations net.add_nodes(N=n_cells, x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], rotation_angle_yaxis=np.random.uniform( 0.0, 2 * np.pi, n_cells), **params) #### Step 4: Used add_edges() to set our connections between cells #### cparameters = { 'd_max': 160.0, # Maximum separation between nodes where connection allowed 'nsyn_min': 3, # If connection exist, minimum number of synapses 'nsyn_max': 7 } # If connection exist, maximum number of synapses net.add_edges( source={ 'ei': 'i' }, # Select all inhibitory cells to apply this connection rule too target={ 'ei': 'i', 'model_type': 'biophysical' }, # for the target cells we will use inhibitory biophysical cells connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.03, distance_range=[0.0, 1e+20], target_sections=['somatic', 'basal'], delay=2.0, dynamics_params='GABA_InhToInh.json', model_template='exp2syn') # inhibitory --> point-inhibitory net.add_edges(source={'ei': 'i'}, target={ 'ei': 'i', 'model_type': 'point_process' }, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.3, delay=2.0, dynamics_params='instanteneousInh.json') # inhibiotry --> biophysical-excitatory net.add_edges(source={'ei': 'i'}, target={ 'ei': 'e', 'model_type': 'biophysical' }, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.3, distance_range=[0.0, 50.0], target_sections=['somatic', 'basal', 'apical'], delay=2.0, dynamics_params='GABA_InhToExc.json', model_template='exp2syn') # inhibitory --> point-excitatory net.add_edges(source={'ei': 'i'}, target={ 'ei': 'e', 'model_type': 'point_process' }, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.4, delay=2.0, dynamics_params='instanteneousInh.json') # excitatory --> PV1 cells net.add_edges(source={'ei': 'e'}, target={'pop_name': 'PV1'}, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.05, distance_range=[0.0, 1e+20], target_sections=['somatic', 'basal'], delay=2.0, dynamics_params='AMPA_ExcToInh.json', model_template='exp2syn') # excitatory --> LIF_inh net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_inh'}, connection_rule=distance_connection_handler, connection_params=cparameters, syn_weight=0.2, delay=2.0, dynamics_params='instanteneousExc.json') # excitatory --> Scnn1a net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Scnn1a'}, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.05, distance_range=[30.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') # excitatory --> LIF_exc net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_exc'}, connection_rule=distance_connection_handler, connection_params={ 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7 }, syn_weight=0.05, delay=2.0, dynamics_params='instanteneousExc.json') #### Step 5: Build and save the network #### net.build() net.save(output_dir=output_dir) return net
''' 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='LIF_exc'), iterator='all_to_one', connection_rule=recurrent_connections_low, connection_params={'n_syns': 1}, syn_weight=0.5, weight_function='wmax', delay=0.0, dynamics_params='instanteneousExc.json') tw.add_edges(source=tw.nodes(), target=net.nodes(pop_name='LIF_inh'), connection_rule=1, syn_weight=0.2, weight_function='wmax', delay=0.0, dynamics_params='instanteneousExc.json') tw.build() tw.save(output_dir='../input/network')''' net_pre.build() net_pre.save(output_dir='../input/network') net_post.build() net_post.save(output_dir='../input/network') print 'done'
morphology='Nr5a1-Cre_Ai14_IVSCC_-169250.03.02.01_471087815_m.swc') # Create synapse from the high-level cell to the low-level cell (0 --> 1) net.add_edges(source={'level': 'high'}, target={'level': 'low'}, connection_rule=5, syn_weight=12.0e-03, target_sections=['somatic'], distance_range=[0.0, 300.0], delay=1.0, dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') # build and save the network. net.build() net.save(output_dir='network') # An external network with 1 (excitatory virtual) cell that will connect to the internal excitatory cell to drive # it with the spikes inputs inputs = NetworkBuilder("external") inputs.add_nodes(N=1, model_type='virtual') inputs.add_edges( source=inputs.nodes(), target=net.nodes(level='low'), connection_rule=1, syn_weight=12.0E-03, # weight_function='wmax', distance_range=[0.0, 300.0], target_sections=['somatic'], delay=1.0, dynamics_params='AMPA_ExcToExc.json',