Exemple #1
0
def setupNeurons(model, **kwargs):
    '''Creates neuron(s) defined by model.

    By default, uses param_sim imported with model (model.param_sim), but
    passing 'param_sim=param_sim' in as a kwarg allows overriding; when called
    in ajustador, the param_sim defined by ajustador is explicitly passed in.'''

    if hasattr(model,'neurons'):
        model.log.warning('Neurons already setup. Returning.')
        return

    # If network (expects Boolean) passed to setupNeurons, get the value. otherwise set to None
    if 'network' in kwargs:
        network = kwargs.pop('network')
    else:
        network = None

    if 'param_sim' in kwargs:
        param_sim = kwargs['param_sim']
    else:
        param_sim = model.param_sim
    if getattr(param_sim, 'neuron_type', None) is not None:
        model.param_cond.neurontypes = util.neurontypes(model.param_cond,
                                                    [param_sim.neuron_type])
    # build neurons and specify returns to model namespace
    model.syn, model.neurons = cell_proto.neuronclasses(model)
    # If calcium and synapses created, could test plasticity at a single synapse
    # in syncomp. Need to debug this since eliminated param_sim.stimtimes. See
    # what else needs to be changed in plasticity_test.
    model.plas = {}
    #if model.plasYN:
    #    model.plas, model.stimtab = plasticity_test.plasticity_test(model)
                                                    #param_sim.syncomp,
                                                    #model.syn,
                                                    #param_sim.stimtimes)

    ########## clocks are critical. assign_clocks also sets up the hsolver

    if not network:
        print("Not simulating network; setting up simpaths and clocks in create_model_sim")
        simpaths=['/'+neurotype for neurotype in util.neurontypes(model.param_cond)]
        clocks.assign_clocks(simpaths, param_sim.simdt, param_sim.plotdt,
                             param_sim.hsolve, model.param_cond.NAME_SOMA)
        # Fix calculation of B parameter in CaConc if using hsolve
        if model.param_sim.hsolve and model.calYN:
            calcium.fix_calcium(util.neurontypes(model.param_cond), model)
    else:
        print("Simulating network; not setting up simpaths and clocks in create_model_sim")

    print('****Model.plasYN = {}*****'.format(model.plasYN))

    return model
Exemple #2
0
def plasticity_test(model, syncomp=None, syn_pop=None, stimtimes=None):
    syntype = model.CaPlasticityParams.Plas_syn.Name
    if stimtimes is None:
        stimtimes = [.1, .12]
    if syncomp is None:
        path = model.neurons[list(model.neurons)[0]].path
        syncomp = moose.wildcardFind(path + '/##/' + syntype +
                                     '[ISA=SynChan]')[0].parent
    plast = {}
    stimtab = {}
    if model.calYN and model.plasYN:
        neu = moose.Neutral('/input')
        for neurtype in util.neurontypes(model.param_cond):
            stimtab[neurtype] = moose.TimeTable('%s/TimTab%s' %
                                                (neu.path, neurtype))
            stimtab[neurtype].vector = stimtimes

            print('**** plasticity test ********', syntype, neurtype, syncomp)
            #synchan=moose.element(syn_pop[neurtype][syntype][syncomp])
            synchan = moose.element(syncomp.path + '/' + syntype)
            sh = synchan.children[0]
            log.info('Synapse added to {.path}', synchan)
            connect.synconn(sh, 0, stimtab[neurtype], model.param_syn)

            ###Synaptic Plasticity
            plast[neurtype] = plasticity.plasticity2(
                synchan, model.CaPlasticityParams.Plas_syn)
    return plast, stimtab
Exemple #3
0
def plasticity_test(model, syncomp=None, syn_pop=None, stimtimes=None):
    syntype = model.CaPlasticityParams.Plas_syn.Name
    if stimtimes is None:
        stimtimes = [.1,.12]
    if syncomp is None:
        path = model.neurons[list(model.neurons)[0]].path
        syncomp = moose.wildcardFind(path+'/##/'+syntype+'[ISA=SynChan]')[0].parent
    plast={}
    stimtab={}
    if model.calYN  and model.plasYN:
        neu = moose.Neutral('/input')
        for neurtype in util.neurontypes(model.param_cond):
            stimtab[neurtype]=moose.TimeTable('%s/TimTab%s' % (neu.path, neurtype))
            stimtab[neurtype].vector = stimtimes

            print('**** plasticity test ********',syntype,neurtype,syncomp)
            #synchan=moose.element(syn_pop[neurtype][syntype][syncomp])
            synchan=moose.element(syncomp.path+'/'+syntype)
            sh = synchan.children[0]
            log.info('Synapse added to {.path}', synchan)
            connect.synconn(sh,0,stimtab[neurtype], model.param_syn)

            ###Synaptic Plasticity
            plast[neurtype] = plasticity.plasticity2(synchan,model.CaPlasticityParams.Plas_syn)
    return plast, stimtab
Exemple #4
0
def neuronclasses(model):
    ##create channels in the library
    chan_proto.chanlib(model)
    syn_proto.synchanlib(model)
    ##now create the neuron prototypes
    neuron={}
    synArray={}
    headArray={}
    caPools = {}
    for ntype in _util.neurontypes(model.param_cond):
        protoname='/library/'+ntype
        #use morph_file[ntype] for cell-type specific morphology
        #create_neuron creates morphology and ion channels only
        neuron[ntype]=create_neuron(model, ntype, model.ghkYN)
        #optionally add spines; includes reverse compensation
        if model.spineYN:
            headArray[ntype]=spines.addSpines(model, ntype, model.ghkYN, model.param_cond.NAME_SOMA)
        #optionally add synapses to dendrites, and possibly to spines
        if model.synYN:
            synArray[ntype] = syn_proto.add_synchans(model, ntype)
        #Calcium concentration - also optional
        #   0: none
        #   1: single tau
        #   2: diffusion, buffering, pumps
        #      this will require many additional function definitions
        if model.calYN:
            caPools[ntype] = calcium.addCalcium(model,ntype)

    return synArray,neuron
Exemple #5
0
def spineFig(model, spinecatab, spinevmtab, simtime):
    f = plt.figure()
    f.canvas.set_window_title('Spines')
    t = np.linspace(0, simtime, len(spinevmtab[0][0].vector))
    if model.calYN:
        plt.subplot(211)
    for neurnum in range(len(neurontypes(model.param_cond))):
        for oid in spinevmtab[neurnum]:
            #find()-2 removes Vm from name, split and join removes dend from name
            name = ''.join(oid.name[oid.name.find('_') - 2:].split('dend'))
            plt.plot(t, oid.vector, label=name)
        plt.ylabel('Vm')
    if model.calYN:
        plt.subplot(212)
        for neurnum in range(len(neurontypes(model.param_cond))):
            for oid in spinecatab[neurnum]:
                name = ''.join(oid.name[oid.name.find('_') - 2:].split('dend'))
                plt.plot(t, 1000 * oid.vector, label=name)
            plt.ylabel('calcium, uM')
    plt.legend()
    plt.show()
Exemple #6
0
def spineFig(model,spinecatab,spinevmtab,simtime):
    f=plt.figure()
    f.canvas.set_window_title('Spines')
    t = np.linspace(0, simtime, len(spinevmtab[0][0].vector))
    if model.calYN:
        plt.subplot(211)
    for neurnum in range(len(neurontypes(model.param_cond))):
        for oid in spinevmtab[neurnum]:
            #find()-2 removes Vm from name, split and join removes dend from name
            name = ''.join(oid.name[oid.name.find('_')-2:].split('dend'))
            plt.plot(t,oid.vector,label=name)
        plt.ylabel('Vm')
    if model.calYN:
        plt.subplot(212)
        for neurnum in range(len(neurontypes(model.param_cond))):
            for oid in spinecatab[neurnum]:
                name=''.join(oid.name[oid.name.find('_')-2:].split('dend'))
                plt.plot(t,1000*oid.vector,label=name)
            plt.ylabel('calcium, uM')
    plt.legend()
    plt.show()
def main(args):
    global param_sim, pulse_gen
    param_sim = option_parser().parse_args(args)
    model = importlib.import_module('moose_nerp.' + param_sim.model)
    model.param_cond.neurontypes = util.neurontypes(model.param_cond,
                                                    [param_sim.neuron_type])
    logger.debug("param_sim::::::::: {}".format(param_sim))
    pulse_gen, hdf5writer = setup(param_sim, model)
    run_simulation(param_sim.injection_current[0], param_sim.simtime,
                   param_sim, model)
    hdf5writer.close()

    if param_sim.plot_vm:
        neuron_graph.graphs(model,
                            param_sim.plot_current,
                            param_sim.simtime,
                            compartments=[0])
        util.block_if_noninteractive()
    if param_sim.save_vm:
        elemname = '/data/Vm{}_0'.format(param_sim.neuron_type)
        np.save(param_sim.save_vm, moose.element(elemname).vector)
Exemple #8
0
def moose_main(p):
    stimfreq, presyn, stpYN, trialnum, prefix, ttGPe, ttstr, ttSTN = p

    import numpy as np
    import os
    import moose

    from moose_nerp.prototypes import (calcium, create_model_sim, clocks,
                                       inject_func, create_network, tables,
                                       net_output, util)
    from moose_nerp import ep as model
    from moose_nerp import ep_net as net
    from moose_nerp.graph import net_graph, neuron_graph, spine_graph

    np.random.seed()
    #additional, optional parameter overrides specified from with python terminal
    model.synYN = True
    model.stpYN = stpYN
    net.single = True
    stimtype = 'PSP_'
    outdir = "ep_net/output/"
    ############## if stim_freq>0, stim_paradigm adds regular input and synaptic plasticity at single synapse ####################
    if stimfreq > 0:
        model.param_sim.stim_paradigm = stimtype + str(stimfreq) + 'Hz'
        model.param_stim.Stimulation.StimLoc = model.param_stim.location[
            presyn]
    else:
        model.param_sim.stim_paradigm = 'inject'
    create_model_sim.setupOptions(model)
    param_sim = model.param_sim
    param_sim.injection_current = [0e-12]
    param_sim.injection_delay = 0.0
    param_sim.plot_synapse = False

    if prefix.startswith('POST-HFS'):
        net.connect_dict['ep']['ampa']['extern1'].weight = 0.6  #STN - weaker
        net.connect_dict['ep']['gaba']['extern2'].weight = 0.8  #GPe - weaker
        net.connect_dict['ep']['gaba']['extern3'].weight = 1.4  #str - stronger
    if prefix.startswith('POST-NoDa'):
        net.connect_dict['ep']['ampa'][
            'extern1'].weight = 1.0  #STN - no change
        net.connect_dict['ep']['gaba']['extern2'].weight = 2.8  #GPe - stronger
        net.connect_dict['ep']['gaba'][
            'extern3'].weight = 1.0  #str - no change

    #override time tables here - before creating model, e.g.
    fname_part = ''
    if len(ttGPe):
        net.param_net.tt_GPe.filename = ttGPe
        print('!!!!!!!!!!!!!! new tt file for GPe:',
              net.param_net.tt_GPe.filename, 'trial', trialnum)
        fname_part = fname_part + '_tg_' + os.path.basename(ttGPe)
    else:
        print('$$$$$$$$$$$$$$ old tt file for GPe:',
              net.param_net.tt_GPe.filename, 'trial', trialnum)
    if len(ttstr):
        net.param_net.tt_str.filename = ttstr
        print('!!!!!!!!!!!!!! new tt file for str:',
              net.param_net.tt_str.filename, 'trial', trialnum)
        fname_part = fname_part + '_ts_' + os.path.basename(ttstr)
    else:
        print('$$$$$$$$$$$$$$ old tt file for str:',
              net.param_net.tt_str.filename, 'trial', trialnum)
    if len(ttSTN):
        net.param_net.tt_STN.filename = ttSTN
        print('!!!!!!!!!!!!!! new tt file for STN:',
              net.param_net.tt_STN.filename, 'trial', trialnum)
        fname_part = fname_part + '_ts_' + os.path.basename(ttSTN)
    else:
        print('$$$$$$$$$$$$$$ old tt file for STN:',
              net.param_net.tt_STN.filename, 'trial', trialnum)
    #################################-----------create the model: neurons, and synaptic inputs
    if model.stpYN == False:
        remember_stpYN = False
        model.stpYN = True
        #create network with stp, and then turn it off for extra synapse (if model.stpYN is False)
    else:
        remember_stpYN = True
    fname_stp = str(1 if model.stpYN else 0) + str(1 if remember_stpYN else 0)

    model = create_model_sim.setupNeurons(model, network=not net.single)
    print('trialnum', trialnum)
    population, connections, plas = create_network.create_network(
        model, net, model.neurons)
    model.stpYN = remember_stpYN

    ####### Set up stimulation - could be current injection or plasticity protocol
    # set num_inject=0 to avoid current injection
    if net.num_inject < np.inf:
        model.inject_pop = inject_func.inject_pop(population['pop'],
                                                  net.num_inject)
        if net.num_inject == 0:
            param_sim.injection_current = [0]
    else:
        model.inject_pop = population['pop']

    ############## Set-up test of synaptic plasticity at single synapse ####################
    if presyn == 'str':
        stp_params = net.param_net.str_plas
    elif presyn == 'GPe':
        stp_params = net.param_net.GPe_plas
    else:
        print('########### unknown synapse type', 'trial', trialnum)

    param_sim.fname = 'ep' + prefix + stimtype + presyn + '_freq' + str(
        stimfreq) + '_plas' + fname_stp + fname_part + 't' + str(trialnum)
    print(
        '>>>>>>>>>> moose_main, presyn {} stpYN {} stimfreq {} simtime {} trial {} plotcomps {} tt {} {}'
        .format(presyn, model.stpYN, stimfreq, param_sim.simtime, trialnum,
                param_sim.plotcomps, ttGPe, ttstr))

    create_model_sim.setupStim(model)
    print('>>>> After setupStim, simtime:', param_sim.simtime, 'trial',
          trialnum, 'stpYN', model.stpYN)
    ##############--------------output elements
    if net.single:
        create_model_sim.setupOutput(model)
    else:  #population of neurons
        model.spiketab, model.vmtab, model.plastab, model.catab = net_output.SpikeTables(
            model, population['pop'], net.plot_netvm, plas, net.plots_per_neur)
        #simpath used to set-up simulation dt and hsolver
        simpath = [net.netname]
        clocks.assign_clocks(simpath, param_sim.simdt, param_sim.plotdt,
                             param_sim.hsolve, model.param_cond.NAME_SOMA)
        # Fix calculation of B parameter in CaConc if using hsolve
        if model.param_sim.hsolve and model.calYN:
            calcium.fix_calcium(util.neurontypes(model.param_cond), model)
    #
    if model.synYN and (param_sim.plot_synapse or net.single):
        #overwrite plastab above, since it is empty
        model.syntab, model.plastab, model.stp_tab = tables.syn_plastabs(
            connections, model)
    #
    #add short term plasticity to synapse as appropriate
    param_dict = {
        'syn': presyn,
        'freq': stimfreq,
        'plas': model.stpYN,
        'inj': param_sim.injection_current,
        'simtime': param_sim.simtime,
        'trial': trialnum,
        'dt': param_sim.plotdt
    }
    if stimfreq > 0:
        from moose_nerp.prototypes import plasticity_test as plas_test
        extra_syntab = {ntype: [] for ntype in model.neurons.keys()}
        extra_plastabset = {ntype: [] for ntype in model.neurons.keys()}
        for ntype in model.neurons.keys():
            for tt_syn_tuple in model.tuples[ntype].values():
                if model.stpYN:
                    extra_syntab[ntype], extra_plastabset[
                        ntype] = plas_test.short_term_plasticity_test(
                            tt_syn_tuple,
                            syn_delay=0,
                            simdt=model.param_sim.simdt,
                            stp_params=stp_params)
                    print('!!!!!!!!!!!!! setting up plasticity, stpYN',
                          model.stpYN)
                else:
                    extra_syntab[ntype] = plas_test.short_term_plasticity_test(
                        tt_syn_tuple, syn_delay=0)
                    print('!!!!!!!!!!!!! NO plasticity, stpYN', model.stpYN)
            param_dict[ntype] = {
                'syn_tt':
                [(k, tt[0].vector) for k, tt in model.tuples[ntype].items()]
            }
    #
    #################### Actually run the simulation
    param_sim.simtime = 5.0
    print('$$$$$$$$$$$$$$ paradigm=',
          model.param_stim.Stimulation.Paradigm.name, ' inj=0? ',
          np.all([inj == 0 for inj in param_sim.injection_current]),
          'simtime:', param_sim.simtime, 'trial', trialnum, 'fname',
          outdir + param_sim.fname)
    if model.param_stim.Stimulation.Paradigm.name is not 'inject' and not np.all(
        [inj == 0 for inj in param_sim.injection_current]):
        pg = inject_func.setupinj(model, param_sim.injection_delay,
                                  model.param_sim.simtime, model.inject_pop)
        inj = [i for i in param_sim.injection_current if i != 0]
        pg.firstLevel = param_sim.injection_current[0]
        create_model_sim.runOneSim(model, simtime=model.param_sim.simtime)
    else:
        for inj in model.param_sim.injection_current:
            create_model_sim.runOneSim(model,
                                       simtime=model.param_sim.simtime,
                                       injection_current=inj)

    #net_output.writeOutput(model, param_sim.fname+'vm',model.spiketab,model.vmtab,population)
    #
    #Save results: spike time, Vm, parameters, input time tables
    from moose_nerp import ISI_anal
    spike_time, isis = ISI_anal.spike_isi_from_vm(
        model.vmtab, param_sim.simtime, soma=model.param_cond.NAME_SOMA)
    vmout = {
        ntype: [tab.vector for tab in tabset]
        for ntype, tabset in model.vmtab.items()
    }
    if np.any([len(st) for tabset in spike_time.values() for st in tabset]):
        np.savez(outdir + param_sim.fname,
                 spike_time=spike_time,
                 isi=isis,
                 params=param_dict,
                 vm=vmout)
    else:
        print('no spikes for', param_sim.fname, 'saving vm and parameters')
        np.savez(outdir + param_sim.fname, params=param_dict, vm=vmout)
    if net.single:
        #save spiketime of all input time tables
        timtabs = {}
        for neurtype, neurtype_dict in connections.items():
            for neur, neur_dict in neurtype_dict.items():
                for syn, syn_dict in neur_dict.items():
                    timtabs[syn] = {}
                    for pretype, pre_dict in syn_dict.items():
                        timtabs[syn][pretype] = {}
                        for branch, presyn in pre_dict.items():
                            for i, possible_tt in enumerate(presyn):
                                if 'TimTab' in possible_tt:
                                    timtabs[syn][pretype][
                                        branch + '_syn' +
                                        str(i)] = moose.element(
                                            possible_tt).vector
        np.save(outdir + 'tt' + param_sim.fname, timtabs)

    #create dictionary with the output (vectors) from test plasticity
    tab_dict = {}
    if stimfreq > 0:
        for ntype, tabset in extra_syntab.items():
            tab_dict[ntype] = {
                'syn': tabset.vector,
                'syndt': tabset.dt,
                'tt': {
                    ntype + '_' + pt: tab.vector
                    for pt, tab in model.tt[ntype].items()
                }
            }
            if model.stpYN:
                tab_dict[ntype]['plas'] = {
                    tab.name: tab.vector
                    for tab in extra_plastabset[ntype]
                }
    return param_dict, tab_dict, vmout, spike_time, isis
Exemple #9
0
streamer.outfile = 'streamertest.npy'
for t in allTables:
    streamer.addTable(t)

################### Actually run the simulation
def run_simulation(injection_current, simtime):
    print(u'◢◤◢◤◢◤◢◤ injection_current = {} ◢◤◢◤◢◤◢◤'.format(injection_current))
    pg.firstLevel = injection_current
    moose.reinit()
    moose.start(simtime)

traces, names = [], []
for inj in param_sim.injection_current:
    run_simulation(injection_current=inj, simtime=param_sim.simtime)
    if net.single and len(model.vmtab):
        for neurnum,neurtype in enumerate(util.neurontypes(model.param_cond)):
            traces.append(model.vmtab[neurtype][0].vector)
            names.append('{} @ {}'.format(neurtype, inj))
        if model.synYN:
            net_graph.syn_graph(connections, syntab, param_sim)
        if model.plasYN:
            net_graph.syn_graph(connections, plastab, param_sim, graph_title='Plas Weight')
            net_graph.syn_graph(connections, nonstim_plastab, param_sim, graph_title='NonStim Plas Weight')

        if model.spineYN:
            spine_graph.spineFig(model,model.spinecatab,model.spinevmtab, param_sim.simtime)
    else:
        if net.plot_netvm:
            net_graph.graphs(population['pop'], param_sim.simtime, vmtab,catab,plastab)
        if model.synYN and param_sim.plot_synapse:
            net_graph.syn_graph(connections, syntab, param_sim)
Exemple #10
0
################### Actually run the simulation
def run_simulation(injection_current, simtime, continue_sim=False):
    print(u'◢◤◢◤◢◤◢◤ injection_current = {} ◢◤◢◤◢◤◢◤'.format(injection_current))
    pg.firstLevel = injection_current
    if not continue_sim:
        moose.reinit()
    moose.start(simtime)


continue_sim = False
traces, names = [], []
for inj in param_sim.injection_current:
    run_simulation(injection_current=inj, simtime=param_sim.simtime, continue_sim=continue_sim)
    if net.single and len(model.vmtab):
        for neurnum, neurtype in enumerate(util.neurontypes(model.param_cond)):
            traces.append(model.vmtab[neurtype][0].vector)
            names.append('{} @ {}'.format(neurtype, inj))
        if model.synYN:
            net_graph.syn_graph(connections, syntab, param_sim)
        if model.plasYN:
            net_graph.syn_graph(connections, plastab, param_sim, graph_title='Plas Weight')
            net_graph.syn_graph(connections, nonstim_plastab, param_sim, graph_title='NonStim Plas Weight')

        if model.spineYN:
            spine_graph.spineFig(model, model.spinecatab, model.spinevmtab, param_sim.simtime)
    else:
        if net.plot_netvm:
            net_graph.graphs(population['pop'], param_sim.simtime, vmtab, catab, plastab)
        if model.synYN and param_sim.plot_synapse:
            net_graph.syn_graph(connections, syntab, param_sim)
Exemple #11
0
def moose_main(p):
    stimfreq,presyn,stpYN,trialnum=p

    import numpy as np
    import moose

    from moose_nerp.prototypes import (create_model_sim,
                                       clocks,
                                       inject_func,
                                       create_network,
                                       tables,
                                       net_output,
                                       util)
    from moose_nerp import ep as model
    from moose_nerp import ep_net as net
    from moose_nerp.graph import net_graph, neuron_graph, spine_graph


    #additional, optional parameter overrides specified from with python terminal
    model.synYN = True
    model.stpYN = stpYN
    net.single=True
    model.param_sim.stim_paradigm='PSP_'+str(stimfreq)+'Hz'
    model.param_stim.Stimulation.StimLoc=model.param_stim.location[presyn]

    create_model_sim.setupOptions(model)
    param_sim = model.param_sim
    param_sim.injection_current = [0e-12]
    param_sim.injection_delay = 0.0
    param_sim.plot_synapse=False

    #################################-----------create the model: neurons, and synaptic inputs
    model=create_model_sim.setupNeurons(model,network=not net.single)
    population,connections,plas=create_network.create_network(model, net, model.neurons)

    ####### Set up stimulation - could be current injection or plasticity protocol
    # set num_inject=0 to avoid current injection
    if net.num_inject<np.inf :
        model.inject_pop=inject_func.inject_pop(population['pop'],net.num_inject)
    else:
        model.inject_pop=population['pop']
        if net.num_inject==0:
            param_sim.injection_current=[0]

    ############## Set-up test of synaptic plasticity at single synapse ####################
    if presyn=='str':
        stp_params=net.param_net.str_plas
    elif presyn=='GPe':
        stp_params=net.param_net.GPe_plas
    else:
        print('########### unknown synapse type')

    param_sim.fname='epGABA_syn'+presyn+'_freq'+str(stimfreq)+'_plas'+str(1 if model.stpYN else 0)+'_inj'+str(param_sim.injection_current[0])+'t'+str(trialnum)
    print('>>>>>>>>>> moose_main, presyn {} stpYN {} stimfreq {} trial {}'.format(presyn,model.stpYN,stimfreq,trialnum))

    create_model_sim.setupStim(model)
    if model.param_stim.Stimulation.Paradigm.name is not 'inject' and not np.all([inj==0 for inj in param_sim.injection_current]):
        pg=inject_func.setupinj(model, param_sim.injection_delay,param_sim.injection_width,model.inject_pop)
        pg.firstLevel = param_sim.injection_current[0]


    ##############--------------output elements
    if net.single:
        #fname=model.param_stim.Stimulation.Paradigm.name+'_'+model.param_stim.location.stim_dendrites[0]+'.npz'
        create_model_sim.setupOutput(model)
    else:   #population of neurons
        spiketab,vmtab,plastab,catab=net_output.SpikeTables(model, population['pop'], net.plot_netvm, plas, net.plots_per_neur)
        #simpath used to set-up simulation dt and hsolver
        simpath=[net.netname]
        clocks.assign_clocks(simpath, param_sim.simdt, param_sim.plotdt, param_sim.hsolve,model.param_cond.NAME_SOMA)
        # Fix calculation of B parameter in CaConc if using hsolve
        if model.param_sim.hsolve and model.calYN:
            calcium.fix_calcium(util.neurontypes(model.param_cond), model)

    if model.synYN and (param_sim.plot_synapse or net.single):
        #overwrite plastab above, since it is empty
        syntab, plastab, stp_tab=tables.syn_plastabs(connections,model)

    from moose_nerp.prototypes import plasticity_test as plas_test
    extra_syntab={ntype:[] for ntype in  model.neurons.keys()}
    extra_plastabset={ntype:[] for ntype in  model.neurons.keys()}
    param_dict={'syn':presyn,'freq':stimfreq,'plas':model.stpYN,'inj':param_sim.injection_current,'simtime':param_sim.simtime, 'trial': trialnum}
    for ntype in model.neurons.keys():
        for tt_syn_tuple in model.tuples[ntype].values():
            if model.stpYN:
                extra_syntab[ntype],extra_plastabset[ntype]=plas_test.short_term_plasticity_test(tt_syn_tuple,syn_delay=0,
                                                                        simdt=model.param_sim.simdt,stp_params=stp_params)
            else:
                extra_syntab[ntype]=plas_test.short_term_plasticity_test(tt_syn_tuple,syn_delay=0)
        param_dict[ntype]={'syn_tt': [(k,tt[0].vector) for k,tt in model.tuples[ntype].items()]}
    #
    #################### Actually run the simulation
    if not np.all([inj==0 for inj in param_sim.injection_current]):
        inj=[i for i in param_sim.injection_current if i !=0]
        create_model_sim.runOneSim(model, simtime=model.param_sim.simtime, injection_current=inj[0])
    else:
        create_model_sim.runOneSim(model)
    #net_output.writeOutput(model, param_sim.fname+'vm',spiketab,vmtab,population)
    #
    import ISI_anal
    #stim_spikes are spikes that occur during stimulation - they prevent correct psp_amp calculation
    spike_time,isis=ISI_anal.spike_isi_from_vm(model.vmtab,param_sim.simtime)
    stim_spikes=ISI_anal.stim_spikes(spike_time,model.tt)
    if np.any([len(st) for tabset in spike_time.values() for st in tabset]):
        np.savez(param_sim.fname,spike_time=spike_time,isi=isis,params=param_dict)
    else:
        print('no spikes for',param_sim.fname)
    #create dictionary with the output (vectors) from tables 
    tab_dict={}
    for ntype,tabset in extra_syntab.items():
        tab_dict[ntype]={'syn':tabset.vector,'syndt':tabset.dt, 
        'tt': {ntype+'_'+pt:tab.vector for pt,tab in model.tt[ntype].items()}}#,'tt_dt':tabset.dt}
        if model.stpYN:
            tab_dict[ntype]['plas']={tab.name:tab.vector for tab in extra_plastabset[ntype]}
    vmtab={ntype:[tab.vector for tab in tabset] for ntype,tabset in model.vmtab.items()}
    return param_dict,tab_dict,vmtab,spike_time,isis
Exemple #12
0
if model.param_stim.Stimulation.Paradigm.name is not 'inject' and not np.all([inj==0 for inj in param_sim.injection_current]):
    pg=inject_func.setupinj(model, param_sim.injection_delay,param_sim.injection_width,model.inject_pop)
    pg.firstLevel = param_sim.injection_current[0]

##############--------------output elements
if net.single:
    #fname=model.param_stim.Stimulation.Paradigm.name+'_'+model.param_stim.location.stim_dendrites[0]+'.npz'
    create_model_sim.setupOutput(model)
else:   #population of neurons
    spiketab,vmtab,plastab,catab=net_output.SpikeTables(model, population['pop'], net.plot_netvm, plas, net.plots_per_neur)
    #simpath used to set-up simulation dt and hsolver
    simpath=[net.netname]
    clocks.assign_clocks(simpath, param_sim.simdt, param_sim.plotdt, param_sim.hsolve,model.param_cond.NAME_SOMA)
    # Fix calculation of B parameter in CaConc if using hsolve
    if model.param_sim.hsolve and model.calYN:
        calcium.fix_calcium(util.neurontypes(model.param_cond), model)

if model.synYN and (param_sim.plot_synapse or net.single):
    #overwrite plastab above, since it is empty
    syntab, plastab, stp_tab=tables.syn_plastabs(connections,model)

#add short term plasticity to synapse as appropriate
from moose_nerp.prototypes import plasticity_test as plas_test
extra_syntab={ntype:[] for ntype in  model.neurons.keys()}
extra_plastabset={ntype:[] for ntype in  model.neurons.keys()}
param_dict={'syn':presyn,'freq':stimfreq,'plas':model.stpYN,'inj':param_sim.injection_current,'simtime':param_sim.simtime}
for ntype in model.neurons.keys():
    for tt_syn_tuple in model.tuples[ntype].values():
        if model.stpYN:
            extra_syntab[ntype],extra_plastabset[ntype]=plas_test.short_term_plasticity_test(tt_syn_tuple,syn_delay=0,
                                                                    simdt=model.param_sim.simdt,stp_params=stp_params)
Exemple #13
0
create_model_sim.setupStim(model)
print('>>>> After setupStim, simtime:', param_sim.simtime)
##############--------------output elements
if net.single:
    create_model_sim.setupOutput(model)
else:  # population of neurons
    spiketab, vmtab, plastab, catab = net_output.SpikeTables(
        model, population['pop'], net.plot_netvm, plas, net.plots_per_neur)
    # simpath used to set-up simulation dt and hsolver
    simpath = [net.netname]
    clocks.assign_clocks(simpath, param_sim.simdt, param_sim.plotdt,
                         param_sim.hsolve, model.param_cond.NAME_SOMA)
    # Fix calculation of B parameter in CaConc if using hsolve
    if model.param_sim.hsolve and model.calYN:
        calcium.fix_calcium(util.neurontypes(model.param_cond), model)

if model.synYN and (param_sim.plot_synapse or net.single):
    # overwrite plastab above, since it is empty
    syntab, plastab, stp_tab = tables.syn_plastabs(connections, model)

# add short term plasticity to synapse as appropriate
param_dict = {
    'syn': presyn,
    'freq': stimfreq,
    'plas': model.stpYN,
    'inj': param_sim.injection_current,
    'simtime': param_sim.simtime,
    'dt': param_sim.plotdt
}
if stimfreq > 0: