def generate(reference, 
             only_areas_matching=None, 
             only_ids_matching=None,
             include_contra=False,
             include_connections=True,
             include_detailed_cells=False):

    colors = {}
    centres = {}
    pop_ids = []
    used_ids = {}
    names = {}
    areas = {}

    with open('nature13186-s2_1.csv', 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='"')
        for w in reader:
            print w
            if w[0] != 'id':
                short = w[3].replace(', ','_')
                name = w[4].strip('"')
                names[short]=name

    with open('nature13186-s2_2.csv', 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='"')
        for w in reader:
            print w
            if w[0] != 'ID':
                short = w[2].replace(', ','_')
                area = w[4].strip('"')
                areas[short]=area

    for n in names: print('%s: \t%s'%(n,names[n]))
    for a in areas: print('%s: \t%s'%(a,areas[a]))
    #exit()

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

    net = Network(id=reference)
    net.notes = "NOTE: this is only a quick demo!! Do not use it for your research assuming an accurate conversion of the source data!!! "

    #cell = Cell(id='dummycell', pynn_cell='IF_cond_alpha')
    #cell.parameters = { "tau_refrac":5, "i_offset":.1 }
    cell = Cell(id='dummycell', neuroml2_source_file='passiveSingleCompCell.cell.nml')
    
    
    net.cells.append(cell)

    net.synapses.append(Synapse(id='ampa', 
                                pynn_receptor_type='excitatory', 
                                pynn_synapse_type='cond_alpha', 
                                parameters={'e_rev':-10, 'tau_syn':2}))

    '''                            
    r1 = RectangularRegion(id='region1', x=0,y=0,z=0,width=1000,height=100,depth=1000)
    net.regions.append(r1)
    default_cell = Cell(id='L23PyrRS', neuroml2_source_file='TestSmall/L23PyrRS.cell.nml')
    net.cells.append(default_cell)
    p0 = Population(id='pop0', size=5, component=default_cell.id, properties={'color':'0 .8 0'})
    net.populations.append(p0)
    net.populations[0].random_layout = RandomLayout(region=r1.id)'''

    detailed_cells = ['AA0289'] if include_detailed_cells else []
    
    for dc in detailed_cells:
        
        ll = SingleLocation()
        ll.location = Location(x=0,y=0,z=0)
        orig_file='%s_active.cell.nml'%dc
        
        new_ref, new_cell_file = get_oriented_cell(orig_file, math.pi,math.pi/2, 5500, 5300, 700)
        
        print("Translated %s to %s"%(orig_file, new_cell_file))

        mo = Cell(id=dc, neuroml2_source_file='%s_active.cell.nml'%dc)
        net.cells.append(mo)
        p1 = Population(id='pop_%s'%dc, 
                        size=1, 
                        component=mo.id, 
                        properties={'color':'.8 0 0'})
        p1.single_location=ll 
        #net.populations.append(p1)
        
        mo = Cell(id=new_ref, neuroml2_source_file=new_cell_file)
        net.cells.append(mo)
        p1 = Population(id='pop_%s'%new_ref, 
                        size=1, 
                        component=new_ref, 
                        properties={'color':'0 0.8 0'})
        p1.single_location=ll 
        net.populations.append(p1)


    f = open('ABA12.tsv')
    for l in f:
        w = l.split()
        print w
        pre_id = w[0].replace('-','_').replace('/','_')
        if pre_id != '[0]':

            match = False
            if only_ids_matching==None:
                match = True
            else:
                for i in only_ids_matching:
                    if i=='*' or i in pre_id:
                        match = True


            if match:

                scale = 1000
                x0 = float(w[2])*scale
                all = [ (pre_id, x0)]
                if include_contra:
                    all = [ (pre_id, x0), ('CONTRA_%s'%pre_id, x0*-1)]

                for a in all:
                    id = a[0]
                    x = a[1]
                    centres[id] = (x,float(w[3])*scale,float(w[4])*scale)
                    colors[id] = w[1]

                    repl = id
                    name = names[w[0]]
                    short_name3 = w[0][:3]
                    short_name4 = w[0][:4]
                    short_name5 = w[0][:5]
                    short_name6 = w[0][:6]
                    short_name7 = w[0][:7]

                    if w[0] in areas:
                        area = areas[w[0]]  
                    elif short_name7 in areas:
                           area = areas[short_name7]  
                    elif short_name6 in areas:
                           area = areas[short_name6]  
                    elif short_name5 in areas:
                           area = areas[short_name5]  
                    elif short_name4 in areas:
                           area = areas[short_name4]  
                    elif short_name3 in areas:
                           area = areas[short_name3]  
                    else:
                        area = '???'

                    match = False
                    if only_areas_matching==None:
                        match = True
                    else:
                        for a in only_areas_matching:
                            if a in area:
                                match = True


                    if match:

                        p = centres[repl]
                        used_ids[id] = '_%s'%repl if repl[0].isdigit() else repl

                        region_name = name.split(',')[0].replace(' ','_')
                        region_name = used_ids[id]
                        r = RectangularRegion(id=region_name, x=p[0],y=p[1],z=p[2],width=1,height=1,depth=1)
                        net.regions.append(r)


                        color = '.8 .8 .8'
                        if 'Thalamus' in area:
                            color = '.3 .3 .3'
                        if 'Isocortex' in area:
                            color = occ.L23_PRINCIPAL_CELL
                        if 'bulb' in area:
                            color = '0 0 1'
                        if 'Cerebe' in area:
                            color = '.6 .6 .6'
                        #if 'Hippocampal' in area:
                        #    color = occ.L6_PRINCIPAL_CELL

                        if '1' in id:
                            color = occ.THALAMUS_2
                        if '2_3' in id:
                            color = occ.L23_PRINCIPAL_CELL
                        if '4' in id:
                            color = occ.L4_PRINCIPAL_CELL
                        if '5' in id:
                            color = occ.L5_PRINCIPAL_CELL
                        if '6' in id:
                            color = occ.L6_PRINCIPAL_CELL


                        p0 = Population(id=used_ids[id], 
                                        size=1, 
                                        component=cell.id, 
                                        properties={'color':'%s'%(color),
                                                    'radius':50,
                                                    'name':name,
                                                    'area':area},
                                        random_layout = RandomLayout(region=r.id))

                        net.populations.append(p0)
                        pop_ids.append(id)

    #print centres.keys()


    if include_connections:
        with open('nature13186-s4_W_ipsi.csv', 'rb') as csvfile:
            reader = csv.reader(csvfile, delimiter=',', quotechar='"')
            indices = {}
            for w in reader:
                #print w
                if w[0]=='ROOT':
                    for i in range(len(w)):
                        indices[i]=w[i]
                    print indices
                else:
                    pre = w[0]
                    for i in range(len(w)):
                        if i!=0:
                            weight = float(w[i])
                            if weight>0:
                                post = indices[i]
                                print('Connection %s -> %s of %s'%(pre, post, weight))

                                if weight>0.0:

                                    if pre in used_ids and post in used_ids:
                                        print('Adding conn from %s -> %s of %s'%(pre, post, weight))


                                        ################################################################################
                                        ###   Add a projection

                                        net.projections.append(Projection(id='proj_%s_%s'%(used_ids[pre],used_ids[post]),
                                                                          presynaptic=used_ids[pre], 
                                                                          postsynaptic=used_ids[post],
                                                                          synapse='ampa',
                                                                          weight=weight,
                                                                          random_connectivity=RandomConnectivity(probability=1)))




    from neuromllite import Simulation
    #print(net)

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

    sim = Simulation(id='Sim_%s'%net.id,
                     network=new_file,
                     duration='1000',
                     dt='0.025',
                     recordTraces={'all':'*'})


    ################################################################################
    ###   Export to some formats
    ###   Try:
    ###        python Example1.py -graph2

    from neuromllite.NetworkGenerator import check_to_generate_or_run
    import sys

    check_to_generate_or_run(sys.argv, sim)
示例#2
0
          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={
                     pE.id: '*',
                     pI.id: '*'
                 })

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys
示例#3
0
def generate():
    ################################################################################
    ###   Build new network

    net = Network(id='ExampleK')
    net.notes = 'Example...'

    net.parameters = {'pop_size': '8', 'stim_amp': '0.3'}

    cell = Cell(id='kuramoto1', lems_source_file='CellExamples.xml')

    net.cells.append(cell)

    input_source = InputSource(id='iclamp0',
                               neuroml2_input='PulseGeneratorDL',
                               parameters={
                                   'amplitude': 'stim_amp',
                                   'delay': '100ms',
                                   'duration': '800ms'
                               })
    net.input_sources.append(input_source)
    '''

    input_source = InputSource(id='poissonFiringSyn', 
                               neuroml2_input='poissonFiringSynapse',
                               parameters={'average_rate':"eta", 'synapse':"ampa", 'spike_target':"./ampa"})


'''

    r1 = RectangularRegion(id='region1',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pE = Population(id='Epop',
                    size='pop_size',
                    component=cell.id,
                    properties={'color': '1 0 0'},
                    random_layout=RandomLayout(region=r1.id))

    net.populations.append(pE)
    '''
    net.synapses.append(Synapse(id='ampa', 
                                pynn_receptor_type='excitatory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))


    net.projections.append(Projection(id='projEinput',
                                      presynaptic=pEpoisson.id, 
                                      postsynaptic=pE.id,
                                      synapse='ampa',
                                      delay=2,
                                      weight=0.02,
                                      one_to_one_connector=OneToOneConnector()))
               
    net.projections.append(Projection(id='projEE',
                                      presynaptic=pE.id, 
                                      postsynaptic=pE.id,
                                      synapse='ampa',
                                      delay=2,
                                      weight=0.002,
                                      random_connectivity=RandomConnectivity(probability=.5)))

    net.projections.append(Projection(id='projEI',
                                      presynaptic=pE.id, 
                                      postsynaptic=pI.id,
                                      synapse='ampa',
                                      delay=2,
                                      weight=0.02,
                                      random_connectivity=RandomConnectivity(probability=.5)))
    
    net.projections.append(Projection(id='projIE',
                                      presynaptic=pI.id, 
                                      postsynaptic=pE.id,
                                      synapse='gaba',
                                      delay=2,
                                      weight=0.02,
                                      random_connectivity=RandomConnectivity(probability=.5)))
    '''
    net.inputs.append(
        Input(id='stim',
              input_source=input_source.id,
              population=pE.id,
              percentage=50))

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

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

    sim = Simulation(id='SimExampleK',
                     network=new_file,
                     duration='1000',
                     dt='0.025',
                     seed=123,
                     recordVariables={'sin_theta': {
                         pE.id: '*'
                     }})

    sim.to_json_file()

    return sim, net
示例#4
0
def generate():

    dt = 0.025
    simtime = 1000

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

    net = Network(id="Example7_Brunel2000")
    net.notes = "Example 7: based on network of Brunel 2000"

    net.parameters = {
        "g": 4,
        "eta": 1,
        "order": 5,
        "epsilon": 0.1,
        "J": 0.1,
        "delay": 1.5,
        "tauMem": 20.0,
        "tauSyn": 0.1,
        "tauRef": 2.0,
        "U0": 0.0,
        "theta": 20.0,
    }

    cell = Cell(id="ifcell", pynn_cell="IF_curr_alpha")

    cell.parameters = {
        "tau_m": "tauMem",
        "tau_refrac": "tauRef",
        "v_rest": "U0",
        "v_reset": "U0",
        "v_thresh": "theta",
        "cm": 0.001,
        "i_offset": 0,
    }

    # cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml')
    net.cells.append(cell)

    poisson_input = Cell(id="poisson_input", pynn_cell="SpikeSourcePoisson")
    poisson_input.parameters = {
        "rate":
        "1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)",
        "start": 0,
        "duration": 1e9,
    }
    net.cells.append(poisson_input)

    r1 = RectangularRegion(id="region1",
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pE = Population(
        id="Epop",
        size="4*order",
        component=cell.id,
        properties={
            "color": ".9 0 0",
            "radius": 5
        },
        random_layout=RandomLayout(region=r1.id),
    )
    pEpoisson = Population(
        id="expoisson",
        size="4*order",
        component=poisson_input.id,
        properties={
            "color": "0.9 0.7 0.7",
            "radius": 3
        },
        random_layout=RandomLayout(region=r1.id),
    )
    pI = Population(
        id="Ipop",
        size="1*order",
        component=cell.id,
        properties={
            "color": "0 0 .9",
            "radius": 5
        },
        random_layout=RandomLayout(region=r1.id),
    )
    pIpoisson = Population(
        id="inpoisson",
        size="1*order",
        component=poisson_input.id,
        properties={
            "color": "0.7 0.7 0.9",
            "radius": 3
        },
        random_layout=RandomLayout(region=r1.id),
    )

    net.populations.append(pE)
    net.populations.append(pEpoisson)
    net.populations.append(pI)
    net.populations.append(pIpoisson)

    net.synapses.append(
        Synapse(
            id="ampa",
            pynn_receptor_type="excitatory",
            pynn_synapse_type="curr_alpha",
            parameters={"tau_syn": 0.1},
        ))

    net.synapses.append(
        Synapse(
            id="gaba",
            pynn_receptor_type="inhibitory",
            pynn_synapse_type="curr_alpha",
            parameters={"tau_syn": 0.1},
        ))

    delay_ext = dt

    downscale = 1
    J_eff = "J*%s" % (downscale)
    # synaptic weights, scaled for alpha functions, such that
    # for constant membrane potential, charge J would be deposited
    fudge = 0.00041363506632638  # ensures dV = J at V=0
    JE = "((%s)/tauSyn)*%s" % (J_eff, fudge)
    JI = "-1*g*%s" % (JE)

    net.projections.append(
        Projection(
            id="projEinput",
            presynaptic=pEpoisson.id,
            postsynaptic=pE.id,
            synapse="ampa",
            delay=delay_ext,
            weight=JE,
            one_to_one_connector=OneToOneConnector(),
        ))

    net.projections.append(
        Projection(
            id="projIinput",
            presynaptic=pIpoisson.id,
            postsynaptic=pI.id,
            synapse="ampa",
            delay=delay_ext,
            weight=JE,
            one_to_one_connector=OneToOneConnector(),
        ))

    net.projections.append(
        Projection(
            id="projEE",
            presynaptic=pE.id,
            postsynaptic=pE.id,
            synapse="ampa",
            delay="delay",
            weight=JE,
            random_connectivity=RandomConnectivity(probability="epsilon"),
        ))

    net.projections.append(
        Projection(
            id="projEI",
            presynaptic=pE.id,
            postsynaptic=pI.id,
            synapse="ampa",
            delay="delay",
            weight=JE,
            random_connectivity=RandomConnectivity(probability="epsilon"),
        ))

    net.projections.append(
        Projection(
            id="projIE",
            presynaptic=pI.id,
            postsynaptic=pE.id,
            synapse="gaba",
            delay="delay",
            weight=JI,
            random_connectivity=RandomConnectivity(probability="epsilon"),
        ))

    net.projections.append(
        Projection(
            id="projII",
            presynaptic=pI.id,
            postsynaptic=pI.id,
            synapse="gaba",
            delay="delay",
            weight=JI,
            random_connectivity=RandomConnectivity(probability="epsilon"),
        ))

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

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

    sim = Simulation(
        id="SimExample7",
        network=new_file,
        duration=simtime,
        dt=dt,
        seed=123,
        record_traces={
            pE.id: [0, 1],
            pI.id: [0, 1]
        },
        record_spikes={
            pE.id: "*",
            pI.id: "*",
            pEpoisson.id: [0, 1, 2, 3, 4],
            pIpoisson.id: [0, 1, 2, 3, 4],
        },
    )

    sim.to_json_file()

    return sim, net
示例#5
0
          population=pop2.id,
          percentage=50))

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

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

sim = Simulation(
    id="SimSpikers",
    network=new_file,
    duration="10000",
    dt="0.025",
    record_traces={
        "pop0": "*",
        "pop1": "*",
        "pop2": "*"
    },
    record_spikes={"all": "*"},
)

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
                                 'amplitude': 'inh_input',
                                 'delay': 'input_delay',
                                 'duration': 'input_duration'
                             })
net.input_sources.append(input_source_i)
net.inputs.append(
    Input(id='Inh_stim',
          input_source=input_source_i.id,
          population=inh_pop.id,
          percentage=100))

# Save to JSON format
net.id = 'WC'
new_file = net.to_json_file('WC.json')

sim = Simulation(id='SimWC',
                 duration='100',
                 dt='0.005',
                 network=new_file,
                 recordRates={'all': '*'},
                 plots2D={
                     'E-I': {
                         'x_axis': 'Excitatory/0/Exc/r',
                         'y_axis': 'Inhibitory/0/Inh/r'
                     }
                 })

sim.to_json_file('SimWC.nmllite.json')

check_to_generate_or_run(sys.argv, sim)
示例#7
0
def generate():

    dt = 0.1
    simtime = 1

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

    net = Network(id='ABC')
    net.notes = 'Example of simplified network'

    net.parameters = {'A_initial': 0, 'A_slope': 5}

    cellInput = Cell(id='a_input',
                     lems_source_file='PNL.xml',
                     parameters={'variable': 'A_initial'})
    net.cells.append(cellInput)

    cellA = Cell(id='a',
                 lems_source_file='PNL.xml',
                 parameters={'slope': 'A_slope'})
    net.cells.append(cellA)
    cellB = Cell(id='b', lems_source_file='PNL.xml')
    net.cells.append(cellB)
    cellC = Cell(id='c', lems_source_file='PNL.xml')
    net.cells.append(cellC)

    rsDL = Synapse(id='rsDL', lems_source_file='PNL.xml')
    net.synapses.append(rsDL)

    r1 = RectangularRegion(id='region1',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pAin = Population(id='A_input',
                      size='1',
                      component=cellInput.id,
                      properties={
                          'color': '0.2 0.2 0.2',
                          'radius': 3
                      },
                      random_layout=RandomLayout(region=r1.id))
    net.populations.append(pAin)

    pA = Population(id='A',
                    size='1',
                    component=cellA.id,
                    properties={
                        'color': '0 0.9 0',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    net.populations.append(pA)

    pB = Population(id='B',
                    size='1',
                    component=cellB.id,
                    properties={
                        'color': '.9 0 0',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    net.populations.append(pB)

    pC = Population(id='C',
                    size='1',
                    component=cellC.id,
                    properties={
                        'color': '0.7 0 0',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    net.populations.append(pC)

    silentDLin = Synapse(id='silentSyn_proj_input', lems_source_file='PNL.xml')
    net.synapses.append(silentDLin)
    net.projections.append(
        Projection(id='proj_input',
                   presynaptic=pA.id,
                   postsynaptic=pB.id,
                   synapse=rsDL.id,
                   pre_synapse=silentDLin.id,
                   type='continuousProjection',
                   weight=1,
                   random_connectivity=RandomConnectivity(probability=1)))

    silentDL0 = Synapse(id='silentSyn_proj0', lems_source_file='PNL.xml')
    net.synapses.append(silentDL0)
    net.projections.append(
        Projection(id='proj0',
                   presynaptic=pAin.id,
                   postsynaptic=pA.id,
                   synapse=rsDL.id,
                   pre_synapse=silentDL0.id,
                   type='continuousProjection',
                   weight=1,
                   random_connectivity=RandomConnectivity(probability=1)))

    silentDL1 = Synapse(id='silentSyn_proj1', lems_source_file='PNL.xml')
    net.synapses.append(silentDL1)
    net.projections.append(
        Projection(id='proj1',
                   presynaptic=pA.id,
                   postsynaptic=pC.id,
                   synapse=rsDL.id,
                   pre_synapse=silentDL1.id,
                   type='continuousProjection',
                   weight=1,
                   random_connectivity=RandomConnectivity(probability=1)))

    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=simtime,
                     dt=dt,
                     seed=123,
                     recordVariables={
                         'OUTPUT': {
                             'all': '*'
                         },
                         'INPUT': {
                             'all': '*'
                         }
                     })

    sim.to_json_file()

    return sim, net
示例#8
0
sim = Simulation(id='SimExample9',
                 network=new_file,
                 duration='1000000',
                 dt='25',
                 recordVariables={
                     'x': {
                         'all': '*'
                     },
                     'y': {
                         'all': '*'
                     },
                     'z': {
                         'all': '*'
                     }
                 },
                 plots2D={
                     'X-Y': {
                         'x_axis': 'hrPop[0]/x',
                         'y_axis': 'hrPop[0]/y'
                     },
                     'Y-Z': {
                         'x_axis': 'hrPop[0]/y',
                         'y_axis': 'hrPop[0]/z'
                     },
                     'X-Z': {
                         'x_axis': 'hrPop[0]/x',
                         'y_axis': 'hrPop[0]/z'
                     }
                 },
                 plots3D={
                     'X-Y-Z': {
                         'x_axis': 'hrPop[0]/x',
                         'y_axis': 'hrPop[0]/y',
                         'z_axis': 'hrPop[0]/z'
                     }
                 })
示例#9
0
    Input(id="stim",
          input_source=input_source.id,
          population=p0.id,
          percentage=50))

print(net.to_json())
net_json_file = net.to_json_file("%s.json" % net.id)
net_yaml_file = net.to_yaml_file("%s.yaml" % net.id)

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

sim = Simulation(
    id="SimExample4",
    network=net_json_file,
    duration="1000",
    dt="0.01",
    recordTraces={"all": "*"},
    recordSpikes={"pop0": "*"},
)

sim.to_json_file()
sim.network = net_yaml_file
sim.to_yaml_file()

sim.network = net_json_file  # reverting, for call below...

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys
示例#10
0
    )
)
net.synapses.append(
    Synapse(
        id="ampa", neuroml2_source_file="../../../examples/test_files/ampa.synapse.nml"
    )
)


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


################################################################################
###   Use a handler which just prints info on positions, etc.

def_handler = DefaultNetworkHandler()

generate_network(net, def_handler)


################################################################################
###   Export to some formats, e.g. try:
###        python Example2.py -graph2

from neuromllite.NetworkGenerator import check_to_generate_or_run
from neuromllite import Simulation
import sys

check_to_generate_or_run(sys.argv, Simulation(id="Sim%s" % net.id, network=new_file))
示例#11
0
文件: FN.py 项目: kmantel/MDFTests
def generate():
    
    dt = 0.05
    simtime = 100
    
    ################################################################################
    ###   Build new network

    net = Network(id='FN')
    net.notes = 'Example of simplified network'
    
    net.parameters = { 'initial_w': 0.0, 
                       'initial_v': -1, 
                       'a_v': -0.3333333333333333, 
                       'b_v': 0.0, 
                       'c_v': 1.0, 
                       'd_v': 1, 
                       'e_v': -1.0, 
                       'f_v': 1.0, 
                       'time_constant_v': 1.0, 
                       'a_w': 1.0, 
                       'b_w': -0.8, 
                       'c_w': 0.7, 
                       'time_constant_w': 12.5, 
                       'threshold': -1.0, 
                       'mode': 1.0, 
                       'uncorrelated_activity': 0.0, 
                       'Iext': 0 }

    cellInput = Cell(id='fn', 
                     lems_source_file='FN_Definitions.xml',
                     parameters={})
    for p in net.parameters:
        cellInput.parameters[p]=p
    net.cells.append(cellInput)


    r1 = RectangularRegion(id='region1', x=0,y=0,z=0,width=1000,height=100,depth=1000)
    net.regions.append(r1)


    pop = Population(id='FNpop', 
                    size='1', 
                    component=cellInput.id, 
                    properties={'color':'0.2 0.2 0.2', 'radius':3},
                    random_layout = RandomLayout(region=r1.id))
    net.populations.append(pop)


    

    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=simtime,
                     dt=dt,
                     seed= 123,
                     recordVariables={'V':{'all':'*'},'W':{'all':'*'}},
                     plots2D={'VW':{'x_axis':'%s/0/fn/V'%pop.id,
                                 'y_axis':'%s/0/fn/W'%pop.id}})

    sim.to_json_file()
    
    return sim, net
示例#12
0
def generate():

    dt = 0.025
    simtime = 1000

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

    net = Network(id='ExampleIF')
    net.notes = 'Example with IF'

    net.parameters = {
        'tauMem': 20.0,
        'tauSyn': 0.1,
        'tauRef': 2,
        'V0': -70,
        'theta': -50.0,
        'scale': 1,
        'in_weight': 0.01,
        'in_rate': 50
    }

    ifcell = Cell(id='ifcell', pynn_cell='IF_curr_alpha')

    ifcell.parameters = {
        'tau_m': 'tauMem',
        'tau_refrac': 'tauRef',
        'v_rest': 'V0',
        'v_reset': 'V0',
        'v_thresh': 'theta',
        'cm': 0.001,
        "i_offset": 0
    }

    net.cells.append(ifcell)

    poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson')
    poisson_input.parameters = {'rate': 'in_rate', 'start': 0, 'duration': 1e9}
    net.cells.append(poisson_input)

    r1 = RectangularRegion(id='region1',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pIF = Population(id='IFpop',
                     size='1*scale',
                     component=ifcell.id,
                     properties={
                         'color': '.9 0 0',
                         'radius': 5
                     },
                     random_layout=RandomLayout(region=r1.id))
    net.populations.append(pIF)

    pLNP = Population(id='LNPpop',
                      size='1*scale',
                      component=ifcell.id,
                      properties={
                          'color': '.9 0.9 0',
                          'radius': 5
                      },
                      random_layout=RandomLayout(region=r1.id))
    net.populations.append(pLNP)

    pEpoisson = Population(id='expoisson',
                           size='10',
                           component=poisson_input.id,
                           properties={
                               'color': '0.9 0.7 0.7',
                               'radius': 3
                           },
                           random_layout=RandomLayout(region=r1.id))

    net.populations.append(pEpoisson)

    net.synapses.append(
        Synapse(id='ampa',
                pynn_receptor_type='excitatory',
                pynn_synapse_type='curr_alpha',
                parameters={'tau_syn': 0.1}))

    net.projections.append(
        Projection(id='proj0',
                   presynaptic=pEpoisson.id,
                   postsynaptic=pIF.id,
                   synapse='ampa',
                   delay=0,
                   weight='in_weight',
                   random_connectivity=RandomConnectivity(probability=0.7)))

    net.projections.append(
        Projection(id='proj1',
                   presynaptic=pEpoisson.id,
                   postsynaptic=pLNP.id,
                   synapse='ampa',
                   delay=0,
                   weight='in_weight',
                   random_connectivity=RandomConnectivity(probability=0.7)))

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

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

    sim = Simulation(id='SimExampleIF',
                     network=new_file,
                     duration=simtime,
                     dt=dt,
                     seed=123,
                     recordTraces={pIF.id: '*'},
                     recordSpikes={'all': '*'})

    sim.to_json_file()

    return sim, net
示例#13
0
net.inputs.append(Input(id='stim2',
                        input_source=input_source1.id,
                        population=pop2.id,
                        percentage=50))

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


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

sim = Simulation(id='SimSpikers',
                 network=new_file,
                 duration='10000',
                 dt='0.025',
                 recordTraces={'pop0':'*','pop1':'*','pop2':'*'},
                 recordSpikes={'all':'*'})
                 
sim.to_json_file()



################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#14
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
示例#15
0
        weight="weightInput",
    )
)

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


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

sim = Simulation(
    id="SimExample8",
    network=new_file,
    duration="1000",
    seed="1111",
    dt="0.025",
    record_traces={"all": "*"},
)

sim.to_json_file()


################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#16
0
def generate():

    dt = 0.025
    simtime = 500

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

    net = Network(id='SpikingEI')
    net.notes = 'SpikingEI'

    net.parameters = {
        'order': 5,
        'wee': 8,
        'wei': 12,
        'wie': -12,
        'wii': -3,
        'w_scale': 0.001,
        'in_rate': 400,
        'epsilon': 0.5,
        'tauMem': 20.0,
        'tauSyn': 0.1,
        'tauRef': 2.0
    }

    cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha')

    cell.parameters = {
        'tau_m': 'tauMem',
        'tau_refrac': 'tauRef',
        'v_rest': -70,
        'v_reset': -70,
        'v_thresh': -50,
        'cm': 0.001,
        "i_offset": 0
    }

    #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml')
    net.cells.append(cell)

    poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson')
    poisson_input.parameters = {'rate': 'in_rate', 'start': 0, 'duration': 1e9}
    net.cells.append(poisson_input)

    r1 = RectangularRegion(id='region1',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pE = Population(id='Excitatory',
                    size='4*order',
                    component=cell.id,
                    properties={
                        'color': '.9 0 0',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    pEpoisson = Population(id='expoisson',
                           size='4*order',
                           component=poisson_input.id,
                           properties={
                               'color': '0.9 0.7 0.7',
                               'radius': 3
                           },
                           random_layout=RandomLayout(region=r1.id))
    pI = Population(id='Inhibitory',
                    size='1*order',
                    component=cell.id,
                    properties={
                        'color': '0 0 .9',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    pIpoisson = Population(id='inpoisson',
                           size='1*order',
                           component=poisson_input.id,
                           properties={
                               'color': '0.7 0.7 0.9',
                               'radius': 3
                           },
                           random_layout=RandomLayout(region=r1.id))

    net.populations.append(pE)
    net.populations.append(pEpoisson)
    net.populations.append(pI)
    net.populations.append(pIpoisson)

    net.synapses.append(
        Synapse(id='ampa',
                pynn_receptor_type='excitatory',
                pynn_synapse_type='curr_alpha',
                parameters={'tau_syn': 0.1}))

    net.synapses.append(
        Synapse(id='gaba',
                pynn_receptor_type='inhibitory',
                pynn_synapse_type='curr_alpha',
                parameters={'tau_syn': 0.1}))

    delay_ext = dt

    net.projections.append(
        Projection(id='projEinput',
                   presynaptic=pEpoisson.id,
                   postsynaptic=pE.id,
                   synapse='ampa',
                   delay=delay_ext,
                   weight=0.01,
                   one_to_one_connector=OneToOneConnector()))

    net.projections.append(
        Projection(id='projIinput',
                   presynaptic=pIpoisson.id,
                   postsynaptic=pI.id,
                   synapse='ampa',
                   delay=delay_ext,
                   weight=0.01,
                   one_to_one_connector=OneToOneConnector()))

    net.projections.append(
        Projection(
            id='projEE',
            presynaptic=pE.id,
            postsynaptic=pE.id,
            synapse='ampa',
            delay=delay_ext,
            weight='wee * w_scale',
            random_connectivity=RandomConnectivity(probability='epsilon')))

    net.projections.append(
        Projection(
            id='projEI',
            presynaptic=pE.id,
            postsynaptic=pI.id,
            synapse='ampa',
            delay=delay_ext,
            weight='wei * w_scale',
            random_connectivity=RandomConnectivity(probability='epsilon')))

    net.projections.append(
        Projection(
            id='projIE',
            presynaptic=pI.id,
            postsynaptic=pE.id,
            synapse='gaba',
            delay=delay_ext,
            weight='wie * w_scale',
            random_connectivity=RandomConnectivity(probability='epsilon')))

    net.projections.append(
        Projection(
            id='projII',
            presynaptic=pI.id,
            postsynaptic=pI.id,
            synapse='gaba',
            delay=delay_ext,
            weight='wii * w_scale',
            random_connectivity=RandomConnectivity(probability='epsilon')))

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

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

    sim = Simulation(id='SimSpiking',
                     network=new_file,
                     duration=simtime,
                     dt=dt,
                     seed=123,
                     recordTraces={
                         pE.id: '*',
                         pI.id: '*'
                     },
                     recordSpikes={'all': '*'})

    sim.to_json_file()

    return sim, net
示例#17
0
def generate():
    ################################################################################
    ###   Build new network

    net = Network(id='Example7_Brunel2000')
    net.notes = 'Example 7: based on network of Brunel 2000'

    net.parameters = {
        'g': 4,
        'eta': 1,
        'order': 5,
        'epsilon': 0.1,
        'J': 0.1,
        'delay': 1.5,
        'tauMem': 20.0,
        'tauSyn': 0.1,
        'tauRef': 2.0,
        'U0': 0.0,
        'theta': 20.0
    }

    cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha')

    cell.parameters = {
        'tau_m': 'tauMem',
        'tau_refrac': 'tauRef',
        'v_rest': 'U0',
        'v_reset': 'U0',
        'v_thresh': 'theta',
        'cm': 0.001,
        "i_offset": 0
    }

    #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml')
    net.cells.append(cell)

    expoisson = Cell(id='expoisson', pynn_cell='SpikeSourcePoisson')
    expoisson.parameters = {
        'rate':
        '1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)',
        'start': 0,
        'duration': 1e9
    }
    net.cells.append(expoisson)
    '''
    input_source = InputSource(id='iclamp0', 
                               pynn_input='DCSource', 
                               parameters={'amplitude':0.002, 'start':100., 'stop':900.})

    input_source = InputSource(id='poissonFiringSyn', 
                               neuroml2_input='poissonFiringSynapse',
                               parameters={'average_rate':"eta", 'synapse':"ampa", 'spike_target':"./ampa"})



    net.input_sources.append(input_source)'''

    pE = Population(id='Epop',
                    size='4*order',
                    component=cell.id,
                    properties={'color': '1 0 0'})
    pEpoisson = Population(id='Einput',
                           size='4*order',
                           component=expoisson.id,
                           properties={'color': '.5 0 0'})
    pI = Population(id='Ipop',
                    size='1*order',
                    component=cell.id,
                    properties={'color': '0 0 1'})

    net.populations.append(pE)
    net.populations.append(pEpoisson)
    net.populations.append(pI)

    net.synapses.append(
        Synapse(id='ampa',
                pynn_receptor_type='excitatory',
                pynn_synapse_type='curr_alpha',
                parameters={'tau_syn': 0.1}))
    net.synapses.append(
        Synapse(id='gaba',
                pynn_receptor_type='inhibitory',
                pynn_synapse_type='curr_alpha',
                parameters={'tau_syn': 0.1}))

    net.projections.append(
        Projection(id='projEinput',
                   presynaptic=pEpoisson.id,
                   postsynaptic=pE.id,
                   synapse='ampa',
                   delay=2,
                   weight=0.02,
                   one_to_one_connector=OneToOneConnector()))
    '''           
    net.projections.append(Projection(id='projEE',
                                      presynaptic=pE.id, 
                                      postsynaptic=pE.id,
                                      synapse='ampa',
                                      delay=2,
                                      weight=0.002,
                                      random_connectivity=RandomConnectivity(probability=.5)))'''

    net.projections.append(
        Projection(id='projEI',
                   presynaptic=pE.id,
                   postsynaptic=pI.id,
                   synapse='ampa',
                   delay=2,
                   weight=0.02,
                   random_connectivity=RandomConnectivity(probability=.5)))
    '''
    net.projections.append(Projection(id='projIE',
                                      presynaptic=pI.id, 
                                      postsynaptic=pE.id,
                                      synapse='gaba',
                                      delay=2,
                                      weight=0.02,
                                      random_connectivity=RandomConnectivity(probability=.5)))

    net.inputs.append(Input(id='stim',
                            input_source=input_source.id,
                            population=pE.id,
                            percentage=50))'''

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

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

    sim = Simulation(id='SimExample7',
                     network=new_file,
                     duration='1000',
                     dt='0.025',
                     seed=123,
                     recordTraces={
                         pE.id: '*',
                         pI.id: '*'
                     },
                     recordSpikes={'all': '*'})

    sim.to_json_file()

    return sim, net
示例#18
0
################################################################################
###   Build Simulation object & save as JSON

sim = Simulation(
    id='Sim%s' % net.id,
    network=new_file,
    duration='700',
    dt='0.025',
    recordVariables={
        'v': {
            'all': '*'
        },
        'u': {
            'all': '*'
        }
    },
    plots2D={'vu': {
        'x_axis': 'izhPop[0]/v',
        'y_axis': 'izhPop[0]/u'
    }},
    plots3D={
        'X-Y-Z': {
            'x_axis': 't',
            'y_axis': 'izhPop[0]/u',
            'z_axis': 'izhPop[0]/v'
        }
    })

sim.to_json_file()

################################################################################
示例#19
0
def generate():

    dt = 0.025
    simtime = 1000

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

    net = Network(id='McCPNet')
    net.notes = 'Example of simplified McCulloch-Pitts based Network'

    net.parameters = {'amp': 1.5, 'scale': 3}

    cell = Cell(id='mccp0', lems_source_file='McCPTest.xml')
    net.cells.append(cell)

    silentDL = Synapse(id='silentSyn_proj0', lems_source_file='McCPTest.xml')
    net.synapses.append(silentDL)
    rsDL = Synapse(id='rsDL', lems_source_file='McCPTest.xml')
    net.synapses.append(rsDL)

    r1 = RectangularRegion(id='region1',
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    p0 = Population(id='McCPpop0',
                    size='1*scale',
                    component=cell.id,
                    properties={
                        'color': '.9 0.9 0',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    net.populations.append(p0)

    p1 = Population(id='McCPpop1',
                    size='1*scale',
                    component=cell.id,
                    properties={
                        'color': '.9 0 0.9',
                        'radius': 5
                    },
                    random_layout=RandomLayout(region=r1.id))
    net.populations.append(p1)

    net.projections.append(
        Projection(id='proj0',
                   presynaptic=p0.id,
                   postsynaptic=p1.id,
                   synapse=rsDL.id,
                   pre_synapse=silentDL.id,
                   type='continuousProjection',
                   weight='random()',
                   random_connectivity=RandomConnectivity(probability=0.6)))
    '''
                                      
    
    net.synapses.append(Synapse(id='ampa', 
                                pynn_receptor_type='excitatory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))
                                
    
    net.projections.append(Projection(id='proj1',
                                      presynaptic=pEpoisson.id, 
                                      postsynaptic=pLNP.id,
                                      synapse='ampa',
                                      delay=0,
                                      weight='in_weight',
                                      random_connectivity=RandomConnectivity(probability=0.7)))'''

    input_source0 = InputSource(id='sg0', neuroml2_source_file='inputs.nml')
    net.input_sources.append(input_source0)
    input_source1 = InputSource(id='sg1', neuroml2_source_file='inputs.nml')
    net.input_sources.append(input_source1)

    for pop in [p0.id]:
        net.inputs.append(
            Input(id='stim0_%s' % pop,
                  input_source=input_source0.id,
                  population=pop,
                  percentage=60))

        net.inputs.append(
            Input(id='stim1_%s' % pop,
                  input_source=input_source1.id,
                  population=pop,
                  percentage=60))

    #print(net)
    #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=simtime,
                     dt=dt,
                     seed=123,
                     recordVariables={
                         'R': {
                             'all': '*'
                         },
                         'ISyn': {
                             'all': '*'
                         }
                     })

    sim.to_json_file()

    return sim, net
示例#20
0
                        population=pE.id,
                        percentage=100,
                        weight='weightInput'))

print(net)
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='1000',
                 seed='1111',
                 dt='0.025',
                 recordTraces={'all':'*'},
                 recordSpikes={'all':'*'})
                 
sim.to_json_file()



################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#21
0
def generate():
    
    dt = 0.025
    simtime = 1000
    
    ################################################################################
    ###   Build new network

    net = Network(id='Example7_Brunel2000')
    net.notes = 'Example 7: based on network of Brunel 2000'
    

    net.parameters = { 'g':       4, 
                       'eta':     1, 
                       'order':   5,
                       'epsilon': 0.1,
                       'J':       0.1,
                       'delay':   1.5,
                       'tauMem':  20.0,
                       'tauSyn':  0.1,
                       'tauRef':  2.0,
                       'U0':      0.0,
                       'theta':   20.0}

    cell = Cell(id='ifcell', pynn_cell='IF_curr_alpha')


    cell.parameters = { 'tau_m':       'tauMem', 
                        'tau_refrac':  'tauRef',
                        'v_rest':      'U0',
                        'v_reset':     'U0',
                        'v_thresh':    'theta',
                        'cm':          0.001,
                        "i_offset":    0}

    #cell = Cell(id='hhcell', neuroml2_source_file='test_files/hhcell.cell.nml')
    net.cells.append(cell)

    poisson_input = Cell(id='poisson_input', pynn_cell='SpikeSourcePoisson')
    poisson_input.parameters = { 'rate':       '1000 * (eta*theta/(J*4*order*epsilon*tauMem)) * (4*order*epsilon)',
                             'start':      0,
                             'duration':   1e9}
    net.cells.append(poisson_input)

    r1 = RectangularRegion(id='region1', x=0,y=0,z=0,width=1000,height=100,depth=1000)
    net.regions.append(r1)

    pE = Population(id='Epop', 
                    size='4*order', 
                    component=cell.id, 
                    properties={'color':'.9 0 0', 'radius':5},
                    random_layout = RandomLayout(region=r1.id))
    pEpoisson = Population(id='expoisson', 
                           size='4*order', 
                           component=poisson_input.id, 
                           properties={'color':'0.9 0.7 0.7', 'radius':3},
                           random_layout = RandomLayout(region=r1.id))
    pI = Population(id='Ipop', 
                    size='1*order', 
                    component=cell.id, 
                    properties={'color':'0 0 .9', 'radius':5},
                    random_layout = RandomLayout(region=r1.id))
    pIpoisson = Population(id='inpoisson', 
                           size='1*order', 
                           component=poisson_input.id, 
                           properties={'color':'0.7 0.7 0.9', 'radius':3},
                           random_layout = RandomLayout(region=r1.id))

    net.populations.append(pE)
    net.populations.append(pEpoisson)
    net.populations.append(pI)
    net.populations.append(pIpoisson)


    net.synapses.append(Synapse(id='ampa', 
                                pynn_receptor_type='excitatory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))
                                
    net.synapses.append(Synapse(id='gaba', 
                                pynn_receptor_type='inhibitory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))

    delay_ext = dt
    
    downscale   = 1
    J_eff     = 'J*%s'%(downscale)
    # synaptic weights, scaled for alpha functions, such that
    # for constant membrane potential, charge J would be deposited
    fudge = 0.00041363506632638  # ensures dV = J at V=0
    JE = '((%s)/tauSyn)*%s'%(J_eff,fudge)
    JI = '-1*g*%s'%(JE)
    
    net.projections.append(Projection(id='projEinput',
                                      presynaptic=pEpoisson.id, 
                                      postsynaptic=pE.id,
                                      synapse='ampa',
                                      delay=delay_ext,
                                      weight=JE,
                                      one_to_one_connector=OneToOneConnector()))
    
    net.projections.append(Projection(id='projIinput',
                                      presynaptic=pIpoisson.id, 
                                      postsynaptic=pI.id,
                                      synapse='ampa',
                                      delay=delay_ext,
                                      weight=JE,
                                      one_to_one_connector=OneToOneConnector()))
                                      
           
    net.projections.append(Projection(id='projEE',
                                      presynaptic=pE.id, 
                                      postsynaptic=pE.id,
                                      synapse='ampa',
                                      delay='delay',
                                      weight=JE,
                                      random_connectivity=RandomConnectivity(probability='epsilon')))

    net.projections.append(Projection(id='projEI',
                                      presynaptic=pE.id, 
                                      postsynaptic=pI.id,
                                      synapse='ampa',
                                      delay='delay',
                                      weight=JE,
                                      random_connectivity=RandomConnectivity(probability='epsilon')))
    
    net.projections.append(Projection(id='projIE',
                                      presynaptic=pI.id, 
                                      postsynaptic=pE.id,
                                      synapse='gaba',
                                      delay='delay',
                                      weight=JI,
                                      random_connectivity=RandomConnectivity(probability='epsilon')))
                                      
    net.projections.append(Projection(id='projII',
                                      presynaptic=pI.id, 
                                      postsynaptic=pI.id,
                                      synapse='gaba',
                                      delay='delay',
                                      weight=JI,
                                      random_connectivity=RandomConnectivity(probability='epsilon')))

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


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

    sim = Simulation(id='SimExample7',
                     network=new_file,
                     duration=simtime,
                     dt=dt,
                     seed= 123,
                     recordTraces={pE.id:[0,1],pI.id:[0,1]},
                     recordSpikes={pE.id:'*', pI.id:'*',pEpoisson.id:[0,1,2,3,4],pIpoisson.id:[0,1,2,3,4]})

    sim.to_json_file()
    
    return sim, net
示例#22
0
net.inputs.append(
    Input(id="stim",
          input_source=input_source.id,
          population=p0.id,
          percentage=50))

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

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

sim = Simulation(
    id="SimSonataExample",
    network=new_file,
    duration="1000",
    dt="0.01",
    recordTraces={"all": "*"},
    recordSpikes={"pop0": "*"},
)

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#23
0
nml_file_name, nml_doc = generate_neuroml2_from_network(
    net,
    nml_file_name="%s.net.nml%s" %
    (net.id, ".h5" if format_ == "hdf5" else ""),
    format=format_,
)

from neuromllite import Simulation

record_traces = {"all": "*"}
record_spikes = {"all": "*"}

sim = Simulation(
    id="SimExample5",
    network=new_file,
    duration=500,
    dt=0.025,
    record_traces=record_traces,
    record_spikes=record_spikes,
)

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#24
0
        if fln>0.0:
            net.projections.append(Projection(id='proj_%s_%s'%(src,tgt),
                                              presynaptic=src, 
                                              postsynaptic=tgt,
                                              synapse='ampa',
                                              weight=fln))

            #net.projections[0].random_connectivity=RandomConnectivity(probability=0.5)



print(net)
net.id = 'TestNetwork'

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


################################################################################
###   Export to some formats
###   Try:
###        python Example1.py -graph2

from neuromllite.NetworkGenerator import check_to_generate_or_run
from neuromllite import Simulation
import sys

check_to_generate_or_run(sys.argv, Simulation(id='SimExample1',network=new_file))

示例#25
0
文件: FN.py 项目: kmantel/MDF
def generate():

    dt = 0.05
    simtime = 100

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

    net = Network(id="FN")
    net.notes = "FitzHugh Nagumo cell model - originally specified in NeuroML/LEMS"

    net.parameters = {
        "initial_w": 0.0,
        "initial_v": -1,
        "a_v": -0.3333333333333333,
        "b_v": 0.0,
        "c_v": 1.0,
        "d_v": 1,
        "e_v": -1.0,
        "f_v": 1.0,
        "time_constant_v": 1.0,
        "a_w": 1.0,
        "b_w": -0.8,
        "c_w": 0.7,
        "time_constant_w": 12.5,
        "threshold": -1.0,
        "mode": 1.0,
        "uncorrelated_activity": 0.0,
        "Iext": 0,
    }

    cellInput = Cell(id="fn",
                     lems_source_file="FN_Definitions.xml",
                     parameters={})
    for p in net.parameters:
        cellInput.parameters[p] = p
    net.cells.append(cellInput)

    r1 = RectangularRegion(id="region1",
                           x=0,
                           y=0,
                           z=0,
                           width=1000,
                           height=100,
                           depth=1000)
    net.regions.append(r1)

    pop = Population(
        id="FNpop",
        size="1",
        component=cellInput.id,
        properties={
            "color": "0.2 0.2 0.2",
            "radius": 3
        },
        random_layout=RandomLayout(region=r1.id),
    )
    net.populations.append(pop)

    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=simtime,
        dt=dt,
        seed=123,
        recordVariables={
            "V": {
                "all": "*"
            },
            "W": {
                "all": "*"
            }
        },
        plots2D={
            "VW": {
                "x_axis": "%s/0/fn/V" % pop.id,
                "y_axis": "%s/0/fn/W" % pop.id
            }
        },
    )

    sim.to_json_file()

    return sim, net
示例#26
0
net.projections[1].random_connectivity=RandomConnectivity(probability=1)'''

net.inputs.append(
    Input(id='stim',
          input_source=input_source.id,
          population=p0.id,
          percentage=50))

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

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

sim = Simulation(id='SimSonataExample',
                 network=new_file,
                 duration='1000',
                 dt='0.01',
                 recordTraces={'all': '*'},
                 recordSpikes={'pop0': '*'})

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#27
0
          percentage=100))

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

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

sim = Simulation(
    id="SimExample11",
    network=new_file,
    duration="1000",
    dt="0.01",
    record_traces={"all": "*"},
    record_variables={
        "synapses:%s:0/g" % ampaSyn.id: {
            "pop1": "*"
        },
        "synapses:%s:0/g" % nmdaSyn.id: {
            "pop1": "*"
        },
    },
    record_spikes={"pop0": "*"},
)

sim.to_json_file()

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys
示例#28
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
示例#29
0
    Input(id="stim",
          input_source=input_source.id,
          population=p0.id,
          cell_ids=[1, 2]))

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

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

sim = Simulation(
    id="Sim%s" % net.id,
    network=new_file,
    duration="100",
    dt="0.01",
    record_traces={"all": "*"},
    record_spikes={"pop0": "*"},
)

sim.to_json_file()
sim.network = new_file_yaml
sim.to_yaml_file('%s.yaml' % sim.id)

################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)
示例#30
0
文件: parse3.py 项目: pgleeson/rate
                                        (used_ids[pre], used_ids[post]),
                                        presynaptic=used_ids[pre],
                                        postsynaptic=used_ids[post],
                                        synapse='ampa',
                                        weight=weight,
                                        random_connectivity=RandomConnectivity(
                                            probability=1)))

print(net)
net.id = 'MouseConns'

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

sim = Simulation(id='SimExample',
                 network=new_file,
                 duration='100',
                 dt='0.025',
                 recordTraces={'all': '*'})

################################################################################
###   Export to some formats
###   Try:
###        python Example1.py -graph2

from neuromllite.NetworkGenerator import check_to_generate_or_run
from neuromllite import Simulation
import sys

check_to_generate_or_run(sys.argv, sim)
def generate():
    ################################################################################
    ###   Build new network

    net = Network(id='RunStims')
    net.notes = 'Example with spike producers'

    net.parameters = { 'rate':       50, 
                       'rateHz':     '50Hz', 
                       'periodms':     '20ms'}
    
    
    ssp = Cell(id='ssp', pynn_cell='SpikeSourcePoisson')
    ssp.parameters = { 'rate':       'rate',
                       'start':      0,
                       'duration':   1e9}
    net.cells.append(ssp)
    sspPop = Population(id='sspPop', size=1, component=ssp.id, properties={'color':'.5 0 0'})
    net.populations.append(sspPop)


    sg = Cell(id='sg', neuroml2_cell='SpikeGenerator')
    sg.parameters = { 'period':       'periodms'}
    net.cells.append(sg)
    sgPop = Population(id='sgPop', size=1, component=sg.id, properties={'color':'.5 0 0'})
    net.populations.append(sgPop)
    

    sgp = Cell(id='sgp', neuroml2_cell='spikeGeneratorPoisson')
    sgp.parameters = { 'average_rate':       'rateHz'}
    net.cells.append(sgp)
    sgpPop = Population(id='sgpPop', size=1, component=sgp.id, properties={'color':'.5 0 0'})
    net.populations.append(sgpPop)


    net.synapses.append(Synapse(id='ampa', 
                                pynn_receptor_type='excitatory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))
    net.synapses.append(Synapse(id='gaba', 
                                pynn_receptor_type='inhibitory', 
                                pynn_synapse_type='curr_alpha', 
                                parameters={'tau_syn':0.1}))


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


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

    sim = Simulation(id='SimTest',
                     network=new_file,
                     duration='10000',
                     dt='0.025',
                     seed= 123,
                     recordTraces={'xxx':'*'},
                     recordSpikes={'all':'*'})

    sim.to_json_file()
    
    return sim, net