Пример #1
0
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)
Пример #2
0
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')
Пример #3
0
net1.add_nodes(N=1,
               pop_name='hco2',
               cell_name='HCOCell2',
               model_type='biophysical',
               model_template='hoc:HCOcell',
               morphology='blank.swc')

net1.build()
net1.save_nodes(output_dir='network')

net1.add_edges(source={'pop_name': 'hco1'},
               target={'pop_name': 'hco2'},
               connection_rule=1,
               syn_weight=40.0e-03,
               dynamics_params='GABA_InhToInh.json',
               model_template='Exp2Syn',
               delay=0.0,
               target_sections=["soma"],
               distance_range=99999999)

net1.add_edges(source={'pop_name': 'hco2'},
               target={'pop_name': 'hco1'},
               connection_rule=1,
               syn_weight=40.0e-03,
               dynamics_params='GABA_InhToInh.json',
               model_template='Exp2Syn',
               delay=0.0,
               target_sections=["soma"],
               distance_range=99999999)
Пример #4
0
    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(pop_name='Scnn1a'),
                   connection_rule=connect_random,
                   connection_params={
                       'nsyn_min': 0,
                       'nsyn_max': 12
                   },
                   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')

thalamus.build()
thalamus.save_nodes(output_dir='network')
thalamus.save_edges(output_dir='network')
Пример #5
0
                  pop_name=name,
                  location='VisL4',
                  **cell_props)

'''
net.build()
net.save_nodes('tmp_nodes.h5', 'tmp_node_types.csv')
exit()
'''

cparameters = {'d_weight_min': 0.0, 'd_weight_max': 1.0, 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7}
net.add_edges(sources={'ei': 'i'}, targets={'ei': 'i', 'level_of_detail': 'biophysical'},
              func=distance_connection_handler, func_params=cparameters,
              weight_max=0.0002,
              weight_function='wmax',
              distance_range=[0.0, 1e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              params_file='GABA_InhToInh.json',
              set_params_function='exp2syn')

net.add_edges(sources={'ei': 'i'}, targets={'ei': 'i', 'level_of_detail': 'intfire'},
              func=distance_connection_handler,
              func_params=cparameters,
              weight_max=0.00225,
              weight_function='wmax',
              delay=2.0,
              params_file='instanteneousInh.json',
              set_params_function='exp2syn')

cparameters = {'d_weight_min': 0.0, 'd_weight_max': 1.0, 'd_max': 160.0, 'nsyn_min': 3, 'nsyn_max': 7}
Пример #6
0
              morphology='blank.swc'
            )
            
net1.add_nodes(N=1, 
              cell_name='HCOCell2',
              model_type='biophysical',
              model_template='hoc:HCOcell',
              morphology='blank.swc'
            )
            

                        
net1.add_edges(source={'cell_name': 'HCOCell1'}, target={'cell_name':'HCOCell2'},
              connection_rule=1,
              syn_weight=40.0e-02,
              dynamics_params='GABA_InhToInh.json',
              model_template='Exp2Syn',
              delay=0.0,
              target_sections=["soma"],
              distance_range=[0,999])
              
net1.add_edges(source={'cell_name': 'HCOCell2'}, target={'cell_name':'HCOCell1'},
              connection_rule=1,
              syn_weight=40.0e-02,
              dynamics_params='GABA_InhToInh.json',
              model_template='Exp2Syn',
              delay=0.0,
              target_sections=["soma"],
              distance_range=[0,999])

net1.build()
net1.save_nodes(output_dir='network')             
Пример #7
0
    #syn_weight = np.random.lognormal(mean=mu,sigma=sigma)
    syn_weight = mu

    return syn_weight,0,0.5


def one_to_one(source,target):
    tmp_syn = 1
    return tmp_syn

# Add connections -----------------------------------------

conn = net.add_edges(source=net.nodes(pop_name='PUDaff'), target=net.nodes(pop_name='INmminus'),
                   connection_rule=one_to_one,
                   delay=0.5,
                   syn_weight = 0.07,
                   target_sections=['somatic'],
                   distance_range=[0.0, 300.0],
                   dynamics_params='AMPA_ExcToExc.json',
                   model_template='Exp2Syn')
				
conn = net.add_edges(source=net.nodes(pop_name='PUDaff'), target=net.nodes(pop_name='INmplus'),
                   connection_rule=one_to_one,
                   delay=0.5,
                   syn_weight = 0.044,
                   target_sections=['somatic'],
                   distance_range=[0.0, 300.0],
                   dynamics_params='AMPA_ExcToExc.json',
                   model_template='Exp2Syn')

conn = net.add_edges(source=net.nodes(pop_name='PUDaff'), target=net.nodes(pop_name='IND'),
                   connection_rule=one_to_one,
Пример #8
0
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)
Пример #9
0
              dynamics_params='IntFire1_exc_point.json')

net.add_nodes(N=100, pop_name='LIF_inh', location='L4', ei='i',
              positions=positions_columinar(N=100, center=[0, 50.0, 0], min_radius=30.0, max_radius=60.0, height=100.0),
              model_type='point_process',
              model_template='nest:iaf_psc_alpha',
              dynamics_params='IntFire1_inh_point.json')



"""Create edges"""
## E-to-E connections
net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Scnn1a'},
              connection_rule=distance_connector,
              connection_params={'d_weight_min': 0.0, 'd_weight_max': 0.34, 'd_max': 300.0, 'nsyn_min': 3, 'nsyn_max': 7},
              syn_weight=5.0,
              delay=2.0,
              dynamics_params='ExcToExc.json',
              model_template='static_synapse')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_exc'},
              connection_rule=distance_connector,
              connection_params={'d_weight_min': 0.0, 'd_weight_max': 0.34, 'd_max': 300.0, 'nsyn_min': 3, 'nsyn_max': 7},
              syn_weight=10.0,
              delay=2.0,
              dynamics_params='instanteneousExc.json',
              model_template='static_synapse')


### Generating I-to-I connections
net.add_edges(source={'ei': 'i'}, target={'pop_name': 'PV'},
Пример #10
0
                         (218.04, -327.333, -635.593)],
              model_type='point_process',
              model_template='nrn:IntFire1',
              dynamics_params='IntFire1_inh_1.json')

# 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': 'i'
    },  # For our synaptic source cells we select all inhibitory cells (ei==i), incl. both biophys and point
    target={
        'ei': 'i',
        'model_type': 'biophysical'
    },  # For our synaptic target we select all inhibitory biophysically detailed cells
    connection_rule=5,  # All matching source/target pairs will have
    syn_weight=0.0002,  # synaptic weight
    target_sections=['somatic',
                     'basal'],  # Gives the simulator the target sections and
    distance_range=[0.0,
                    1e+20],  # distances (from soma) when creating connections
    delay=2.0,
    dynamics_params='GABA_InhToInh.json',
    model_template='exp2syn')

net.add_edges(
    source={'ei': 'i'},
    target={
        'ei': 'i',
        'model_type': 'point_process'
    },
Пример #11
0
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
Пример #12
0

def recurrent_connections_low2(src_cells, trg_cell, n_syns):

    synapses = [
        n_syns * (np.random.random() > .1) for i in range(len(src_cells))
    ]

    return synapses


net_pre.add_edges(source=net_pre.nodes(),
                  target=net_post.nodes(pop_name='Exc'),
                  iterator='all_to_one',
                  connection_rule=recurrent_connections_low,
                  connection_params={'n_syns': 1},
                  syn_weight=5,
                  weight_function='wmax',
                  delay=0.0,
                  dynamics_params='instanteneousExc.json')
'''                 
  '''
'''
net.add_edges(source={'ei': 'i'}, target={'ei': 'i', 'model_type': 'point_process'},
              iterator='all_to_one',
              connection_rule=recurrent_connections,
              connection_params={'n_syns': 10},
              syn_weight=0.01,
              weight_function='wmax',
              delay=0.0,
              dynamics_params='instanteneousInh.json')
Пример #13
0
    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',
              connection_rule=select_source_cells,
              connection_params={
                  'nsources_min': 10,
                  'nsources_max': 25
              },
              syn_weight=4e-03,
              weight_function='wmax',
              distance_range=[0.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              dynamics_params='AMPA_ExcToExc.json',
              model_template='exp2syn')

lgn.add_edges(source=lgn.nodes(),
              target=net.nodes(pop_name='PV1'),
              connection_rule=select_source_cells,
              connection_params={
                  'nsources_min': 15,
                  'nsources_max': 30
              },
Пример #14
0
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')
Пример #15
0
net.add_nodes(
    N=1,
    level='low',
    ei='e',
    model_type='biophysical',
    model_template='ctdb:Biophys1.hoc',
    model_processing='aibs_perisomatic',
    dynamics_params='473863035_fit.json',
    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(),
Пример #16
0
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')
Пример #17
0
          max(zcoords) - min(zcoords))
print "> L4 mean center:", str(l4_mean)

cparams = {
    'lgn_mean': lgn_mean,
    'lgn_dim': lgn_dim,
    'l4_mean': l4_mean,
    'l4_dim': l4_dim,
    'N_syn': 30
}
v1_net.add_edges(sources=lgn_net.nodes(),
                 targets={'name': 'Rorb'},
                 iterator='all_to_one',
                 func=select_source_cells,
                 func_params=cparams,
                 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')

v1_net.add_edges(sources=lgn_net.nodes(),
                 targets={'name': 'Nr5a1'},
                 iterator='all_to_one',
                 func=select_source_cells,
                 func_params=cparams,
                 weight_max=5e-05,
                 weight_function='wmax',
                 distance_range=[0.0, 150.0],
                 target_sections=['basal', 'apical'],
Пример #18
0
# EXCITATORY POPULATION, CONNECTIONS

# gEE reccurent excitation
net.add_edges(source={
    'ei': 'e',
    'model_type': 'biophysical'
},
              target={
                  'ei': 'e',
                  'model_type': 'biophysical'
              },
              connection_rule=connection_phi_same_layer,
              connection_params={
                  'nedges': 100,
                  'nsyns_min': 2,
                  'nsyns_max': 5,
                  'divergence': 50
              },
              iterator='one_to_all',
              syn_weight=0.00013,
              weight_function='wmax',
              distance_range=[0.0, 150],
              target_sections=['apical', 'basal'],
              delay=0.8,
              model_template='exp2syn',
              dynamics_params='AMPA_ExcToExc_GC_GC.json')

# additional reccurent connections
net.add_edges(source={
    'ei': 'e',
Пример #19
0
        print("connecting {} cell {} to {} cell {}".format(
            source_name, sid, target_name, tid))
        tmp_nsyn = 1
    else:
        return None

    return tmp_nsyn


# Add connections
# Blad afferent --> INd
net.add_edges(source=net.nodes(pop_name='Bladaff'),
              target=net.nodes(pop_name='IND'),
              connection_rule=one_to_one,
              syn_weight=12.0e-03,
              target_sections=['somatic'],
              delay=2.0,
              distance_range=[0.0, 300.0],
              dynamics_params='AMPA_ExcToExc.json',
              model_template='Exp2Syn')

# EUS afferent --> INd
net.add_edges(source=net.nodes(pop_name='EUSaff'),
              target=net.nodes(pop_name='IND'),
              connection_rule=one_to_one,
              syn_weight=12.0e-03,
              target_sections=['somatic'],
              delay=2.0,
              distance_range=[0.0, 300.0],
              dynamics_params='AMPA_ExcToExc.json',
              model_template='Exp2Syn')
Пример #20
0
def build_l4():
    net = NetworkBuilder("V1/L4")
    net.add_nodes(N=2, pop_name='Scnn1a',
                  positions=[(28.753, -364.868, -161.705), (48.753, -344.868, -141.705)],
                  tuning_angle=[0.0, 25.0],
                  rotation_angle_yaxis=[3.55501, 3.55501],
                  location='VisL4',
                  ei='e',
                  level_of_detail='biophysical',
                  params_file='472363762_fit.json',
                  morphology_file='Scnn1a-Tg3-Cre_Ai14_IVSCC_-177300.01.02.01_473845048_m.swc',
                  rotation_angle_zaxis=-3.646878266,
                  set_params_function='Biophys1')

    net.add_nodes(N=2, pop_name='Rorb',
                  positions=[(241.092, -349.263, 146.916), (201.092, -399.263, 126.916)],
                  tuning_angle=[50.0, 75.0],
                  rotation_angle_yaxis=[3.50934, 3.50934],
                  location='VisL4',
                  ei='e',
                  level_of_detail='biophysical',
                  params_file='473863510_fit.json',
                  morphology_file='Rorb-IRES2-Cre-D_Ai14_IVSCC_-168053.05.01.01_325404214_m.swc',
                  rotation_angle_zaxis=-4.159763785,
                  set_params_function='Biophys1')

    net.add_nodes(N=2, pop_name='Nr5a1',
                  positions=[(320.498, -351.259, 20.273), (310.498, -371.259, 10.273)],
                  tuning_angle=[100.0, 125.0],
                  rotation_angle_yaxis=[0.72202, 0.72202],
                  location='VisL4',
                  ei='e',
                  level_of_detail='biophysical',
                  params_file='473863035_fit.json',
                  morphology_file='Nr5a1-Cre_Ai14_IVSCC_-169250.03.02.01_471087815_m.swc',
                  rotation_angle_zaxis=-2.639275277,
                  set_params_function='Biophys1')

    net.add_nodes(N=2, pop_name='PV1',
                  positions=[(122.373, -352.417, -216.748), (102.373, -342.417, -206.748)],
                  tuning_angle=['NA', 'NA'],
                  rotation_angle_yaxis=[2.92043, 2.92043],
                  location='VisL4',
                  ei='i',
                  level_of_detail='biophysical',
                  params_file='472912177_fit.json',
                  morphology_file='Pvalb-IRES-Cre_Ai14_IVSCC_-176847.04.02.01_470522102_m.swc',
                  rotation_angle_zaxis=-2.539551891,
                  set_params_function='Biophys1')

    net.add_nodes(N=2, pop_name='PV2',
                  positions=[(350.321, -372.535, -18.282), (360.321, -371.535, -12.282)],
                  tuning_angle=['NA', 'NA'],
                  rotation_angle_yaxis=[5.043336, 5.043336],
                  location='VisL4',
                  ei='i',
                  level_of_detail='biophysical',
                  params_file='473862421_fit.json',
                  morphology_file='Pvalb-IRES-Cre_Ai14_IVSCC_-169125.03.01.01_469628681_m.swc',
                  rotation_angle_zaxis=-3.684439949,
                  set_params_function='Biophys1')

    net.add_nodes(N=2, pop_name='LIF_exc',
                  positions=[(-243.04, -342.352, -665.666), (-233.04, -332.352, -675.666)],
                  tuning_angle=['NA', 'NA'],
                  #rotation_angle_yaxis=[5.11801, 5.11801],
                  location='VisL4',
                  ei='e',
                  level_of_detail='intfire',
                  params_file='IntFire1_exc_1.json',
                  set_params_function='IntFire1')

    net.add_nodes(N=2, pop_name='LIF_inh',
                  positions=[(211.04, -321.333, -631.593), (218.04, -327.333, -635.593)],
                  tuning_angle=[150.0, 175.0],
                  #rotation_angle_yaxis=[4.566091, 4.566091],
                  location='VisL4',
                  ei='i',
                  level_of_detail='intfire',
                  params_file='IntFire1_inh_1.json',
                  set_params_function='IntFire1')

    print("Setting connections...")
    print("Generating I-to-I connections.")
    net.add_edges(source={'ei': 'i'}, target={'ei': 'i', 'level_of_detail': 'biophysical'},
                  connection_rule=5,
                  weight_max=0.0002,
                  weight_function='wmax',
                  distance_range=[0.0, 1e+20],
                  target_sections=['somatic', 'basal'],
                  delay=2.0,
                  params_file='GABA_InhToInh.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'i'}, target={'ei': 'i', 'level_of_detail': 'intfire'},
                  connection_rule=5,
                  weight_max=0.00225,
                  weight_function='wmax',
                  delay=2.0,
                  params_file='instanteneousInh.json',
                  set_params_function='exp2syn')

    print("Generating I-to-E connections.")
    net.add_edges(source={'ei': 'i'}, target={'ei': 'e', 'level_of_detail': 'biophysical'},
                  connection_rule=lambda trg, src: 5,
                  weight_max=0.00018,
                  weight_function='wmax',
                  distance_range=[0.0, 50.0],
                  target_sections=['somatic', 'basal', 'apical'],
                  delay=2.0,
                  params_file='GABA_InhToExc.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'i'}, target={'ei': 'e', 'level_of_detail': 'intfire'},
                  connection_rule=5,
                  weight_max=0.009,
                  weight_function='wmax',
                  delay=2.0,
                  params_file='instanteneousInh.json',
                  set_params_function='exp2syn')

    print("Generating E-to-I connections.")
    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'PV1'},
                  connection_rule=5,
                  weight_max=0.00035,
                  weight_function='wmax',
                  distance_range=[0.0, 1e+20],
                  target_sections=['somatic', 'basal'],
                  delay=2.0,
                  params_file='AMPA_ExcToInh.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'PV2'},
                  connection_rule=5,
                  weight_max=0.00027,
                  weight_function='wmax',
                  distance_range=[0.0, 1e+20],
                  target_sections=['somatic', 'basal'],
                  delay=2.0,
                  params_file='AMPA_ExcToInh.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_inh'},
                  connection_rule=5,
                  weight_max=0.0043,
                  weight_function='wmax',
                  delay=2.0,
                  params_file='instanteneousExc.json',
                  set_params_function='exp2syn')

    print("Generating E-to-E connections.")
    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Scnn1a'},
                  connection_rule=5,
                  weight_max=6.4e-05,
                  weight_function='gaussianLL',
                  weight_sigma=50.0,
                  distance_range=[30.0, 150.0],
                  target_sections=['basal', 'apical'],
                  delay=2.0,
                  params_file='AMPA_ExcToExc.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Rorb'},
                  connection_rule=5,
                  weight_max=5.5e-05,
                  weight_function='gaussianLL',
                  weight_sigma=50.0,
                  distance_range=[30.0, 150.0],
                  target_sections=['basal', 'apical'],
                  delay=2.0,
                  params_file='AMPA_ExcToExc.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Nr5a1'},
                  connection_rule=5,
                  weight_max=7.2e-05,
                  weight_function='gaussianLL',
                  weight_sigma=50.0,
                  distance_range=[30.0, 150.0],
                  target_sections=['basal', 'apical'],
                  delay=2.0,
                  params_file='AMPA_ExcToExc.json',
                  set_params_function='exp2syn')

    net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_exc'},
                  connection_rule=5,
                  weight_max=0.0019,
                  weight_function='gaussianLL',
                  weight_sigma=50.0,
                  delay=2.0,
                  params_file='instanteneousExc.json',
                  set_params_function='exp2syn')


    net.build()
    net.save_nodes(nodes_file_name='output/v1_nodes.h5', node_types_file_name='output/v1_node_types.csv')
    net.save_edges(edges_file_name='output/v1_v1_edges.h5', edge_types_file_name='output/v1_v1_edge_types.csv')

    assert(os.path.exists('output/v1_node_types.csv'))
    node_types_csv = pd.read_csv('output/v1_node_types.csv', sep=' ')
    assert(len(node_types_csv) == 7)
    assert(set(node_types_csv.columns) == {'node_type_id', 'location', 'ei', 'level_of_detail', 'params_file',
                                           'pop_name', 'set_params_function', 'rotation_angle_zaxis',
                                           'morphology_file'})

    assert(os.path.exists('output/v1_nodes.h5'))
    nodes_h5 = h5py.File('output/v1_nodes.h5')
    assert(len(nodes_h5['/nodes/node_gid']) == 14)
    assert(len(nodes_h5['/nodes/node_type_id']) == 14)
    assert(len(nodes_h5['/nodes/node_group']) == 14)
    assert(len(nodes_h5['/nodes/node_group_index']) == 14)
    assert(set(nodes_h5['/nodes/0'].keys()) == {'positions', 'rotation_angle_yaxis', 'tuning_angle'})
    assert(len(nodes_h5['/nodes/0/positions']) == 10)
    assert(len(nodes_h5['/nodes/1/positions']) == 4)

    assert(os.path.exists('output/v1_v1_edge_types.csv'))
    edge_types_csv = pd.read_csv('output/v1_v1_edge_types.csv', sep=' ')
    assert(len(edge_types_csv) == 11)
    assert(set(edge_types_csv.columns) == {'weight_max', 'edge_type_id', 'target_query', 'params_file',
                                           'set_params_function', 'delay', 'target_sections', 'weight_function',
                                           'weight_sigma', 'source_query', 'distance_range'})

    assert(os.path.exists('output/v1_v1_edges.h5'))
    edges_h5 = h5py.File('output/v1_v1_edges.h5')
    assert(len(edges_h5['/edges/index_pointer']) == 14+1)
    assert(len(edges_h5['/edges/target_gid']) == 14*14)
    assert(len(edges_h5['/edges/source_gid']) == 14*14)
    assert(len(edges_h5['/edges/0/nsyns']) == 14*14)

    return net
              rotation_angle_yaxis=0,
              rotation_angle_zaxis=-3.011895, # Note that the y-axis rotation is differnt for each cell (ie. given a list of size N), but with z-axis rotation all cells have the same value
              model_type='biophysical',  # The type of cell we are using
              model_template='ctdb:Biophys1.hoc',  # Tells the simulator that when building cells models use a hoc_template specially created for parsing Allen Cell-types file models. Value would be different if we were using NeuronML or different model files
              model_processing='aibs_allactive_ani_directed',  # further instructions for how to processes a cell model. In this case aibs_perisomatic is a built-in directive to cut the axon in a specific way
              dynamics_params='optim_param_571654895.json',  # Name of file (downloaded from Allen Cell-Types) used to set model parameters and channels
              morphology='571654895.swc'),  # Name of morphology file downloaded


# 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):
Пример #22
0
    model_type='biophysical',  # The type of cell we are using
    model_template=
    'ctdb:Biophys1.hoc',  # Tells the simulator that when building cells models use a hoc_template specially created for parsing Allen Cell-types file models. Value would be different if we were using NeuronML or different model files
    model_processing=
    'aibs_allactive_ani_directed',  # further instructions for how to processes a cell model. In this case aibs_perisomatic is a built-in directive to cut the axon in a specific way
    dynamics_params=
    'hof_param_CELLID_0.json',  # Name of file (downloaded from Allen Cell-Types) used to set model parameters and channels
    morphology='CELLID.swc'),  # Name of morphology file downloaded

# 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': 'i'},
              target={'pop_name': 'POPNAME'},
              connection_rule=5,
              syn_weight=6.4e-05,
              weight_function='wmax',
              distance_range=[0.0, 1e+20],
              target_sections=['somatic', 'basal'],
              delay=2.0,
              dynamics_params='GABA_InhToInh.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):
Пример #23
0
        return None

    # filter out nodes by treating the weight as a probability of connection
    if random.random() > tw:
        return None

    # Add the number of synapses for every connection.
    # It is probably very useful to take this out into a separate function.
    return random.randint(nsyn_min, nsyn_max)

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'Scnn1a'},
              connection_rule=dist_tuning_connector,
              connection_params={'d_weight_min': 0.0, 'd_weight_max': 0.34, 'd_max': 300.0, 't_weight_min': 0.5,
                                 't_weight_max': 1.0, 'nsyn_min': 3, 'nsyn_max': 7},
              weight_max=6.4e-05,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              distance_range=[30.0, 150.0],
              target_sections=['basal', 'apical'],
              delay=2.0,
              params_file='AMPA_ExcToExc.json',
              set_params_function='exp2syn')

net.add_edges(source={'ei': 'e'}, target={'pop_name': 'LIF_exc'},
              connection_rule=dist_tuning_connector,
              connection_params={'d_weight_min': 0.0, 'd_weight_max': 0.34, 'd_max': 300.0, 't_weight_min': 0.5,
                                 't_weight_max': 1.0, 'nsyn_min': 3, 'nsyn_max': 7},
              weight_max=0.0019,
              weight_function='gaussianLL',
              weight_sigma=50.0,
              delay=2.0,
              params_file='instanteneousExc.json',
Пример #24
0
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()
thalamus.save_nodes(output_dir='network')
thalamus.save_edges(output_dir='network')
Пример #25
0
                 potental='exc',
                 level_of_detail='biophysical',
                 params_file='472363762_fit.json',
                 morphology_file='Scnn1a.swc',
                 set_params_function='Biophys1')

cortex.build()
cortex.save_nodes(output_dir='network')

thalamus = NetworkBuilder('mthalamus')
thalamus.add_nodes(N=10,
                   pop_name='tON',
                   potential='exc',
                   level_of_detail='filter')

thalamus.add_edges(source={'pop_name': 'tON'},
                   target=cortex.nodes(),
                   connection_rule=5,
                   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')

thalamus.build()
thalamus.save_nodes(output_dir='network')
thalamus.save_edges(output_dir='network')
#thalamus.save_edges(edges_file_name='thalamus_cortex_edges.h5', edge_types_file_name='thalamus_cortex_edge_types.h5')
Пример #26
0
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')
Пример #27
0
    If done this way the function will need to be imported in the run script, consider refactoring?
    """

    #syn_weight = np.random.lognormal(mean=mu,sigma=sigma)
    syn_weight = mu

    return syn_weight,0,0.5


# Add connections -----------------------------------------

# Blad afferent --> INd (Grill et al. 2016)
conn = net.add_edges(source=net.nodes(pop_name='Bladaff'), target=net.nodes(pop_name='IND'),
                   connection_rule=percent_connector,
                   connection_params={'percent':100.0}, 
				   target_sections=['somatic'],
                   delay=2.0,
                   distance_range=[0.0, 300.0],
                   dynamics_params='AMPA_ExcToExc.json',
                   model_template='Exp2Syn')
				
conn.add_properties(names=['syn_weight', 'sec_id', 'sec_x'],
                    rule=conn_props,
                    rule_params={'mu':10.0e-3,'sigma':1},
                    dtypes=[np.float, np.int32, np.float])

# Blad afferent --> Hypogastric (Hou et al. 2014)
# conn = net.add_edges(source=net.nodes(pop_name='Bladaff'), target=net.nodes(pop_name='Hypo'),
                   # connection_rule=percent_connector,
                   # connection_params={'percent':10.0},
				   # target_sections=['somatic'],
                   # delay=2.0,
Пример #28
0
from bmtk.builder.networks import NetworkBuilder


def crule(src, trg):
    # print src.node_id, trg.node_id
    return 2


net1 = NetworkBuilder('NET1')
net1.add_nodes(N=100,
               position=[(0.0, 1.0, -1.0)] * 100,
               cell_type='Scnna1',
               ei='e')
net1.add_edges(source={'ei': 'e'}, target={'ei': 'e'}, connection_rule=5)
net1.build()

net2 = NetworkBuilder('NET2')
net2.add_nodes(N=10, position=[(0.0, 1.0, -1.0)] * 10, cell_type='PV1', ei='i')
net2.add_edges(connection_rule=10)
net2.add_edges(source=net1.nodes(), connection_rule=1)
net2.add_edges(target=net1.nodes(), connection_rule=crule)
net2.build()

#net1.save_edges(output_dir='tmp_output')
net2.save_edges(output_dir='tmp_output')
Пример #29
0
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')

cortex.build()
cortex.save_nodes(output_dir='network')
cortex.save_edges(output_dir='network')
Пример #30
0
                 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.build()
cortex.save_nodes(output_dir='network')


thalamus = NetworkBuilder('mthalamus')
thalamus.add_nodes(N=10,
                   pop_name='tON',
                   potential='exc',
                   level_of_detail='filter')

thalamus.add_edges(source={'pop_name': 'tON'}, target=cortex.nodes(),
                   connection_rule=5,
                   syn_weight=0.001,
                   delay=2.0,
                   weight_function='wmax',
                   target_sections=['basal', 'apical'],
                   distance_range=[0.0, 150.0],
                   dynamics_params='AMPA_ExcToExc.json',
                   model_template='exp2syn')

thalamus.build()
thalamus.save_nodes(output_dir='network')
thalamus.save_edges(output_dir='network')