def loadAndRun(solver=True): simtime = 500e-3 model = moose.loadModel('../data/h10.CNG.swc', '/cell') comp = moose.element('/cell/apical_e_177_0') soma = moose.element('/cell/soma') for i in range(10): moose.setClock(i, dt) if solver: solver = moose.HSolve('/cell/solver') solver.target = soma.path solver.dt = dt stim = moose.PulseGen('/cell/stim') stim.delay[0] = 50e-3 stim.delay[1] = 1e9 stim.level[0] = 1e-9 stim.width[0] = 2e-3 moose.connect(stim, 'output', comp, 'injectMsg') tab = moose.Table('/cell/Vm') moose.connect(tab, 'requestOut', comp, 'getVm') tab_soma = moose.Table('/cell/Vm_soma') moose.connect(tab_soma, 'requestOut', soma, 'getVm') moose.reinit() print('[INFO] Running for %s' % simtime) moose.start(simtime ) vec = tab_soma.vector moose.delete( '/cell' ) return vec
def test_elec_alone(): eeDt = 2e-6 hSolveDt = 2e-5 runTime = 0.02 make_spiny_compt() make_elec_plots() head2 = moose.element( '/n/head2' ) moose.setClock( 0, 2e-6 ) moose.setClock( 1, 2e-6 ) moose.setClock( 2, 2e-6 ) moose.setClock( 8, 0.1e-3 ) moose.useClock( 0, '/n/##[ISA=Compartment]', 'init' ) moose.useClock( 1, '/n/##[ISA=Compartment]', 'process' ) moose.useClock( 2, '/n/##[ISA=ChanBase],/n/##[ISA=SynBase],/n/##[ISA=CaConc],/n/##[ISA=SpikeGen]','process') moose.useClock( 8, '/graphs/elec/#', 'process' ) moose.reinit() moose.start( runTime ) dump_plots( 'instab.png' ) # make Hsolver and rerun hsolve = moose.HSolve( '/n/hsolve' ) moose.useClock( 1, '/n/hsolve', 'process' ) hsolve.dt = 20e-6 hsolve.target = '/n/compt' moose.le( '/n' ) for dt in ( 20e-6, 50e-6, 100e-6 ): print(('running at dt =', dt)) moose.setClock( 0, dt ) moose.setClock( 1, dt ) moose.setClock( 2, dt ) hsolve.dt = dt moose.reinit() moose.start( runTime ) dump_plots( 'h_instab' + str( dt ) + '.png' )
def testNeuroMeshMultiscale(): useHsolve = 1 runtime = 0.5 if useHsolve: elecDt = 50e-6 else: elecDt = 10e-6 chemDt = 0.005 ePlotDt = 0.5e-3 cPlotDt = 0.005 plotName = 'nm.plot' makeNeuroMeshModel() print("after model is completely done") for i in moose.wildcardFind('/model/chem/#/#/#/transloc#'): print((i[0].name, i[0].Kf, i[0].Kb, i[0].kf, i[0].kb)) makeChemPlots() makeElecPlots() makeCaPlots() moose.setClock(0, elecDt) moose.setClock(1, elecDt) moose.setClock(2, elecDt) moose.setClock(4, chemDt) moose.setClock(5, chemDt) moose.setClock(6, chemDt) moose.setClock(7, cPlotDt) moose.setClock(8, ePlotDt) if useHsolve: hsolve = moose.HSolve('/model/elec/hsolve') moose.useClock(1, '/model/elec/hsolve', 'process') hsolve.dt = elecDt hsolve.target = '/model/elec/compt' moose.reinit() else: moose.useClock(0, '/model/elec/##[ISA=Compartment]', 'init') moose.useClock(1, '/model/elec/##[ISA=Compartment]', 'process') moose.useClock( 2, '/model/elec/##[ISA=ChanBase],/model/##[ISA=SynBase],/model/##[ISA=CaConc]', 'process') moose.useClock(1, '/model/elec/##[ISA=SpikeGen]', 'process') moose.useClock(2, '/model/##[ISA=SynBase],/model/##[ISA=CaConc]', 'process') moose.useClock(4, '/model/chem/#/dsolve', 'process') moose.useClock(4, '/model/chem/#/ksolve', 'init') moose.useClock(5, '/model/chem/#/ksolve', 'process') moose.useClock(6, '/model/chem/spine/adaptCa', 'process') moose.useClock(6, '/model/chem/dend/DEND/adaptCa', 'process') moose.useClock(7, '/graphs/chem/#', 'process') moose.useClock(8, '/graphs/elec/#,/graphs/ca/#', 'process') moose.element('/model/elec/soma').inject = 2e-10 moose.element('/model/chem/psd/Ca').concInit = 0.001 moose.element('/model/chem/spine/Ca').concInit = 0.002 moose.element('/model/chem/dend/DEND/Ca').concInit = 0.003 moose.reinit() moose.start(runtime) makeGraphics(cPlotDt, ePlotDt)
def main(): """ A toy compartmental neuronal + chemical model that causes bad things to happen to the hsolver, as of 28 May 2013. Hopefully this will become irrelevant soon """ fineDt = 1e-5 coarseDt = 5e-5 make_spiny_compt() make_plots() for i in range(8): moose.setClock(i, fineDt) moose.setClock(8, coarseDt) moose.reinit() moose.start(0.1) display_plots('instab.plot') # make Hsolver and rerun hsolve = moose.HSolve('/n/hsolve') for i in range(8): moose.setClock(i, coarseDt) hsolve.dt = coarseDt hsolve.target = '/n/compt' moose.reinit() moose.start(0.1) display_plots('h_instab.plot') pylab.show()
def setup_model(model_path, synapse_locations, passive=False, solver='hsolve'): """Set up a single cell model under `model_path` with synapses created in the compartments listed in `synapse_locations`. `model_path` - location where the model should be created. `synapse_locations`: compartment names for the synapses. """ cell = moose.copy(make_prototype(passive), model_path) if solver.lower() == 'hsolve': hsolve = moose.HSolve('%s/solve' % (cell.path)) hsolve.dt = simdt hsolve.target = cell.path syninfo_list = [] for compname in synapse_locations: comppath = '%s/%s' % (cell.path, compname) print('1111 Creating synapse in', comppath) compartment = moose.element(comppath) syninfo = make_synapse(compartment) syninfo_list.append(syninfo) # connect pulse stimulus stim_path = '%s/%s/stim' % (cell.path, compname) print('2222 Creating stimuls in', stim_path) stim = moose.PulseGen(stim_path) moose.connect(stim, 'output', syninfo['spike'], 'Vm') syninfo['stimulus'] = stim return {'neuron': cell, 'syninfo': syninfo_list}
def setupSolver(self, path='/hsolve'): """Setting up HSolver """ hsolve = moose.HSolve(path) hsolve.dt = self.simDt moose.setClock(1, self.simDt) moose.useClock(1, hsolve.path, 'process') hsolve.target = self.cablePath
def testNeuroMeshMultiscale(): runtime = 0.5 #elecDt = 0.2e-6 elecDt = 10e-6 chemDt = 0.0025 ePlotDt = 0.5e-3 cPlotDt = 0.0025 plotName = 'nm.plot' makeNeuroMeshModel() print("after model is completely done") for i in moose.wildcardFind('/model/chem/#/#/#/transloc#'): print((i[0].name, i[0].Kf, i[0].Kb, i[0].kf, i[0].kb)) makeChemPlots() makeElecPlots() makeCaPlots() hsolve = moose.HSolve('/model/elec/hsolve') hsolve.dt = elecDt hsolve.target = '/model/elec/compt' plotlist = makeGraphics() moose.reinit() moose.element('/model/elec/soma').inject = 2e-10 moose.element('/model/chem/psd/Ca').concInit = 0.001 moose.element('/model/chem/spine/Ca').concInit = 0.002 moose.element('/model/chem/dend/DEND/Ca').concInit = 0.003 moose.reinit() numDivs = 200 partialRuntime = runtime / numDivs for i in range(numDivs): moose.start(partialRuntime) updateGraphics(plotlist) finalizeGraphics(plotlist, cPlotDt, ePlotDt)
def assign_clocks(model_container_list, simdt, plotdt, hsolveYN, name_soma): log.info('SimDt={}, PlotDt={}', simdt, plotdt) for tab in moose.wildcardFind(DATA_NAME + '/##[TYPE=Table]'): moose.setClock(tab.tick, plotdt) for tick in range(0, 13): moose.setClock(tick, simdt) # 1 - CaConc, DifShell, DifBuffer # 2 — channels and synchans # 4 — compartments # 5 - SpikeGen # 6 — hsolver # 7 - TimeTables for moose_nerp (see ttables.py) # 8 - Tables # 12 - Function # problem if TimeTable uses plotdt? moose.setClock(8, plotdt) # 8 — hdf5datawriter, tables for path in model_container_list: if hsolveYN: hsolve = moose.HSolve(path + '/hsolve') hsolve.dt = simdt # Compartment is transformed into zombiecompartment after below statement. hsolve.target = path + '/' + name_soma log.info("Using HSOLVE for {} clock {}", hsolve.path, hsolve.tick) moose.reinit()
def assign_clocks(model_container, data_container, solver='euler'): """Assign clockticks to elements. Parameters ---------- model_container: element All model components are under this element. The model elements are assigned clocks as required to maintain the right update sequence. INITCLOCK = 0 calls `init` method in Compartments ELECCLOCK = 1 calls `process` method of Compartments CHANCLOCK = 2 calls `process` method for HHChannels POOLCLOCK = 3 is not used in electrical simulation LOOKUPCLOCK = 6 is not used in these simulations. STIMCLOCK = 7 calls `process` method in stimulus objects like PulseGen. data_container: element All data recording tables are under this element. They are assigned PLOTCLOCK, the clock whose update interval is plotdt. PLOTCLOCK = 8 calls `process` method of Table elements under data_container """ moose.useClock(STIMCLOCK, model_container.path+'/##[TYPE=PulseGen]', 'process') moose.useClock(PLOTCLOCK, data_container.path+'/##[TYPE=Table]', 'process') if solver == 'hsolve': for neuron in moose.wildcardFind('%s/##[TYPE=Neuron]'): solver = moose.HSolve(neuron.path+'/solve') solver.dt = moose.element('/clock/tick[0]').dt solver.target = neuron.path moose.useClock(INITCLOCK, model_container.path+'/##[TYPE=HSolve]', 'process') else: moose.useClock(INITCLOCK, model_container.path+'/##[TYPE=Compartment]', 'init') moose.useClock(ELECCLOCK, model_container.path+'/##[TYPE=Compartment]', 'process') moose.useClock(CHANCLOCK, model_container.path+'/##[TYPE=HHChannel]', 'process') moose.useClock(POOLCLOCK, model_container.path+'/##[TYPE=CaConc]', 'process')
def __init__(self, path): if not moose.exists(path): path_tokens = path.rpartition('/') moose.copy(self.prototype, path_tokens[0], path_tokens[-1]) moose.Neutral.__init__(self, path) self.solver = moose.HSolve('{}/solver'.format(path, 'solver')) self.solver.target = path self.solver.dt = config.simulationSettings.simulationDt
def testNeuroMeshMultiscale(): runtime = 0.5 #elecDt = 0.2e-6 elecDt = 10e-6 chemDt = 0.0025 ePlotDt = 0.5e-3 cPlotDt = 0.0025 plotName = 'nm.plot' makeNeuroMeshModel() print "after model is completely done" for i in moose.wildcardFind('/model/chem/#/#/#/transloc#'): print i[0].name, i[0].Kf, i[0].Kb, i[0].kf, i[0].kb makeChemPlots() makeElecPlots() makeCaPlots() for i in range(10): moose.setClock(i, elecDt) for i in range(10, 20): moose.setClock(i, chemDt) moose.setClock(8, ePlotDt) moose.setClock(18, cPlotDt) moose.useClock(8, '/graphs/elec/#,/graphs/ca/#', 'process') moose.useClock(18, '/graphs/chem/#', 'process') hsolve = moose.HSolve('/model/elec/hsolve') hsolve.dt = elecDt hsolve.target = '/model/elec/compt' plotlist = makeGraphics() moose.reinit() moose.element('/model/elec/soma').inject = 2e-10 moose.element('/model/chem/psd/Ca').concInit = 0.001 moose.element('/model/chem/spine/Ca').concInit = 0.002 moose.element('/model/chem/dend/DEND/Ca').concInit = 0.003 moose.reinit() numDivs = 200 partialRuntime = runtime / numDivs max_voxel = find_max_voxel() voxel_val_dict = { 'spine': numpy.zeros((max_voxel, numDivs)), 'dend': numpy.zeros((max_voxel, numDivs)), 'elec': numpy.zeros((max_voxel, numDivs)), 'spineCaM': numpy.zeros((max_voxel, numDivs)), 'psdCaM': numpy.zeros((max_voxel, numDivs)) } for i in range(numDivs): moose.start(partialRuntime) voxel_val_dict = updateGraphics(plotlist, voxel_val_dict, i) #Edited by Chaitanya # moose.element( '/model/elec/soma' ).inject = 0 # moose.start( 0.25 ) save_NSDF(cPlotDt, ePlotDt, voxel_val_dict, [max_voxel, numDivs, partialRuntime]) #Edited by Chaitanya finalizeGraphics(plotlist, cPlotDt, ePlotDt)
def __init__(self, path): self.path = path if not moose.exists(self.path): path_tokens = path.rpartition('/') moose.copy(self.prototype, path_tokens[0], path_tokens[-1]) self.name = path.split('/')[-1] self.solver = moose.HSolve('{}/solver'.format(path)) self.solver.target = path self.solver.dt = config.simulationSettings.simulationDt
def _configureClocks( self ): for i in range( 0, 8 ): moose.setClock( i, self.elecDt ) moose.setClock( 10, self.diffDt ) for i in range( 11, 18 ): moose.setClock( i, self.chemDt ) moose.setClock( 18, self.chemDt * 5.0 ) hsolve = moose.HSolve( self.elecid.path + '/hsolve' ) hsolve.dt = self.elecDt hsolve.target = self.soma.path
def test_hsolve_calcium(): for tick in range(0, 7): moose.setClock(tick, 10e-6) moose.setClock(8, 0.005) lib = moose.Neutral('/library') model = moose.loadModel(p_file, 'neuron') assert model, model pulse = moose.PulseGen('/neuron/pulse') inject = 100e-10 chan_proto.chan_proto('/library/SK', param_chan.SK) chan_proto.chan_proto('/library/CaL12', param_chan.Cal) pulse.delay[0] = 8. pulse.width[0] = 500e-12 pulse.level[0] = inject pulse.delay[1] = 1e9 for comp in moose.wildcardFind('/neuron/#[TYPE=Compartment]'): new_comp = moose.element(comp) new_comp.initVm = -.08 difs, difb = td.add_difshells_and_buffers(new_comp, difshell_no, difbuf_no) for name in cond: chan = td.addOneChan(name, cond[name], new_comp) if 'Ca' in name: moose.connect(chan, "IkOut", difs[0], "influx") if 'SK' in name: moose.connect(difs[0], 'concentrationOut', chan, 'concen') data = moose.Neutral('/data') vmtab = moose.Table('/data/Vm') shelltab = moose.Table('/data/Ca') caltab = moose.Table('/data/CaL_Gk') sktab = moose.Table('/data/SK_Gk') moose.connect(vmtab, 'requestOut', moose.element('/neuron/soma'), 'getVm') moose.connect(shelltab, 'requestOut', difs[0], 'getC') moose.connect(caltab, 'requestOut', moose.element('/neuron/soma/CaL12'), 'getGk') moose.connect(sktab, 'requestOut', moose.element('/neuron/soma/SK'), 'getGk') hsolve = moose.HSolve('/neuron/hsolve') hsolve.dt = 10e-6 hsolve.target = ('/neuron/soma') t_stop = 10. moose.reinit() moose.start(t_stop) vec1 = sktab.vector vec2 = shelltab.vector assert_stat(vec1, [0.0, 5.102834e-22, 4.79066e-22, 2.08408e-23]) assert_stat(vec2, [5.0e-5, 5.075007e-5, 5.036985e-5, 2.1950117e-7]) assert len(np.where(sktab.vector < 1e-19)[0]) == 2001 assert len(np.where(shelltab.vector > 50e-6)[0]) == 2000
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)
def testNeuroMeshMultiscale(): elecDt = 50e-6 chemDt = 2e-3 plotDt = 5e-4 plotName = 'nm.plot' makeNeuroMeshModel() """ moose.le( '/model/chem/spineMesh/ksolve' ) print 'Neighbors:' for t in moose.element( '/model/chem/spineMesh/ksolve/junction' ).neighbors['masterJunction']: print 'masterJunction <-', t.path for t in moose.wildcardFind( '/model/chem/#Mesh/ksolve' ): k = moose.element( t[0] ) print k.path + ' localVoxels=', k.numLocalVoxels, ', allVoxels= ', k.numAllVoxels """ makeChemPlots() makeElecPlots() moose.setClock(0, elecDt) moose.setClock(1, elecDt) moose.setClock(2, elecDt) moose.setClock(5, chemDt) moose.setClock(6, chemDt) moose.setClock(7, plotDt) moose.setClock(8, plotDt) moose.useClock(0, '/model/elec/##[ISA=Compartment]', 'init') moose.useClock(1, '/model/elec/##[ISA=SpikeGen]', 'process') moose.useClock( 2, '/model/elec/##[ISA=ChanBase],/model/##[ISA=SynBase],/model/##[ISA=CaConc]', 'process') moose.useClock( 5, '/model/chem/##[ISA=PoolBase],/model/##[ISA=ReacBase],/model/##[ISA=EnzBase]', 'process') moose.useClock(6, '/model/chem/##[ISA=Adaptor]', 'process') moose.useClock(7, '/graphs/#', 'process') moose.useClock(8, '/graphs/elec/#', 'process') moose.useClock(5, '/model/chem/#Mesh/ksolve', 'init') moose.useClock(6, '/model/chem/#Mesh/ksolve', 'process') hsolve = moose.HSolve('/model/elec/hsolve') moose.useClock(1, '/model/elec/hsolve', 'process') hsolve.dt = elecDt hsolve.target = '/model/elec/compt' moose.reinit() moose.reinit() moose.start(1.0) dumpPlots(plotName)
def makeSolvers(elecDt): # Put in the solvers, see how they fare. # Here we kludge in a single chem solver for the whole system. ksolve = moose.Ksolve('/model/ksolve') stoich = moose.Stoich('/model/stoich') stoich.compartment = moose.element('/model/chem/neuroMesh') stoich.ksolve = ksolve stoich.path = '/model/chem/##' moose.useClock(5, '/model/ksolve', 'init') moose.useClock(6, '/model/ksolve', 'process') # Here is the elec solver hsolve = moose.HSolve('/model/hsolve') moose.useClock(1, '/model/hsolve', 'process') hsolve.dt = elecDt hsolve.target = '/model/elec/compt'
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()
def main(): """ Demonstrates how one can visualise morphology of a neuron using the MOOSE. """ app = QtGui.QApplication(sys.argv) filename = 'barrionuevo_cell1zr.CNG.swc' moose.Neutral('/library') moose.Neutral('/model') cell = moose.loadModel(filename, '/model/testSwc') for i in range(8): moose.setClock(i, simdt) hsolve = moose.HSolve('/model/testSwc/hsolve') hsolve.dt = simdt hsolve.target = '/model/testSwc/soma' moose.le(cell) moose.reinit() # Now we set up the display compts = moose.wildcardFind("/model/testSwc/#[ISA=CompartmentBase]") compts[0].inject = inject ecomptPath = [x.path for x in compts] morphology = moogli.extensions.moose.read(path="/model/testSwc", vertices=15) viewer = moogli.Viewer("Viewer") viewer.attach_shapes(morphology.shapes.values()) view = moogli.View("main-view") viewer.attach_view(view) # morphology = moogli.read_morphology_from_moose(name = "", path = "/model/testSwc") # morphology.create_group( "group_all", ecomptPath, -0.08, 0.02, \ # [0.0, 0.5, 1.0, 1.0], [1.0, 0.0, 0.0, 0.9] ) # viewer = moogli.DynamicMorphologyViewerWidget(morphology) def callback(morphology, viewer): moose.start(frameRunTime) Vm = [moose.element(x).Vm for x in compts] morphology.set_color("group_all", Vm) currTime = moose.element('/clock').currentTime #print currTime, compts[0].Vm if (currTime < runtime): return True return False #viewer.set_callback( callback, idletime = 0 ) #viewer.showMaximized() viewer.show() app.exec_()
def testCubeMultiscale(useSolver): elecDt = 10e-6 chemDt = 1e-4 plotDt = 5e-4 plotName = 'cm.plot' if (useSolver): elecDt = 50e-6 chemDt = 2e-3 plotName = 'solve_cm.plot' makeModelInCubeMesh() makeChemPlots() makeElecPlots() ''' moose.setClock( 0, elecDt ) moose.setClock( 1, elecDt ) moose.setClock( 2, elecDt ) moose.setClock( 5, chemDt ) moose.setClock( 6, chemDt ) moose.setClock( 7, plotDt ) moose.setClock( 8, plotDt ) moose.useClock( 1, '/n/##[ISA=SpikeGen]', 'process' ) moose.useClock( 2, '/n/##[ISA=SynBase]','process') moose.useClock( 6, '/n/##[ISA=Adaptor]', 'process' ) moose.useClock( 7, '/graphs/#', 'process' ) moose.useClock( 8, '/graphs/elec/#', 'process' ) moose.useClock( 0, '/n/##[ISA=Compartment]', 'init' ) moose.useClock( 1, '/n/##[ISA=Compartment]', 'process' ) moose.useClock( 2, '/n/##[ISA=ChanBase],/n/##[ISA=SynBase],/n/##[ISA=CaConc]','process') moose.useClock( 5, '/n/##[ISA=PoolBase],/n/##[ISA=ReacBase],/n/##[ISA=EnzBase]', 'process' ) ''' if (useSolver): ksolve = moose.Ksolve('/n/ksolve') stoich = moose.Stoich('/n/stoich') stoich.compartment = moose.element('/n/chem/neuroMesh') stoich.ksolve = ksolve stoich.path = '/n/##' ksolve.method = 'rk5' #moose.useClock( 5, '/n/ksolve', 'process' ) hsolve = moose.HSolve('/n/hsolve') #moose.useClock( 1, '/n/hsolve', 'process' ) hsolve.dt = elecDt hsolve.target = '/n/compt' moose.reinit() moose.start(1) displayPlots()
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)
def _configureClocks(self): if self.turnOffElec: elecDt = 1e6 diffDt = 0.1 chemDt = 0.1 else: elecDt = self.elecDt diffDt = self.diffDt chemDt = self.chemDt for i in range(0, 9): moose.setClock(i, elecDt) moose.setClock(10, diffDt) for i in range(11, 18): moose.setClock(i, chemDt) moose.setClock(18, chemDt * 5.0) hsolve = moose.HSolve(self.elecid.path + '/hsolve') hsolve.dt = elecDt hsolve.target = self.soma.path
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}
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()
def assign_clocks(model_container_list, simdt, plotdt, hsolveYN, name_soma): log.info('SimDt={}, PlotDt={}', simdt, plotdt) for tab in moose.wildcardFind(DATA_NAME + '/##[TYPE=Table]'): moose.setClock(tab.tick, plotdt) for tick in range(0, 7): moose.setClock(tick, simdt) # 2 — channels # 4 — compartments # 6 — hsolver moose.setClock(8, plotdt) # 8 — hdf5datawriter for path in model_container_list: if hsolveYN: hsolve = moose.HSolve(path + '/hsolve') hsolve.dt = simdt hsolve.target = path + '/' + name_soma log.info("Using HSOLVE for {} clock {}", hsolve.path, hsolve.tick) moose.reinit()
def main(): fineDt = 1e-5 coarseDt = 5e-5 make_spiny_compt() make_plots() for i in range(8): moose.setClock(i, fineDt) moose.setClock(8, coarseDt) moose.reinit() moose.start(0.1) display_plots('instab.plot') # make Hsolver and rerun hsolve = moose.HSolve('/n/hsolve') for i in range(8): moose.setClock(i, coarseDt) hsolve.dt = coarseDt hsolve.target = '/n/compt' moose.reinit() moose.start(0.1) display_plots('h_instab.plot') pylab.show()
def testNeuroMeshMultiscale(): useHsolve = 0 runtime = 0.5 elecDt = 10e-6 chemDt = 0.005 ePlotDt = 0.5e-3 cPlotDt = 0.005 plotName = 'nm.plot' makeNeuroMeshModel() print("after model is completely done") for i in moose.wildcardFind('/model/chem/#/#/#/transloc#'): print((i[0].name, i[0].Kf, i[0].Kb, i[0].kf, i[0].kb)) makeChemPlots() makeElecPlots() makeCaPlots() for i in range(10): moose.setClock(i, elecDt) for i in range(10, 20): moose.setClock(i, chemDt) moose.setClock(8, ePlotDt) moose.setClock(18, cPlotDt) if useHsolve: hsolve = moose.HSolve('/model/elec/hsolve') #moose.useClock( 1, '/model/elec/hsolve', 'process' ) hsolve.dt = elecDt hsolve.target = '/model/elec/compt' moose.reinit() #soma = moose.element( '/model/elec/soma' ) moose.useClock(18, '/graphs/chem/#', 'process') moose.useClock(8, '/graphs/elec/#,/graphs/ca/#', 'process') moose.element('/model/elec/soma').inject = 2e-10 moose.element('/model/chem/psd/Ca').concInit = 0.001 moose.element('/model/chem/spine/Ca').concInit = 0.002 moose.element('/model/chem/dend/DEND/Ca').concInit = 0.003 moose.reinit() moose.start(runtime) makeGraphics(cPlotDt, ePlotDt)
def main(): app = QtGui.QApplication(sys.argv) filename = 'barrionuevo_cell1zr.CNG.swc' moose.Neutral('/library') moose.Neutral('/model') cell = moose.loadModel(filename, '/model/testSwc') for i in range(8): moose.setClock(i, simdt) hsolve = moose.HSolve('/model/testSwc/hsolve') hsolve.dt = simdt hsolve.target = '/model/testSwc/soma' moose.le(cell) moose.reinit() # Now we set up the display compts = moose.wildcardFind("/model/testSwc/#[ISA=CompartmentBase]") compts[0].inject = inject ecomptPath = map(lambda x: x.path, compts) morphology = moogli.read_morphology_from_moose(name="", path="/model/testSwc") morphology.create_group( "group_all", ecomptPath, -0.08, 0.02, \ [0.0, 0.5, 1.0, 1.0], [1.0, 0.0, 0.0, 0.9] ) viewer = moogli.DynamicMorphologyViewerWidget(morphology) def callback(morphology, viewer): moose.start(frameRunTime) Vm = map(lambda x: moose.element(x).Vm, compts) morphology.set_color("group_all", Vm) currTime = moose.element('/clock').currentTime #print currTime, compts[0].Vm if (currTime < runtime): return True return False viewer.set_callback(callback, idletime=0) viewer.showMaximized() viewer.show() app.exec_()
dt = 50e-6 moose.setClock( 0, dt ) moose.setClock( 1, dt ) moose.setClock( 2, dt ) moose.setClock( 3, 2e-4 ) moose.useClock( 0, '/cell/##[ISA=Compartment]', 'init' ) moose.useClock( 1, '/cell/##[ISA=Compartment]', 'process' ) moose.useClock( 2, '/cell/##[ISA!=Compartment]', 'process' ) moose.useClock( 3, '/graphs/soma,/graphs/ca', 'process' ) print 2 moose.reinit() print 3 moose.start( 0.1 ) dumpPlots( '50usec.plot' ) print 4 moose.reinit() hsolve = moose.HSolve( '/cell/hsolve' ) moose.useClock( 1, '/cell/hsolve', 'process' ) hsolve.dt = dt hsolve.target = '/cell/soma' moose.reinit() moose.reinit() print 5 moose.start( 0.1 ) print 6 dumpPlots( 'h50usec.plot' ) print 7
def loadFile(filename, target, solver="gsl", merge=True): """Try to load a model from specified `filename` under the element `target`. if `merge` is True, the contents are just loaded at target. If false, everything is deleted from the parent of target unless the parent is root. Returns ------- a dict containing at least these three entries: modeltype: type of the loaded model. subtype: subtype of the loaded model, None if no specific subtype modelroot: root element of the model, None if could not be located - as is the case with Python scripts """ num = 1 newTarget = target while moose.exists(newTarget): newTarget = target + "-" + str(num) num = num + 1 target = newTarget istext = True with open(filename, 'rb') as infile: istext = mtypes.istextfile(infile) if not istext: print 'Cannot handle any binary formats yet' return None parent, child = posixpath.split(target) p = moose.Neutral(parent) if not merge and p.path != '/': for ch in p.children: moose.delete(ch) try: modeltype = mtypes.getType(filename) subtype = mtypes.getSubtype(filename, modeltype) except KeyError: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) pwe = moose.getCwe() #self.statusBar.showMessage('Loading model, please wait') # app = QtGui.qApp # app.setOverrideCursor(QtGui.QCursor(Qt.Qt.BusyCursor)) #shows a hourglass - or a busy/working arrow if modeltype == 'genesis': if subtype == 'kkit' or subtype == 'prototype': model, modelpath = loadGenCsp(target, filename, solver) if moose.exists(moose.element(modelpath).path): moose.Annotator(moose.element(modelpath).path + '/info').modeltype = "kkit" else: print " path doesn't exists" moose.le(modelpath) else: print 'Only kkit and prototype files can be loaded.' elif modeltype == 'cspace': model, modelpath = loadGenCsp(target, filename) if moose.exists(modelpath): moose.Annotator( (moose.element(modelpath).path + '/info')).modeltype = "cspace" addSolver(modelpath, 'gsl') elif modeltype == 'xml': if subtype == 'neuroml': popdict, projdict = neuroml.loadNeuroML_L123(filename) # Circus to get the container of populations from loaded neuroml for popinfo in popdict.values(): for cell in popinfo[1].values(): solver = moose.HSolve(cell.path + "/hsolve") solver.target = cell.path # model = cell.parent # break # break # Moving model to a new location under the model name # model name is the filename without extension model = moose.Neutral("/" + splitext(basename(filename))[0]) element = moose.Neutral(model.path + "/model") if (moose.exists("/cells")): moose.move("/cells", element.path) if (moose.exists("/elec")): moose.move("/elec", model.path) if (moose.exists("/library")): moose.move("/library", model.path) # moose.move("cells/", cell.path) elif subtype == 'sbml': if target != '/': if moose.exists(target): moose.delete(target) model = mooseReadSBML(filename, target) if moose.exists(moose.element(model).path): moose.Annotator(moose.element(model).path + '/info').modeltype = "sbml" addSolver(target, 'gsl') else: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) moose.setCwe( pwe ) # The MOOSE loadModel changes the current working element to newly loaded model. We revert that behaviour # TODO: check with Aditya how to specify the target for # neuroml reader # app.restoreOverrideCursor() return {'modeltype': modeltype, 'subtype': subtype, 'model': model}