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 simulate(self, simtime=simtime, dt=dt, plotif=False, **kwargs): self.dt = dt self.simtime = simtime self.T = np.ceil(simtime / dt) self.trange = np.arange(0, self.simtime + dt, dt) self._init_network(**kwargs) if plotif: self._init_plots() # moose simulation moose.useClock(0, "/network/syns", "process") moose.useClock(1, "/network", "process") moose.useClock(2, "/plotSpikes", "process") moose.useClock(3, "/plotVms", "process") moose.useClock(3, "/plotWeights", "process") moose.setClock(0, dt) moose.setClock(1, dt) moose.setClock(2, dt) moose.setClock(3, dt) moose.setClock(9, dt) t1 = time.time() print "reinit MOOSE" moose.reinit() print "reinit time t = ", time.time() - t1 t1 = time.time() print "starting" moose.start(self.simtime) print "runtime, t = ", time.time() - t1 if plotif: self._plot()
def simulate(self,simtime=simtime,dt=dt,plotif=False,**kwargs): self.dt = dt self.simtime = simtime self.T = np.ceil(simtime/dt) self.trange = np.arange(0,self.simtime+dt,dt) self._init_network(**kwargs) if plotif: self._init_plots() # moose simulation moose.useClock( 0, '/network/syns', 'process' ) moose.useClock( 1, '/network', 'process' ) moose.useClock( 2, '/plotSpikes', 'process' ) moose.useClock( 3, '/plotVms', 'process' ) moose.useClock( 3, '/plotWeights', 'process' ) moose.setClock( 0, dt ) moose.setClock( 1, dt ) moose.setClock( 2, dt ) moose.setClock( 3, dt ) moose.setClock( 9, dt ) t1 = time.time() print 'reinit MOOSE -- takes a while ~20s.' moose.reinit() print 'reinit time t = ', time.time() - t1 t1 = time.time() print 'starting' moose.start(self.simtime) print 'runtime, t = ', time.time() - t1 if plotif: self._plot()
def test_crossing_single(): """This function creates an ematrix of two PulseGen elements and another ematrix of two Table elements. The two pulsegen elements have same amplitude but opposite phase. Table[0] is connected to PulseGen[1] and Table[1] to Pulsegen[0]. In the plot you should see two square pulses of opposite phase. """ size = 2 pg = moose.PulseGen('pulsegen', size) for ix, ii in enumerate(pg.vec): pulse = moose.element(ii) pulse.delay[0] = 1.0 pulse.width[0] = 2.0 pulse.level[0] = (-1)**ix tab = moose.Table('table', size) moose.connect(tab.vec[0], 'requestOut', pg.vec[1], 'getOutputValue', 'Single') moose.connect(tab.vec[1], 'requestOut', pg.vec[0], 'getOutputValue', 'Single') print 'Neighbors:' for t in tab.vec: print t.path for n in moose.element(t).neighbors['requestOut']: print 'requestOut <-', n.path moose.setClock(0, 0.1) moose.useClock(0, '/##', 'process') moose.start(5) for ii in tab.vec: t = moose.Table(ii).vector print len(t) pylab.plot(t) pylab.show()
def setup_hdf5_output(model, neuron, filename=None, compartments=DEFAULT_HDF5_COMPARTMENTS): # Make sure /hdf5 exists if not moose.exists(HDF5WRITER_NAME): print('creating', HDF5WRITER_NAME) writer = moose.HDF5DataWriter(HDF5WRITER_NAME) #writer = moose.NSDFWriter(HDF5WRITER_NAME) writer.mode = 2 # Truncate existing file if filename is not None: writer.filename = filename moose.useClock(8, HDF5WRITER_NAME, 'process') else: print('using', HDF5WRITER_NAME) writer = moose.element(HDF5WRITER_NAME) for typenum,neur_type in enumerate(neuron.keys()): for ii,compname in enumerate(compartments): #neur_comps): comp=moose.element(neur_type+'/'+compname) moose.connect(writer, 'requestOut', comp, 'getVm') if model.calYN: for typenum,neur_type in enumerate(neuron.keys()): for ii,compname in enumerate(compartments): #neur_comps): comp=moose.element(neur_type+'/'+compname) for child in comp.children: if child.className in {"CaConc", "ZombieCaConc"}: cal = moose.element(comp.path+'/'+child.name) moose.connect(writer, 'requestOut', cal, 'getCa') elif child.className == 'DifShell': cal = moose.element(comp.path+'/'+child.name) moose.connect(writer, 'requestOut', cal, 'getC') return writer
def main(): make_spiny_compt() make_plots() moose.setClock( 0, 1e-5 ) moose.setClock( 1, 1e-5 ) moose.setClock( 2, 1e-5 ) moose.setClock( 8, 0.1e-3 ) moose.useClock( 0, '/n/#', 'init' ) moose.useClock( 1, '/n/#', 'process' ) moose.useClock( 2, '/n/#/#', 'process' ) moose.useClock( 8, '/graphs/#', 'process' ) moose.reinit() moose.start( 0.1 ) dump_plots( 'instab.plot' ) # make Hsolver and rerun hsolve = moose.HSolve( '/n/hsolve' ) moose.useClock( 1, '/n/hsolve', 'process' ) moose.setClock( 0, 2e-5 ) moose.setClock( 1, 2e-5 ) moose.setClock( 2, 2e-5 ) hsolve.dt = 2e-5 hsolve.target = '/n/compt' moose.reinit() moose.start( 0.1 ) dump_plots( 'h_instab.plot' )
def testElecAlone(): makeSpinyCompt() makeElecPlots() head2 = moose.element( '/n/head2' ) kchan = moose.element( '/n/compt/K' ) 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/#', 'init' ) #moose.useClock( 1, '/n/#', 'process' ) #moose.useClock( 2, '/n/#/#', 'process' ) #print moose.wildcardFind( '/n/##[ISA=SpikeGen]' ) 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( 0.1 ) dumpPlots( 'instab.plot' ) # make Hsolver and rerun hsolve = moose.HSolve( '/n/hsolve' ) moose.useClock( 1, '/n/hsolve', 'process' ) moose.setClock( 0, 2e-5 ) moose.setClock( 1, 2e-5 ) moose.setClock( 2, 2e-5 ) hsolve.dt = 2e-5 hsolve.target = '/n/compt' moose.reinit() #print kchan, ', Gbar = ', kchan.Gbar #kchan.Gbar = 0.1e-3 #print 'Gbar = ', kchan.Gbar moose.start( 0.11 ) dumpPlots( 'h_instab.plot' )
def assign_clocks(model_container_list, simdt, plotdt): """ Assign clocks to elements under the listed paths. This should be called only after all model components have been created. Anything created after this will not be scheduled. """ global inited # `inited` is for avoiding double scheduling of the same object if not inited: print(('SimDt=%g, PlotDt=%g' % (simdt, plotdt))) moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.setClock(3, simdt) moose.setClock(4, plotdt) for path in model_container_list: print(('Scheduling elements under:', path)) moose.useClock(0, '%s/##[TYPE=Compartment]' % (path), 'init') moose.useClock(1, '%s/##[TYPE=Compartment]' % (path), 'process') moose.useClock(2, '%s/##[TYPE=SynChan],%s/##[TYPE=HHChannel]' % (path, path), 'process') moose.useClock(3, '%s/##[TYPE=SpikeGen],%s/##[TYPE=PulseGen]' % (path, path), 'process') moose.useClock(4, '/data/##[TYPE=Table]', 'process') inited = True moose.reinit()
def main(): makeModel() gsolve = moose.Gsolve("/model/compartment/gsolve") stoich = moose.Stoich("/model/compartment/stoich") stoich.compartment = moose.element("/model/compartment") stoich.ksolve = gsolve stoich.path = "/model/compartment/##" # solver.method = "rk5" # mesh = moose.element( "/model/compartment/mesh" ) # moose.connect( mesh, "remesh", solver, "remesh" ) moose.setClock(5, 1.0) # clock for the solver moose.useClock(5, "/model/compartment/gsolve", "process") moose.reinit() moose.start(100.0) # Run the model for 100 seconds. a = moose.element("/model/compartment/a") b = moose.element("/model/compartment/b") # move most molecules over to bgsolve b.conc = b.conc + a.conc * 0.9 a.conc = a.conc * 0.1 moose.start(100.0) # Run the model for 100 seconds. # move most molecules back to a a.conc = a.conc + b.conc * 0.99 b.conc = b.conc * 0.01 moose.start(100.0) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() quit()
def main(): """ Example of Interpol object. """ simtime = 1.0 simdt = 0.001 model = moose.Neutral('/model') data = moose.Neutral('/data') interpol = moose.Interpol('/model/sin') vec = np.sin(np.linspace(-3.14, 3.14, 100)) interpol.vector = vec interpol.xmax = 3.14 interpol.xmin = -3.14 recorded = moose.Table('/data/output') moose.connect(recorded, 'requestOut', interpol, 'getY') stimtab = moose.StimulusTable('/model/x') stimtab.stepSize = 0.0 # stimtab.startTime = 0.0 # stimtab.stopTime = simtime stimtab.vector = np.linspace(-4, 4, 1000) print((stimtab.vector)) print((interpol.vector)) moose.connect(stimtab, 'output', interpol, 'input') moose.setClock(0, simdt) moose.useClock(0, '/data/##,/model/##', 'process') moose.reinit() moose.start(simtime) plt.plot(np.linspace(0, simtime, len(recorded.vector)), recorded.vector, 'b-+', label='interpolated') plt.plot(np.linspace(0, simtime, len(vec)), vec, 'r-+', label='original') plt.show()
def example(): """In this example we create a square-pulse generator object and record the output using a table. The steps are: 1. Create a PulseGen element `pulse`. 2. Set `delay[0]=1.0`, `width[0]=0.2`, `level[0]=0.5`, so it generates 0.2 s wide square pulses with 0.5 amplitude every 1 s. 3. Create a Table element `tab`. 4. Connect the `outputValue` field of `pulse` to `tab`. 5. We set tick-interval of ticks 0 and 1 to 0.01 and schedule `pulse` on tick 0 and `tab` on tick 1. 5. Run the simulation for 5 s and save data to the ascii file `output_tabledemo.csv`. """ pg = moose.PulseGen('pulse') pg.delay[0] = 1.0 pg.width[0] = 0.2 pg.level[0] = 0.5 tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 0.01) moose.setClock(1, 0.01) moose.useClock(0, pg.path, 'process') moose.useClock(1, tab.path, 'process') moose.reinit() moose.start(5.0) tab.plainPlot('output_tabledemo.csv')
def main(): makeModel() solver = moose.GslStoich("/model/compartment/solver") solver.path = "/model/compartment/##" solver.method = "rk5" mesh = moose.element("/model/compartment/mesh") moose.connect(mesh, "remesh", solver, "remesh") moose.setClock(5, 1.0) # clock for the solver moose.useClock(5, "/model/compartment/solver", "process") moose.reinit() moose.start(100.0) # Run the model for 100 seconds. a = moose.element("/model/compartment/a") b = moose.element("/model/compartment/b") # move most molecules over to b b.conc = b.conc + a.conc * 0.9 a.conc = a.conc * 0.1 moose.start(100.0) # Run the model for 100 seconds. # move most molecules back to a a.conc = a.conc + b.conc * 0.99 b.conc = b.conc * 0.01 moose.start(100.0) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. for x in moose.wildcardFind("/model/graphs/conc#"): moose.element(x[0]).xplot("scriptKineticSolver.plot", x[0].name) quit()
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.plot' ) print "||||", len(moose.wildcardFind('/##[ISA=HHChannel]')) # 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 ) + '.plot' )
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' ) ''' 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( 5, '/model/chem/##[ISA=PoolBase],/model/##[ISA=ReacBase],/model/##[ISA=EnzBase]', 'process' ) #moose.useClock( 4, '/model/chem/##[ISA=Adaptor]', 'process' ) moose.useClock( 4, '/model/chem/#/dsolve', 'process' ) 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( 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 ) # moose.element( '/model/elec/soma' ).inject = 0 # moose.start( 0.25 ) makeGraphics( cPlotDt, ePlotDt )
def main(): """ This demo shows how to start, stop, and continue a simulation. This is commonly done when we want to run a model till settling, then change a parameter or deliver a stimulus, and then continue the simulation. Here, the model is just the output of a PulseGen object which generates periodic pulses. The demo shows how to start the simulation. using the *moose.reinit* command to reset the model to its initial state, and *moose.start* command to run the model for the specified duration. We issue multiple *moose.start* commands and do different things to the model between them. First, we change the delay of the pulseGen. Then we show a number of ways to assign the timestep (dt) to the table object in the simulation. Note that throughout this simulation the pulsegen is going at a uniform rate, it is just being sampled by the output table at different intervals. """ dt = 0.1 steps = 100 simtime = dt * steps # Pulsegen is on tick 0, we can pre-emptively set its dt. moose.setClock(0, dt) table = setup_model() pulse = moose.element("/model/pulse") # The 'tick' field is on every object, we can use this to set its dt. moose.setClock(table.tick, dt) moose.reinit() clock = moose.element("/clock") print dt print "dt = ", dt, ", Total simulation time = ", simtime print "Running simulation for", simtime, "seconds" moose.start(simtime) print "Simulator time:", clock.currentTime # Here we change the pulse delay and then run again. pulse.delay[0] = 1.0 moose.start(simtime) # We change the table tick and use a different dt for it: table.tick = 2 moose.setClock(table.tick, dt * 2) moose.start(simtime) # Here is yet another way to change clocks used by the table moose.useClock(9, "/model/pulse/tab", "process") print table.tick moose.setClock(9, dt / 2.0) moose.start(simtime) # Finally, here we change the pulse delay to 1 second and run again. print "Simulator time at end of simulation", clock.currentTime pylab.plot(pylab.linspace(0, clock.currentTime, len(table.vector)), table.vector) pylab.show()
def makeModel(): # create container for model r0 = 1e-6 # m r1 = 0.5e-6 # m. Note taper. num = 200 diffLength = 1e-6 # m comptLength = num * diffLength # m diffConst = 20e-12 # m^2/sec concA = 1 # millimolar dt4 = 0.02 # for the diffusion dt5 = 0.2 # for the reaction mfile = '../../Genesis_files/M1719.g' model = moose.Neutral( 'model' ) compartment = moose.CylMesh( '/model/kinetics' ) # load in model modelId = moose.loadModel( mfile, '/model', 'ee' ) a = moose.element( '/model/kinetics/a' ) b = moose.element( '/model/kinetics/b' ) c = moose.element( '/model/kinetics/c' ) ac = a.concInit bc = b.concInit cc = c.concInit compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = comptLength compartment.diffLength = diffLength assert( compartment.numDiffCompts == num ) # Assign parameters for x in moose.wildcardFind( '/model/kinetics/##[ISA=PoolBase]' ): #print 'pools: ', x, x.name x.diffConst = diffConst # Make solvers ksolve = moose.Ksolve( '/model/kinetics/ksolve' ) dsolve = moose.Dsolve( '/model/dsolve' ) # Set up clocks. The dsolver to know before assigning stoich moose.setClock( 4, dt4 ) moose.setClock( 5, dt5 ) moose.useClock( 4, '/model/dsolve', 'process' ) # Ksolve must be scheduled after dsolve. moose.useClock( 5, '/model/kinetics/ksolve', 'process' ) stoich = moose.Stoich( '/model/kinetics/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = "/model/kinetics/##" print 'dsolve.numPools, num = ', dsolve.numPools, num b.vec[num-1].concInit *= 1.01 # Break symmetry.
def main(): # Schedule the whole lot moose.setClock( 4, 0.1 ) # for the computational objects moose.setClock( 5, 0.2 ) # clock for the solver moose.setClock( 8, 1.0 ) # for the plots # The wildcard uses # for single level, and ## for recursive. compartment = makeModel() ksolve = moose.Ksolve( '/model/compartment/ksolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve ksolve.stoich = stoich stoich.path = "/model/compartment/##" state = moose.SteadyState( '/model/compartment/state' ) #solver.method = "rk5" #mesh = moose.element( "/model/compartment/mesh" ) #moose.connect( mesh, "remesh", solver, "remesh" ) #moose.useClock( 4, '/model/compartment/##', 'process' ) moose.useClock( 5, '/model/compartment/ksolve', 'process' ) moose.useClock( 8, '/model/graphs/#', 'process' ) moose.reinit() state.stoich = stoich state.showMatrices() state.convergenceCriterion = 1e-7 for i in range( 0, 100 ): getState( ksolve, state ) # state.randomInit() # moose.start( 50.0 ) # Run the model for 100 seconds. # state.resettle() # print ksolve.nVec[0], sum( ksolve.nVec[0] ) # print state.nIter, state.status, state.stateType, state.nNegEigenvalues, state.nPosEigenvalues, state.solutionStatus moose.start( 100.0 ) # Run the model for 100 seconds. a = moose.element( '/model/compartment/a' ) b = moose.element( '/model/compartment/b' ) # move most molecules over to b b.conc = b.conc + a.conc * 0.9 a.conc = a.conc * 0.1 moose.start( 100.0 ) # Run the model for 100 seconds. # move most molecules back to a a.conc = a.conc + b.conc * 0.99 b.conc = b.conc * 0.01 moose.start( 100.0 ) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() quit()
def main(): utils.parser nml.loadNeuroML_L123('./two_cells_nml_1.8/two_cells.nml') #mumbl.loadMumbl("./two_cells_nml_1.8/mumbl.xml") table1 = utils.recordTarget('/tableA', '/cells/purkinjeGroup_0/Dend_37_41', 'vm') table2 = utils.recordTarget('/tableB', '/cells/granuleGroup_0/Soma_0', 'vm') moose.setClock(0, 5e-6) moose.useClock(0, '/##', 'process') moose.useClock(0, '/##', 'init') moose.reinit() utils.run(0.1) graphviz.writeGraphviz(__file__+".dot", ignore='/library')
def main(): # Schedule the whole lot moose.setClock( 4, 0.1 ) # for the computational objects moose.setClock( 5, 0.1 ) # clock for the solver moose.setClock( 8, 1.0 ) # for the plots # The wildcard uses # for single level, and ## for recursive. #compartment = makeModel() moose.loadModel( '../Genesis_files/M1719.cspace', '/model', 'ee' ) compartment = moose.element( 'model/kinetics' ) compartment.name = 'compartment' ksolve = moose.Ksolve( '/model/compartment/ksolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve #ksolve.stoich = stoich stoich.path = "/model/compartment/##" state = moose.SteadyState( '/model/compartment/state' ) moose.useClock( 5, '/model/compartment/ksolve', 'process' ) moose.useClock( 8, '/model/graphs/#', 'process' ) moose.reinit() state.stoich = stoich #state.showMatrices() state.convergenceCriterion = 1e-7 moose.le( '/model/graphs' ) a = moose.element( '/model/compartment/a' ) b = moose.element( '/model/compartment/b' ) c = moose.element( '/model/compartment/c' ) for i in range( 0, 100 ): getState( ksolve, state ) moose.start( 100.0 ) # Run the model for 100 seconds. b = moose.element( '/model/compartment/b' ) c = moose.element( '/model/compartment/c' ) # move most molecules over to b b.conc = b.conc + c.conc * 0.95 c.conc = c.conc * 0.05 moose.start( 100.0 ) # Run the model for 100 seconds. # move most molecules back to a c.conc = c.conc + b.conc * 0.95 b.conc = b.conc * 0.05 moose.start( 100.0 ) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() quit()
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 setup_model(): model_container = moose.Neutral('/model') pulse = moose.PulseGen('/model/pulse') pulse.level[0] = 1.0 pulse.delay[0] = 0.5 pulse.width[0] = 0.5 table = moose.Table('%s/tab' % (pulse.path)) moose.connect(table, 'requestOut', pulse, 'getOutputValue') moose.setClock(0, 0.1) moose.setClock(1, 0.1) moose.setClock(2, 0.1) moose.useClock(0, '%s,%s' % (pulse.path, table.path), 'process') return table
def run_simulation(container, simdt, simtime): """Schedule and run a simulation""" moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.setClock(3, simdt) moose.useClock(0, container.path + '/##[ISA=HSolve]', 'process') moose.useClock(1, container.path + '/##[ISA=Compartment]', 'init') moose.useClock(2, container.path + '/##[ISA=Compartment]', 'process') moose.useClock(3, container.path + '/##[ISA=PulseGen]', 'process') moose.useClock(3, container.path + '/##[ISA=Table]', 'process') moose.reinit() moose.start(simtime)
def setup_model(): model_container = moose.Neutral("/model") pulse = moose.PulseGen("/model/pulse") pulse.level[0] = 1.0 pulse.delay[0] = 0.5 pulse.width[0] = 0.5 table = moose.Table("%s/tab" % (pulse.path)) moose.connect(table, "requestData", pulse, "get_output") moose.setClock(0, 0.1) moose.setClock(1, 0.1) moose.setClock(2, 0.1) moose.useClock(0, "%s,%s" % (pulse.path, table.path), "process") return table
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'
def setupCurrentStepModel(testId, celltype, pulsearray, dt): """Setup a single cell simulation. simid - integer identifying the model celltype - str cell type pulsearray - an nx3 array with row[i] = (delay[i], width[i], level[i]) of current injection. """ modelContainer = moose.Neutral("/test%d" % (testId)) dataContainer = moose.Neutral("/data%d" % (testId)) cell = TCR("%s/TCR" % (modelContainer.path)) # moose.copy(cells.TCR.prototype, modelContainer.path)# pulsegen = moose.PulseGen("%s/pulse" % (modelContainer.path)) pulsegen.count = len(pulsearray) for ii in range(len(pulsearray)): pulsegen.delay[ii] = pulsearray[ii][0] pulsegen.width[ii] = pulsearray[ii][1] pulsegen.level[ii] = pulsearray[ii][2] moose.connect(pulsegen, "output", cell.soma, "injectMsg") somaVm = moose.Table("%s/vm" % (dataContainer.path)) moose.connect(somaVm, "requestOut", cell.soma, "getVm") pulseTable = moose.Table("%s/pulse" % (dataContainer.path)) moose.connect(pulseTable, "requestOut", pulsegen, "getOutputValue") setupClocks(dt) moose.useClock(0, "%s/##[ISA=Compartment]" % (cell.path), "init") moose.useClock(1, "%s/##[ISA=Compartment]" % (cell.path), "process") moose.useClock(7, pulsegen.path, "process") moose.useClock(8, "%s/##" % (dataContainer.path), "process") return {"cell": cell, "stimulus": pulsegen, "vmTable": somaVm, "stimTable": pulseTable}
def main(): utils.parser p = os.path.join(modeldir, "two_cells_nml_1.8/two_cells.nml") nml.loadNeuroML_L123(p) # mumbl.loadMumbl("./two_cells_nml_1.8/mumbl.xml") table1 = utils.recordTarget("/tableA", "/cells/purkinjeGroup_0/Dend_37_41", "vm") table2 = utils.recordTarget("/tableB", "/cells/granuleGroup_0/Soma_0", "vm") moose.setClock(0, 5e-6) moose.useClock(0, "/##", "process") moose.useClock(0, "/##", "init") moose.reinit() utils.run(0.1, verify=True) graphviz.writeGraphviz("test_mumble.dot", ignore="/library") utils.plotRecords({"Dend 37": table1, "Soma 0": table2}, outfile="%s.png" % sys.argv[0], subplot=True)
def testChemAlone(): nid = makeChemInCubeMesh() moose.le( '/n' ) makeChemPlots() moose.setClock( 5, 1e-2 ) moose.setClock( 6, 1e-2 ) moose.setClock( 7, 1.0 ) moose.setClock( 8, 1.0 ) moose.setClock( 9, 1.0 ) moose.useClock( 5, '/n/##', 'init' ) moose.useClock( 6, '/n/##', 'process' ) #moose.useClock( 7, '/graphs/#', 'process' ) moose.useClock( 8, '/graphs/#', 'process' ) moose.reinit() moose.start( 100 ) dumpPlots( 'chem.plot' ) # Make ksolver and rerun. ksolve = moose.GslStoich( '/n/solver' ) ksolve.path = '/n/##' ksolve.method = 'rk5' moose.useClock( 5, '/n/solver', 'process' ) moose.setClock( 5, 1 ) moose.setClock( 6, 1 ) moose.reinit() moose.start( 100 ) dumpPlots( 'kchem.plot' )
def testModel( useSolver ): elecDt = 20e-6 chemDt = 1e-4 plotDt = 2e-4 plotName = 'gn.plot' if ( useSolver ): elecDt = 50e-6 chemDt = 2e-3 plotName = 'mcs.plot' makeModel() 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/##[ISA=Compartment]', 'init' ) moose.useClock( 1, '/model/##[ISA=Compartment],/model/##[ISA=SpikeGen]', 'process' ) moose.useClock( 2, '/model/##[ISA=SynBase],/model/##[ISA=ChanBase],/model/##[ISA=CaConc]','process') moose.useClock( 8, '/graphs/#', 'process' ) moose.reinit() moose.start( 0.1 ) dumpPlots( plotName )
def example(): pg = moose.PulseGen('pulse') pg.delay[0] = 1.0 pg.width[0] = 0.2 pg.level[0] = 0.5 tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 0.01) moose.setClock(1, 0.01) moose.useClock(0, pg.path, 'process') moose.useClock(1, tab.path, 'process') moose.reinit() moose.start(5.0) tab.plainPlot('output_tabledemo.csv')
def setupCurrentStepModel(testId, celltype, pulsearray, dt): """Setup a single cell simulation. simid - integer identifying the model celltype - str cell type pulsearray - an nx3 array with row[i] = (delay[i], width[i], level[i]) of current injection. """ modelContainer = moose.Neutral('/test%d' % (testId)) dataContainer = moose.Neutral('/data%d' % (testId)) cell = TCR('%s/TCR' % (modelContainer.path)) # moose.copy(cells.TCR.prototype, modelContainer.path)# pulsegen = moose.PulseGen('%s/pulse' % (modelContainer.path)) pulsegen.count = len(pulsearray) for ii in range(len(pulsearray)): pulsegen.delay[ii] = pulsearray[ii][0] pulsegen.width[ii] = pulsearray[ii][1] pulsegen.level[ii] = pulsearray[ii][2] moose.connect(pulsegen, 'output', cell.soma, 'injectMsg') somaVm = moose.Table('%s/vm' % (dataContainer.path)) moose.connect(somaVm, 'requestOut', cell.soma, 'getVm') pulseTable = moose.Table('%s/pulse' % (dataContainer.path)) moose.connect(pulseTable, 'requestOut', pulsegen, 'getOutputValue') setupClocks(dt) moose.useClock(0, '%s/##[ISA=Compartment]' % (cell.path), 'init') moose.useClock(1, '%s/##[ISA=Compartment]' % (cell.path), 'process') moose.useClock(7, pulsegen.path, 'process') moose.useClock(8, '%s/##' % (dataContainer.path), 'process') return {'cell': cell, 'stimulus': pulsegen, 'vmTable': somaVm, 'stimTable': pulseTable }
def main(): utils.parser nml.loadNeuroML_L123('./two_cells_nml_1.8/two_cells.nml') #mumbl.loadMumbl("./two_cells_nml_1.8/mumbl.xml") table1 = utils.recordTarget('/tableA', '/cells/purkinjeGroup_0/Dend_37_41', 'vm') table2 = utils.recordTarget('/tableB', '/cells/granuleGroup_0/Soma_0', 'vm') moose.setClock(0, 5e-6) moose.useClock(0, '/##', 'process') moose.useClock(0, '/##', 'init') moose.reinit() utils.run(0.1, verify=True) graphviz.writeGraphviz(__file__ + ".dot", ignore='/library') utils.plotTables([table1, table2])
def test_one_to_one(size=2): pg = moose.PulseGen('pulsegen', size) for ix, ii in enumerate(pg.vec): pulse = moose.element(ii) pulse.delay[0] = 1.0 pulse.width[0] = 2.0 pulse.level[0] = (-1)**ix tab = moose.Table('pulseamp', size) moose.connect(tab, 'requestOut', pg, 'getOutputValue', 'OneToOne') moose.setClock(0, 0.1) moose.useClock(0, '/##', 'process') moose.start(5) for ii in tab.vec: t = moose.Table(ii).vector pylab.plot(t) pylab.show()
def main(): # Schedule the whole lot moose.setClock(4, 0.1) # for the computational objects moose.setClock(5, 0.2) # clock for the solver moose.setClock(8, 1.0) # for the plots # The wildcard uses # for single level, and ## for recursive. #compartment = makeModel() moose.loadModel('../../genesis/M1719.g', '/model', 'ee') compartment = moose.element('model/kinetics') compartment.name = 'compartment' ksolve = moose.Ksolve('/model/compartment/ksolve') stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = compartment stoich.ksolve = ksolve #ksolve.stoich = stoich stoich.path = "/model/compartment/##" state = moose.SteadyState('/model/compartment/state') moose.useClock(5, '/model/compartment/ksolve', 'process') moose.useClock(8, '/model/graphs/#', 'process') moose.reinit() state.stoich = stoich #state.showMatrices() state.convergenceCriterion = 1e-7 for i in range(0, 50): getState(ksolve, state) moose.start(100.0) # Run the model for 100 seconds. b = moose.element('/model/compartment/b') c = moose.element('/model/compartment/c') # move most molecules over to b b.conc = b.conc + c.conc * 0.95 c.conc = c.conc * 0.05 moose.start(100.0) # Run the model for 100 seconds. # move most molecules back to a c.conc = c.conc + b.conc * 0.95 b.conc = b.conc * 0.05 moose.start(100.0) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() quit()
def main(): runtime = 400 dt4 = 0.02 # for the diffusion dt5 = 0.2 # for the reaction # Set up clocks. The dsolver to know before assigning stoich moose.setClock( 4, dt4 ) moose.setClock( 5, dt5 ) model = moose.Neutral( '/model' ) cellId = loadElec() makeChemModel( cellId ) moose.useClock( 4, '/model/compartment/dsolve', 'process' ) # Ksolve must be scheduled after dsolve. moose.useClock( 5, '/model/compartment/ksolve', 'process' ) print("finished loading") moose.reinit() for i in range( 10 ): moose.start( runtime / 10 ) # Run the model for 10 seconds. # print 'done', i displayPlots( i ) print("finished running") """ a = moose.element( '/model/compartment/a' ) b = moose.element( '/model/compartment/b' ) s = moose.element( '/model/compartment/s' ) atot = sum( a.vec.conc ) btot = sum( b.vec.conc ) stot = sum( s.vec.conc ) print "a = ", a.vec.conc print "b = ", b.vec.conc print "s = ", s.vec.conc print 'tot = ', atot, btot, atot + btot + stot displayPlots() """ """ dsolve = moose.element( '/model/compartment/dsolve' ) x = dsolve.nVec[0] print dsolve.numPools, x, sum(x) print dsolve.nVec[1], sum( dsolve.nVec[1] ) print dsolve.nVec[2], sum( dsolve.nVec[2] ) print dsolve.nVec[3], sum( dsolve.nVec[3] ) """ quit()
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 for i in range(numDivs): moose.start(partialRuntime) updateGraphics(plotlist) # moose.element( '/model/elec/soma' ).inject = 0 # moose.start( 0.25 ) finalizeGraphics(plotlist, cPlotDt, ePlotDt)
def multilevel_pulsegen(): """Demonstrates a pulsegen with multiple levels, delays and widths.""" pg = moose.PulseGen('pulsegen') pg.count = 5 for ii in range(pg.count): pg.level[ii] = ii + 1 pg.width[ii] = 0.1 pg.delay[ii] = 0.5 * (ii + 1) tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 0.01) moose.useClock(0, '%s,%s' % (pg.path, tab.path), 'process') moose.reinit() moose.start(20.0) plt.plot(tab.vector) plt.show()
def run(self, runtime, simdt=1e-6): self.squid_axon.updateEk() moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.setClock(3, simdt) if not self.clocks_assigned: moose.useClock(0, '%s/#[TYPE=Compartment]' % (self.path), 'init') moose.useClock(0, '%s/#[TYPE=PulseGen]' % (self.path), 'process') moose.useClock(1, '%s/#[TYPE=Compartment]' % (self.path), 'process') moose.useClock(2, '%s/#[TYPE=HHChannel]' % (self.squid_axon.path), 'process') moose.useClock(3, '%s/#[TYPE=Table]' % (self.path), 'process') self.clocks_assigned = True moose.reinit() moose.start(runtime)
def stimulus_table_demo(): model = moose.Neutral('/model') data = moose.Neutral('/data') # This is the stimulus generator stimtable = moose.StimulusTable('/model/stim') recorded = moose.Table('/data/stim') moose.connect(recorded, 'requestOut', stimtable, 'getOutputValue') simtime = 100 simdt = 1e-3 # Inter-stimulus-intervals with rate=20/s rate = 20 np.random.seed(1) # ensure repeatability isi = np.random.exponential(rate, int(simtime / rate)) # The stimulus times are the cumulative sum of the inter-stimulus intervals. stimtimes = np.cumsum(isi) # Select only stimulus times that are within simulation time - # this may leave out some possible stimuli at the end, but the # exoected number of Poisson events within simtime is # simtime/rate. stimtimes = stimtimes[stimtimes < simtime] ts = np.arange(0, simtime, simdt) # Find the indices of table entries corresponding to time of stimulus stimidx = np.searchsorted(ts, stimtimes) stim = np.zeros(len(ts)) # Since linear interpolation is forced, we need at least three # consecutive entries to have same value to get correct # magnitude. And still we shall be off by at least one time step. indices = np.concatenate((stimidx - 1, stimidx, stimidx + 1)) stim[indices] = 1.0 stimtable.vector = stim stimtable.stepSize = 0 # This forces use of current time as x value for interpolation stimtable.stopTime = simtime moose.setClock(0, simdt) moose.useClock(0, '/model/##,/data/##', 'process') moose.reinit() moose.start(simtime) plt.plot(np.linspace(0, simtime, len(recorded.vector)), recorded.vector, 'r-+', label='generated stimulus') plt.plot(ts, stim, 'b-x', label='originally assigned values') plt.ylim((-1, 2)) plt.legend() plt.title('Exmaple of StimulusTable') plt.show()
def chirp(gen_name="chirp", amp=1, f0=1, f1=50, T=0.8, start=0.1, end=0.5, simdt=10E-5, phase=0, amp_offset=0): ''' Chirp injection stimultus ''' chirper = moose.element('/chirpgen') if moose.exists('/chirpgen') else moose.Neutral('/chirpgen') func_1 = moose.Func(chirper.path + '/' + gen_name) func_1.mode = 3 func_1.expr = '{A}*cos(2*pi*(({f1}-{f0})/{T})*x^2 + 2*pi*{f1}*x + {p})+{o}'.format(f0=f0, f1=f1, T=T, A=amp, p=phase, o=amp_offset) input = moose.StimulusTable(chirper.path + '/xtab') xarr = np.arange(start, end, simdt) input.vector = xarr input.startTime = 0.0 input.stepPosition = xarr[0] input.stopTime = xarr[-1] - xarr[0] moose.connect(input, 'output', func_1, 'xIn') moose.useClock(0, '%s/##[TYPE=StimulusTable]' % (chirper.path), 'process') moose.useClock(0, '%s/##[TYPE=Func]' % (chirper.path), 'process') return func_1
def main(): """ This example illustrates how to set up a kinetic solver and kinetic model using the scripting interface. Normally this would be done using the Shell::doLoadModel command, and normally would be coordinated by the SimManager as the base of the entire model. This example creates a bistable model having two enzymes and a reaction. One of the enzymes is autocatalytic. The model is set up to run using Exponential Euler integration. """ makeModel() gsolve = moose.Gsolve( '/model/compartment/gsolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = moose.element( '/model/compartment' ) stoich.ksolve = gsolve stoich.path = "/model/compartment/##" #solver.method = "rk5" #mesh = moose.element( "/model/compartment/mesh" ) #moose.connect( mesh, "remesh", solver, "remesh" ) moose.setClock( 5, 1.0 ) # clock for the solver moose.useClock( 5, '/model/compartment/gsolve', 'process' ) moose.reinit() moose.start( 100.0 ) # Run the model for 100 seconds. a = moose.element( '/model/compartment/a' ) b = moose.element( '/model/compartment/b' ) # move most molecules over to bgsolve b.conc = b.conc + a.conc * 0.9 a.conc = a.conc * 0.1 moose.start( 100.0 ) # Run the model for 100 seconds. # move most molecules back to a a.conc = a.conc + b.conc * 0.99 b.conc = b.conc * 0.01 moose.start( 100.0 ) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() quit()
def main(): solver = "gsl" makeModel() if (len(sys.argv) == 2): solver = sys.argv[1] stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = moose.element('/model/compartment') if (solver == 'gssa'): gsolve = moose.Gsolve('/model/compartment/ksolve') stoich.ksolve = gsolve else: ksolve = moose.Ksolve('/model/compartment/ksolve') stoich.ksolve = ksolve stoich.path = "/model/compartment/##" #solver.method = "rk5" #mesh = moose.element( "/model/compartment/mesh" ) #moose.connect( mesh, "remesh", solver, "remesh" ) moose.setClock(5, 1.0) # clock for the solver moose.useClock(5, '/model/compartment/ksolve', 'process') moose.reinit() moose.start(100.0) # Run the model for 100 seconds. a = moose.element('/model/compartment/a') b = moose.element('/model/compartment/b') # move most molecules over to b b.conc = b.conc + a.conc * 0.9 a.conc = a.conc * 0.1 moose.start(100.0) # Run the model for 100 seconds. # move most molecules back to a a.conc = a.conc + b.conc * 0.99 b.conc = b.conc * 0.01 moose.start(100.0) # Run the model for 100 seconds. # Iterate through all plots, dump their contents to data.plot. displayPlots() try: raw_input('Press any key to quit') except NameError as e: input('Press any key to quit')
def main(): solver = "gsl" makeModel() if (len(sys.argv) == 2): solver = sys.argv[1] stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = moose.element('/model/compartment') if (solver == 'gssa'): gsolve = moose.Gsolve('/model/compartment/ksolve') stoich.ksolve = gsolve else: ksolve = moose.Ksolve('/model/compartment/ksolve') stoich.ksolve = ksolve stoich.path = "/model/compartment/##" moose.setClock(5, 1.0) # clock for the solver moose.useClock(5, '/model/compartment/ksolve', 'process') runSim() makeDisplay() print("Hit 'enter' to exit") sys.stdin.read(1) quit()
def simulate(self, simTime, simDt, plotDt=None): '''Simulate the cable ''' self.simDt = simDt self.setupDUT() # Setup clocks moose.setClock(0, self.simDt) # Use clocks moose.useClock(0, '/##', 'process') moose.useClock(0, '/##', 'init') utils.dump("STEP", [ "Simulating cable for {} sec".format(simTime), " simDt: %s" % self.simDt ]) utils.verify() moose.reinit() self.setupSolver() moose.start(simTime)
def main(): """ Example of using multithreading to run a MOOSE simulation in parallel with querying MOOSE objects involved. See the documentatin of the classes to get an idea of this demo's function. """ pg = moose.PulseGen('pg') pg.firstDelay = 10.0 pg.firstLevel = 10.0 pg.firstWidth = 5.0 tab = moose.Table('tab') moose.connect(tab, 'requestOut', pg, 'getOutputValue') moose.setClock(0, 1.0) moose.useClock(0, 'pg,tab', 'process') t1 = WorkerThread(10000) t2 = StatusThread(tab) t2.start() t1.start() status_queue.get(True) tab.xplot('threading_demo.dat', 'pulsegen_output') print(('Ending threading_demo: final length of table', len(tab.vector)))
def main(): utils.parser p = os.path.join(modeldir, 'two_cells_nml_1.8/two_cells.nml') nml.loadNeuroML_L123(p) #mumbl.loadMumbl("./two_cells_nml_1.8/mumbl.xml") table1 = utils.recordTarget('/tableA', '/cells/purkinjeGroup_0/Dend_37_41', 'vm') table2 = utils.recordTarget('/tableB', '/cells/granuleGroup_0/Soma_0', 'vm') moose.setClock(0, 5e-6) moose.useClock(0, '/##', 'process') moose.useClock(0, '/##', 'init') moose.reinit() utils.run(0.1, verify=True) graphviz.writeGraphviz('test_mumble.dot', ignore='/library') utils.plotRecords({ 'Dend 37': table1, 'Soma 0': table2 }, outfile='%s.png' % sys.argv[0], subplot=True)
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 setupSteadyState(simdt, plotDt): ksolve = moose.Ksolve('/model/kinetics/ksolve') stoich = moose.Stoich('/model/kinetics/stoich') stoich.compartment = moose.element('/model/kinetics') stoich.ksolve = ksolve #ksolve.stoich = stoich stoich.path = "/model/kinetics/##" state = moose.SteadyState('/model/kinetics/state') #### Set clocks here moose.useClock(4, "/model/kinetics/##[]", "process") moose.setClock(4, float(simdt)) moose.setClock(5, float(simdt)) moose.useClock(5, '/model/kinetics/ksolve', 'process') moose.useClock(8, '/model/graphs/#', 'process') moose.setClock(8, float(plotDt)) moose.reinit() state.stoich = stoich state.showMatrices() state.convergenceCriterion = 1e-8 return ksolve, state
def simulate(self, simTime, simDt=1e-3, plotDt=None): '''Simulate the cable ''' if plotDt is None: plotDt = simDt / 2 self.simDt = simDt self.plotDt = plotDt self.setupDUT() # Setup clocks utils.dump("STEP", "Setting up the clocks ... ") moose.setClock(0, self.simDt) moose.setClock(1, self.simDt) moose.setClock(2, self.simDt) ## Use clocksc moose.useClock(0, '/cable/##'.format(self.cablePath), 'process') moose.useClock(1, '/cable/##'.format(self.cablePath), 'init') moose.useClock(2, '{}/##'.format(self.tablePath), 'process') utils.dump("STEP", [ "Simulating cable for {} sec".format(simTime), " simDt: %s, plotDt: %s" % (self.simDt, self.plotDt) ]) self.setupHSolve() moose.reinit() utils.verify() moose.start(simTime)
def test_elec_alone(dump_dir): 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.plot' ) dump_data(dump_dir, 'instab') # 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 ) + '.plot' ) dump_data(dump_dir, 'h_instab' + str(dt))
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)
def main(): dt4 = 0.01 dt5 = 0.01 runtime = 10.0 # seconds # Set up clocks. The dsolver to know before assigning stoich moose.setClock( 4, dt4 ) moose.setClock( 5, dt5 ) makeModel() moose.useClock( 4, '/model/compartment/dsolve', 'process' ) # Ksolve must be scheduled after dsolve. moose.useClock( 5, '/model/compartment/ksolve', 'process' ) moose.reinit() moose.start( runtime ) # Run the model a = moose.element( '/model/compartment/a' ) b = moose.element( '/model/compartment/b' ) c = moose.element( '/model/compartment/c' ) d = moose.element( '/model/compartment/d' ) atot = sum( a.vec.conc ) btot = sum( b.vec.conc ) ctot = sum( c.vec.conc ) dtot = sum( d.vec.conc ) print(('tot = ', atot, btot, ctot, dtot, ' (b+c)=', btot+ctot)) displayPlots() moose.start( runtime ) # Run the model atot = sum( a.vec.conc ) btot = sum( b.vec.conc ) ctot = sum( c.vec.conc ) dtot = sum( d.vec.conc ) print(('tot = ', atot, btot, ctot, dtot, ' (b+c)=', btot+ctot)) quit()
def schedule(): moose.setClock(0, dt) moose.setClock(1, dt) moose.setClock(2, dt) moose.setClock(3, dt) moose.useClock(0, '/model/##[ISA=Compartment]', 'init') moose.useClock(1, '/model/##', 'process') moose.useClock(3, '/data/##', 'process') moose.reinit()
def simulate(runTime, dt): """ Simulate the cable """ moose.useClock(0, '/cable/##', 'process') moose.useClock(0, '/cable/##', 'init') moose.useClock(1, '/##', 'process') moose.reinit() setupSolver(hsolveDt=dt) utils.verify() moose.start(runTime)
def run_simulation(self): # Setup data recording data = moose.Neutral('/data') Vm = moose.Table('/data/Vm') moose.connect(Vm, 'requestData', self.compartments[0], 'get_Vm') # Now schedule the sequence of operations and time resolutions moose.setClock(0, self.dt) moose.setClock(1, self.dt) moose.setClock(2, self.dt) moose.setClock(3, self.dt) moose.setClock(4, self.dt) #quite a hack: current_clamp = self.current_clamp # useClock: First argument is clock no. # Second argument is a wildcard path matching all elements of type Compartment # Last argument is the processing function to be executed at each tick of clock 0 moose.useClock(0, '/model/#[TYPE=Compartment]', 'init') moose.useClock(1, '/model/#[TYPE=Compartment]', 'process') moose.useClock(2, Vm.path, 'process') moose.useClock(3, current_clamp.path, 'process') moose.useClock(4, '/model/#/#[TYPE=HHChannel]', 'process') # Now initialize everything and get set moose.reinit() moose.start(self.sim_time) #handle to the global clock: clock = moose.Clock('/clock') #vectors: self.rec_v = Vm.vec self.t_final = clock.currentTime
def simulate( runTime, dt): """ Simulate the cable """ moose.useClock(0, '/cable/##', 'process') moose.useClock(0, '/cable/##', 'init') moose.useClock(1, '/##', 'process') moose.reinit() setupSolver( hsolveDt = dt ) t = time.time( ) moose.start( runTime ) print( 'Time taken to simulate %f = %f' % ( runTime, time.time() - t ) )
def test_symcompartment(): """This example demonstrates the use of SymCompartment class of MOOSE.""" model = moose.Neutral('model') soma = moose.SymCompartment('%s/soma' % (model.path)) soma.Em = -60e-3 soma.Rm = 1000402560 soma.Cm = 2.375043912e-11 soma.Ra = 233957.7812 d1 = moose.SymCompartment('%s/d1' % (model.path)) d1.Rm = 397887392 d1.Cm = 2.261946489e-12 d1.Ra = 24867960 d2 = moose.SymCompartment('%s/d2' % (model.path)) d2.Rm = 2.877870285e+10 d2.Cm = 8.256105218e-13 d2.Ra = 20906072 moose.connect(d1, 'proximal', soma, 'distal') moose.connect(d2, 'proximal', soma, 'distal') moose.connect(d1, 'sibling', d2, 'sibling') pg = moose.PulseGen('/model/pulse') pg.delay[0] = 10e-3 pg.width[0] = 20e-3 pg.level[0] = 1e-6 pg.delay[1] = 1e9 moose.connect(pg, 'output', d1, 'injectMsg') data = moose.Neutral('/data') tab_soma = moose.Table('%s/soma_Vm' % (data.path)) tab_d1 = moose.Table('%s/d1_Vm' % (data.path)) tab_d2 = moose.Table('%s/d2_Vm' % (data.path)) moose.connect(tab_soma, 'requestOut', soma, 'getVm') moose.connect(tab_d1, 'requestOut', d1, 'getVm') moose.connect(tab_d2, 'requestOut', d2, 'getVm') moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.useClock( 0, '/model/##[ISA=Compartment]', 'init' ) # This is allowed because SymCompartment is a subclass of Compartment moose.useClock(1, '/model/##', 'process') moose.useClock(2, '/data/##[ISA=Table]', 'process') moose.reinit() moose.start(simtime) t = np.linspace(0, simtime, len(tab_soma.vector)) data_matrix = np.vstack((t, tab_soma.vector, tab_d1.vector, tab_d2.vector)) np.savetxt('symcompartment.txt', data_matrix.transpose()) pylab.plot(t, tab_soma.vector, label='Vm_soma') pylab.plot(t, tab_d1.vector, label='Vm_d1') pylab.plot(t, tab_d2.vector, label='Vm_d2') pylab.show()
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 test_symcompartment(): model = moose.Neutral('model') soma = moose.SymCompartment('%s/soma' % (model.path)) soma.Em = -60e-3 soma.Rm = 1e9 soma.Cm = 1e-11 soma.Ra = 1e6 d1 = moose.SymCompartment('%s/d1' % (model.path)) d1.Rm = 1e8 d1.Cm = 1e-10 d1.Ra = 1e7 d2 = moose.SymCompartment('%s/d2' % (model.path)) d2.Rm = 1e8 d2.Cm = 1e-10 d2.Ra = 2e7 moose.connect(d1, 'proximal', soma, 'distal') moose.connect(d2, 'proximal', soma, 'distal') moose.connect(d1, 'sibling', d2, 'sibling') pg = moose.PulseGen('/model/pulse') pg.delay[0] = 10e-3 pg.width[0] = 20e-3 pg.level[0] = 1e-6 pg.delay[1] = 1e9 moose.connect(pg, 'output', d1, 'injectMsg') data = moose.Neutral('/data') tab_soma = moose.Table('%s/soma_Vm' % (data.path)) tab_d1 = moose.Table('%s/d1_Vm' % (data.path)) tab_d2 = moose.Table('%s/d2_Vm' % (data.path)) moose.connect(tab_soma, 'requestOut', soma, 'getVm') moose.connect(tab_d1, 'requestOut', d1, 'getVm') moose.connect(tab_d2, 'requestOut', d2, 'getVm') moose.setClock(0, simdt) moose.setClock(1, simdt) moose.setClock(2, simdt) moose.useClock( 0, '/model/##[ISA=Compartment]', 'init' ) # This is allowed because SymCompartment is a subclass of Compartment moose.useClock(1, '/model/##', 'process') moose.useClock(2, '/data/##[ISA=Table]', 'process') moose.reinit() moose.start(simtime) t = np.linspace(0, simtime, len(tab_soma.vector)) data_matrix = np.vstack((t, tab_soma.vector, tab_d1.vector, tab_d2.vector)) np.savetxt('symcompartment.txt', data_matrix.transpose()) pylab.plot(t, tab_soma.vector, label='Vm_soma') pylab.plot(t, tab_d1.vector, label='Vm_d1') pylab.plot(t, tab_d2.vector, label='Vm_d2') pylab.show()
def example(): model = moose.Neutral('/model') comp = moose.Compartment('/model/c') hdfwriter = moose.HDF5DataWriter('h') hdfwriter.mode = 2 # Truncate existing file moose.connect(hdfwriter, 'requestOut', comp, 'getVm') moose.connect(hdfwriter, 'requestOut', comp, 'getIm') hdfwriter.filename = 'output_hdfdemo.h5' hdfwriter.compressor = 'zlib' hdfwriter.compression = 7 # Flush data from memory to disk after accumulating every 1K entries. hdfwriter.flushLimit = 1024 # We allow simple attributes of type string, double and long. # This allows for file-level metadata/annotation. hdfwriter.stringAttr['note'] = 'This is a test.' # All paths are taken relative to the root. The last token is the name # of the attribute. hdfwriter.doubleAttr['{}/vm/a_double_attribute'.format( comp.path)] = 3.141592 hdfwriter.longAttr['an_int_attribute'] = 8640 # In addition, vectors of string, long and double can also be stored # as attributes. hdfwriter.stringVecAttr['stringvec'] = ['I wonder', 'why', 'I wonder'] hdfwriter.doubleVecAttr['{}/dvec'.format(comp.path)] = [3.141592, 2.71828] hdfwriter.longVecAttr['{}/lvec'.format(comp.path)] = [3, 14, 1592, 271828] vm_tab = moose.Table('Vm') moose.connect(vm_tab, 'requestOut', comp, 'getVm') moose.setClock(0, 1e-3) moose.setClock(1, 1e-3) moose.setClock(2, 1e-3) moose.useClock(0, '/model/c', 'init') moose.useClock(1, '/##[TYPE!=HDF5DataWriter]', 'process') moose.useClock(2, '/##[TYPE=HDF5DataWriter]', 'process') moose.reinit() comp.inject = 0.1 moose.start(30.0) hdfwriter.close() vm_tab.plainPlot('hdfdemo_Vm.csv') print(('Finished simulation. Data was saved in', hdfwriter.filename))