def test_positions_columinar(): np.random.seed(1) points = positions_columinar(N=10, center=[0.0, 0.0, 0.0], height=10.0, min_radius=1.0, max_radius=2.0) assert(points.shape == (10, 3)) # check height restriction ys = points[:, 1] assert(np.min(ys) >= -5.0) assert(np.max(ys) <= 5.0) # check radius restrictions xz_plane = points[:,[0,2]] dists = np.linalg.norm(xz_plane, axis=1) assert(np.min(dists) >= 1.0) assert(np.max(dists) <= 2.0)
from bmtk.builder.networks import NetworkBuilder from bmtk.builder.auxi.node_params import positions_columinar, xiter_random from bmtk.builder.auxi.edge_connectors import distance_connector import math import numpy as np import random cortex = NetworkBuilder('mcortex') cortex.add_nodes(N=100, pop_name='Scnn1a', positions=positions_columinar(N=100, center=[0, 50.0, 0], max_radius=30.0, height=100.0), rotation_angle_yaxis=xiter_random(N=100, min_x=0.0, max_x=2*np.pi), rotation_angle_zaxis=3.646878266, potental='exc', model_type='biophysical', model_template='ctdb:Biophys1.hoc', model_processing='aibs_perisomatic', dynamics_params='472363762_fit.json', morphology='Scnn1a_473845048_m.swc') cortex.add_edges(source={'pop_name': 'Scnn1a'}, target={'pop_name': 'Scnn1a'}, connection_rule=distance_connector, connection_params={'d_weight_min': 0.0, 'd_weight_max': 0.34, 'd_max': 50.0, 'nsyn_min': 0, 'nsyn_max': 10}, syn_weight=2.0e-04, distance_range=[30.0, 150.0], target_sections=['basal', 'apical', 'soma'], delay=2.0, dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn')
}, { 'model_name': 'LIF_inh', 'ei': 'i', 'model_template': 'nest:iaf_psc_alpha', 'dynamics_params': 'IntFire1_inh_point.json' }] # Build a network of 300 glif cells to simulate internal = NetworkBuilder("internal") for i, model_props in enumerate(glif_models): n_cells = 80 if model_props[ 'ei'] == 'e' else 30 # 80% excitatory, 20% inhib # Randomly get positions uniformly distributed in a column positions = positions_columinar(N=n_cells, center=[0, 10.0, 0], max_radius=50.0, height=200.0) internal.add_nodes( N=n_cells, x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], rotation_angle_yaxis=xiter_random(N=n_cells, min_x=0.0, max_x=2 * np.pi), # randomly rotate y axis rotation_angle_zaxis=xiter_random(N=n_cells, min_x=0.0, max_x=2 * np.pi), # model_type='point_process',
}, 'LIF_inh': { 'N': 40, 'ei': 'i', 'pop_name': 'LIF_inh', 'model_type': 'point_process', 'model_template': 'nest:iaf_psc_delta', 'dynamics_params': 'iaf_psc_delta_inh.json' } } net = NetworkBuilder('cortex') for model in LIF_models: params = LIF_models[model].copy() positions = positions_columinar(N=LIF_models[model]['N'], center=[0, 10.0, 0], max_radius=50.0, height=200.0) net.add_nodes(x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], **params) net.add_edges(source={'ei': 'e'}, connection_rule=random_connections, connection_params={'p': 0.1}, syn_weight=2.0, delay=1.5, dynamics_params='ExcToInh.json', model_template='static_synapse') net.add_edges(source={'ei': 'i'}, connection_rule=random_connections, connection_params={'p': 0.1},
def build_lif_network(): ### Define all the cell models in a dictionary. print('Building Internal Network') LIF_models = { 'LIF_exc': { 'N': N_LIF_exc, 'ei': 'e', 'pop_name': 'LIF_exc', 'model_type': 'point_process', 'model_template': 'nest:iaf_psc_exp', 'dynamics_params': 'excitatory.json' }, 'LIF_inh': { 'N': N_LIF_inh, 'ei': 'i', 'pop_name': 'LIF_inh', 'model_type': 'point_process', 'model_template': 'nest:iaf_psc_exp', 'dynamics_params': 'inhibitory.json' } } net = NetworkBuilder('internal') for model in LIF_models: params = LIF_models[model].copy() positions = positions_columinar(N=LIF_models[model]['N'], center=[0, 10.0, 0], max_radius=50.0, height=200.0) net.add_nodes(x=positions[:, 0], y=positions[:, 1], z=positions[:, 2], **params) net.add_edges(source={'ei': 'e'}, target={'ei': 'e'}, connection_rule=random_connections, connection_params={'p': eps}, syn_weight=200, delay=D, dynamics_params='ExcToExc.json', model_template='static_synapse') net.add_edges(source={'ei': 'e'}, target={'ei': 'i'}, connection_rule=random_connections, connection_params={'p': eps}, syn_weight=300, delay=D, dynamics_params='ExcToInh.json', model_template='static_synapse') net.add_edges(source={'ei': 'i'}, target={'ei': 'e'}, connection_rule=random_connections, connection_params={'p': eps}, syn_weight=-550, delay=D, dynamics_params='InhToExc.json', model_template='static_synapse') net.add_edges(source={'ei': 'i'}, target={'ei': 'i'}, connection_rule=random_connections, connection_params={'p': eps}, syn_weight=-300, delay=D, dynamics_params='InhToInh.json', model_template='static_synapse') net.build() net.save(output_dir='network') # net.save_edges(edges_file_name='edges.h5', edge_types_file_name='edge_types.csv', output_dir='network') # net.save_nodes(nodes_file_name='nodes.h5', node_types_file_name='node_types.csv', output_dir='network') return net
'''Customs functions like this must return a list of size N''' # def cortex_positions(N): # # codex to create a list/numpy array of N (x, y, z) positions. # return np.random.rand(N,3) # Create network of cells '''Once we have a network, we can add nodes (i.e. cells) by calling the add_nodes() method. Here, we have 100 cell. all of which are of the same type, but with different locations and y-axis rotations. The positions of each cell is defined by the columinar built-in method, which will random place our cells in a column. The rotation_angle_yaxis is similarly defined by a built-in function that randomly assigns each cell a given y angle.''' N = 10 cortex.add_nodes( N=N, # number of cells pop_name='Scnn1a', positions=positions_columinar( N=N, center=[0, 50.0, 0], max_radius=30.0, height=100.0), # position cells within column # positions = cortex_positions(N) # custom positions function rotation_angle_yaxis=xiter_random(N=N, min_x=0.0, max_x=2 * np.pi), rotation_angle_zaxis= 3.646878266, # note here that z rotations are all the same, but they could be different by using the function above potental='exc', # indicate that it is an excitatory type cell (optional) model_type= 'biophysical', # used by the simulator to indicate that we are using a biophysical cell. dynamics_params= '472363762_fit.json', # model parameters (file will be downloaded from the Allen Cell Types Database) morphology= 'Scnn1a_473845048_m.swc', # - Model morphology (file will be downloaded from the Allen Cell Types Database) model_processing= 'aibs_perisomatic', # - a custom function used by the simulator to load the model into NEURON using Allen Cell-Types files for perisomatic models model_template='ctdb:Biophys1.hoc'