Ejemplo n.º 1
0
 def runsim(self, simtime, stepsize=0.1, pulsearray=None):
     """Run the simulation for `simtime`. Save the data at the
     end."""
     config.logger.info('running: simtime=%g, stepsize=%g, pulsearray=%s' %
                        (simtime, stepsize, str(pulsearray)))
     self.simtime = simtime
     if pulsearray is not None:
         self.tweak_stimulus(pulsearray)
     for ii in range(self.pulsegen.count):
         config.logger.info(
             'pulse[%d]: delay=%g, width=%g, level=%g' %
             (ii, self.pulsegen.delay[ii], self.pulsegen.width[ii],
              self.pulsegen.level[ii]))
     config.logger.info('Start reinit')
     self.schedule(self.simdt, self.plotdt, self.solver)
     moose.reinit()
     config.logger.info('Finished reinit')
     ts = datetime.now()
     mutils.stepRun(simtime,
                    simtime / 10.0,
                    verbose=True,
                    logger=config.logger)
     # The sleep is required to get all threads to end
     while moose.isRunning():
         time.sleep(0.1)
     te = datetime.now()
     td = te - ts
     config.logger.info('Simulation time of %g s at simdt=%g with solver %s: %g s' % \
         (simtime, self.simdt, self.solver,
          td.seconds + td.microseconds * 1e-6))
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def _runSlot(self):
     if moose.isRunning():
         print("Stopping simulation in progress ...")
         moose.stop()
     self._runtime = self.getFloatInput(self._runTimeEdit, self._runTimeLabel.text())
     self._overlayPlots(self._overlayAction.isChecked())
     self._simdt = self.getFloatInput(self._simTimeStepEdit, self._simTimeStepLabel.text())
     clampMode = None
     singlePulse = True
     if self._electronicsTab.currentWidget() == self._vClampCtrlBox:
         clampMode = "vclamp"
         baseLevel = self.getFloatInput(self._holdingVEdit, self._holdingVLabel.text())
         firstDelay = self.getFloatInput(self._holdingTimeEdit, self._holdingTimeLabel.text())
         firstWidth = self.getFloatInput(self._prePulseTimeEdit, self._prePulseTimeLabel.text())
         firstLevel = self.getFloatInput(self._prePulseVEdit, self._prePulseVLabel.text())
         secondDelay = firstWidth
         secondWidth = self.getFloatInput(self._clampTimeEdit, self._clampTimeLabel.text())
         secondLevel = self.getFloatInput(self._clampVEdit, self._clampVLabel.text())
         if not self._autoscaleAction.isChecked():
             self._im_axes.set_ylim(-10.0, 10.0)
     else:
         clampMode = "iclamp"
         baseLevel = self.getFloatInput(self._baseCurrentEdit, self._baseCurrentLabel.text())
         firstDelay = self.getFloatInput(self._firstDelayEdit, self._firstDelayLabel.text())
         firstWidth = self.getFloatInput(self._firstPulseWidthEdit, self._firstPulseWidthLabel.text())
         firstLevel = self.getFloatInput(self._firstPulseEdit, self._firstPulseLabel.text())
         secondDelay = self.getFloatInput(self._secondDelayEdit, self._secondDelayLabel.text())
         secondLevel = self.getFloatInput(self._secondPulseEdit, self._secondPulseLabel.text())
         secondWidth = self.getFloatInput(self._secondPulseWidthEdit, self._secondPulseWidthLabel.text())
         singlePulse = self._pulseMode.currentIndex() == 0
         if not self._autoscaleAction.isChecked():
             self._im_axes.set_ylim(-0.4, 0.4)
     self.squid_setup.clamp_ckt.configure_pulses(
         baseLevel=baseLevel,
         firstDelay=firstDelay,
         firstWidth=firstWidth,
         firstLevel=firstLevel,
         secondDelay=secondDelay,
         secondWidth=secondWidth,
         secondLevel=secondLevel,
         singlePulse=singlePulse,
     )
     if self._kConductanceToggle.isChecked():
         self.squid_setup.squid_axon.specific_gK = 0.0
     else:
         self.squid_setup.squid_axon.specific_gK = SquidAxon.defaults["specific_gK"]
     if self._naConductanceToggle.isChecked():
         self.squid_setup.squid_axon.specific_gNa = 0.0
     else:
         self.squid_setup.squid_axon.specific_gNa = SquidAxon.defaults["specific_gNa"]
     self.squid_setup.squid_axon.celsius = self.getFloatInput(self._temperatureEdit, self._temperatureLabel.text())
     self.squid_setup.squid_axon.K_out = self.getFloatInput(self._kOutEdit, self._kOutLabel.text())
     self.squid_setup.squid_axon.Na_out = self.getFloatInput(self._naOutEdit, self._naOutLabel.text())
     self.squid_setup.squid_axon.K_in = self.getFloatInput(self._kInEdit, self._kInLabel.text())
     self.squid_setup.squid_axon.Na_in = self.getFloatInput(self._naInEdit, self._naInLabel.text())
     self.squid_setup.squid_axon.updateEk()
     self.squid_setup.schedule(self._simdt, self._plotdt, clampMode)
     # The following line is for use with Qthread
     self.squid_setup.run(self._runtime)
     self._updateAllPlots()
Ejemplo n.º 4
0
 def _runSlot(self):
     if moose.isRunning():
         print('Stopping simulation in progress ...')
         moose.stop()
     self._runtime = self.getFloatInput(self._runTimeEdit, self._runTimeLabel.text())
     self._overlayPlots(self._overlayAction.isChecked())
     self._simdt = self.getFloatInput(self._simTimeStepEdit, self._simTimeStepLabel.text())
     clampMode = None
     singlePulse = True
     if self._electronicsTab.currentWidget() == self._vClampCtrlBox:
         clampMode = 'vclamp'
         baseLevel = self.getFloatInput(self._holdingVEdit, self._holdingVLabel.text())
         firstDelay = self.getFloatInput(self._holdingTimeEdit, self._holdingTimeLabel.text())
         firstWidth = self.getFloatInput(self._prePulseTimeEdit, self._prePulseTimeLabel.text())
         firstLevel = self.getFloatInput(self._prePulseVEdit, self._prePulseVLabel.text())
         secondDelay = firstWidth
         secondWidth = self.getFloatInput(self._clampTimeEdit, self._clampTimeLabel.text())
         secondLevel = self.getFloatInput(self._clampVEdit, self._clampVLabel.text())
         if not self._autoscaleAction.isChecked():
             self._im_axes.set_ylim(-10.0, 10.0)
     else:
         clampMode = 'iclamp'
         baseLevel = self.getFloatInput(self._baseCurrentEdit, self._baseCurrentLabel.text())
         firstDelay = self.getFloatInput(self._firstDelayEdit, self._firstDelayLabel.text())
         firstWidth = self.getFloatInput(self._firstPulseWidthEdit, self._firstPulseWidthLabel.text())
         firstLevel = self.getFloatInput(self._firstPulseEdit, self._firstPulseLabel.text())
         secondDelay = self.getFloatInput(self._secondDelayEdit, self._secondDelayLabel.text())
         secondLevel = self.getFloatInput(self._secondPulseEdit, self._secondPulseLabel.text())
         secondWidth = self.getFloatInput(self._secondPulseWidthEdit, self._secondPulseWidthLabel.text())
         singlePulse = (self._pulseMode.currentIndex() == 0)
         if not self._autoscaleAction.isChecked():
             self._im_axes.set_ylim(-0.4, 0.4)
     self.squid_setup.clamp_ckt.configure_pulses(baseLevel=baseLevel,
                                                 firstDelay=firstDelay,
                                                 firstWidth=firstWidth,
                                                 firstLevel=firstLevel,
                                                 secondDelay=secondDelay,
                                                 secondWidth=secondWidth,
                                                 secondLevel=secondLevel,
                                                 singlePulse=singlePulse)
     if self._kConductanceToggle.isChecked():
         self.squid_setup.squid_axon.specific_gK = 0.0
     else:
         self.squid_setup.squid_axon.specific_gK = SquidAxon.defaults['specific_gK']
     if self._naConductanceToggle.isChecked():
         self.squid_setup.squid_axon.specific_gNa = 0.0
     else:
         self.squid_setup.squid_axon.specific_gNa = SquidAxon.defaults['specific_gNa']
     self.squid_setup.squid_axon.celsius = self.getFloatInput(self._temperatureEdit, self._temperatureLabel.text())
     self.squid_setup.squid_axon.K_out = self.getFloatInput(self._kOutEdit, self._kOutLabel.text())
     self.squid_setup.squid_axon.Na_out = self.getFloatInput(self._naOutEdit, self._naOutLabel.text())
     self.squid_setup.squid_axon.K_in = self.getFloatInput(self._kInEdit, self._kInLabel.text())
     self.squid_setup.squid_axon.Na_in = self.getFloatInput(self._naInEdit, self._naInLabel.text())
     self.squid_setup.squid_axon.updateEk()
     self.squid_setup.schedule(self._simdt, self._plotdt, clampMode)
     # The following line is for use with Qthread
     self.squid_setup.run(self._runtime)
     self._updateAllPlots()
Ejemplo n.º 5
0
 def run(self):
     print((self.name, 'Starting run for', self.runtime, ' seconds'))
     moose.reinit()
     moose.start(self.runtime)
     while moose.isRunning():
         time.sleep(1.0)
         print((self.name, 'Table length', len(moose.Table('/tab').vector)))
     print((self.name, 'Finishing simulation'))
     worker_queue.put(self.name)
Ejemplo n.º 6
0
 def run(self, key):
     try:
         Vm = self.Vm_tables[key]
         u = self.u_tables[key]
     except KeyError as e:
         Vm = moose.Table(self.data_container.path + '/' + key + '_Vm')
         nrn = self.neurons[key]
         moose.connect(Vm, 'requestOut', nrn, 'getVm')
         utable = moose.Table(self.data_container.path + '/' + key + '_u')
         utable.connect('requestOut', self.neurons[key], 'getU')
         self.Vm_tables[key] = Vm
         self.u_tables[key] = utable
     try:
         Im = self.inject_tables[key]
     except KeyError as e:
         Im = moose.Table(
             self.data_container.path + '/' + key +
             '_inject')  # May be different for non-pulsegen sources.
         Im.connect('requestOut', self._get_neuron(key), 'getIm')
         self.inject_tables[key] = Im
     self.simtime = IzhikevichDemo.parameters[key][7] * 1e-3
     for obj in moose.wildcardFind('%s/##' % (self.model_container.path)):
         if obj not in self.scheduled:
             moose.useClock(0, obj.path, 'process')
             self.scheduled[obj] = True
     for obj in moose.wildcardFind('%s/##' % (self.data_container.path)):
         if obj not in self.scheduled:
             moose.useClock(2, obj.path, 'process')
             self.scheduled[obj] = True
     moose.reinit()
     moose.start(self.simtime)
     while moose.isRunning():
         time.sleep(100)
     time = linspace(0, IzhikevichDemo.parameters[key][7], len(Vm.vector))
     # DEBUG
     nrn = self._get_neuron(key)
     print(('a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g' %
            (nrn.a, nrn.b, nrn.c, nrn.d, nrn.initVm, nrn.initU)))
     #! DEBUG
     return (time, Vm, Im)
Ejemplo n.º 7
0
 def runsim(self, simtime, stepsize=0.1, pulsearray=None):
     """Run the simulation for `simtime`. Save the data at the
     end."""
     config.logger.info('running: simtime=%g, stepsize=%g, pulsearray=%s' % (simtime, stepsize, str(pulsearray)))
     self.simtime = simtime
     if pulsearray is not None:            
         self.tweak_stimulus(pulsearray)
     for ii in range(self.pulsegen.count):
         config.logger.info('pulse[%d]: delay=%g, width=%g, level=%g' % (ii, self.pulsegen.delay[ii], self.pulsegen.width[ii], self.pulsegen.level[ii]))
     config.logger.info('Start reinit')
     self.schedule(self.simdt, self.plotdt, self.solver)
     moose.reinit()
     config.logger.info('Finished reinit')
     ts = datetime.now()
     mutils.stepRun(simtime, simtime/10.0, verbose=True, logger=config.logger)
     # The sleep is required to get all threads to end 
     while moose.isRunning():
         time.sleep(0.1)
     te = datetime.now()
     td = te - ts
     config.logger.info('Simulation time of %g s at simdt=%g with solver %s: %g s' % \
         (simtime, self.simdt, self.solver, 
          td.seconds + td.microseconds * 1e-6))
Ejemplo n.º 8
0
 def run(self, key):
     try:
         Vm = self.Vm_tables[key]
         u = self.u_tables[key]
     except KeyError as e:
         Vm = moose.Table(self.data_container.path + '/' + key + '_Vm')
         nrn = self.neurons[key]
         moose.connect(Vm, 'requestOut', nrn, 'getVm')
         utable = moose.Table(self.data_container.path + '/' + key + '_u')
         utable.connect('requestOut', self.neurons[key], 'getU')
         self.Vm_tables[key] = Vm
         self.u_tables[key] = utable
     try:
         Im = self.inject_tables[key]
     except KeyError as e:
         Im = moose.Table(self.data_container.path + '/' + key + '_inject') # May be different for non-pulsegen sources.
         Im.connect('requestOut', self._get_neuron(key), 'getIm')
         self.inject_tables[key] = Im
     self.simtime = IzhikevichDemo.parameters[key][7] * 1e-3
     for obj in moose.wildcardFind('%s/##' % (self.model_container.path)):
         if obj not in self.scheduled:
             moose.useClock(0, obj.path, 'process')
             self.scheduled[obj] = True
     for obj in moose.wildcardFind('%s/##' % (self.data_container.path)):
         if obj not in self.scheduled:
             moose.useClock(2, obj.path, 'process')
             self.scheduled[obj] = True
     moose.reinit()
     moose.start(self.simtime)
     while moose.isRunning():
         time.sleep(100)
     time = linspace(0, IzhikevichDemo.parameters[key][7], len(Vm.vector))
     # DEBUG
     nrn = self._get_neuron(key)
     print(('a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g' % (nrn.a,nrn.b, nrn.c, nrn.d, nrn.initVm, nrn.initU)))
     #! DEBUG
     return (time, Vm, Im)
Ejemplo n.º 9
0
                self.data_container.path + "/" + key + "_inject"
            )  # May be different for non-pulsegen sources.
            Im.connect("requestOut", self._get_neuron(key), "getIm")
            self.inject_tables[key] = Im
        self.simtime = IzhikevichDemo.parameters[key][7] * 1e-3
        for obj in moose.wildcardFind("%s/##" % (self.model_container.path)):
            if obj not in self.scheduled:
                moose.useClock(0, obj.path, "process")
                self.scheduled[obj] = True
        for obj in moose.wildcardFind("%s/##" % (self.data_container.path)):
            if obj not in self.scheduled:
                moose.useClock(2, obj.path, "process")
                self.scheduled[obj] = True
        moose.reinit()
        moose.start(self.simtime)
        while moose.isRunning():
            time.sleep(100)
        time = linspace(0, IzhikevichDemo.parameters[key][7], len(Vm.vector))
        # DEBUG
        nrn = self._get_neuron(key)
        print "a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g" % (
            nrn.a,
            nrn.b,
            nrn.c,
            nrn.d,
            nrn.initVm,
            nrn.initU,
        )
        #! DEBUG
        return (time, Vm, Im)
Ejemplo n.º 10
0
        except KeyError, e:
            Im = moose.Table(self.data_container.path + '/' + key + '_inject') # May be different for non-pulsegen sources.
            Im.connect('requestOut', self._get_neuron(key), 'getIm')
            self.inject_tables[key] = Im
        self.simtime = IzhikevichDemo.parameters[key][7] * 1e-3
        for obj in moose.wildcardFind('%s/##' % (self.model_container.path)):
            if obj not in self.scheduled:
                moose.useClock(0, obj.path, 'process')
                self.scheduled[obj] = True
        for obj in moose.wildcardFind('%s/##' % (self.data_container.path)):
            if obj not in self.scheduled:
                moose.useClock(2, obj.path, 'process')
                self.scheduled[obj] = True
        moose.reinit()
        moose.start(self.simtime)
        while moose.isRunning():
            time.sleep(100)
        time = linspace(0, IzhikevichDemo.parameters[key][7], len(Vm.vector))
        # DEBUG
        nrn = self._get_neuron(key)
        print 'a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g' % (nrn.a,nrn.b, nrn.c, nrn.d, nrn.initVm, nrn.initU)
        #! DEBUG
        return (time, Vm, Im)


    def _get_neuron(self, key):
        try:
            params = IzhikevichDemo.parameters[key]
        except KeyError as e:
            print ' %s : Invalid neuron type. The valid types are:' % (key)
            for key in IzhikevichDemo.parameters: