Beispiel #1
0
def generate(reference = "SimpleNet",
             scale=1,
             format='xml'):

    population_size = scale_pop_size(3,scale)

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(nml_doc, 'izhikevich/RS.cell.nml')

    pop = oc.add_population_in_rectangular_region(network,
                                                  'RS_pop',
                                                  'RS',
                                                  population_size,
                                                  0,0,0,
                                                  100,100,100,
                                                  color='0 .8 0')
    import neuroml
    pop.properties.append(neuroml.Property('radius',10))

    syn = oc.add_exp_two_syn(nml_doc, 
                             id="syn0", 
                             gbase="2nS",
                             erev="0mV",
                             tau_rise="0.5ms",
                             tau_decay="10ms")

    pfs = oc.add_poisson_firing_synapse(nml_doc,
                                       id="poissonFiringSyn",
                                       average_rate="50 Hz",
                                       synapse_id=syn.id)

    oc.add_inputs_to_population(network,
                                "Stim0",
                                pop,
                                pfs.id,
                                all_cells=True)

    nml_file_name = '%s.net.nml'%network.id
    oc.save_network(nml_doc, 
                    nml_file_name,
                    validate=(format=='xml'),
                    format = format)

    if format=='xml':
        oc.generate_lems_simulation(nml_doc, 
                                    network, 
                                    nml_file_name, 
                                    duration =      500, 
                                    dt =            0.025,
                                    report_file_name='report.simple.txt')
def generate(reference = "DendConn",
             num_pyr = 4,
             num_bask = 0,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=True,
             global_delay = 0,
             duration = 500,
             segments_to_plot_record = {'pop_pyr':[0],'pop_bask':[0]},
             format='xml'):


    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(nml_doc, 'acnet2/pyr_4_sym.cell.nml')
    oc.include_opencortex_cell(nml_doc, 'acnet2/bask.cell.nml')
    
    xDim = 500*scalex
    yDim = 50*scaley
    zDim = 500*scalez

    pop_pyr = oc.add_population_in_rectangular_region(network, 'pop_pyr',
                                                  'pyr_4_sym', num_pyr,
                                                  0,0,0, xDim,yDim,zDim)

    pop_bask = oc.add_population_in_rectangular_region(network, 'pop_bask',
                                                  'bask', num_bask,
                                                  0,yDim,0, xDim,yDim+yDim,zDim)
                   
    ampa_syn = oc.add_exp_two_syn(nml_doc, id="AMPA_syn", 
                             gbase="30e-9S", erev="0mV",
                             tau_rise="0.003s", tau_decay="0.0031s")


    pg = oc.add_pulse_generator(nml_doc,
                           id="pg0",
                           delay="10ms",
                           duration="300ms",
                           amplitude="0.7nA")          
                                
    total_conns = 0
    if connections:

        this_syn=ampa_syn.id
        proj = oc.add_targeted_projection(network,
                                        "Proj_pyr_pyr",
                                        pop_pyr,
                                        pop_pyr,
                                        targeting_mode='convergent',
                                        synapse_list=[this_syn],
                                        pre_segment_group = 'soma_group',
                                        post_segment_group = 'dendrite_group',
                                        number_conns_per_cell=1,
                                        delays_dict = {this_syn:global_delay})
        if proj:                           
            total_conns += len(proj[0].connection_wds)


            
            
    oc.add_targeted_inputs_to_population(network, "Stim0",
                                pop_pyr, pg.id, 
                                segment_group='soma_group',
                                number_per_cell = 1,
                                all_cells=False,
                                only_cells=[0])
        
    
        
    nml_file_name = '%s.net.%s'%(network.id,'nml.h5' if format == 'hdf5' else 'nml')
    target_dir = 'HDF5/' if format == 'hdf5' else './'
    
    oc.save_network(nml_doc, 
                    nml_file_name, 
                    validate=(format=='xml'),
                    format = format,
                    target_dir=target_dir)


    gen_plots_for_quantities = {}   #  Dict with displays vs lists of quantity paths
    gen_saves_for_quantities = {}   #  Dict with file names vs lists of quantity paths

    for pop in segments_to_plot_record.keys():
        pop_nml = network.get_by_id(pop)
        if pop_nml is not None and pop_nml.size>0:

            group = len(segments_to_plot_record[pop]) == 1
            if group:
                display = 'Display_%s_v'%(pop)
                file_ = 'Sim_%s.%s.v.dat'%(nml_doc.id,pop)
                gen_plots_for_quantities[display] = []
                gen_saves_for_quantities[file_] = []

            for i in range(int(pop_nml.size)):
                if not group:
                    display = 'Display_%s_%i_v'%(pop,i)
                    file_ = 'Sim_%s.%s.%i.v.dat'%(nml_doc.id,pop,i)
                    gen_plots_for_quantities[display] = []
                    gen_saves_for_quantities[file_] = []

                for seg in segments_to_plot_record[pop]:
                    quantity = '%s/%i/%s/%i/v'%(pop,i,pop_nml.component,seg)
                    gen_plots_for_quantities[display].append(quantity)
                    gen_saves_for_quantities[file_].append(quantity)

    lems_file_name = oc.generate_lems_simulation(nml_doc, 
                            network, 
                            target_dir+nml_file_name, 
                            duration =      duration, 
                            dt =            0.025,
                            gen_plots_for_all_v = False,
                            gen_plots_for_quantities = gen_plots_for_quantities,
                            gen_saves_for_all_v = False,
                            gen_saves_for_quantities = gen_saves_for_quantities,
                            target_dir=target_dir)
                                
    return nml_doc, nml_file_name, lems_file_name
def generate(reference = "Balanced",
             scalePops = 1,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=True,
             connections_scaling=1,
             duration = 1000,
             global_delay = 2,
             max_in_pop_to_plot_and_save = 5,
             gen_spike_saves_for_all_somas = True,
             deterministic = True,
             format='xml'):

    num_exc = scale_pop_size(80,scalePops)
    num_inh = scale_pop_size(40,scalePops)
    
    if scalePops!=1:
        reference += '_%s'%scalePops
    
    nml_doc, network = oc.generate_network(reference)
    
    oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml')
    oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml')
    
    xDim = 400*scalex
    yDim = 500*scaley
    zDim = 300*scalez

    xs = -200
    ys = -150
    zs = 100

    #####   Synapses

    synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="1nS",
                             erev="0mV", tau_rise="0.5ms", tau_decay="5ms")

    synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="2nS",
                             erev="-80mV", tau_rise="1ms", tau_decay="20ms")

    #####   Input types

    if not deterministic:
        pfs1 = oc.add_poisson_firing_synapse(nml_doc,
                                           id="psf1",
                                           average_rate="150 Hz",
                                           synapse_id=synAmpa1.id)



    #####   Populations

    popExc = oc.add_population_in_rectangular_region(network,
                                                  'popExc',
                                                  'HH_477127614',
                                                  num_exc,
                                                  xs,ys,zs,
                                                  xDim,yDim,zDim)

    popInh = oc.add_population_in_rectangular_region(network,
                                                  'popInh',
                                                  'HH_476686112',
                                                  num_inh,
                                                  xs,ys,zs,
                                                  xDim,yDim,zDim)


    #####   Projections

    total_conns = 0
    if connections:
        proj = oc.add_probabilistic_projection(network, "proj0",
                                        popExc, popExc,
                                        synAmpa1.id, connections_scaling*0.3, delay = global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network, "proj1",
                                        popExc, popInh,
                                        synAmpa1.id, connections_scaling*0.5, delay = global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network, "proj3",
                                        popInh, popExc,
                                        synGaba1.id, connections_scaling*0.7, delay = global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network, "proj4",
                                        popInh, popInh,
                                        synGaba1.id, connections_scaling*0.5, delay = global_delay)
        total_conns += len(proj.connection_wds)


    #####   Inputs

    if not deterministic:
        oc.add_inputs_to_population(network, "Stim0",
                                popExc, pfs1.id,
                                all_cells=True)
                                
    else:

        for i in range(num_exc):

            pg = oc.add_pulse_generator(nml_doc,
                                   id="pg_%i"%i,
                                   delay="0ms",
                                   duration="10000ms",
                                   amplitude="%snA"%(random()*0.5))

            oc.add_inputs_to_population(network, "Stim_%i"%i,
                                    popExc, pg.id,
                                    all_cells=False,
                                    only_cells=[i])
                               



    #####   Save NeuroML and LEMS Simulation files      
    

    nml_file_name = '%s%s.net.%s'%('XH_' if format == 'xml_hdf5' else '', network.id,'nml.h5' if format == 'hdf5' else 'nml')
    
    oc.save_network(nml_doc, 
                    nml_file_name, 
                    validate=(format=='xml'),
                    format = format)


    plot_v = {popExc.id:[],popInh.id:[]}
    save_v = {'%s_v.dat'%popExc.id:[],'%s_v.dat'%popInh.id:[]}

    for i in range(min(max_in_pop_to_plot_and_save,num_exc)):
        plot_v[popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component))
        save_v['%s_v.dat'%popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component))

    for i in range(min(max_in_pop_to_plot_and_save,num_inh)):
        plot_v[popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component))
        save_v['%s_v.dat'%popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component))
        
    lems_file_name = "LEMS_%s.xml"%network.id
    if format != 'xml':
        lems_file_name = "LEMS_%s_%s.xml"%(network.id,format)
        

    lems_file_name = oc.generate_lems_simulation(nml_doc, network, 
                            nml_file_name, 
                            duration =      duration, 
                            dt =            0.025,
                            gen_plots_for_all_v = False,
                            gen_plots_for_quantities = plot_v,
                            gen_saves_for_all_v = False,
                            gen_saves_for_quantities = save_v,
                            gen_spike_saves_for_all_somas = gen_spike_saves_for_all_somas,
                            lems_file_name = lems_file_name)
                                
    return nml_doc, nml_file_name, lems_file_name
def generate(reference="DendConn",
             num_pyr=4,
             num_bask=0,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=True,
             global_delay=0,
             duration=500,
             segments_to_plot_record={
                 'pop_pyr': [0],
                 'pop_bask': [0]
             },
             format='xml'):

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(nml_doc, 'acnet2/pyr_4_sym.cell.nml')
    oc.include_opencortex_cell(nml_doc, 'acnet2/bask.cell.nml')

    xDim = 500 * scalex
    yDim = 50 * scaley
    zDim = 500 * scalez

    pop_pyr = oc.add_population_in_rectangular_region(network, 'pop_pyr',
                                                      'pyr_4_sym', num_pyr, 0,
                                                      0, 0, xDim, yDim, zDim)

    pop_bask = oc.add_population_in_rectangular_region(network, 'pop_bask',
                                                       'bask', num_bask, 0,
                                                       yDim, 0, xDim,
                                                       yDim + yDim, zDim)

    ampa_syn = oc.add_exp_two_syn(nml_doc,
                                  id="AMPA_syn",
                                  gbase="30e-9S",
                                  erev="0mV",
                                  tau_rise="0.003s",
                                  tau_decay="0.0031s")

    pg = oc.add_pulse_generator(nml_doc,
                                id="pg0",
                                delay="10ms",
                                duration="300ms",
                                amplitude="0.7nA")

    total_conns = 0
    if connections:

        this_syn = ampa_syn.id
        proj = oc.add_targeted_projection(network,
                                          "Proj_pyr_pyr",
                                          pop_pyr,
                                          pop_pyr,
                                          targeting_mode='convergent',
                                          synapse_list=[this_syn],
                                          pre_segment_group='soma_group',
                                          post_segment_group='dendrite_group',
                                          number_conns_per_cell=1,
                                          delays_dict={this_syn: global_delay})
        if proj:
            total_conns += len(proj[0].connection_wds)

    oc.add_targeted_inputs_to_population(network,
                                         "Stim0",
                                         pop_pyr,
                                         pg.id,
                                         segment_group='soma_group',
                                         number_per_cell=1,
                                         all_cells=False,
                                         only_cells=[0])

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    target_dir = 'HDF5/' if format == 'hdf5' else './'

    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format,
                    target_dir=target_dir)

    gen_plots_for_quantities = {
    }  #  Dict with displays vs lists of quantity paths
    gen_saves_for_quantities = {
    }  #  Dict with file names vs lists of quantity paths

    for pop in segments_to_plot_record.keys():
        pop_nml = network.get_by_id(pop)
        if pop_nml is not None and pop_nml.size > 0:

            group = len(segments_to_plot_record[pop]) == 1
            if group:
                display = 'Display_%s_v' % (pop)
                file_ = 'Sim_%s.%s.v.dat' % (nml_doc.id, pop)
                gen_plots_for_quantities[display] = []
                gen_saves_for_quantities[file_] = []

            for i in range(int(pop_nml.size)):
                if not group:
                    display = 'Display_%s_%i_v' % (pop, i)
                    file_ = 'Sim_%s.%s.%i.v.dat' % (nml_doc.id, pop, i)
                    gen_plots_for_quantities[display] = []
                    gen_saves_for_quantities[file_] = []

                for seg in segments_to_plot_record[pop]:
                    quantity = '%s/%i/%s/%i/v' % (pop, i, pop_nml.component,
                                                  seg)
                    gen_plots_for_quantities[display].append(quantity)
                    gen_saves_for_quantities[file_].append(quantity)

    lems_file_name = oc.generate_lems_simulation(
        nml_doc,
        network,
        target_dir + nml_file_name,
        duration=duration,
        dt=0.025,
        gen_plots_for_all_v=False,
        gen_plots_for_quantities=gen_plots_for_quantities,
        gen_saves_for_all_v=False,
        gen_saves_for_quantities=gen_saves_for_quantities,
        target_dir=target_dir)

    return nml_doc, nml_file_name, lems_file_name
Beispiel #5
0
import opencortex.core as oc

nml_doc, network = oc.generate_network("IClamps")

oc.include_opencortex_cell(nml_doc, 'izhikevich/RS.cell.nml')
oc.include_opencortex_cell(nml_doc, 'acnet2/pyr_4_sym_soma.cell.nml')
#oc.include_opencortex_cell(nml_doc, '../NeuroML2/prototypes/BlueBrainProject_NMC/cADpyr229_L23_PC_5ecbf9b163_0_0.cell.nml')

popIzh = oc.add_single_cell_population(network, 'popIzh', 'RS')

popHH = oc.add_single_cell_population(network,
                                      'popHH',
                                      'pyr_4_sym_soma',
                                      z=100)
'''
popBBP = oc.add_single_cell_population(network,
                                     'popBBP',
                                     'cADpyr229_L23_PC_5ecbf9b163_0_0',
                                     z=200)'''

pgIzh = oc.add_pulse_generator(nml_doc,
                               id="pgIzh",
                               delay="100ms",
                               duration="300ms",
                               amplitude="0.5nA")

pgHH = oc.add_pulse_generator(nml_doc,
                              id="pgHH",
                              delay="100ms",
                              duration="300ms",
                              amplitude="0.7nA")
def generate(reference="Balanced",
             scalePops=1,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=True,
             connections_scaling=1,
             duration=1000,
             global_delay=2,
             max_in_pop_to_plot_and_save=5,
             gen_spike_saves_for_all_somas=True,
             deterministic=True,
             format='xml'):

    num_exc = scale_pop_size(80, scalePops)
    num_inh = scale_pop_size(40, scalePops)

    if scalePops != 1:
        reference += '_%s' % scalePops

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml')
    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml')

    xDim = 400 * scalex
    yDim = 500 * scaley
    zDim = 300 * scalez

    xs = -200
    ys = -150
    zs = 100

    #####   Synapses

    synAmpa1 = oc.add_exp_two_syn(nml_doc,
                                  id="synAmpa1",
                                  gbase="1nS",
                                  erev="0mV",
                                  tau_rise="0.5ms",
                                  tau_decay="5ms")

    synGaba1 = oc.add_exp_two_syn(nml_doc,
                                  id="synGaba1",
                                  gbase="2nS",
                                  erev="-80mV",
                                  tau_rise="1ms",
                                  tau_decay="20ms")

    #####   Input types

    if not deterministic:
        pfs1 = oc.add_poisson_firing_synapse(nml_doc,
                                             id="psf1",
                                             average_rate="150 Hz",
                                             synapse_id=synAmpa1.id)

    #####   Populations

    popExc = oc.add_population_in_rectangular_region(network, 'popExc',
                                                     'HH_477127614', num_exc,
                                                     xs, ys, zs, xDim, yDim,
                                                     zDim)

    popInh = oc.add_population_in_rectangular_region(network, 'popInh',
                                                     'HH_476686112', num_inh,
                                                     xs, ys, zs, xDim, yDim,
                                                     zDim)

    #####   Projections

    total_conns = 0
    if connections:
        proj = oc.add_probabilistic_projection(network,
                                               "proj0",
                                               popExc,
                                               popExc,
                                               synAmpa1.id,
                                               connections_scaling * 0.3,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj1",
                                               popExc,
                                               popInh,
                                               synAmpa1.id,
                                               connections_scaling * 0.5,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj3",
                                               popInh,
                                               popExc,
                                               synGaba1.id,
                                               connections_scaling * 0.7,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj4",
                                               popInh,
                                               popInh,
                                               synGaba1.id,
                                               connections_scaling * 0.5,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

    #####   Inputs

    if not deterministic:
        oc.add_inputs_to_population(network,
                                    "Stim0",
                                    popExc,
                                    pfs1.id,
                                    all_cells=True)

    else:

        for i in range(num_exc):

            pg = oc.add_pulse_generator(nml_doc,
                                        id="pg_%i" % i,
                                        delay="0ms",
                                        duration="10000ms",
                                        amplitude="%snA" % (random() * 0.5))

            oc.add_inputs_to_population(network,
                                        "Stim_%i" % i,
                                        popExc,
                                        pg.id,
                                        all_cells=False,
                                        only_cells=[i])

    #####   Save NeuroML and LEMS Simulation files

    nml_file_name = '%s%s.net.%s' % ('XH_' if format == 'xml_hdf5' else '',
                                     network.id,
                                     'nml.h5' if format == 'hdf5' else 'nml')

    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format)

    plot_v = {popExc.id: [], popInh.id: []}
    save_v = {'%s_v.dat' % popExc.id: [], '%s_v.dat' % popInh.id: []}

    for i in range(min(max_in_pop_to_plot_and_save, num_exc)):
        plot_v[popExc.id].append("%s/%i/%s/v" %
                                 (popExc.id, i, popExc.component))
        save_v['%s_v.dat' % popExc.id].append("%s/%i/%s/v" %
                                              (popExc.id, i, popExc.component))

    for i in range(min(max_in_pop_to_plot_and_save, num_inh)):
        plot_v[popInh.id].append("%s/%i/%s/v" %
                                 (popInh.id, i, popInh.component))
        save_v['%s_v.dat' % popInh.id].append("%s/%i/%s/v" %
                                              (popInh.id, i, popInh.component))

    lems_file_name = "LEMS_%s.xml" % network.id
    if format != 'xml':
        lems_file_name = "LEMS_%s_%s.xml" % (network.id, format)

    lems_file_name = oc.generate_lems_simulation(
        nml_doc,
        network,
        nml_file_name,
        duration=duration,
        dt=0.025,
        gen_plots_for_all_v=False,
        gen_plots_for_quantities=plot_v,
        gen_saves_for_all_v=False,
        gen_saves_for_quantities=save_v,
        gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas,
        lems_file_name=lems_file_name)

    return nml_doc, nml_file_name, lems_file_name
Beispiel #7
0
def generate(reference="GapJunctions",
             num_pre=5,
             num_post=2,
             connections=True,
             duration=1000,
             segments_to_plot_record={
                 'pop_pre': [0],
                 'pop_post': [0]
             },
             format='xml'):

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(nml_doc, 'acnet2/pyr_4_sym.cell.nml')

    xDim = 500
    yDim = 50
    zDim = 500

    pop_pre = oc.add_population_in_rectangular_region(network, 'pop_pre',
                                                      'pyr_4_sym', num_pre, 0,
                                                      0, 0, xDim, yDim, zDim)

    pop_post = oc.add_population_in_rectangular_region(network, 'pop_post',
                                                       'pyr_4_sym', num_post,
                                                       0, yDim, 0, xDim,
                                                       yDim + yDim, zDim)

    ampa_syn = oc.add_exp_two_syn(nml_doc,
                                  id="AMPA_syn",
                                  gbase="30e-9S",
                                  erev="0mV",
                                  tau_rise="0.003s",
                                  tau_decay="0.0031s")

    gj_syn = oc.add_gap_junction_synapse(nml_doc, id="gj0", conductance="5nS")

    pfs = oc.add_poisson_firing_synapse(nml_doc,
                                        id="poissonFiringSyn",
                                        average_rate="30 Hz",
                                        synapse_id=ampa_syn.id)

    oc.add_inputs_to_population(network,
                                "Stim0",
                                pop_pre,
                                pfs.id,
                                all_cells=True)

    total_conns = 0
    if connections:

        this_syn = gj_syn.id
        proj = oc.add_targeted_electrical_projection(
            nml_doc,
            network,
            "Proj0",
            pop_pre,
            pop_post,
            targeting_mode='convergent',
            synapse_list=[this_syn],
            pre_segment_group='soma_group',
            post_segment_group='dendrite_group',
            number_conns_per_cell=3)
        if proj:
            total_conns += len(proj[0].electrical_connections) + len(
                proj[0].electrical_connection_instances)

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format)

    if format == 'xml':

        gen_plots_for_quantities = {
        }  #  Dict with displays vs lists of quantity paths
        gen_saves_for_quantities = {
        }  #  Dict with file names vs lists of quantity paths

        for pop in segments_to_plot_record.keys():
            pop_nml = network.get_by_id(pop)
            if pop_nml is not None and pop_nml.size > 0:

                group = len(segments_to_plot_record[pop]) == 1
                if group:
                    display = 'Display_%s_v' % (pop)
                    file_ = 'Sim_%s.%s.v.dat' % (nml_doc.id, pop)
                    gen_plots_for_quantities[display] = []
                    gen_saves_for_quantities[file_] = []

                for i in range(int(pop_nml.size)):
                    if not group:
                        display = 'Display_%s_%i_v' % (pop, i)
                        file_ = 'Sim_%s.%s.%i.v.dat' % (nml_doc.id, pop, i)
                        gen_plots_for_quantities[display] = []
                        gen_saves_for_quantities[file_] = []

                    for seg in segments_to_plot_record[pop]:
                        quantity = '%s/%i/%s/%i/v' % (pop, i,
                                                      pop_nml.component, seg)
                        gen_plots_for_quantities[display].append(quantity)
                        gen_saves_for_quantities[file_].append(quantity)

        lems_file_name = oc.generate_lems_simulation(
            nml_doc,
            network,
            nml_file_name,
            duration=duration,
            dt=0.025,
            gen_plots_for_all_v=False,
            gen_plots_for_quantities=gen_plots_for_quantities,
            gen_saves_for_all_v=False,
            gen_saves_for_quantities=gen_saves_for_quantities)
    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name
Beispiel #8
0
import opencortex.core as oc

population_size0 = 10
population_size1 = 10

nml_doc, network = oc.generate_network("SpikingNet")

oc.include_opencortex_cell(nml_doc, 'izhikevich/RS.cell.nml')

pop_pre = oc.add_population_in_rectangular_region(network,
                                              'pop_pre',
                                              'RS',
                                              population_size0,
                                              0,0,0,
                                              100,100,100,
                                              color='.8 0 0')
import neuroml
pop_pre.properties.append(neuroml.Property('radius',10))

pop_post = oc.add_population_in_rectangular_region(network,
                                              'pop_post',
                                              'RS',
                                              population_size1,
                                              0,100,0,
                                              100,200,100,
                                              color='0 0 .8')
                                              
pop_post.properties.append(neuroml.Property('radius',10))
                                              
syn0 = oc.add_exp_two_syn(nml_doc, 
Beispiel #9
0
def generate(scalePops=1,
             percentage_exc_detailed=0,
             scalex=1,
             scaley=1,
             scalez=1,
             ratio_inh_exc=2,
             connections=True,
             duration=1000,
             input_rate=150,
             global_delay=2,
             max_in_pop_to_plot_and_save=5,
             format='xml',
             run_in_simulator=None):

    reference = ("Multiscale__g%s__i%s" % (ratio_inh_exc, input_rate)).replace(
        '.', '_')

    num_exc = scale_pop_size(80, scalePops)
    num_exc2 = int(0.5 + num_exc * percentage_exc_detailed / 100.0)
    num_exc -= num_exc2
    num_inh = scale_pop_size(40, scalePops)

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml')
    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml')
    oc.include_opencortex_cell(nml_doc,
                               'L23Pyr_SmithEtAl2013/L23_NoHotSpot.cell.nml')

    xDim = 1000 * scalex
    yDim = 300 * scaley
    zDim = 1000 * scalez

    xs = -200
    ys = -150
    zs = 100

    #####   Synapses

    exc_syn_nS = 1.

    synAmpa1 = oc.add_exp_two_syn(nml_doc,
                                  id="synAmpa1",
                                  gbase="%snS" % exc_syn_nS,
                                  erev="0mV",
                                  tau_rise="0.5ms",
                                  tau_decay="5ms")

    synGaba1 = oc.add_exp_two_syn(nml_doc,
                                  id="synGaba1",
                                  gbase="%snS" % (exc_syn_nS * ratio_inh_exc),
                                  erev="-80mV",
                                  tau_rise="1ms",
                                  tau_decay="20ms")

    #####   Input types

    pfs1 = oc.add_poisson_firing_synapse(nml_doc,
                                         id="psf1",
                                         average_rate="%s Hz" % input_rate,
                                         synapse_id=synAmpa1.id)

    #####   Populations

    popExc = oc.add_population_in_rectangular_region(network,
                                                     'popExc',
                                                     'HH_477127614',
                                                     num_exc,
                                                     xs,
                                                     ys,
                                                     zs,
                                                     xDim,
                                                     yDim,
                                                     zDim,
                                                     color='0 0 1')

    popExc2 = oc.add_population_in_rectangular_region(network,
                                                      'popExc2',
                                                      'L23_NoHotSpot',
                                                      num_exc2,
                                                      xs,
                                                      ys,
                                                      zs,
                                                      xDim,
                                                      yDim,
                                                      zDim,
                                                      color='0 1 0')

    allExc = [popExc, popExc2]

    popInh = oc.add_population_in_rectangular_region(network,
                                                     'popInh',
                                                     'HH_476686112',
                                                     num_inh,
                                                     xs,
                                                     ys,
                                                     zs,
                                                     xDim,
                                                     yDim,
                                                     zDim,
                                                     color='1 0 0')

    #####   Projections

    if connections:

        for pop1 in allExc:

            for pop2 in allExc:
                proj = oc.add_probabilistic_projection(network,
                                                       "proj0",
                                                       pop1,
                                                       pop2,
                                                       synAmpa1.id,
                                                       0.5,
                                                       delay=global_delay)

            proj = oc.add_probabilistic_projection(network,
                                                   "proj1",
                                                   pop1,
                                                   popInh,
                                                   synAmpa1.id,
                                                   0.7,
                                                   delay=global_delay)

            proj = oc.add_probabilistic_projection(network,
                                                   "proj2",
                                                   popInh,
                                                   pop1,
                                                   synGaba1.id,
                                                   0.7,
                                                   delay=global_delay)

        proj = oc.add_probabilistic_projection(network,
                                               "proj3",
                                               popInh,
                                               popInh,
                                               synGaba1.id,
                                               0.5,
                                               delay=global_delay)

    #####   Inputs

    for pop in allExc:
        oc.add_inputs_to_population(network,
                                    "Stim_%s" % pop.id,
                                    pop,
                                    pfs1.id,
                                    all_cells=True)

    #####   Save NeuroML and LEMS Simulation files

    target_dir = './temp/'

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format,
                    target_dir=target_dir)

    if format == 'xml':

        plot_v = {popExc.id: [], popExc2.id: [], popInh.id: []}
        exc_traces = '%s_%s_v.dat' % (network.id, popExc.id)
        exc2_traces = '%s_%s_v.dat' % (network.id, popExc2.id)
        inh_traces = '%s_%s_v.dat' % (network.id, popInh.id)
        save_v = {exc_traces: [], inh_traces: [], exc2_traces: []}

        for i in range(min(max_in_pop_to_plot_and_save, num_exc)):
            plot_v[popExc.id].append("%s/%i/%s/v" %
                                     (popExc.id, i, popExc.component))
            save_v[exc_traces].append("%s/%i/%s/v" %
                                      (popExc.id, i, popExc.component))

        for i in range(min(max_in_pop_to_plot_and_save, num_exc2)):
            plot_v[popExc2.id].append("%s/%i/%s/v" %
                                      (popExc2.id, i, popExc2.component))
            save_v[exc2_traces].append("%s/%i/%s/v" %
                                       (popExc2.id, i, popExc2.component))

        for i in range(min(max_in_pop_to_plot_and_save, num_inh)):
            plot_v[popInh.id].append("%s/%i/%s/v" %
                                     (popInh.id, i, popInh.component))
            save_v[inh_traces].append("%s/%i/%s/v" %
                                      (popInh.id, i, popInh.component))

        gen_spike_saves_for_all_somas = run_in_simulator != 'jNeuroML_NetPyNE'

        lems_file_name = oc.generate_lems_simulation(
            nml_doc,
            network,
            target_dir + nml_file_name,
            duration=duration,
            dt=0.025,
            gen_plots_for_all_v=False,
            gen_plots_for_quantities=plot_v,
            gen_saves_for_all_v=False,
            gen_saves_for_quantities=save_v,
            gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas,
            target_dir=target_dir)

        if run_in_simulator:

            print("Running %s in %s" % (lems_file_name, run_in_simulator))

            traces, events = oc.simulate_network(lems_file_name,
                                                 run_in_simulator,
                                                 max_memory='4000M',
                                                 nogui=True,
                                                 load_saved_data=True,
                                                 reload_events=True,
                                                 plot=False,
                                                 verbose=False)

            print("Reloaded traces: %s" % traces.keys())
            #print("Reloaded events: %s"%events.keys())

            use_events_for_rates = False

            exc_rate = 0
            inh_rate = 0

            if use_events_for_rates:
                if (run_in_simulator == 'jNeuroML_NetPyNE'):
                    raise (
                        'Saving of spikes (and so calculation of rates) not yet supported in jNeuroML_NetPyNE'
                    )
                for ek in events.keys():
                    rate = 1000 * len(events[ek]) / float(duration)
                    print("Cell %s has rate %s Hz" % (ek, rate))
                    if 'popExc' in ek:
                        exc_rate += rate / num_exc
                    if 'popInh' in ek:
                        inh_rate += rate / num_inh

            else:
                tot_exc_rate = 0
                exc_cells = 0
                tot_inh_rate = 0
                inh_cells = 0
                tt = [t * 1000 for t in traces['t']]
                for tk in traces.keys():
                    if tk != 't':
                        rate = get_rate_from_trace(
                            tt, [v * 1000 for v in traces[tk]])
                        print("Cell %s has rate %s Hz" % (tk, rate))
                        if 'popExc' in tk:
                            tot_exc_rate += rate
                            exc_cells += 1
                        if 'popInh' in tk:
                            tot_inh_rate += rate
                            inh_cells += 1

                exc_rate = tot_exc_rate / exc_cells
                inh_rate = tot_inh_rate / inh_cells

            print("Run %s: Exc rate: %s Hz; Inh rate %s Hz" %
                  (reference, exc_rate, inh_rate))

            return exc_rate, inh_rate, traces

    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name
Beispiel #10
0
def generate(reference = "Weights",
             num_each = 6,
             connections=True,
             duration = 1000,
             format='xml'):

    nml_doc, network = oc.generate_network(reference)

    cell_id = 'HH_477127614'
    cell = oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/%s.cell.nml'%cell_id)

    xDim = 500
    yDim = 500
    zDim = 30

    pop_pre = oc.add_population_in_rectangular_region(network, 'pop_pre',
                                                  cell_id, num_each,
                                                  0,0,0, xDim,yDim,zDim,
                                                  color='.8 0 0')

    pop_post_chem_exc = oc.add_population_in_rectangular_region(network, 'pop_post_chem_exc',
                                                  cell_id, num_each+1,
                                                  0,yDim,0, xDim,yDim,zDim,
                                                  color='0 0 .8')

    pop_post_chem_inh = oc.add_population_in_rectangular_region(network, 'pop_post_chem_inh',
                                                  cell_id, num_each+2,
                                                  xDim,yDim,0, xDim,yDim,zDim,
                                                  color='0 .8 .8')
                                                  
    pop_post_cont = oc.add_population_in_rectangular_region(network, 'pop_post_cont',
                                                  cell_id, num_each+3,
                                                  xDim,0,0, xDim,yDim,zDim,
                                                  color='0 .8 0')

    ampa_syn = oc.add_exp_two_syn(nml_doc, id="AMPA_syn", 
                             gbase="10nS", erev="0mV",
                             tau_rise="2ms", tau_decay="10ms")
                             
    gaba_syn = oc.add_exp_two_syn(nml_doc, id="GABA_syn", 
                             gbase="10nS", erev="-80mV",
                             tau_rise="3ms", tau_decay="30ms")

    gj_syn = oc.add_gap_junction_synapse(nml_doc, id="gj0", 
                             conductance=".05nS")
                             
    
    analog_syn = GradedSynapse(id='analog_syn',
                             conductance="10nS",
                             delta="5mV",
                             Vth="-35mV",
                             k="0.025per_ms",
                             erev="0mV")
    silent_syn = SilentSynapse(id="silent1")
    
    nml_doc.graded_synapses.append(analog_syn)
    nml_doc.silent_synapses.append(silent_syn)


    pfs = oc.add_poisson_firing_synapse(nml_doc, id="poissonFiringSyn",
                                       average_rate="10 Hz", synapse_id=ampa_syn.id)

    oc.add_inputs_to_population(network, "Stim0",
                                pop_pre, pfs.id, all_cells=True)


    if connections:
        
        proj_chem_exc = oc.add_probabilistic_projection(network,
                                "proj_chem_exc",
                                pop_pre,
                                pop_post_chem_exc,
                                ampa_syn.id,
                                0.7,
                                weight=1,
                                delay=5)
                                
        for conn in proj_chem_exc.connection_wds:
            if conn.get_pre_cell_id() < 3 and conn.get_post_cell_id() < 3:
                conn.weight = 0.5
        
        proj_chem_inh = oc.add_probabilistic_projection(network,
                                "proj_chem_inh",
                                pop_pre,
                                pop_post_chem_inh,
                                gaba_syn.id,
                                0.7,
                                weight=1,
                                delay=5)
                                
        for conn in proj_chem_inh.connection_wds:
            if conn.get_pre_cell_id() < 3 and conn.get_post_cell_id() < 3:
                conn.weight = 2
            
        
        proj_cont = ContinuousProjection(id='proj_cont', \
                           presynaptic_population=pop_pre.id,
                           postsynaptic_population=pop_post_cont.id)
        network.continuous_projections.append(proj_cont)
        
        for i in range(pop_pre.get_size()):
            for j in range(pop_post_cont.get_size()):
                conn0 = ContinuousConnectionInstanceW(id='%s'%(j+i*pop_pre.get_size()), \
                           pre_cell='../%s/%s/%s'%(pop_pre.id,i,cell_id),
                           post_cell='../%s/%s/%s'%(pop_post_cont.id,j,cell_id),
                           pre_component=silent_syn.id,
                           post_component=analog_syn.id,
                           weight=(i+j)/10.0)
                proj_cont.continuous_connection_instance_ws.append(conn0)
        
        
            
        gj_pops = [pop_pre, pop_post_chem_exc, pop_post_chem_inh, pop_post_cont]
        
        for pre in gj_pops:
            for post in gj_pops:
                
                proj_gap = oc.add_targeted_electrical_projection(nml_doc, 
                                                network,
                                                "proj_",
                                                pre,
                                                post,
                                                targeting_mode='convergent',
                                                synapse_list=[gj_syn.id],
                                                pre_segment_group = 'soma_group',
                                                post_segment_group = 'soma_group',
                                                number_conns_per_cell=3)

                for conn in network.electrical_projections[-1].electrical_connection_instance_ws:
                    conn.weight = conn.get_pre_cell_id() + conn.get_post_cell_id()


    nml_file_name = '%s.net.%s'%(network.id,'nml.h5' if format == 'hdf5' else 'nml')
    target_dir = 'HDF5/' if format == 'hdf5' else './'
    
    oc.save_network(nml_doc, 
                    nml_file_name, 
                    validate=(format=='xml'),
                    format = format,
                    target_dir=target_dir)

    if format=='xml':

        lems_file_name = oc.generate_lems_simulation(nml_doc, network, 
                                nml_file_name, 
                                duration =      duration, 
                                dt =            0.025,
                                gen_plots_for_all_v = True,
                                gen_saves_for_all_v = True)
    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name
Beispiel #11
0
def generate(reference="VClamp",
             poisson_inputs=True,
             use_vclamp=False,
             duration=500,
             format='xml'):

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(nml_doc, 'Thalamocortical/L23PyrRS.cell.nml')

    num_cells = 4

    pop_rs = oc.add_population_in_rectangular_region(network,
                                                     'popRS',
                                                     'L23PyrRS',
                                                     num_cells,
                                                     0,
                                                     0,
                                                     0,
                                                     1000,
                                                     20,
                                                     20,
                                                     color='.8 0 0')

    syn0 = oc.add_exp_two_syn(nml_doc,
                              id="syn0",
                              gbase="1nS",
                              erev="0mV",
                              tau_rise="0.5ms",
                              tau_decay="10ms")

    if poisson_inputs:

        pfs = oc.add_transient_poisson_firing_synapse(nml_doc,
                                                      id="poissonFiringSyn",
                                                      average_rate="20 Hz",
                                                      delay="50 ms",
                                                      duration="400 ms",
                                                      synapse_id=syn0.id)

        oc.add_targeted_inputs_to_population(network,
                                             "pfs_noise",
                                             pop_rs,
                                             pfs.id,
                                             segment_group='dendrite_group',
                                             number_per_cell=100,
                                             all_cells=True)

    all_vclamp_segs = [0, 142, 87]
    vclamp_segs = {0: [], 1: [0], 2: [0, 142], 3: all_vclamp_segs}

    gen_plots_for_quantities = {
    }  #  Dict with displays vs lists of quantity paths
    gen_saves_for_quantities = {
    }  #  Dict with file names vs lists of quantity paths

    if use_vclamp:

        v_clamped = '-70mV'

        for cell_id in vclamp_segs:

            for seg_id in vclamp_segs[cell_id]:

                vc = oc.add_voltage_clamp_triple(
                    nml_doc,
                    id='vclamp_cell%i_seg%i' % (cell_id, seg_id),
                    delay='0ms',
                    duration='%sms' % duration,
                    conditioning_voltage=v_clamped,
                    testing_voltage=v_clamped,
                    return_voltage=v_clamped,
                    simple_series_resistance="1e1ohm",
                    active="1")

                vc_dat_file = 'v_clamps_i_cell%s_seg%s.dat' % (cell_id, seg_id)

                gen_saves_for_quantities[vc_dat_file] = []

                oc.add_inputs_to_population(network,
                                            "input_vClamp_cell%i_seg%i" %
                                            (cell_id, seg_id),
                                            pop_rs,
                                            vc.id,
                                            all_cells=False,
                                            only_cells=[cell_id],
                                            segment_ids=[seg_id])

                q = '%s/%s/%s/%s/%s/i' % (pop_rs.id, cell_id, pop_rs.component,
                                          seg_id, vc.id)

                gen_saves_for_quantities[vc_dat_file].append(q)

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format)

    segments_to_plot_record = {pop_rs.id: all_vclamp_segs + [20, 50, 99, 139]}

    if format == 'xml':

        for pop in segments_to_plot_record.keys():
            pop_nml = network.get_by_id(pop)
            if pop_nml is not None and pop_nml.size > 0:
                for i in range(int(pop_nml.size)):
                    gen_plots_for_quantities['Display_%s_%i_v' % (pop, i)] = []
                    gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' %
                                             (nml_doc.id, pop, i)] = []

                    for seg in segments_to_plot_record[pop]:
                        quantity = '%s/%i/%s/%i/v' % (pop, i,
                                                      pop_nml.component, seg)
                        gen_plots_for_quantities['Display_%s_%i_v' %
                                                 (pop, i)].append(quantity)
                        gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' %
                                                 (nml_doc.id, pop,
                                                  i)].append(quantity)

        lems_file_name = oc.generate_lems_simulation(
            nml_doc,
            network,
            nml_file_name,
            duration=duration,
            dt=0.025,
            gen_plots_for_all_v=False,
            gen_plots_for_quantities=gen_plots_for_quantities,
            gen_saves_for_all_v=False,
            gen_saves_for_quantities=gen_saves_for_quantities)
    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name
Beispiel #12
0
'''
Generates a NeuroML 2 file with a LEMS file recording many details of the network
'''

import opencortex.core as oc

nml_doc, network = oc.generate_network("Recording")

#####   Cells

oc.include_opencortex_cell(nml_doc, 'acnet2/pyr_4_sym.cell.nml')

xDim = 500
yDim = 100
zDim = 500
offset = 0

#####   Synapses

synAmpa1 = oc.add_exp_two_syn(nml_doc,
                              id="synAmpa1",
                              gbase="1nS",
                              erev="0mV",
                              tau_rise="0.5ms",
                              tau_decay="10ms")

synAmpa2 = oc.add_exp_two_syn(nml_doc,
                              id="synAmpa2",
                              gbase="0.5nS",
                              erev="0mV",
                              tau_rise="0.5ms",
Beispiel #13
0
def generate(reference="Balanced",
             num_bbp=1,
             scalePops=1,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=True,
             duration=1000,
             input_rate=150,
             global_delay=0,
             max_in_pop_to_plot_and_save=5,
             gen_spike_saves_for_all_somas=True,
             format='xml'):

    num_exc = scale_pop_size(80, scalePops)
    num_inh = scale_pop_size(40, scalePops)

    nml_doc, network = oc.generate_network(reference)

    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml')
    oc.include_opencortex_cell(
        nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml')

    if num_bbp > 0:
        oc.include_opencortex_cell(
            nml_doc,
            'BlueBrainProject_NMC/cADpyr229_L23_PC_5ecbf9b163_0_0.cell.nml')

    xDim = 400 * scalex
    yDim = 500 * scaley
    zDim = 300 * scalez

    xs = -200
    ys = -150
    zs = 100

    #####   Synapses

    synAmpa1 = oc.add_exp_two_syn(nml_doc,
                                  id="synAmpa1",
                                  gbase="1nS",
                                  erev="0mV",
                                  tau_rise="0.5ms",
                                  tau_decay="5ms")

    synGaba1 = oc.add_exp_two_syn(nml_doc,
                                  id="synGaba1",
                                  gbase="2nS",
                                  erev="-80mV",
                                  tau_rise="1ms",
                                  tau_decay="20ms")

    #####   Input types

    pfs1 = oc.add_poisson_firing_synapse(nml_doc,
                                         id="psf1",
                                         average_rate="%s Hz" % input_rate,
                                         synapse_id=synAmpa1.id)

    #####   Populations

    popExc = oc.add_population_in_rectangular_region(network,
                                                     'popExc',
                                                     'HH_477127614',
                                                     num_exc,
                                                     xs,
                                                     ys,
                                                     zs,
                                                     xDim,
                                                     yDim,
                                                     zDim,
                                                     color='.8 0 0')

    popInh = oc.add_population_in_rectangular_region(network,
                                                     'popInh',
                                                     'HH_476686112',
                                                     num_inh,
                                                     xs,
                                                     ys,
                                                     zs,
                                                     xDim,
                                                     yDim,
                                                     zDim,
                                                     color='0 0 .8')
    if num_bbp == 1:
        popBBP = oc.add_single_cell_population(
            network,
            'popBBP',
            'cADpyr229_L23_PC_5ecbf9b163_0_0',
            z=200,
            color='0 .8 0')
    elif num_bbp > 1:

        popBBP = oc.add_population_in_rectangular_region(
            network,
            'popBBP',
            'cADpyr229_L23_PC_5ecbf9b163_0_0',
            num_bbp,
            xs,
            ys,
            zs,
            xDim,
            yDim,
            zDim,
            color='0 .8 0')

    #####   Projections

    total_conns = 0
    if connections:

        proj = oc.add_probabilistic_projection(network,
                                               "proj0",
                                               popExc,
                                               popExc,
                                               synAmpa1.id,
                                               0.5,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj1",
                                               popExc,
                                               popInh,
                                               synAmpa1.id,
                                               0.7,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj3",
                                               popInh,
                                               popExc,
                                               synGaba1.id,
                                               0.7,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        proj = oc.add_probabilistic_projection(network,
                                               "proj4",
                                               popInh,
                                               popInh,
                                               synGaba1.id,
                                               0.5,
                                               delay=global_delay)
        total_conns += len(proj.connection_wds)

        if num_bbp > 0:
            proj = oc.add_probabilistic_projection(network,
                                                   "proj5",
                                                   popExc,
                                                   popBBP,
                                                   synAmpa1.id,
                                                   0.5,
                                                   delay=global_delay)

        total_conns += len(proj.connection_wds)

    #####   Inputs

    oc.add_inputs_to_population(network,
                                "Stim0",
                                popExc,
                                pfs1.id,
                                all_cells=True)

    #####   Save NeuroML and LEMS Simulation files

    if num_bbp != 1:
        new_reference = 'Balanced_%scells_%sconns' % (num_bbp + num_exc +
                                                      num_inh, total_conns)
        network.id = new_reference
        nml_doc.id = new_reference

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format)

    if format == 'xml':

        plot_v = {popExc.id: [], popInh.id: []}
        save_v = {'%s_v.dat' % popExc.id: [], '%s_v.dat' % popInh.id: []}

        if num_bbp > 0:
            plot_v[popBBP.id] = []
            save_v['%s_v.dat' % popBBP.id] = []

        for i in range(min(max_in_pop_to_plot_and_save, num_exc)):
            plot_v[popExc.id].append("%s/%i/%s/v" %
                                     (popExc.id, i, popExc.component))
            save_v['%s_v.dat' % popExc.id].append(
                "%s/%i/%s/v" % (popExc.id, i, popExc.component))

        for i in range(min(max_in_pop_to_plot_and_save, num_inh)):
            plot_v[popInh.id].append("%s/%i/%s/v" %
                                     (popInh.id, i, popInh.component))
            save_v['%s_v.dat' % popInh.id].append(
                "%s/%i/%s/v" % (popInh.id, i, popInh.component))

        for i in range(min(max_in_pop_to_plot_and_save, num_bbp)):
            plot_v[popBBP.id].append("%s/%i/%s/v" %
                                     (popBBP.id, i, popBBP.component))
            save_v['%s_v.dat' % popBBP.id].append(
                "%s/%i/%s/v" % (popBBP.id, i, popBBP.component))

        lems_file_name = oc.generate_lems_simulation(
            nml_doc,
            network,
            nml_file_name,
            duration=duration,
            dt=0.025,
            gen_plots_for_all_v=False,
            gen_plots_for_quantities=plot_v,
            gen_saves_for_all_v=False,
            gen_saves_for_quantities=save_v,
            gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas)
    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name
nml_doc, network = oc.generate_network("SimpleNet")

scale = 7
min_pop_size = 1

def scale_pop_size(baseline):
    return max(min_pop_size, int(baseline*scale))

xDim = 500
yDim = 100
zDim = 500
offset = 0

#####   Cells

oc.include_opencortex_cell(nml_doc, 'izhikevich/RS.cell.nml')
# TODO: add method oc.add_spike_generator_poisson(...)
spike_gen = neuroml.SpikeGeneratorPoisson(id="poissonInput",
                                          average_rate="50Hz")
                                          
nml_doc.spike_generator_poissons.append(spike_gen)



#####   Synapses


oc.include_neuroml2_file(nml_doc,'AMPA_NMDA.synapse.nml')

                         
Beispiel #15
0
def generate(reference="L23TraubDemo",
             num_rs=DEFAULT_RS_POP_SIZE,
             num_bask=DEFAULT_BASK_POP_SIZE,
             scalex=1,
             scaley=1,
             scalez=1,
             connections=False,
             poisson_inputs=True,
             offset_curent_range_pA=None,
             global_delay=0,
             duration=300,
             segments_to_plot_record={
                 'pop_rs': [0],
                 'pop_bask': [0]
             },
             format='xml'):

    nml_doc, network = oc.generate_network(reference)

    #oc.add_cell_and_channels(nml_doc, 'acnet2/pyr_4_sym.cell.nml','pyr_4_sym')
    oc.include_opencortex_cell(nml_doc, 'Thalamocortical/L23PyrRS.cell.nml')
    oc.include_opencortex_cell(nml_doc, 'Thalamocortical/SupBasket.cell.nml')

    xDim = 500 * scalex
    yDim = 200 * scaley
    zDim = 500 * scalez

    pop_rs = oc.add_population_in_rectangular_region(network, 'pop_rs',
                                                     'L23PyrRS', num_rs, 0, 0,
                                                     0, xDim, yDim, zDim)

    pop_bask = oc.add_population_in_rectangular_region(network, 'pop_bask',
                                                       'SupBasket', num_bask,
                                                       0, 0, 0, xDim, yDim,
                                                       zDim)

    syn0 = oc.add_exp_two_syn(nml_doc,
                              id="syn0",
                              gbase="1nS",
                              erev="0mV",
                              tau_rise="0.5ms",
                              tau_decay="10ms")

    syn1 = oc.add_exp_two_syn(nml_doc,
                              id="syn1",
                              gbase="2nS",
                              erev="0mV",
                              tau_rise="1ms",
                              tau_decay="15ms")

    if poisson_inputs:

        pfs = oc.add_poisson_firing_synapse(nml_doc,
                                            id="poissonFiringSyn",
                                            average_rate="150 Hz",
                                            synapse_id=syn0.id)

        oc.add_inputs_to_population(network,
                                    "Stim0",
                                    pop_rs,
                                    pfs.id,
                                    all_cells=True)
        '''                            
        oc.add_inputs_to_population(network,
                                    "Stim1",
                                    pop_bask,
                                    pfs.id,
                                    all_cells=True)'''
    if offset_curent_range_pA:

        for pop_id in offset_curent_range_pA:

            pop = next(p for p in network.populations if p.id == pop_id)

            pg0 = oc.add_pulse_generator(nml_doc,
                                         id="offset_current_%s" % pop.id,
                                         delay="0ms",
                                         duration="%sms" % duration,
                                         amplitude="1pA")

            import neuroml
            import random

            input_list = neuroml.InputList(id="inputs_offset_current_%s" %
                                           pop.id,
                                           component=pg0.id,
                                           populations=pop.id)

            network.input_lists.append(input_list)

            min_, max_ = offset_curent_range_pA[pop_id]

            for i in range(pop.get_size()):

                input = neuroml.InputW(
                    id=i,
                    target="../%s/%i/%s" % (pop.id, i, pop.component),
                    destination="synapses",
                    weight=(min_ + (max_ - min_) * random.random()))

                input_list.input_ws.append(input)

    total_conns = 0
    if connections:

        proj = oc.add_probabilistic_projection(network,
                                               "proj0",
                                               pop_rs,
                                               pop_bask,
                                               syn1.id,
                                               1,
                                               weight=1,
                                               delay=global_delay)
        '''
        proj = oc.add_targeted_projection(nml_doc,
                                        network,
                                        "proj0",
                                        presynaptic_population = pop_rs,
                                        postsynaptic_population = pop_bask,
                                        targeting_mode = 'convergent',
                                        synapse_list = [syn1.id],
                                        number_conns_per_cell = 1,
                                        pre_segment_group = 'axon_group',
                                        post_segment_group = 'dendrite_group',
                                        delays_dict = {syn1.id:2},
                                        weights_dict = {syn1.id:1})'''

        if proj:
            total_conns += len(proj.connection_wds)

    if num_rs != DEFAULT_RS_POP_SIZE or num_bask != DEFAULT_BASK_POP_SIZE:
        new_reference = '%s_%scells_%sconns' % (nml_doc.id, num_rs + num_bask,
                                                total_conns)
        network.id = new_reference
        nml_doc.id = new_reference

    nml_file_name = '%s.net.%s' % (network.id,
                                   'nml.h5' if format == 'hdf5' else 'nml')
    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=(format == 'xml'),
                    format=format)

    if format == 'xml':
        gen_plots_for_quantities = {
        }  #  Dict with displays vs lists of quantity paths
        gen_saves_for_quantities = {
        }  #  Dict with file names vs lists of quantity paths

        for pop in segments_to_plot_record.keys():
            pop_nml = network.get_by_id(pop)
            if pop_nml is not None and pop_nml.size > 0:
                for i in range(int(pop_nml.size)):
                    gen_plots_for_quantities['Display_%s_%i_v' % (pop, i)] = []
                    gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' %
                                             (nml_doc.id, pop, i)] = []

                    for seg in segments_to_plot_record[pop]:
                        quantity = '%s/%i/%s/%i/v' % (pop, i,
                                                      pop_nml.component, seg)
                        gen_plots_for_quantities['Display_%s_%i_v' %
                                                 (pop, i)].append(quantity)
                        gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' %
                                                 (nml_doc.id, pop,
                                                  i)].append(quantity)

        lems_file_name = oc.generate_lems_simulation(
            nml_doc,
            network,
            nml_file_name,
            duration=duration,
            dt=0.025,
            gen_plots_for_all_v=False,
            gen_plots_for_quantities=gen_plots_for_quantities,
            gen_saves_for_all_v=False,
            gen_saves_for_quantities=gen_saves_for_quantities)
    else:
        lems_file_name = None

    return nml_doc, nml_file_name, lems_file_name