def generate(cell_id, duration, reference, iRange):

    cell_file = '%s.cell.nml'%cell_id

    #cell_id = 'Cell0'
    #cell_file = 'L23_morph.cell.nml'

    nml_doc, network = oc.generate_network(reference, temperature='35degC')

    oc.include_neuroml2_cell_and_channels(nml_doc,cell_file,cell_id)



    population_size = len(iRange)

    pop = oc.add_population_in_rectangular_region(network,
                                                  'L23_pop',
                                                  cell_id,
                                                  population_size,
                                                  0,0,0,
                                                  1000,100,1000)
    for i in range(iRange.size):
        stim_id = ("Stim_%i"%i)
        pg = oc.add_pulse_generator(nml_doc,
                               id=stim_id,
                               delay="50ms",
                               duration="250ms",
                               amplitude="%fnA"%iRange[i])

        oc.add_inputs_to_population(network,
                                    stim_id,
                                    pop,
                                    pg.id,
                                    all_cells=False,
                                    only_cells=[i])

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


    oc.generate_lems_simulation(nml_doc, 
                                network, 
                                nml_file_name, 
                                duration, 
                                dt = 0.025)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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")
'''                                     
pgBBP = oc.add_pulse_generator(nml_doc,
                       id="pgBBP",
                       delay="100ms",
                       duration="300ms",
                       amplitude="0.7nA")'''
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
                              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",
                              tau_decay="5ms")

#####   Input types

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

pg1 = oc.add_pulse_generator(nml_doc,
                             id="pg1",
                             delay="50ms",
                             duration="400ms",
                             amplitude="0.35nA")

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

#####   Populations
Ejemplo n.º 8
0
oc.include_neuroml2_file(nml_doc,'AMPA_NMDA.synapse.nml')

                         

#####   Input types

                             
pfs100 = oc.add_poisson_firing_synapse(nml_doc,
                                   id="poissonFiringSyn100",
                                   average_rate="100 Hz",
                                   synapse_id='AMPA_noplast')
                                   
pg0 = oc.add_pulse_generator(nml_doc,
                       id="pg0",
                       delay="1000ms",
                       duration="1000ms",
                       amplitude="0.2nA")
                                     
                             
#####   Populations

pop0 = oc.add_population_in_rectangular_region(network,
                                              'pop0',
                                              'RS',
                                              scale_pop_size(1),
                                              0,offset,0,
                                              xDim,yDim,zDim)
offset+=yDim

pop1 = oc.add_population_in_rectangular_region(network,
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def generate(cell_id,
             duration,
             reference,
             format='hdf5',
             num_cells=10,
             simulator=None):

    #Insyn = int(Ensyn * 0.2)
    #bInsyn = int(bEnsyn * 0.2)

    cell_file = '../%s.cell.nml' % cell_id
    if '/' in cell_id:
        cell_id = cell_id.split('/')[-1]

    nml_doc, network = oc.generate_network(reference, temperature='35degC')

    oc.include_neuroml2_cell_and_channels(nml_doc, cell_file, cell_id)

    pop = oc.add_population_in_rectangular_region(network, 'L23_pop', cell_id,
                                                  num_cells, 0, 0, 0, 100, 100,
                                                  100)

    to_plot = {'Some_voltages': []}
    to_save = {'%s_%s_voltages.dat' % (reference, cell_id): []}

    interesting_seg_ids = [0, 200, 1000, 2000, 2500,
                           2949]  # [soma, .. some dends .. , axon]
    interesting_seg_ids = [0]  # [soma, .. some dends .. , axon]

    pg0 = oc.add_pulse_generator(nml_doc,
                                 id="pg0",
                                 delay="200ms",
                                 duration="600ms",
                                 amplitude="0.4nA")

    pg1 = oc.add_pulse_generator(nml_doc,
                                 id="pg1",
                                 delay="100ms",
                                 duration="400ms",
                                 amplitude="0.02nA")

    oc.add_targeted_inputs_to_population(network,
                                         "PG_fixed",
                                         pop,
                                         pg0.id,
                                         segment_group='soma_group',
                                         number_per_cell=1,
                                         all_cells=True)

    oc.add_targeted_inputs_to_population(
        network,
        "PG_variable",
        pop,
        'cond0',  # from ../../../ConductanceClamp.xml
        segment_group='soma_group',
        number_per_cell=1,
        all_cells=True,
        weights='random()')

    for i in range(num_cells):

        for seg_id in interesting_seg_ids:
            to_plot.values()[0].append('%s/%s/%s/%s/v' %
                                       (pop.id, i, pop.component, seg_id))
            to_save.values()[0].append('%s/%s/%s/%s/v' %
                                       (pop.id, i, pop.component, seg_id))

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

    target_dir = './'

    oc.save_network(nml_doc,
                    nml_file_name,
                    validate=False,
                    use_subfolder=True,
                    target_dir=target_dir,
                    format=format)

    lems_file_name, lems_sim = oc.generate_lems_simulation(
        nml_doc,
        network,
        nml_file_name,
        duration,
        dt=0.025,
        target_dir=target_dir,
        include_extra_lems_files=['../../../ConductanceClamp.xml'],
        gen_plots_for_all_v=False,
        plot_all_segments=False,
        gen_plots_for_quantities=
        to_plot,  #  Dict with displays vs lists of quantity paths
        gen_saves_for_all_v=False,
        save_all_segments=False,
        gen_saves_for_quantities=
        to_save,  #  Dict with file names vs lists of quantity paths
        verbose=True)

    if simulator:

        print("Running %s for %sms in %s" %
              (lems_file_name, duration, simulator))

        traces, events = oc.simulate_network(lems_file_name,
                                             simulator,
                                             max_memory='4000M',
                                             nogui=True,
                                             load_saved_data=True,
                                             reload_events=True,
                                             plot=False,
                                             verbose=True,
                                             num_processors=min(num_cells, 16))