コード例 #1
0
def run_sim(model, data, simtime=100e-3, simdt=1e-6, plotdt=1e-4, solver='ee'):
    """Reset and run the simulation.

    model: model container element

    data: data container element

    simtime: simulation run time

    simdt: simulation timestep

    plotdt: plotting time step

    solver: neuronal solver to use.

    """
    global inited
    if not inited:
        utils.resetSim([model.path, data.path],
                       simdt,
                       plotdt,
                       simmethod=solver)
        inited = True
    else:
        moose.reinit()
    moose.start(simtime)
コード例 #2
0
ファイル: cell_test_util.py プロジェクト: Vivek-sagar/moose-1
 def runsim(self, simtime, stepsize=0.1, pulsearray=None):
     """Run the simulation for `simtime`. Save the data at the
     end."""
     mutils.resetSim([self.model_container.path, self.data_container.path], self.simdt, self.plotdt, simmethod=self.solver)
     if pulsearray is not None:            
         self.tweak_stimulus(pulsearray)
     moose.reinit()
     start = datetime.now()
     step_run(simtime, stepsize)
     end = datetime.now()
     # The sleep is required to get all threads to end 
     while moose.isRunning():
         time.sleep(0.1)
     delta = end - start
     config.logger.info('Simulation time with solver %s: %g s' % \
         (self.solver, 
          delta.seconds + delta.microseconds * 1e-6))
     self.tseries = np.arange(0, simtime+self.plotdt, self.plotdt)
     # Now save the data
     for table_id in self.data_container.children:
         try:
             data = np.vstack((self.tseries, table_id[0].vec))
         except ValueError as e:
             self.tseries = np.linspace(0, simtime, len(table_id[0].vec))
             data = np.vstack((self.tseries, table_id[0].vec))
         fname = 'data/%s_%s_%s.dat' % (self.celltype, 
                                        table_id[0].name,
                                        self.solver)
         np.savetxt(fname, np.transpose(data))
         print 'Saved', table_id[0].name, 'in', fname
コード例 #3
0
ファイル: MooseGUI.py プロジェクト: Vivek-sagar/moose-1
 def assignClocks(self,modelpath,modeltype):
     if modeltype == MooseHandler.type_kkit:
         #self.mooseHandler.updateClocks(MooseHandler.DEFAULT_SIMDT_KKIT, MooseHandler.DEFAULT_PLOTDT_KKIT)
         #script auto asigns clocks!
         pass
     elif modeltype == MooseHandler.type_neuroml:
         #self.mooseHandler.updateClocks(MooseHandler.DEFAULT_SIMDT, MooseHandler.DEFAULT_PLOTDT)
         #print MooseHandler.DEFAULT_SIMDT, MooseHandler.DEFAULT_PLOTDT
         if moose.exists('/cells'):
             #use Aditya's method to assign clocks - also reinits!
             ## Exponential Euler
             #mooseUtils.resetSim(['/cells','/elec'], MooseHandler.DEFAULT_SIMDT, MooseHandler.DEFAULT_PLOTDT, simmethod='ee')
             ## HSolve
             mooseUtils.resetSim(['/cells','/elec'], MooseHandler.DEFAULT_SIMDT, MooseHandler.DEFAULT_PLOTDT)
         else:
             print "This NeuroML model does not have any <population> of cells."
             print "You need to load a NetworkML or NeuroML level 3 model."
     elif modeltype == MooseHandler.type_python:
         #specific for the hopfield tutorial!
         #self.mooseHandler.updateClocks(MooseHandler.DEFAULT_SIMDT, MooseHandler.DEFAULT_PLOTDT)
         clock = 1e-4
         self.simControlSimdtLineEdit.setText(str(clock))
         self.simControlPlotdtLineEdit.setText(str(clock))
         self.mooseHandler.updateClocks(clock, clock) #simdt,plotdt
         moose.useClock(1, '/hopfield/##[TYPE=IntFire]', 'process')
         moose.useClock(2, '/hopfield/##[TYPE=PulseGen]', 'process')
         moose.useClock(2, '/hopfield/##[TYPE=SpikeGen]', 'process')
         moose.useClock(8, '/hopfield/##[TYPE=Table]', 'process') 
     else:
         print 'Clocks have not been assigned! - GUI does not support this format yet'
コード例 #4
0
def test_hhcomp():
    """Create and simulate a single spherical compartment with
    Hodgkin-Huxley Na and K channel.

    Plots Vm, injected current, channel conductances.

    """
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')    
    comp, na, k = create_hhcomp(parent=model.path)
    print comp.Rm, comp.Cm, na.Ek, na.Gbar, k.Ek, k.Gbar
    pg = moose.PulseGen('%s/pg' % (model.path))
    pg.firstDelay = 20e-3
    pg.firstWidth = 40e-3
    pg.firstLevel = 1e-9
    pg.secondDelay = 1e9
    moose.connect(pg, 'output', comp, 'injectMsg')
    inj = moose.Table('%s/pulse' % (data.path))
    moose.connect(inj, 'requestOut', pg, 'getOutputValue')
    vm = moose.Table('%s/Vm' % (data.path))
    moose.connect(vm, 'requestOut', comp, 'getVm')
    gK = moose.Table('%s/gK' % (data.path))
    moose.connect(gK, 'requestOut', k, 'getGk')
    gNa = moose.Table('%s/gNa' % (data.path))
    moose.connect(gNa, 'requestOut', na, 'getGk')
    simdt = 1e-6
    plotdt = 1e-4
    simtime = 100e-3
    if (1):
        moose.showmsg( '/clock' )
        for i in range(8):
            moose.setClock( i, simdt )
        moose.setClock( 8, plotdt )
        moose.reinit()
    else:
        utils.resetSim([model.path, data.path], simdt, plotdt, simmethod='ee')
        moose.showmsg( '/clock' )
    moose.start(simtime)
    t = np.linspace(0, simtime, len(vm.vector))
    plt.subplot(211)
    plt.plot(t, vm.vector * 1e3, label='Vm (mV)')
    plt.plot(t, inj.vector * 1e9, label='injected (nA)')
    plt.legend()
    plt.title('Vm')
    plt.subplot(212)
    plt.title('Conductance (uS)')
    plt.plot(t, gK.vector * 1e6, label='K')
    plt.plot(t, gNa.vector * 1e6, label='Na')
    plt.legend()
    plt.show()
    plt.close()
コード例 #5
0
ファイル: traub_naf.py プロジェクト: dilawar/moose-examples
def run_sim(model, data, simtime=100e-3, simdt=1e-6, plotdt=1e-4, solver='ee'):
    """Reset and run the simulation.

        model: model container element \n
        data: data container element \n
        simtime: simulation run time \n
        simdt: simulation timestep \n
        plotdt: plotting time step \n
        solver: neuronal solver to use \n

    """
    global inited
    if not inited:
        utils.resetSim([model.path, data.path], simdt, plotdt, simmethod=solver)
        inited = True
    else:
        moose.reinit()
    moose.start(simtime)
コード例 #6
0
ファイル: vclamptest.py プロジェクト: physicalist/moose
def vclamptest(compartment,
               vclamp,
               duration=50e-3,
               delay=150e-3,
               solver='ee',
               vhold=None,
               mc=None,
               dc=None,
               simdt=1e-5,
               plotdt=0.25e-3):
    """Do a series of voltage clamp experiemnts on compartment.

    parameters:
    
    compartment: Compartment object to be voltage clamped

    vclamp: array of clamping voltage values.

    duration: duration of each clamp

    delay: delay between successive application of clamping voltages

    vhold: holding voltage, If None, the Em of the
    compartment is used.

    mc: model container, the vclamp object will be created inside
    mc/electronics. If None, we use compartment.parent.parent

    dc: data container, the data recording tables will be created
    inside it. If None, we use compartment.parent.parent
    """
    if vhold is None:
        vhold = compartment.Em
    if mc is None:
        mc = compartment.parent.parent
    if dc is None:
        dc = compartment.parent.parent
    electronics = moose.Neutral('%s/electronics' % (mc.path))
    command = moose.PulseGen('%s/command_source' % (electronics.path))
    clamp = moose.VClamp('%s/vclamp' % (electronics.path))
    moose.connect(command, 'output', clamp, 'commandIn')
    moose.connect(compartment, 'VmOut', clamp, 'sensedIn')
    moose.connect(clamp, 'currentOut', compartment, 'injectMsg')
    simtime = 0
    command.count = len(vclamp)
    command.baseLevel = vhold
    for ii, clamping_voltage in enumerate(vclamp):
        simtime += delay + duration
        command.delay[ii] = delay
        command.width[ii] = duration
        command.level[ii] = clamping_voltage
    injected = moose.Table('%s/Iinject' % (dc.path))
    moose.connect(injected, 'requestData', clamp, 'getCurrent')
    voltage = moose.Table('%s/Vcommand' % (dc.path))
    moose.connect(voltage, 'requestData', command, 'getOutputValue')
    vm = moose.Table('%s/Vm' % (dc.path))
    moose.connect(vm, 'requestData', compartment, 'getVm')
    utils.resetSim([mc.path, dc.path], simdt, plotdt, simmethod=solver)
    moose.start(simtime)
    ivec = np.asarray(injected.vector)
    vvec = np.asarray(voltage.vector)
    vmvec = np.asarray(vm.vector)
    ts = np.linspace(0, simtime, len(vvec))
    sidx = np.nonzero(np.diff(vvec) > 0)[0]
    eidx = np.nonzero(np.diff(vvec) < 0)[0]
    iarrays = []
    for ii in range(len(vclamp)):
        iarrays.append(ivec[sidx[ii]:eidx[ii]].copy())
    return {
        "Vm": vmvec,
        "commandVoltage": vvec,
        "inject": ivec,
        "ts": ts,
        "injectArrays": iarrays
    }
コード例 #7
0
ファイル: vclamptest.py プロジェクト: dilawar/moose-examples
def vclamptest(compartment, vclamp, duration=50e-3, delay=150e-3, solver='ee', vhold=None, mc=None, dc=None, simdt=1e-5, plotdt=0.25e-3):
    """Do a series of voltage clamp experiemnts on compartment.

    parameters:
    
    compartment: Compartment object to be voltage clamped

    vclamp: array of clamping voltage values.

    duration: duration of each clamp

    delay: delay between successive application of clamping voltages

    vhold: holding voltage, If None, the Em of the
    compartment is used.

    mc: model container, the vclamp object will be created inside
    mc/electronics. If None, we use compartment.parent.parent

    dc: data container, the data recording tables will be created
    inside it. If None, we use compartment.parent.parent
    """
    if vhold is None:
        vhold = compartment.Em
    if mc is None:
        mc = compartment.parent.parent
    if dc is None:
        dc = compartment.parent.parent
    electronics = moose.Neutral('%s/electronics' % (mc.path))
    command = moose.PulseGen('%s/command_source' % (electronics.path))
    clamp = moose.VClamp('%s/vclamp' % (electronics.path))
    moose.connect(command, 'output', clamp, 'commandIn')
    moose.connect(compartment, 'VmOut', clamp, 'sensedIn')
    moose.connect(clamp, 'currentOut', compartment, 'injectMsg')
    simtime = 0
    command.count = len(vclamp)
    command.baseLevel = vhold
    for ii, clamping_voltage in enumerate(vclamp):
        simtime += delay + duration
        command.delay[ii] = delay
        command.width[ii] = duration
        command.level[ii] = clamping_voltage
    injected = moose.Table('%s/Iinject' % (dc.path))
    moose.connect(injected, 'requestOut', clamp, 'getCurrent')
    voltage = moose.Table('%s/Vcommand' % (dc.path))
    moose.connect(voltage, 'requestOut', command, 'getOutputValue')
    vm = moose.Table('%s/Vm' % (dc.path))
    moose.connect(vm, 'requestOut', compartment, 'getVm')
    utils.resetSim([mc.path, dc.path], simdt, plotdt, simmethod=solver)
    moose.start(simtime)
    ivec = np.asarray(injected.vector)
    vvec = np.asarray(voltage.vector)
    vmvec = np.asarray(vm.vector)
    ts = np.linspace(0, simtime, len(vvec))
    sidx = np.nonzero(np.diff(vvec) > 0)[0]
    eidx = np.nonzero(np.diff(vvec) < 0)[0]
    iarrays = []
    for ii in range(len(vclamp)):
        iarrays.append(ivec[sidx[ii]: eidx[ii]].copy())
    return {
        "Vm": vmvec,
        "commandVoltage": vvec,
        "inject": ivec,
        "ts": ts,
        "injectArrays": iarrays}