def build_tw(): if not os.path.exists('output'): os.makedirs('output') TW = NetworkBuilder("TW") TW.add_nodes(N=3000, pop_name='TW', ei='e', location='TW', level_of_detail='filter') # Save cells.csv and cell_types.csv TW.save_nodes(nodes_file_name='output/tw_nodes.h5', node_types_file_name='output/tw_node_types.csv') VL4 = NetworkBuilder('V1/L4') VL4.import_nodes(nodes_file_name='output/v1_nodes.h5', node_types_file_name='output/v1_node_types.csv') VL4.add_edges(source=TW.nodes(), target={'pop_name': 'Rorb'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.00015, 'weight_function': 'wmax', 'distance_range': [30.0, 150.0], 'target_sections': ['basal', 'apical'], 'delay': 2.0, 'params_file': 'AMPA_ExcToExc.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'Scnn1a'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.00019, 'weight_function': 'wmax', 'distance_range': [30.0, 150.0], 'target_sections': ['basal', 'apical'], 'delay': 2.0, 'params_file': 'AMPA_ExcToExc.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'Nr5a1'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.00019, 'weight_function': 'wmax', 'distance_range': [30.0, 150.0], 'target_sections': ['basal', 'apical'], 'delay': 2.0, 'params_file': 'AMPA_ExcToExc.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'PV1'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.0022, 'weight_function': 'wmax', 'distance_range': [0.0, 1.0e+20], 'target_sections': ['somatic', 'basal'], 'delay': 2.0, 'params_file': 'AMPA_ExcToInh.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'PV2'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.0013, 'weight_function': 'wmax', 'distance_range': [0.0, 1.0e+20], 'target_sections': ['somatic', 'basal'], 'delay': 2.0, 'params_file': 'AMPA_ExcToInh.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'LIF_exc'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.015, 'weight_function': 'wmax', 'delay': 2.0, 'params_file': 'instanteneousExc.json', 'set_params_function': 'exp2syn'})) VL4.add_edges(source=TW.nodes(), target={'pop_name': 'LIF_inh'}, connection_rule=lambda trg, src: 5, **({'weight_max': 0.05, 'weight_function': 'wmax', 'delay': 2.0, 'params_file': 'instanteneousExc.json', 'set_params_function': 'exp2syn'})) VL4.build() VL4.save_edges(edges_file_name='output/tw_v1_edges.h5', edge_types_file_name='output/tw_v1_edge_types.csv')
lgn_net.add_nodes(model_params['N'], position=positions, tuning_angle=tuning_angles, ei=model_params['ei'], location=model_params['location'], level_of_detail=model_params['level_of_detail'], pop_name=model_params['pop_name'], pop_id=model_params['pop_id']) lgn_net.build() lgn_net.save_nodes('lgn_nodes.h5', 'lgn_node_types.csv') exit() v1_net = NetworkBuilder('V1') v1_net.import_nodes('v1_nodes.h5', 'v1_node_types.csv') lgn_mean = (np.mean(xcoords), np.mean(ycoords)) lgn_dim = (140.0, 70.0) print "> LGN mean center:" # Determine the mean center of the CC cells xcoords = [n['position'][0] for n in v1_net.nodes()] ycoords = [n['position'][1] for n in v1_net.nodes()] zcoords = [n['position'][2] for n in v1_net.nodes()] l4_mean = (np.mean(xcoords), np.mean(ycoords), np.mean(zcoords)) l4_dim = (max(xcoords) - min(xcoords), max(ycoords) - min(ycoords), max(zcoords) - min(zcoords)) print "> L4 mean center:", str(l4_mean) cparams = {
def build_ext5_nodes(): if not os.path.exists('network'): os.makedirs('network') EXT = NetworkBuilder("EXT") # need 5 cells to stimulate at 5 different frequencies EXT.add_nodes(N=5, pop_name='EXT', model_type='virtual', firing_rate=firing_rate) # Save cells.csv and cell_types.csv EXT.save_nodes(nodes_file_name='network/ext_nodes.h5', node_types_file_name='network/ext_node_types.csv') net = NetworkBuilder('slice') net.import_nodes(nodes_file_name='network/slice_nodes.h5', node_types_file_name='network/slice_node_types.csv') net.add_edges(source=EXT.nodes(firing_rate=10), target=net.nodes(firing_rate=10, synapse_model='a'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'AMPA_ExcToExc.json', 'model_template': 'expsyn' })) net.add_edges(source=EXT.nodes(firing_rate=20), target=net.nodes(firing_rate=20, synapse_model='a'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'AMPA_ExcToExc.json', 'model_template': 'expsyn' })) net.add_edges(source=EXT.nodes(firing_rate=50), target=net.nodes(firing_rate=50, synapse_model='a'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'AMPA_ExcToExc.json', 'model_template': 'expsyn' })) net.add_edges(source=EXT.nodes(firing_rate=100), target=net.nodes(firing_rate=100, synapse_model='a'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'AMPA_ExcToExc.json', 'model_template': 'expsyn' })) net.add_edges(source=EXT.nodes(firing_rate=200), target=net.nodes(firing_rate=200, synapse_model='a'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'AMPA_ExcToExc.json', 'model_template': 'expsyn' })) net.add_edges(source=EXT.nodes(firing_rate=10), target=net.nodes(firing_rate=10, synapse_model='b'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'pvalb_pvalb.json', 'model_template': 'stp2syn' })) net.add_edges(source=EXT.nodes(firing_rate=20), target=net.nodes(firing_rate=20, synapse_model='b'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'pvalb_pvalb.json', 'model_template': 'stp2syn' })) net.add_edges(source=EXT.nodes(firing_rate=50), target=net.nodes(firing_rate=50, synapse_model='b'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'pvalb_pvalb.json', 'model_template': 'stp2syn' })) net.add_edges(source=EXT.nodes(firing_rate=100), target=net.nodes(firing_rate=100, synapse_model='b'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'pvalb_pvalb.json', 'model_template': 'stp2syn' })) net.add_edges(source=EXT.nodes(firing_rate=200), target=net.nodes(firing_rate=200, synapse_model='b'), connection_rule=5, **({ 'syn_weight': 0.002, 'weight_function': 'wmax', 'distance_range': [0.0, 50.0], 'target_sections': ['somatic', 'basal', 'apical'], 'delay': 2.0, 'dynamics_params': 'pvalb_pvalb.json', 'model_template': 'stp2syn' })) net.build() net.save_edges(edges_file_name='network/ext_to_slice_edges.h5', edge_types_file_name='network/ext_to_slice_edge_types.csv')
#print np.random.geometric(p=0.5) #print np.sqrt(1-0.005)/0.005 """ def connect_random(source, target, nsyn_min=0, nsyn_max=10, distribution=None): return np.random.randint(nsyn_min, nsyn_max) """ thalamus = NetworkBuilder('mthalamus') thalamus.add_nodes(N=100, pop_name='tON', potential='exc', level_of_detail='filter') cortex = NetworkBuilder('mcortex') cortex.import_nodes(nodes_file_name='network/mcortex_nodes.h5', node_types_file_name='network/mcortex_node_types.csv') thalamus.add_edges(source=thalamus.nodes(), target=cortex.nodes(), connection_rule=connect_random, connection_params={ 'nsyn_min': 0, 'nsyn_max': 12 }, syn_weight=1.0e-04, distance_range=[0.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') thalamus.build()
import numpy as np from bmtk.builder.networks import NetworkBuilder lgn = NetworkBuilder('LGN') lgn.add_nodes(N=500, pop_name='tON', potential='exc', level_of_detail='filter') v1 = NetworkBuilder('V1') v1.import_nodes(nodes_file_name='network/V1_nodes.h5', node_types_file_name='network/V1_node_types.csv') def select_source_cells(sources, target, nsources_min=10, nsources_max=30, nsyns_min=3, nsyns_max=12): total_sources = len(sources) nsources = np.random.randint(nsources_min, nsources_max) selected_sources = np.random.choice(total_sources, nsources, replace=False) syns = np.zeros(total_sources) syns[selected_sources] = np.random.randint(nsyns_min, nsyns_max, size=nsources) return syns lgn.add_edges(source=lgn.nodes(), target=net.nodes(pop_name='Scnn1a'), iterator='all_to_one',
def build_lgn(): 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_cell, trg_cell, n_syns_exc, n_syns_inh): #if trg_cell['tuning_angle'] is not None: # 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] # will always give synapse number depending on type if n_syns_exc > 0: n_synapses = n_syns_exc if n_syns_inh > 0: n_synapses = n_syns_inh return n_synapses # varible number of synapses #return np.random.randint(n_syns_min, n_syns_max) #return synapses if not os.path.exists('output'): os.makedirs('output') LGN = NetworkBuilder("LGN") LGN.add_nodes(N=1000, positions=generate_positions(1000), location='LGN', level_of_detail='filter', pop_name='ExcIN', ei='e') LGN.add_nodes(N=1, positions=generate_positions(1), location='LGN', level_of_detail='filter', pop_name='InhIN', ei='i') VL4 = NetworkBuilder('V1/L4') VL4.import_nodes(nodes_file_name='output/v1_nodes.h5', node_types_file_name='output/v1_node_types.csv') cm = VL4.add_edges(source=LGN.nodes(ei='e'), #target={'pop_name': 'DG_GC'}, connection_rule=select_source_cells, connection_params={'n_syns_exc': 1, 'n_syns_inh': 0}, weight_max=10e-03, weight_function='wmax', distance_range=[1, 1e+20], target_sections=['apical'], delay=2.0, params_file='AMPA_ExcToExc.json', set_params_function='exp2syn') VL4.build() LGN.save_nodes(nodes_file_name='output/lgn_nodes.h5', node_types_file_name='output/lgn_node_types.csv') VL4.save_edges(edges_file_name='output/lgn_v1_edges.h5', edge_types_file_name='output/lgn_v1_edge_types.csv')
def build_lgn(): 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 trg_cell['tuning_angle'] is not None: 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 if not os.path.exists('output'): os.makedirs('output') LGN = NetworkBuilder("LGN") LGN.add_nodes(N=3000, positions=generate_positions(3000), location='LGN', level_of_detail='filter', pop_name='tON', ei='e') LGN.add_nodes(N=3000, positions=generate_positions(3000), location='LGN', level_of_detail='filter', pop_name='tOFF', ei='e') LGN.add_nodes(N=3000, positions=generate_positions(3000), location='LGN', level_of_detail='filter', pop_name='tONOFF', ei='e') VL4 = NetworkBuilder('V1/L4') VL4.import_nodes(nodes_file_name='output/v1_nodes.h5', node_types_file_name='output/v1_node_types.csv') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'Rorb'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=5e-05, weight_function='wmax', distance_range=[0.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, params_file='AMPA_ExcToExc.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'Nr5a1'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=5e-05, weight_function='wmax', distance_range=[0.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, params_file='AMPA_ExcToExc.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'Scnn1a'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=4e-05, weight_function='wmax', distance_range=[0.0, 150.0], target_sections=['basal', 'apical'], delay=2.0, params_file='AMPA_ExcToExc.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'PV1'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=0.0001, weight_function='wmax', distance_range=[0.0, 1.0e+20], target_sections=['somatic', 'basal'], delay=2.0, params_file='AMPA_ExcToInh.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'PV2'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=9e-05, weight_function='wmax', distance_range=[0.0, 1.0e+20], target_sections=['somatic', 'basal'], delay=2.0, params_file='AMPA_ExcToInh.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'LIF_exc'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=0.0045, weight_function='wmax', delay=2.0, params_file='instanteneousExc.json', set_params_function='exp2syn') VL4.add_edges(source=LGN.nodes(), target={'pop_name': 'LIF_inh'}, iterator='all_to_one', connection_rule=select_source_cells, connection_params={'n_syns': 10}, weight_max=0.002, weight_function='wmax', delay=2.0, params_file='instanteneousExc.json', set_params_function='exp2syn') VL4.build() LGN.save_nodes(nodes_file_name='output/lgn_nodes.h5', node_types_file_name='output/lgn_node_types.csv') VL4.save_edges(edges_file_name='output/lgn_v1_edges.h5', edge_types_file_name='output/lgn_v1_edge_types.csv') assert(os.path.exists('output/lgn_node_types.csv')) node_types_csv = pd.read_csv('output/lgn_node_types.csv', sep=' ') assert(len(node_types_csv) == 3) assert(set(node_types_csv.columns) == {'node_type_id', 'location', 'ei', 'level_of_detail', 'pop_name'}) assert(os.path.exists('output/lgn_nodes.h5')) nodes_h5 = h5py.File('output/lgn_nodes.h5') assert(len(nodes_h5['/nodes/node_gid']) == 9000) assert(len(nodes_h5['/nodes/node_type_id']) == 9000) assert(len(nodes_h5['/nodes/node_group']) == 9000) assert(len(nodes_h5['/nodes/node_group_index']) == 9000) assert(set(nodes_h5['/nodes/0'].keys()) == {'positions'}) assert(len(nodes_h5['/nodes/0/positions']) == 9000) assert(os.path.exists('output/lgn_v1_edge_types.csv')) edge_types_csv = pd.read_csv('output/lgn_v1_edge_types.csv', sep=' ') assert(len(edge_types_csv) == 7) assert(set(edge_types_csv.columns) == {'weight_max', 'edge_type_id', 'target_query', 'params_file', 'set_params_function', 'delay', 'target_sections', 'weight_function', 'source_query', 'distance_range'}) assert(os.path.exists('output/lgn_v1_edges.h5')) edges_h5 = h5py.File('output/lgn_v1_edges.h5') assert(len(edges_h5['/edges/index_pointer']) == 14+1) assert(len(edges_h5['/edges/target_gid']) == 6000*14) assert(len(edges_h5['/edges/source_gid']) == 6000*14) assert(len(edges_h5['/edges/0/nsyns']) == 6000*14)