Example #1
0
 def testVmSeriesPlot(self):
     utils.setDefaultDt(elecdt=simdt)
     utils.assignDefaultTicks(modelRoot=self.m2.path)
     utils.assignTicks({0:'%s/##[ISA=HSolve]' % (self.m1.path),
                        1: '%s/##[ISA=PulseGen]' % (self.m1.path),
                        7: '%s/##[ISA=VClamp]' % (self.m1.path)})
     moose.reinit()
     tick = moose.element('/clock/tick')
     for ii in range(10):
         field = 'proc%d' % (ii)
         print 'Connected to', field
         for n in tick.neighbours[field]:
             print '\t', n
     ts = datetime.now()
     moose.start(simtime)
     te = datetime.now()
     td = te - ts
     t1 = np.linspace(0, simtime, len(self.p1['somaVm'].vec))
     t2 = np.linspace(0, simtime, len(self.p2['somaVm'].vec))
     pylab.plot(t1, self.p1['somaVm'].vec, label='hsolve')
     pylab.plot(t2, self.p2['somaVm'].vec, label='euler')
     config.logger.info('Finished simulation of %g s with %d process threads in %g s' % (simtime, moose.NUMPTHREADS, td.seconds + 1e-6 * td.microseconds))
     hsolve_data_file = os.path.join(config.data_dir, 'hsolve_tcr_%s.csv' % (config.filename_suffix))
     eeuler_data_file = os.path.join(config.data_dir, 'ee_tcr_%s.csv' % (config.filename_suffix))        
     np.savetxt(hsolve_data_file, np.vstack((t1, self.p1['somaVm'].vec)).transpose())
     np.savetxt(eeuler_data_file, np.vstack((t2, self.p2['somaVm'].vec)).transpose())
     print 'Saved Exp Euler data in %s\nHSolve data in %s' % (hsolve_data_file, eeuler_data_file)
     pylab.legend()
     pylab.show()
Example #2
0
def run_sim_parallel(passive=True, solver='hsolve'):
    data_info_list = []
    model_info_list = []
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            experiment_name = 'expt_%d_%d' % (jj, ii)
            dinfo, minfo = setup_experiment(experiment_name, st, tonset, ti, passive=passive, solver=solver)
            data_info_list.append(dinfo)
            model_info_list.append(minfo)
    mutils.setDefaultDt(elecdt=simdt)
    mutils.assignDefaultTicks()
    moose.reinit()
    moose.start(tstop)
    print('$$$$$$$$$$$', moose.element('/clock'    ).currentTime)
    axes_vm = fig.add_subplot(111)
    # axes_vm_out = fig.add_subplot(121)
    # axes_vm_in = fig.add_subplot(122, sharex=axes_vm_out, sharey=axes_vm_out)
    ################
    # axes_vm = fig.add_subplot(311)
    # axes_nmda = fig.add_subplot(312)
    # axes_ampa = fig.add_subplot(313)
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            dinfo = data_info_list[jj * len(stim_order) + ii]
            print('Interval=', ti, 'Stim order=', st)
            print('dinfo:', dinfo)
            print(dinfo['soma_vm'])
            print(dinfo['soma_vm'].vector)
            v = dinfo['soma_vm'].vector
            t = np.linspace(0, tstop, len(v))
            print('num points=', len(t), 't0=', t[0], 't_last=', t[-1], 'v0=', v[0], 'v_last=', v[-1])
Example #3
0
def gapjunction_demo():
    model = moose.Neutral('model')
    data = moose.Neutral('data')
    comps = []
    comp1 = make_compartment('%s/comp1' % (model.path))
    comp2 = make_compartment('%s/comp2' % (model.path))
    pulse = moose.PulseGen('%s/pulse' % (model.path))
    pulse.level[0] = 1e-9
    pulse.delay[0] = 50e-3
    pulse.width[0] = 20e-3
    pulse.delay[1] = 1e9
    moose.connect(pulse, 'output', comp1, 'injectMsg')
    gj = moose.GapJunction('%s/gj' % (model.path))
    gj.Gk = 1e-6
    moose.connect(gj, 'channel1', comp1, 'channel')
    moose.connect(gj, 'channel2', comp2, 'channel')
    vm1_tab = moose.Table('%s/Vm1' % (data.path))
    moose.connect(vm1_tab, 'requestOut', comp1, 'getVm')
    vm2_tab = moose.Table('%s/Vm2' % (data.path))
    moose.connect(vm2_tab, 'requestOut', comp2, 'getVm')
    pulse_tab = moose.Table('%s/inject' % (data.path))
    moose.connect(pulse_tab, 'requestOut', pulse, 'getOutputValue')
    utils.setDefaultDt(elecdt=simdt, plotdt2=simdt)
    utils.assignDefaultTicks()
    utils.stepRun(simtime, 10000*simdt)
    # print len(vm1_tab.vector), len(vm2_tab.vector), len(pulse_tab.vector)
    # moose.showmsg(comp1)
    # moose.showmsg(comp2)
    # moose.showmsg(pulse)
    t = pylab.linspace(0, simtime, len(vm1_tab.vector))
    pylab.plot(t, vm1_tab.vector*1000, label='Vm1 (mV)')
    pylab.plot(t, vm2_tab.vector*1000, label='Vm2 (mV)')
    pylab.plot(t, pulse_tab.vector*1e9, label='inject (nA)')
    pylab.legend()
    pylab.show()
Example #4
0
def main():
    """
    This shows the use of SynChan with Izhikevich neuron. This can be
    used for creating a network of Izhikevich neurons.
    """
    
    simtime = 200.0
    stepsize = 10.0
    model_dict = make_model()
    vm, inject, gk, spike = setup_data_recording(model_dict['neuron'],
                                          model_dict['pulse'],
                                          model_dict['synapse'],
                                          model_dict['spike_in'])
    mutils.setDefaultDt(elecdt=0.01, plotdt2=0.25)
    mutils.assignDefaultTicks(solver='ee')
    moose.reinit()
    mutils.stepRun(simtime, stepsize)
    pylab.subplot(411)
    pylab.plot(pylab.linspace(0, simtime, len(vm.vector)), vm.vector, label='Vm (mV)')
    pylab.legend()
    pylab.subplot(412)
    pylab.plot(pylab.linspace(0, simtime, len(inject.vector)), inject.vector, label='Inject (uA)')
    pylab.legend()
    pylab.subplot(413)
    pylab.plot(spike.vector, pylab.ones(len(spike.vector)), '|', label='input spike times')
    pylab.legend()
    pylab.subplot(414)
    pylab.plot(pylab.linspace(0, simtime, len(gk.vector)), gk.vector, label='Gk (mS)')
    pylab.legend()
    pylab.show()
def main():
    """
    This shows the use of SynChan with Izhikevich neuron. This can be
    used for creating a network of Izhikevich neurons.
    """
    
    simtime = 200.0
    stepsize = 10.0
    model_dict = make_model()
    vm, inject, gk, spike = setup_data_recording(model_dict['neuron'],
                                          model_dict['pulse'],
                                          model_dict['synapse'],
                                          model_dict['spike_in'])
    mutils.setDefaultDt(elecdt=0.01, plotdt2=0.25)
    mutils.assignDefaultTicks(solver='ee')
    moose.reinit()
    mutils.stepRun(simtime, stepsize)
    pylab.subplot(411)
    pylab.plot(pylab.linspace(0, simtime, len(vm.vector)), vm.vector, label='Vm (mV)')
    pylab.legend()
    pylab.subplot(412)
    pylab.plot(pylab.linspace(0, simtime, len(inject.vector)), inject.vector, label='Inject (uA)')
    pylab.legend()
    pylab.subplot(413)
    pylab.plot(spike.vector, pylab.ones(len(spike.vector)), '|', label='input spike times')
    pylab.legend()
    pylab.subplot(414)
    pylab.plot(pylab.linspace(0, simtime, len(gk.vector)), gk.vector, label='Gk (mS)')
    pylab.legend()
    pylab.show()
Example #6
0
def main():
    """
    This is an example of how you can create a Leaky Integrate and Fire
    compartment using regular compartment and Func to check for thresold
    crossing and resetting the Vm.
    """
    tables = setup_two_cells()

    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    data = []
    for tab in tables:
        data.append(tab.vector)
    data = np.vstack(data)

    # Travis fix for Ubuntu-12.04
    try:
        np.savetxt('lifcomp.csv',
                   data.transpose(),
                   delimiter='\t',
                   header=' '.join([tab.name for tab in tables]))
    except TypeError as e:  # old numpy may not have header.
        np.savetxt('lifcomp.csv', data.transpose(), delimiter='\t')
Example #7
0
 def simulateSelected(self):
     cellnames = [str(c.text()) for c in self.cellListWidget.selectedItems()]
     assert(len(cellnames) == 1)        
     name = cellnames[0]
     params = self.createCell(name)
     # print 'Here ......'
     # hsolve = moose.HSolve('%s/solver' % (params['cell'].path))
     # hsolve.dt = simdt
     # hsolve.target = params['cell'].path
     mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
     mutils.assignDefaultTicks(modelRoot=params['modelRoot'],
                               dataRoot=params['dataRoot'],
                               solver='hsolve')
     delay = float(str(self.delayText.text())) * 1e-3
     width =  float(str(self.widthText.text())) * 1e-3
     levelMin =  float(str(self.ampMinText.text())) * 1e-12
     levelMax =  float(str(self.ampMaxText.text())) * 1e-12
     levelStep =  float(str(self.ampStepText.text())) * 1e-12
     params['stimulus'].delay[0] = delay 
     params['stimulus'].width[0] = width 
     params['stimulus'].level[0] = levelMin
     simtime = float(str(self.simtimeEdit.text()))*1e-3
     tdlist = []
     self.vmAxes.clear()       
     self.vmAxes.set_title('membrane potential at soma')
     self.vmAxes.set_ylabel('mV')            
     self.vmAxes.get_xaxis().set_visible(False)
     self.stimAxes.clear()
     self.stimAxes.set_title('current injected at soma')
     self.stimAxes.set_ylabel('pA')
     self.stimAxes.set_xlabel('ms')
     styles = ['-', '--', '-.', ':']
     cnt = int((levelMax - levelMin)/levelStep)
     ii = 0
     while params['stimulus'].level[0] < levelMax:
         tstart = datetime.now()
         moose.reinit()
         moose.start(simtime)
         tend = datetime.now()
         td = tend - tstart
         tdlist.append(td.days * 86400 + td.seconds + td.microseconds * 1e-6)
         ts = np.linspace(0, simtime, len(params['somaVm'].vector))
         vm = params['somaVm'].vector
         stim = params['injectionCurrent'].vector
         alpha = 0.1 + 0.9 * params['stimulus'].level[0] / levelMax
         color = cmap(ii*1.0/cnt, cnt)
         self.vmAxes.plot(ts * 1e3, vm * 1e3, color=color, label='%g pA' % (params['stimulus'].level[0]*1e12), alpha=0.8)
         self.stimAxes.plot(ts * 1e3, stim * 1e12, color=color, label='Current (pA)')
         self.plotCanvas.draw()
         params['stimulus'].level[0] += levelStep
         ii += 1
     self.gs.tight_layout(self.plotFigure)
     self.vmAxes.legend()
     self.plotCanvas.draw()
     td = np.mean(tdlist)
     print 'Simulating %g s took %g s of computer time' % (simtime, td)
Example #8
0
 def simulateSelected(self):
     cellnames = [str(c.text()) for c in self.cellListWidget.selectedItems()]
     assert(len(cellnames) == 1)        
     name = cellnames[0]
     params = self.createCell(name)
     # hsolve = moose.HSolve('%s/solver' % (params['cell'].path))
     # hsolve.dt = simdt
     # hsolve.target = params['cell'].path
     mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
     mutils.assignDefaultTicks(modelRoot=params['modelRoot'],
                               dataRoot=params['dataRoot'],
                               solver='hsolve')
     delay = float(str(self.delayText.text())) * 1e-3
     width =  float(str(self.widthText.text())) * 1e-3
     levelMin =  float(str(self.ampMinText.text())) * 1e-12
     levelMax =  float(str(self.ampMaxText.text())) * 1e-12
     levelStep =  float(str(self.ampStepText.text())) * 1e-12
     params['stimulus'].delay[0] = delay 
     params['stimulus'].width[0] = width 
     params['stimulus'].level[0] = levelMin
     simtime = float(str(self.simtimeEdit.text()))*1e-3
     tdlist = []
     self.vmAxes.clear()       
     self.vmAxes.set_title('membrane potential at soma')
     self.vmAxes.set_ylabel('mV')            
     self.vmAxes.get_xaxis().set_visible(False)
     self.stimAxes.clear()
     self.stimAxes.set_title('current injected at soma')
     self.stimAxes.set_ylabel('pA')
     self.stimAxes.set_xlabel('ms')
     styles = ['-', '--', '-.', ':']
     cnt = int((levelMax - levelMin)/levelStep)
     ii = 0
     while params['stimulus'].level[0] < levelMax:
         tstart = datetime.now()
         moose.reinit()
         moose.start(simtime)
         tend = datetime.now()
         td = tend - tstart
         tdlist.append(td.days * 86400 + td.seconds + td.microseconds * 1e-6)
         ts = np.linspace(0, simtime, len(params['somaVm'].vector))
         vm = params['somaVm'].vector
         stim = params['injectionCurrent'].vector
         alpha = 0.1 + 0.9 * params['stimulus'].level[0] / levelMax
         color = cmap(ii*1.0/cnt, cnt)
         self.vmAxes.plot(ts * 1e3, vm * 1e3, color=color, label='%g pA' % (params['stimulus'].level[0]*1e12), alpha=0.8)
         self.stimAxes.plot(ts * 1e3, stim * 1e12, color=color, label='Current (pA)')
         self.plotCanvas.draw()
         params['stimulus'].level[0] += levelStep
         ii += 1
     self.gs.tight_layout(self.plotFigure)
     self.vmAxes.legend()
     self.plotCanvas.draw()
     td = np.mean(tdlist)
     print(('Simulating %g s took %g s of computer time' % (simtime, td)))
Example #9
0
def run_sim_parallel(passive=True, solver='hsolve'):
    data_info_list = []
    model_info_list = []
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            experiment_name = 'expt_%d_%d' % (jj, ii)
            dinfo, minfo = setup_experiment(experiment_name, st, tonset, ti, passive=passive, solver=solver)
            data_info_list.append(dinfo)
            model_info_list.append(minfo)
    mutils.setDefaultDt(elecdt=simdt)
    mutils.assignDefaultTicks()
    moose.reinit()
    moose.start(tstop)
    print '$$$$$$$$$$$', moose.element('/clock'    ).currentTime  
    fig = plt.figure()
    axes_vm = fig.add_subplot(111)
    # axes_vm_out = fig.add_subplot(121)
    # axes_vm_in = fig.add_subplot(122, sharex=axes_vm_out, sharey=axes_vm_out)
    ################
    # axes_vm = fig.add_subplot(311)
    # axes_nmda = fig.add_subplot(312)
    # axes_ampa = fig.add_subplot(313)
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            dinfo = data_info_list[jj * len(stim_order) + ii]
            print 'Interval=', ti, 'Stim order=', st
            print 'dinfo:', dinfo
            print dinfo['soma_vm']
            print dinfo['soma_vm'].vector
            v = dinfo['soma_vm'].vector
            t = np.linspace(0, tstop, len(v))
            print 'num points=', len(t), 't0=', t[0], 't_last=', t[-1], 'v0=', v[0], 'v_last=', v[-1]
            axes_vm.plot(t, v)
            # if ii % 2 == 0:
            #     axes_vm_in.plot(t,
            #                     v,
            #                     color=color[ii])
            # else:
            #     axes_vm_out.plot(t,
            #                      v,
            #                      color=color[ii])
            # for tab in dinfo['nmda_gk']:
            #     axes_nmda.plot(np.linspace(0, tstop, len(tab.vector)),
            #                    tab.vector, color=color[ii])
            # # axes_nmda.legend()
            # for tab in dinfo['ampa_gk']:
            #     axes_ampa.plot(np.linspace(0, tstop, len(tab.vector)),
            #                    tab.vector, label='%s/%s' % (dinfo['data'].name, tab.name), color=color[ii])
    # axes_vm.legend([plt.Line2D([0], [0], color=color[ii]) for ii in range(len(stim_order))],
    #                [str(st) for st in stim_order])
    #axes_vm.legend()
    #axes_nmda.legend()
    #axes_ampa.legend()
    plt.show()
Example #10
0
def run_sim_parallel(passive=True, solver='hsolve'):
    data_info_list = []
    model_info_list = []
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            experiment_name = 'expt_%d_%d' % (jj, ii)
            dinfo, minfo = setup_experiment(experiment_name, st, tonset, ti, passive=passive, solver=solver)
            data_info_list.append(dinfo)
            model_info_list.append(minfo)
    mutils.setDefaultDt(elecdt=simdt)
    mutils.assignDefaultTicks()
    moose.reinit()
    moose.start(tstop)
    print('$$$$$$$$$$$', moose.element('/clock'    ).currentTime)
    fig = plt.figure()
    axes_vm = fig.add_subplot(111)
    # axes_vm_out = fig.add_subplot(121)
    # axes_vm_in = fig.add_subplot(122, sharex=axes_vm_out, sharey=axes_vm_out)
    ################
    # axes_vm = fig.add_subplot(311)
    # axes_nmda = fig.add_subplot(312)
    # axes_ampa = fig.add_subplot(313)
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            dinfo = data_info_list[jj * len(stim_order) + ii]
            print('Interval=', ti, 'Stim order=', st)
            print('dinfo:', dinfo)
            print(dinfo['soma_vm'])
            print(dinfo['soma_vm'].vector)
            v = dinfo['soma_vm'].vector
            t = np.linspace(0, tstop, len(v))
            print('num points=', len(t), 't0=', t[0], 't_last=', t[-1], 'v0=', v[0], 'v_last=', v[-1])
            axes_vm.plot(t, v)
            # if ii % 2 == 0:
            #     axes_vm_in.plot(t,
            #                     v,
            #                     color=color[ii])
            # else:
            #     axes_vm_out.plot(t,
            #                      v,
            #                      color=color[ii])
            # for tab in dinfo['nmda_gk']:
            #     axes_nmda.plot(np.linspace(0, tstop, len(tab.vector)),
            #                    tab.vector, color=color[ii])
            # # axes_nmda.legend()
            # for tab in dinfo['ampa_gk']:
            #     axes_ampa.plot(np.linspace(0, tstop, len(tab.vector)),
            #                    tab.vector, label='%s/%s' % (dinfo['data'].name, tab.name), color=color[ii])
    # axes_vm.legend([plt.Line2D([0], [0], color=color[ii]) for ii in range(len(stim_order))],
    #                [str(st) for st in stim_order])
    #axes_vm.legend()
    #axes_nmda.legend()
    #axes_ampa.legend()
    plt.show()
Example #11
0
 def schedule(self, simdt, plotdt, solver):
     config.logger.info('Scheduling: simdt=%g, plotdt=%g, solver=%s' % (simdt, plotdt, solver))
     self.simdt = simdt
     self.plotdt = plotdt
     self.solver = solver
     if self.solver == 'hsolve':
         self.hsolve = moose.HSolve('%s/solver' % (self.cell.path))
         self.hsolve.dt = simdt
         self.hsolve.target = self.cell.path
     mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
     mutils.assignDefaultTicks(modelRoot=self.model_container.path, 
                              dataRoot=self.data_container.path, 
                              solver=self.solver)        
Example #12
0
 def schedule(self, simdt, plotdt, solver):
     config.logger.info('Scheduling: simdt=%g, plotdt=%g, solver=%s' % (simdt, plotdt, solver))
     self.simdt = simdt
     self.plotdt = plotdt
     self.solver = solver
     if self.solver == 'hsolve':
         self.hsolve = moose.HSolve('%s/solver' % (self.cell.path))
         self.hsolve.dt = simdt
         self.hsolve.target = self.cell.path
     mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
     mutils.assignDefaultTicks(modelRoot=self.model_container.path, 
                              dataRoot=self.data_container.path, 
                              solver=self.solver)        
Example #13
0
def run_model():
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    cell = TuftedIB('/model/TuftedIB')
    stim = alpha_stimulus('/model/stim', 1.0e-9, 15e-3, 20e-3, simtime, simdt)
    stim.startTime = 1e9
    p1 = cell.path + '/' + d1
    p2 = cell.path + '/' + d2
    comp_d1 = moose.element(p1) if moose.exists(p1) else moose.Compartment(p1)
    comp_d2 = moose.element(p2) if moose.exists(p2) else moose.Compartment(p2)
    s = '%s/%s' % (cell.path, 'comp_1')
    comp_soma = moose.element(s) if moose.exists(s) else moose.Compartment(s)
    comp_soma.inject = -0.2e-9
    moose.connect(stim, 'output', comp_d1, 'injectMsg')
    tab_d1 = moose.Table('%s/d1_Vm' % (data.path))
    tab_d2 = moose.Table('%s/d2_Vm' % (data.path))
    tab_soma = moose.Table('%s/soma_Vm' % (data.path))
    tab_stim = moose.Table('%s/stim' % (data.path))
    moose.connect(tab_d1, 'requestOut', comp_d1, 'getVm')
    moose.connect(tab_d2, 'requestOut', comp_d2, 'getVm')
    moose.connect(tab_soma, 'requestOut', comp_soma, 'getVm')
    moose.connect(stim, 'output', tab_stim, 'input')
    solver = moose.HSolve('%s/solver' % (cell.path))
    solver.dt = simdt
    solver.target = cell.path
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks()
    moose.reinit()
    utils.stepRun(simtime, 1e5 * simdt, logger=config.logger)
    pylab.subplot(211)
    pylab.plot(np.linspace(0, simtime, len(tab_d1.vector)),
               tab_d1.vector * 1e3,
               label='D1 Vm (mV)')
    pylab.plot(np.linspace(0, simtime, len(tab_d2.vector)),
               tab_d2.vector * 1e3,
               label='D2 Vm (mV)')
    pylab.plot(np.linspace(0, simtime, len(tab_soma.vector)),
               tab_soma.vector * 1e3,
               label='SOMA Vm (mV)')
    pylab.legend()
    pylab.subplot(212)
    pylab.plot(np.linspace(0, simtime, len(tab_stim.vector)),
               tab_stim.vector * 1e9,
               label='Stimulus (nA)')
    pylab.legend()
    pylab.savefig('fig_a4c.png')
    pylab.show()
Example #14
0
def run_current_pulse(amps,
                      delay=100e-3,
                      dur=100e-3,
                      trail=100e-3,
                      outfile='f_i_curves_data.h5'):
    models = []
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    ddict = defaultdict(list)
    for ii, amp in enumerate(amps):
        mc = moose.Neutral('{}/mc_{}'.format(model.path, ii))
        models.append(mc)
        stim = moose.PulseGen('{}/stim_{}'.format(mc.path, ii))
        stim.delay[0] = delay
        stim.width[0] = dur
        stim.level[0] = amp
        stim.delay[
            1] = 1e9  # make delay so large that it does not activate again
        for celltype in [SpinyStellate, DeepBasket, DeepLTS]:
            cell = celltype('{}/{}_{}'.format(mc.path, celltype.__name__, ii))
            solver = moose.HSolve('{}/solver'.format(cell.path))
            solver.dt = simdt
            solver.target = cell.path
            stim.connect('output', cell.soma, 'injectMsg')
            tab = moose.Table('/data/Vm_{}'.format(cell.name))
            ddict[ii].append(tab)
            tab.connect('requestOut', cell.soma, 'getVm')
    mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    mutils.assignDefaultTicks(modelRoot='/model',
                              dataRoot='/data',
                              solver='hsolve')
    moose.reinit()
    print('Finished scheduling')
    moose.start(delay + dur + trail)
    print('Finished simulation')
    # Save data
    fd = h5.File(outfile, 'w')
    for ii, tabs in ddict.items():
        for tab in tabs:
            print('Table', tab.name)
            node = fd.create_dataset(tab.name, data=tab.vector)
            node.attrs['current'] = amps[ii]
            node.attrs['delay'] = delay
            node.attrs['width'] = dur
    fd.close()
    print('Finished saving data in file', outfile)
Example #15
0
def main():
    """
    This is an example of how you can create a Leaky Integrate and Fire
    compartment using regular compartment and Func to check for thresold
    crossing and resetting the Vm.
    """
    tables = setup_two_cells()

    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    for ii, tab in enumerate(tables):
        subplot(len(tables), 1, ii + 1)
        t = np.linspace(0, simtime, len(tab.vector)) * 1e3
        plot(t, tab.vector * 1e3, label=tab.name)
        legend()
    show()
Example #16
0
def main():
    """
    This is an example of how you can create a Leaky Integrate and Fire
    compartment using regular compartment and Func to check for thresold
    crossing and resetting the Vm.
    """
    tables = setup_two_cells()

    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    for ii, tab in enumerate(tables):
        subplot(len(tables), 1, ii+1)
        t = np.linspace(0, simtime, len(tab.vector))*1e3
        plot(t, tab.vector*1e3, label=tab.name)
        legend()
    show()
Example #17
0
def setup_model(root='/', hsolve=True):
    moose.ce(root)
    model = moose.Neutral('model')
    data = moose.Neutral('data')
    cell = DeepBasket('%s/deepbasket' % (model.path))
    soma = moose.Compartment('%s/comp_1' % (cell.path))
    if hsolve:
        solver = moose.HSolve('%s/solve' % (cell.path))
        solver.dt = simdt
        solver.target = cell.path
    pulse = moose.PulseGen('%s/stimulus' % (model.path))
    moose.connect(pulse, 'output', soma, 'injectMsg')
    tab_vm = moose.Table('%s/spinystellate_soma_Vm' % (data.path))
    moose.connect(tab_vm, 'requestOut', soma, 'getVm')
    tab_stim = moose.Table('%s/spinystellate_soma_inject' % (data.path))
    moose.connect(tab_stim, 'requestOut', pulse, 'getOutputValue')
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(model, data)
    return {'stimulus': pulse, 'tab_vm': tab_vm, 'tab_stim': tab_stim}
Example #18
0
def setup_model(root="/", hsolve=True):
    moose.ce(root)
    model = moose.Neutral("model")
    data = moose.Neutral("data")
    cell = DeepBasket("%s/deepbasket" % (model.path))
    soma = moose.Compartment("%s/comp_1" % (cell.path))
    if hsolve:
        solver = moose.HSolve("%s/solve" % (cell.path))
        solver.dt = simdt
        solver.target = cell.path
    pulse = moose.PulseGen("%s/stimulus" % (model.path))
    moose.connect(pulse, "output", soma, "injectMsg")
    tab_vm = moose.Table("%s/spinystellate_soma_Vm" % (data.path))
    moose.connect(tab_vm, "requestOut", soma, "getVm")
    tab_stim = moose.Table("%s/spinystellate_soma_inject" % (data.path))
    moose.connect(tab_stim, "requestOut", pulse, "getOutputValue")
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(model, data)
    return {"stimulus": pulse, "tab_vm": tab_vm, "tab_stim": tab_stim}
Example #19
0
 def simulateSelected(self):
     cellnames = [str(c.text()) for c in self.cellListWidget.selectedItems()]
     assert(len(cellnames) == 1)        
     name = cellnames[0]
     params = self.createCell(name)
     print 'Here ......'
     hsolve = moose.HSolve('%s/solver' % (params['cell'].path))
     hsolve.dt = simdt
     hsolve.target = params['cell'].path
     mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
     mutils.assignDefaultTicks(modelRoot=params['modelRoot'],
                               dataRoot=params['dataRoot'],
                               solver='hsolve')
     delay = float(str(self.delayText.text()))
     width =  float(str(self.widthText.text()))
     level =  float(str(self.ampText.text()))
     params['stimulus'].delay[0] = delay * 1e-3
     params['stimulus'].width[0] = width * 1e-3
     params['stimulus'].level[0] = level * 1e-12
     moose.reinit()
     simtime = float(str(self.simtimeEdit.text()))*1e-3
     ts = datetime.now()
     moose.start(simtime)
     te = datetime.now()
     td = te - ts
     print 'Simulating %g s took %g s of computer time' % (simtime, td.days * 86400 + td.seconds + td.microseconds * 1e-6)
     ts = np.linspace(0, simtime, len(params['somaVm'].vec))
     vm = params['somaVm'].vec
     stim = params['injectionCurrent'].vec
     self.vmAxes.clear()       
     self.vmAxes.set_title('membrane potential at soma')
     self.vmAxes.set_ylabel('mV')            
     self.vmAxes.plot(ts * 1e3, vm * 1e3, 'b-', label='Vm (mV)')
     self.vmAxes.get_xaxis().set_visible(False)
     self.stimAxes.clear()
     self.stimAxes.set_title('current injected at soma')
     self.stimAxes.set_ylabel('pA')
     self.stimAxes.set_xlabel('ms')
     self.stimAxes.plot(ts * 1e3, stim * 1e12, 'r-', label='Current (pA)')
     self.gs.tight_layout(self.plotFigure)
     # self.plotFigure.tight_layout()
     self.plotCanvas.draw()
Example #20
0
def setup_model(root='/', hsolve=True):
    moose.ce(root)
    model = moose.Neutral('model')
    data = moose.Neutral('data')
    cell = SpinyStellate('%s/spinystellate' % (model.path))
    soma = moose.Compartment('%s/comp_1' % (cell.path))
    if hsolve:
        solver = moose.HSolve('%s/solve' % (cell.path))
        solver.dt = simdt
        solver.target = cell.path
    pulse = moose.PulseGen('%s/stimulus' % (model.path))
    moose.connect(pulse, 'output', soma, 'injectMsg')
    tab_vm = moose.Table('%s/spinystellate_soma_Vm' % (data.path))
    moose.connect(tab_vm, 'requestOut', soma, 'getVm')
    tab_stim = moose.Table('%s/spinystellate_soma_inject' % (data.path))
    moose.connect(tab_stim, 'requestOut', pulse, 'getOutputValue')
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(model, data)
    return {'stimulus': pulse,
            'tab_vm': tab_vm,
            'tab_stim': tab_stim}
Example #21
0
def run_current_pulse(amps, delay=100e-3, dur=100e-3, trail=100e-3, outfile='f_i_curves_data.h5'):
    models = []
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    ddict = defaultdict(list)
    for ii, amp in enumerate(amps):
        mc = moose.Neutral('{}/mc_{}'.format(model.path, ii))
        models.append(mc)
        stim = moose.PulseGen('{}/stim_{}'.format(mc.path, ii))
        stim.delay[0] = delay
        stim.width[0] = dur
        stim.level[0] = amp
        stim.delay[1] = 1e9 # make delay so large that it does not activate again
        for celltype in [SpinyStellate, DeepBasket, DeepLTS]:
            cell = celltype('{}/{}_{}'.format(mc.path, celltype.__name__, ii))
            solver = moose.element('{}/solver'.format(cell.path))
            solver.dt = simdt
            solver.target = cell.path
            stim.connect('output', cell.soma, 'injectMsg')
            tab = moose.Table('/data/Vm_{}'.format(cell.name))
            ddict[ii].append(tab)
            tab.connect('requestOut', cell.soma, 'getVm')
    mutils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    mutils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='hsolve')
    moose.reinit()
    print('Finished scheduling')
    moose.start(delay + dur + trail)
    print('Finished simulation')
    # Save data
    fd = h5.File(outfile, 'w')    
    for ii, tabs in list(ddict.items()):
        for tab in tabs:
            print(('Table', tab.name))
            node = fd.create_dataset(tab.name, data=tab.vector)
            node.attrs['current'] = amps[ii]
            node.attrs['delay'] = delay
            node.attrs['width'] = dur
    fd.close()
    print(('Finished saving data in file', outfile))
Example #22
0
def main():
    """
    This is an example of how you can create a Leaky Integrate and Fire
    compartment using regular compartment and Func to check for thresold
    crossing and resetting the Vm.
    """
    tables = setup_two_cells()

    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    data = []
    for tab in tables:
        data.append(tab.vector)
    data = np.vstack(data)

    # Travis fix for Ubuntu-12.04
    try:
        np.savetxt('lifcomp.csv', data.transpose(), delimiter='\t', header=' '.join([tab.name for tab in tables]))
    except TypeError as e:  # old numpy may not have header.
        np.savetxt('lifcomp.csv', data.transpose(), delimiter='\t' )
Example #23
0
def run_sim_parallel(passive=True, solver='hsolve'):
    data_info_list = []
    model_info_list = []
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            experiment_name = 'expt_%d_%d' % (jj, ii)
            dinfo, minfo = setup_experiment(experiment_name,
                                            st,
                                            tonset,
                                            ti,
                                            passive=passive,
                                            solver=solver)
            data_info_list.append(dinfo)
            model_info_list.append(minfo)
    mutils.setDefaultDt(elecdt=simdt)
    mutils.assignDefaultTicks()
    moose.reinit()
    moose.start(tstop)
    print('$$$$$$$$$$$', moose.element('/clock').currentTime)
    axes_vm = fig.add_subplot(111)
    # axes_vm_out = fig.add_subplot(121)
    # axes_vm_in = fig.add_subplot(122, sharex=axes_vm_out, sharey=axes_vm_out)
    ################
    # axes_vm = fig.add_subplot(311)
    # axes_nmda = fig.add_subplot(312)
    # axes_ampa = fig.add_subplot(313)
    for jj, ti in enumerate(intervals):
        for ii, st in enumerate(stim_order):
            dinfo = data_info_list[jj * len(stim_order) + ii]
            print('Interval=', ti, 'Stim order=', st)
            print('dinfo:', dinfo)
            print(dinfo['soma_vm'])
            print(dinfo['soma_vm'].vector)
            v = dinfo['soma_vm'].vector
            t = np.linspace(0, tstop, len(v))
            print('num points=', len(t), 't0=', t[0], 't_last=', t[-1], 'v0=',
                  v[0], 'v_last=', v[-1])
def run_model():
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    cell = TuftedIB('/model/TuftedIB')
    stim = alpha_stimulus('/model/stim', 1.0e-9, 15e-3, 20e-3, simtime, simdt)
    stim.startTime = 1e9
    comp_d1 = moose.element('%s/%s' % (cell.path, d1))
    comp_d2 = moose.element('%s/%s' % (cell.path, d2))
    comp_soma = moose.element('%s/%s' % (cell.path, 'comp_1'))
    comp_soma.inject = -0.2e-9
    moose.connect(stim, 'output', comp_d1, 'injectMsg')
    tab_d1 = moose.Table('%s/d1_Vm' % (data.path))
    tab_d2 = moose.Table('%s/d2_Vm' % (data.path))
    tab_soma = moose.Table('%s/soma_Vm' % (data.path))
    tab_stim = moose.Table('%s/stim' % (data.path))
    moose.connect(tab_d1, 'requestData', comp_d1, 'get_Vm')
    moose.connect(tab_d2, 'requestData', comp_d2, 'get_Vm')
    moose.connect(tab_soma, 'requestData', comp_soma, 'get_Vm')
    moose.connect(stim, 'output', tab_stim, 'input')
    solver = moose.HSolve('%s/solver' % (cell.path))
    solver.dt = simdt
    solver.target = cell.path
    utils.setDefaultDt(elecdt=simdt,plotdt2=plotdt)
    utils.assignDefaultTicks()
    moose.reinit()
    utils.stepRun(simtime, 1e5*simdt, logger=config.logger)
    pylab.subplot(211)
    pylab.plot(np.linspace(0, simtime, len(tab_d1.vec)), tab_d1.vec * 1e3, label='D1 Vm (mV)')
    pylab.plot(np.linspace(0, simtime, len(tab_d2.vec)), tab_d2.vec * 1e3, label='D2 Vm (mV)')
    pylab.plot(np.linspace(0, simtime, len(tab_soma.vec)), tab_soma.vec * 1e3, label='SOMA Vm (mV)')
    pylab.legend()
    pylab.subplot(212)
    pylab.plot(np.linspace(0, simtime, len(tab_stim.vec)), tab_stim.vec * 1e9, label='Stimulus (nA)')
    pylab.legend()
    pylab.savefig('fig_a4c.png')
    pylab.show()
    moose.connect(inject_table, 'requestOut', pulse, 'getOutputValue')
    gk_table = moose.Table('/data/Gk')
    moose.connect(gk_table, 'requestOut', synapse, 'getGk')
    spike_in_table = moose.Table('/data/spike_in')
    moose.connect(spikegen, 'spikeOut', spike_in_table, 'spike')
    return [vm_table, inject_table, gk_table, spike_in_table]

if __name__ == '__main__':
    simtime = 200.0
    stepsize = 10.0
    model_dict = make_model()
    vm, inject, gk, spike = setup_data_recording(model_dict['neuron'],
                                          model_dict['pulse'],
                                          model_dict['synapse'],
                                          model_dict['spike_in'])
    mutils.setDefaultDt(elecdt=0.01, plotdt2=0.25)
    mutils.assignDefaultTicks(solver='ee')
    moose.reinit()
    mutils.stepRun(simtime, stepsize)
    pylab.subplot(411)
    pylab.plot(pylab.linspace(0, simtime, len(vm.vector)), vm.vector, label='Vm (mV)')
    pylab.legend()
    pylab.subplot(412)
    pylab.plot(pylab.linspace(0, simtime, len(inject.vector)), inject.vector, label='Inject (uA)')
    pylab.legend()
    pylab.subplot(413)
    pylab.plot(spike.vector, pylab.ones(len(spike.vector)), '|', label='input spike times')
    pylab.legend()
    pylab.subplot(414)
    pylab.plot(pylab.linspace(0, simtime, len(gk.vector)), gk.vector, label='Gk (mS)')
    pylab.legend()
Example #26
0
def test_mgblock():
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    soma = moose.Compartment('/model/soma')
    soma.Em = -60e-3
    soma.Rm = 1e7
    soma.Cm = 1e-9

    ###################################################
    # This is where we create the synapse with MgBlock
    #--------------------------------------------------
    nmda = moose.SynChan('/model/soma/nmda')
    nmda.Gbar = 1e-9
    mgblock = moose.MgBlock('/model/soma/mgblock')
    mgblock.CMg = 2.0
    mgblock.KMg_A = 1/0.33
    mgblock.KMg_B = 1/60.0
    
    # MgBlock sits between original channel nmda and the
    # compartment. The origChannel receives the channel message from
    # the nmda SynChan.
    moose.connect(nmda, 'channelOut', mgblock, 'origChannel')
    moose.connect(mgblock, 'channel', soma, 'channel')    
    # This is for comparing with MgBlock
    nmda_noMg = moose.element(moose.copy(nmda, soma, 'nmda_noMg'))
    moose.connect(moose.element(nmda_noMg), 'channel', soma, 'channel')

    #########################################
    # The rest is for experiment setup
    spikegen = moose.SpikeGen('/model/spike')
    pulse = moose.PulseGen('/model/input')
    pulse.delay[0] = 10e-3
    pulse.level[0] = 1.0
    pulse.width[0] = 50e-3
    moose.connect(pulse, 'output', spikegen, 'Vm')
    nmda.synapse.num = 1
    syn = moose.element(nmda.synapse.path)
    moose.connect(spikegen, 'spikeOut', syn, 'addSpike')
    nmda_noMg.synapse.num = 1
    moose.connect(spikegen, 'spikeOut', moose.element(nmda_noMg.synapse.path), 'addSpike')
    Gnmda = moose.Table('/data/Gnmda')
    moose.connect(Gnmda, 'requestOut', mgblock, 'getGk')
    Gnmda_noMg = moose.Table('/data/Gnmda_noMg')
    moose.connect(Gnmda_noMg, 'requestOut', nmda_noMg, 'getGk')
    Vm = moose.Table('/data/Vm')
    moose.connect(Vm, 'requestOut', soma, 'getVm')
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data')
    moose.reinit()
    utils.stepRun(simtime, simtime/10)
    for ii in range(10):
        for n in moose.element('/clock/tick').neighbors['proc%d' % (ii)]:
            print ii, n.path
    t = pylab.linspace(0, simtime*1e3, len(Vm.vector))
    pylab.plot(t, Vm.vector*1e3, label='Vm (mV)')
    pylab.plot(t, Gnmda.vector * 1e9, label='Gnmda (nS)')
    pylab.plot(t, Gnmda_noMg.vector * 1e9, label='Gnmda no Mg (nS)')
    pylab.legend()
    data = pylab.vstack((t, Gnmda.vector, Gnmda_noMg.vector)).transpose()
    pylab.savetxt('mgblock.dat', data)
    pylab.show()
    gk_table = moose.Table('/data/Gk')
    moose.connect(gk_table, 'requestOut', synapse, 'getGk')
    spike_in_table = moose.Table('/data/spike_in')
    moose.connect(spikegen, 'spikeOut', spike_in_table, 'spike')
    return [vm_table, inject_table, gk_table, spike_in_table]


if __name__ == '__main__':
    simtime = 200.0
    stepsize = 10.0
    model_dict = make_model()
    vm, inject, gk, spike = setup_data_recording(model_dict['neuron'],
                                                 model_dict['pulse'],
                                                 model_dict['synapse'],
                                                 model_dict['spike_in'])
    mutils.setDefaultDt(elecdt=0.01, plotdt2=0.25)
    mutils.assignDefaultTicks(solver='ee')
    moose.reinit()
    mutils.stepRun(simtime, stepsize)
    pylab.subplot(411)
    pylab.plot(pylab.linspace(0, simtime, len(vm.vector)),
               vm.vector,
               label='Vm (mV)')
    pylab.legend()
    pylab.subplot(412)
    pylab.plot(pylab.linspace(0, simtime, len(inject.vector)),
               inject.vector,
               label='Inject (uA)')
    pylab.legend()
    pylab.subplot(413)
    pylab.plot(spike.vector,
Example #28
0
    data = moose.Neutral('/data')    
    for c in moose.wildcardFind('/##[ISA=Compartment]'):
        tab = moose.Table('%s/%s_Vm' % (data.path, c.name))
        moose.connect(tab, 'requestOut', c, 'getVm')
        tables.append(tab)
    syntab = moose.Table('%s/%s' % (data.path, 'Gk'))
    moose.connect(syntab, 'requestOut', syn, 'getGk')
    tables.append(syntab)
    syn.synapse[0].delay = 1e-3
    syn.Gbar = 1e-6
    return tables

if __name__ == '__main__':
    tables = setup_two_cells()
    
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    data = []
    for tab in tables:
        data.append(tab.vector)
    data = np.concatenate(data)
    np.savetxt('lifcomp.csv', data.transpose(), delimiter='\t', header=' '.join([tab.name for tab in tables]))
    #     subplot(len(tables), 1, ii+1)
    #     t = np.linspace(0, simtime, len(tab.vector))*1e3
    #     plot(t, tab.vector*1e3, label=tab.name)
    #     legend()
    # show()
# 
# lifcomp.py ends here
Example #29
0
    data = moose.Neutral('/data')    
    for c in moose.wildcardFind('/##[ISA=Compartment]'):
        tab = moose.Table('%s/%s' % (data.path, c.name))
        moose.connect(tab, 'requestOut', c, 'getVm')
        tables.append(tab)
        # t1 = moose.Table('%s/%s' % (data.path, c.name))
        # moose.connect(t1, 'requestOut', moose.element('%s/dynamics' % (c.path)), 'getX')
        # tables.append(t1)
    syntab = moose.Table('%s/%s' % (data.path, 'Gk'))
    moose.connect(syntab, 'requestOut', syn, 'getGk')
    tables.append(syntab)
    synh.synapse[0].delay = 1e-3
    syn.Gbar = 1e-6
    return tables

if __name__ == '__main__':
    tables = setup_two_cells()
    
    utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt)
    utils.assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='ee')
    moose.reinit()
    utils.stepRun(simtime, stepsize)
    for ii, tab in enumerate(tables):
        subplot(len(tables), 1, ii+1)
        t = np.linspace(0, simtime, len(tab.vector))*1e3
        plot(t, tab.vector*1e3, label=tab.name)
        legend()
    show()
# 
# multicomp_lif.py ends here