Esempio n. 1
0
net.input_sources.append(input_sourceI)

net.inputs.append(
    Input(id='stimE',
          input_source=input_sourceE.id,
          population=pE.id,
          percentage=100))

net.inputs.append(
    Input(id='stimI',
          input_source=input_sourceI.id,
          population=pI.id,
          percentage=100))

####################### Save network in json file #############################
print(net.to_json())
new_file = net.to_json_file('%s.json' % net.id)

################################################################################
###   Build Simulation object & save as JSON

sim = Simulation(id='SimJoglekar1Network',
                 network=new_file,
                 duration=duration,
                 dt=dt,
                 seed=1234,
                 recordTraces={
                     pE.id: [0, 1],
                     pI.id: [0, 1]
                 },
                 recordSpikes={
Esempio n. 2
0
def generate(ref='Example6_PyNN', add_inputs=True):

    ################################################################################
    ###   Build new network

    net = Network(id=ref,
                  notes='Another network for PyNN - work in progress...')

    net.parameters = {
        'N_scaling': 0.005,
        'layer_height': 400,
        'width': 100,
        'depth': 100,
        'input_weight': 0.1
    }

    cell = Cell(id='CorticalCell', pynn_cell='IF_curr_exp')
    cell.parameters = {
        'cm': 0.25,  # nF
        'i_offset': 0.0,  # nA
        'tau_m': 10.0,  # ms
        'tau_refrac': 2.0,  # ms
        'v_reset': -65.0,  # mV
        'v_rest': -65.0,  # mV
        'v_thresh': -50.0  # mV
    }
    net.cells.append(cell)

    if add_inputs:
        input_cell = Cell(id='InputCell', pynn_cell='SpikeSourcePoisson')
        input_cell.parameters = {
            'start': 0,
            'duration': 10000000000,
            'rate': 150
        }
        net.cells.append(input_cell)

    e_syn = Synapse(id='ampa',
                    pynn_receptor_type='excitatory',
                    pynn_synapse_type='curr_exp',
                    parameters={'tau_syn': 0.5})
    net.synapses.append(e_syn)
    i_syn = Synapse(id='gaba',
                    pynn_receptor_type='inhibitory',
                    pynn_synapse_type='curr_exp',
                    parameters={'tau_syn': 0.5})
    net.synapses.append(i_syn)

    N_full = {
        'L23': {
            'E': 20683,
            'I': 5834
        },
        'L4': {
            'E': 21915,
            'I': 5479
        },
        'L5': {
            'E': 4850,
            'I': 1065
        },
        'L6': {
            'E': 14395,
            'I': 2948
        }
    }

    scale = 0.1

    pops = []
    input_pops = []
    pop_dict = {}

    layers = ['L23']
    layers = ['L23', 'L4', 'L5', 'L6']

    for l in layers:

        i = 3 - layers.index(l)
        r = RectangularRegion(id=l,
                              x=0,
                              y=i * net.parameters['layer_height'],
                              z=0,
                              width=net.parameters['width'],
                              height=net.parameters['layer_height'],
                              depth=net.parameters['depth'])
        net.regions.append(r)

        for t in ['E', 'I']:

            try:
                import opencortex.utils.color as occ
                if l == 'L23':
                    if t == 'E': color = occ.L23_PRINCIPAL_CELL
                    if t == 'I': color = occ.L23_INTERNEURON
                if l == 'L4':
                    if t == 'E': color = occ.L4_PRINCIPAL_CELL
                    if t == 'I': color = occ.L4_INTERNEURON
                if l == 'L5':
                    if t == 'E': color = occ.L5_PRINCIPAL_CELL
                    if t == 'I': color = occ.L5_INTERNEURON
                if l == 'L6':
                    if t == 'E': color = occ.L6_PRINCIPAL_CELL
                    if t == 'I': color = occ.L6_INTERNEURON

            except:
                color = '.8 0 0' if t == 'E' else '0 0 1'

            pop_id = '%s_%s' % (l, t)
            pops.append(pop_id)
            ref = 'l%s%s' % (l[1:], t.lower())
            exec(
                ref +
                " = Population(id=pop_id, size='int(%s*N_scaling)'%N_full[l][t], component=cell.id, properties={'color':color, 'type':t})"
            )
            exec("%s.random_layout = RandomLayout(region = r.id)" % ref)
            exec("net.populations.append(%s)" % ref)
            exec("pop_dict['%s'] = %s" % (pop_id, ref))

            if add_inputs:
                color = '.8 .8 .8'
                input_id = '%s_%s_input' % (l, t)
                input_pops.append(input_id)
                input_ref = 'l%s%s_i' % (l[1:], t.lower())
                exec(
                    input_ref +
                    " = Population(id=input_id, size='int(%s*N_scaling)'%N_full[l][t], component=input_cell.id, properties={'color':color})"
                )
                exec("%s.random_layout = RandomLayout(region = r.id)" %
                     input_ref)
                exec("net.populations.append(%s)" % input_ref)

        #l23i = Population(id='L23_I', size=int(100*scale), component=cell.id, properties={'color':})
        #l23ei = Population(id='L23_E_input', size=int(100*scale), component=input_cell.id)
        #l23ii = Population(id='L23_I_input', size=int(100*scale), component=input_cell.id)

    #net.populations.append(l23e)
    #net.populations.append(l23ei)
    #net.populations.append(l23i)
    #net.populations.append(l23ii)

    conn_probs = [
        [0.1009, 0.1689, 0.0437, 0.0818, 0.0323, 0., 0.0076, 0.],
        [0.1346, 0.1371, 0.0316, 0.0515, 0.0755, 0., 0.0042, 0.],
        [0.0077, 0.0059, 0.0497, 0.135, 0.0067, 0.0003, 0.0453, 0.],
        [0.0691, 0.0029, 0.0794, 0.1597, 0.0033, 0., 0.1057, 0.],
        [0.1004, 0.0622, 0.0505, 0.0057, 0.0831, 0.3726, 0.0204, 0.],
        [0.0548, 0.0269, 0.0257, 0.0022, 0.06, 0.3158, 0.0086, 0.],
        [0.0156, 0.0066, 0.0211, 0.0166, 0.0572, 0.0197, 0.0396, 0.2252],
        [0.0364, 0.001, 0.0034, 0.0005, 0.0277, 0.008, 0.0658, 0.1443]
    ]

    if add_inputs:
        for p in pops:
            proj = Projection(id='proj_input_%s' % p,
                              presynaptic='%s_input' % p,
                              postsynaptic=p,
                              synapse=e_syn.id,
                              delay=2,
                              weight='input_weight')
            proj.one_to_one_connector = OneToOneConnector()
            net.projections.append(proj)

    for pre_i in range(len(pops)):
        for post_i in range(len(pops)):
            pre = pops[pre_i]
            post = pops[post_i]
            prob = conn_probs[post_i][pre_i]  #######   TODO: check!!!!
            weight = 1
            syn = e_syn
            if prob > 0:
                if 'I' in pre:
                    weight = -1
                    syn = i_syn
                proj = Projection(id='proj_%s_%s' % (pre, post),
                                  presynaptic=pre,
                                  postsynaptic=post,
                                  synapse=syn.id,
                                  delay=1,
                                  weight=weight)
                proj.random_connectivity = RandomConnectivity(probability=prob)
                net.projections.append(proj)

    print(net.to_json())
    new_file = net.to_json_file('%s.json' % net.id)

    ################################################################################
    ###   Build Simulation object & save as JSON

    recordTraces = {}
    recordSpikes = {}

    from neuromllite.utils import evaluate
    for p in pops:
        forecast_size = evaluate(pop_dict[p].size, net.parameters)
        recordTraces[p] = list(range(min(2, forecast_size)))
        recordSpikes[p] = '*'
    for ip in input_pops:
        recordSpikes[ip] = '*'

    sim = Simulation(id='Sim%s' % net.id,
                     network=new_file,
                     duration='100',
                     dt='0.025',
                     seed=1234,
                     recordTraces=recordTraces,
                     recordSpikes=recordSpikes)

    sim.to_json_file()

    return sim, net
Esempio n. 3
0
def generate(ref, np2=0, np5=0, nb2=0, nb5=0, recordTraces='*'):
    ################################################################################
    ###   Build new network

    net = Network(id=ref)
    net.notes = 'Example: %s...' % ref

    net.seed = 7890
    net.temperature = 32

    net.parameters = {
        'np2': np2,
        'np5': np5,
        'nb2': nb2,
        'nb5': nb5,
        'offset_curr_l2p': -0.05,
        'weight_bkg_l2p': 0.01,
        'weight_bkg_l5p': 0.01
    }

    l2p_cell = Cell(id='CELL_HH_reduced_L2Pyr',
                    neuroml2_source_file='../CELL_HH_reduced_L2Pyr.cell.nml')
    net.cells.append(l2p_cell)
    l5p_cell = Cell(id='CELL_HH_reduced_L5Pyr',
                    neuroml2_source_file='../CELL_HH_reduced_L5Pyr.cell.nml')
    net.cells.append(l5p_cell)
    l2b_cell = Cell(id='CELL_HH_simple_L2Basket',
                    neuroml2_source_file='../CELL_HH_simple_L2Basket.cell.nml')
    net.cells.append(l2b_cell)
    l5b_cell = Cell(id='CELL_HH_simple_L5Basket',
                    neuroml2_source_file='../CELL_HH_simple_L5Basket.cell.nml')
    net.cells.append(l5b_cell)

    input_source_poisson100 = InputSource(id='poissonFiringSyn100Hz',
                                          neuroml2_source_file='../inputs.nml')
    net.input_sources.append(input_source_poisson100)

    input_offset_curr_l2p = InputSource(id='input_offset_curr_l2p',
                                        pynn_input='DCSource',
                                        parameters={
                                            'amplitude': 'offset_curr_l2p',
                                            'start': 0,
                                            'stop': 1e9
                                        })

    net.input_sources.append(input_offset_curr_l2p)

    l2 = RectangularRegion(id='L2',
                           x=0,
                           y=1000,
                           z=0,
                           width=1000,
                           height=10,
                           depth=1000)
    net.regions.append(l2)
    l5 = RectangularRegion(id='L5',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=10,
                           depth=1000)
    net.regions.append(l5)

    #https://github.com/OpenSourceBrain/OpenCortex
    import opencortex.utils.color as occ

    pop_l2p = Population(id='pop_l2p',
                         size='np2',
                         component=l2p_cell.id,
                         properties={'color': occ.L23_PRINCIPAL_CELL},
                         random_layout=RandomLayout(region=l2.id))
    net.populations.append(pop_l2p)
    pop_l5p = Population(id='pop_l5p',
                         size='np5',
                         component=l5p_cell.id,
                         properties={'color': occ.L5_PRINCIPAL_CELL},
                         random_layout=RandomLayout(region=l5.id))
    net.populations.append(pop_l5p)
    pop_l2b = Population(id='pop_l2b',
                         size='nb2',
                         component=l2b_cell.id,
                         properties={'color': occ.L23_INTERNEURON},
                         random_layout=RandomLayout(region=l2.id))
    net.populations.append(pop_l2b)
    pop_l5b = Population(id='pop_l5b',
                         size='nb5',
                         component=l5b_cell.id,
                         properties={'color': occ.L5_INTERNEURON},
                         random_layout=RandomLayout(region=l5.id))
    net.populations.append(pop_l5b)

    # L2 -> L2
    _add_projection(pop_l2p,
                    pop_l2b,
                    'AMPA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l2b,
                    pop_l2p,
                    'L2Pyr_GABAA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l2b,
                    pop_l2p,
                    'L2Pyr_GABAB',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)

    # L2 -> L5
    _add_projection(pop_l2p,
                    pop_l5p,
                    'L5Pyr_AMPA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l2p,
                    pop_l5b,
                    'AMPA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l2b,
                    pop_l5p,
                    'L5Pyr_GABAA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)

    # L5 -> L5
    _add_projection(pop_l5p,
                    pop_l5b,
                    'AMPA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l5b,
                    pop_l5p,
                    'L5Pyr_GABAA',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)
    _add_projection(pop_l5b,
                    pop_l5p,
                    'L5Pyr_GABAB',
                    delay=0,
                    weight=0.001,
                    probability=0.8,
                    net=net)

    net.inputs.append(
        Input(id='stim_%s' % pop_l2p.id,
              input_source=input_source_poisson100.id,
              population=pop_l2p.id,
              percentage=100,
              weight='weight_bkg_l2p'))
    net.inputs.append(
        Input(id='stim_%s' % pop_l5p.id,
              input_source=input_source_poisson100.id,
              population=pop_l5p.id,
              percentage=100,
              weight='weight_bkg_l5p'))

    print(net.to_json())
    new_file = net.to_json_file('%s.json' % net.id)

    ################################################################################
    ###   Build Simulation object & save as JSON

    sim = Simulation(id='Sim%s' % net.id,
                     network=new_file,
                     duration='500',
                     seed='1111',
                     dt='0.025',
                     recordTraces={'all': recordTraces},
                     recordSpikes={'all': '*'})

    sim.to_json_file()
    print(sim.to_json())

    return sim, net
Esempio n. 4
0
def generate(ref="Example6_PyNN", add_inputs=True):

    ################################################################################
    ###   Build new network

    net = Network(id=ref, notes="Another network for PyNN - work in progress...")

    net.parameters = {
        "N_scaling": 0.005,
        "layer_height": 400,
        "width": 100,
        "depth": 100,
        "input_weight": 0.1,
    }

    cell = Cell(id="CorticalCell", pynn_cell="IF_curr_exp")
    cell.parameters = {
        "cm": 0.25,  # nF
        "i_offset": 0.0,  # nA
        "tau_m": 10.0,  # ms
        "tau_refrac": 2.0,  # ms
        "v_reset": -65.0,  # mV
        "v_rest": -65.0,  # mV
        "v_thresh": -50.0,  # mV
    }
    net.cells.append(cell)

    if add_inputs:
        input_cell = Cell(id="InputCell", pynn_cell="SpikeSourcePoisson")
        input_cell.parameters = {"start": 0, "duration": 10000000000, "rate": 150}
        net.cells.append(input_cell)

    e_syn = Synapse(
        id="ampa",
        pynn_receptor_type="excitatory",
        pynn_synapse_type="curr_exp",
        parameters={"tau_syn": 0.5},
    )
    net.synapses.append(e_syn)
    i_syn = Synapse(
        id="gaba",
        pynn_receptor_type="inhibitory",
        pynn_synapse_type="curr_exp",
        parameters={"tau_syn": 0.5},
    )
    net.synapses.append(i_syn)

    N_full = {
        "L23": {"E": 20683, "I": 5834},
        "L4": {"E": 21915, "I": 5479},
        "L5": {"E": 4850, "I": 1065},
        "L6": {"E": 14395, "I": 2948},
    }

    scale = 0.1

    pops = []
    input_pops = []
    pop_dict = {}

    layers = ["L23"]
    layers = ["L23", "L4", "L5", "L6"]

    for l in layers:

        i = 3 - layers.index(l)
        r = RectangularRegion(
            id=l,
            x=0,
            y=i * net.parameters["layer_height"],
            z=0,
            width=net.parameters["width"],
            height=net.parameters["layer_height"],
            depth=net.parameters["depth"],
        )
        net.regions.append(r)

        for t in ["E", "I"]:

            try:
                import opencortex.utils.color as occ

                if l == "L23":
                    if t == "E":
                        color = occ.L23_PRINCIPAL_CELL
                    if t == "I":
                        color = occ.L23_INTERNEURON
                if l == "L4":
                    if t == "E":
                        color = occ.L4_PRINCIPAL_CELL
                    if t == "I":
                        color = occ.L4_INTERNEURON
                if l == "L5":
                    if t == "E":
                        color = occ.L5_PRINCIPAL_CELL
                    if t == "I":
                        color = occ.L5_INTERNEURON
                if l == "L6":
                    if t == "E":
                        color = occ.L6_PRINCIPAL_CELL
                    if t == "I":
                        color = occ.L6_INTERNEURON

            except:
                color = ".8 0 0" if t == "E" else "0 0 1"

            pop_id = "%s_%s" % (l, t)
            pops.append(pop_id)
            ref = "l%s%s" % (l[1:], t.lower())
            exec(
                ref
                + " = Population(id=pop_id, size='int(%s*N_scaling)'%N_full[l][t], component=cell.id, properties={'color':color, 'type':t})"
            )
            exec("%s.random_layout = RandomLayout(region = r.id)" % ref)
            exec("net.populations.append(%s)" % ref)
            exec("pop_dict['%s'] = %s" % (pop_id, ref))

            if add_inputs:
                color = ".8 .8 .8"
                input_id = "%s_%s_input" % (l, t)
                input_pops.append(input_id)
                input_ref = "l%s%s_i" % (l[1:], t.lower())
                exec(
                    input_ref
                    + " = Population(id=input_id, size='int(%s*N_scaling)'%N_full[l][t], component=input_cell.id, properties={'color':color})"
                )
                exec("%s.random_layout = RandomLayout(region = r.id)" % input_ref)
                exec("net.populations.append(%s)" % input_ref)

        # l23i = Population(id='L23_I', size=int(100*scale), component=cell.id, properties={'color':})
        # l23ei = Population(id='L23_E_input', size=int(100*scale), component=input_cell.id)
        # l23ii = Population(id='L23_I_input', size=int(100*scale), component=input_cell.id)

    # net.populations.append(l23e)
    # net.populations.append(l23ei)
    # net.populations.append(l23i)
    # net.populations.append(l23ii)

    conn_probs = [
        [0.1009, 0.1689, 0.0437, 0.0818, 0.0323, 0.0, 0.0076, 0.0],
        [0.1346, 0.1371, 0.0316, 0.0515, 0.0755, 0.0, 0.0042, 0.0],
        [0.0077, 0.0059, 0.0497, 0.135, 0.0067, 0.0003, 0.0453, 0.0],
        [0.0691, 0.0029, 0.0794, 0.1597, 0.0033, 0.0, 0.1057, 0.0],
        [0.1004, 0.0622, 0.0505, 0.0057, 0.0831, 0.3726, 0.0204, 0.0],
        [0.0548, 0.0269, 0.0257, 0.0022, 0.06, 0.3158, 0.0086, 0.0],
        [0.0156, 0.0066, 0.0211, 0.0166, 0.0572, 0.0197, 0.0396, 0.2252],
        [0.0364, 0.001, 0.0034, 0.0005, 0.0277, 0.008, 0.0658, 0.1443],
    ]

    if add_inputs:
        for p in pops:
            proj = Projection(
                id="proj_input_%s" % p,
                presynaptic="%s_input" % p,
                postsynaptic=p,
                synapse=e_syn.id,
                delay=2,
                weight="input_weight",
            )
            proj.one_to_one_connector = OneToOneConnector()
            net.projections.append(proj)

    for pre_i in range(len(pops)):
        for post_i in range(len(pops)):
            pre = pops[pre_i]
            post = pops[post_i]
            prob = conn_probs[post_i][pre_i]  #######   TODO: check!!!!
            weight = 1
            syn = e_syn
            if prob > 0:
                if "I" in pre:
                    weight = -1
                    syn = i_syn
                proj = Projection(
                    id="proj_%s_%s" % (pre, post),
                    presynaptic=pre,
                    postsynaptic=post,
                    synapse=syn.id,
                    delay=1,
                    weight=weight,
                )
                proj.random_connectivity = RandomConnectivity(probability=prob)
                net.projections.append(proj)

    print(net.to_json())
    new_file = net.to_json_file("%s.json" % net.id)

    ################################################################################
    ###   Build Simulation object & save as JSON

    record_traces = {}
    record_spikes = {}

    from neuromllite.utils import evaluate

    for p in pops:
        forecast_size = evaluate(pop_dict[p].size, net.parameters)
        record_traces[p] = list(range(min(2, forecast_size)))
        record_spikes[p] = "*"
    for ip in input_pops:
        record_spikes[ip] = "*"

    sim = Simulation(
        id="Sim%s" % net.id,
        network=new_file,
        duration="100",
        dt="0.025",
        seed=1234,
        record_traces=record_traces,
        record_spikes=record_spikes,
    )

    sim.to_json_file()

    return sim, net