def _configureSolvers(self): if not hasattr(self, 'chemid'): return if not hasattr(self, 'dendCompt'): raise BuildError("configureSolvers: no chem meshes defined.") dmksolve = moose.Ksolve(self.dendCompt.path + '/ksolve') dmdsolve = moose.Dsolve(self.dendCompt.path + '/dsolve') dmstoich = moose.Stoich(self.dendCompt.path + '/stoich') dmstoich.compartment = self.dendCompt dmstoich.ksolve = dmksolve dmstoich.dsolve = dmdsolve dmstoich.path = self.dendCompt.path + "/##" # Below we have code that only applies if there are spines # Put in spine solvers. Note that these get info from the dendCompt if hasattr(self, 'spineCompt'): if self.useGssa: smksolve = moose.Gsolve(self.spineCompt.path + '/ksolve') else: smksolve = moose.Ksolve(self.spineCompt.path + '/ksolve') smdsolve = moose.Dsolve(self.spineCompt.path + '/dsolve') smstoich = moose.Stoich(self.spineCompt.path + '/stoich') smstoich.compartment = self.spineCompt smstoich.ksolve = smksolve smstoich.dsolve = smdsolve smstoich.path = self.spineCompt.path + "/##" # Put in PSD solvers. Note that these get info from the dendCompt if self.useGssa: pmksolve = moose.Gsolve(self.psdCompt.path + '/ksolve') else: pmksolve = moose.Ksolve(self.psdCompt.path + '/ksolve') pmdsolve = moose.Dsolve(self.psdCompt.path + '/dsolve') pmstoich = moose.Stoich(self.psdCompt.path + '/stoich') pmstoich.compartment = self.psdCompt pmstoich.ksolve = pmksolve pmstoich.dsolve = pmdsolve pmstoich.path = self.psdCompt.path + "/##" # Put in cross-compartment diffusion between ksolvers dmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve) # Put in cross-compartment reactions between ksolvers smstoich.buildXreacs(pmstoich) #pmstoich.buildXreacs( smstoich ) smstoich.buildXreacs(dmstoich) dmstoich.filterXreacs() smstoich.filterXreacs() pmstoich.filterXreacs() # set up the connections so that the spine volume scaling can happen self.elecid.setSpineAndPsdMesh(self.spineCompt, self.psdCompt) self.elecid.setSpineAndPsdDsolve(smdsolve, pmdsolve)
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 makeModel(): if len(sys.argv) == 1: useGsolve = True else: useGsolve = (sys.argv[1] == 'True') # create container for model model = moose.Neutral('model') compartment = moose.CubeMesh('/model/compartment') compartment.volume = 1e-22 # the mesh is created automatically by the compartment moose.le('/model/compartment') mesh = moose.element('/model/compartment/mesh') # create molecules and reactions a = moose.Pool('/model/compartment/a') b = moose.Pool('/model/compartment/b') # create functions of time f1 = moose.Function('/model/compartment/f1') f2 = moose.Function('/model/compartment/f2') # connect them up for reactions moose.connect(f1, 'valueOut', a, 'setConc') moose.connect(f2, 'valueOut', b, 'increment') # Assign parameters a.concInit = 0 b.concInit = 1 #f1.numVars = 1 #f2.numVars = 1 f1.expr = '1 + sin(t)' f2.expr = '10 * cos(t)' # Create the output tables graphs = moose.Neutral('/model/graphs') outputA = moose.Table2('/model/graphs/nA') outputB = moose.Table2('/model/graphs/nB') # connect up the tables moose.connect(outputA, 'requestOut', a, 'getN') moose.connect(outputB, 'requestOut', b, 'getN') # Set up the solvers if useGsolve: gsolve = moose.Gsolve('/model/compartment/gsolve') gsolve.useClockedUpdate = True else: gsolve = moose.Ksolve('/model/compartment/gsolve') stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = compartment stoich.ksolve = gsolve stoich.path = '/model/compartment/##' ''' ''' # We need a finer timestep than the default 0.1 seconds, # in order to get numerical accuracy. for i in range(10, 19): moose.setClock(i, 0.1) # for computational objects
def makeModel(): # create container for model r0 = 2e-6 # m r1 = 1e-6 # m num = 100 diffLength = 1e-6 # m len = num * diffLength # m diffConst = 10e-12 #motorRate = 1e-6 #diffConst = 0 motorRate = 0 model = moose.Neutral('model') compartment = moose.CylMesh('/model/compartment') compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = len compartment.diffLength = diffLength assert (compartment.numDiffCompts == num) # create molecules and reactions a = moose.Pool('/model/compartment/a') b = moose.Pool('/model/compartment/b') c = moose.Pool('/model/compartment/c') d = moose.Pool('/model/compartment/d') r1 = moose.Reac('/model/compartment/r1') moose.connect(r1, 'sub', b, 'reac') moose.connect(r1, 'sub', d, 'reac') moose.connect(r1, 'prd', c, 'reac') r1.Kf = 1000.0 # 1/(mM.sec) r1.Kb = 1 # 1/sec # Assign parameters a.diffConst = diffConst b.diffConst = diffConst / 2.0 b.motorConst = motorRate c.diffConst = diffConst d.diffConst = diffConst # Make solvers ksolve = moose.Gsolve('/model/compartment/ksolve') dsolve = moose.Dsolve('/model/compartment/dsolve') stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve os.kill(PID, signal.SIGUSR1) stoich.path = "/model/compartment/##" print((dsolve.numPools)) assert (dsolve.numPools == 4) a.vec.concInit = concA b.vec.concInit = concA / 5.0 c.vec.concInit = concA d.vec.concInit = concA / 5.0 for i in range(num): d.vec[i].concInit = concA * 2 * i / num
def _configureSolvers(self): dmksolve = moose.Ksolve(self.dendCompt.path + '/ksolve') dmdsolve = moose.Dsolve(self.dendCompt.path + '/dsolve') dmstoich = moose.Stoich(self.dendCompt.path + '/stoich') dmstoich.compartment = self.dendCompt dmstoich.ksolve = dmksolve dmstoich.dsolve = dmdsolve dmstoich.path = self.dendCompt.path + "/##" print 'Dend solver: numPools = ', dmdsolve.numPools, \ ', nvox= ', self.dendCompt.mesh.num, dmksolve.numAllVoxels # Put in spine solvers. Note that these get info from the dendCompt if self.useGssa: smksolve = moose.Gsolve(self.spineCompt.path + '/ksolve') else: smksolve = moose.Ksolve(self.spineCompt.path + '/ksolve') smdsolve = moose.Dsolve(self.spineCompt.path + '/dsolve') smstoich = moose.Stoich(self.spineCompt.path + '/stoich') smstoich.compartment = self.spineCompt smstoich.ksolve = smksolve smstoich.dsolve = smdsolve smstoich.path = self.spineCompt.path + "/##" print 'spine num Pools = ', smstoich.numAllPools, \ ', nvox= ', self.spineCompt.mesh.num, smksolve.numAllVoxels # Put in PSD solvers. Note that these get info from the dendCompt if self.useGssa: pmksolve = moose.Gsolve(self.psdCompt.path + '/ksolve') else: pmksolve = moose.Ksolve(self.psdCompt.path + '/ksolve') pmdsolve = moose.Dsolve(self.psdCompt.path + '/dsolve') pmstoich = moose.Stoich(self.psdCompt.path + '/stoich') pmstoich.compartment = self.psdCompt pmstoich.ksolve = pmksolve pmstoich.dsolve = pmdsolve pmstoich.path = self.psdCompt.path + "/##" print 'psd num Pools = ', pmstoich.numAllPools, \ ', voxels=', self.psdCompt.mesh.num, pmksolve.numAllVoxels # Put in cross-compartment diffusion between ksolvers dmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve) # Put in cross-compartment reactions between ksolvers smstoich.buildXreacs(pmstoich) smstoich.buildXreacs(dmstoich) #smstoich.buildXreacs( pmstoich ) dmstoich.filterXreacs() smstoich.filterXreacs() pmstoich.filterXreacs()
def setCompartmentSolver(modelRoot, solver): comptlist = dict( (c, c.volume) for c in moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]')) comptVol = {} compts = [] vol = [v for k, v in comptlist.items()] volumeSort = sorted(vol) for k, v in comptlist.items(): comptVol[k] = v for volSor in volumeSort: for a, b in comptVol.items(): if b == volSor: compts.append(a) #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))] if (len(compts) == '0'): print("Atleast one compartment is required ") return else: if (len(compts) > 3): print("Warning: setSolverOnCompt Cannot handle ", len(compts), " chemical compartments\n") return elif (len(compts) > 1): positionCompt(compts) if solver != 'ee' or solver != "Exponential Euler": fixXreacs(modelRoot) for compt in compts: if solver != 'ee': if (solver == 'gsl') or (solver == 'Runge Kutta'): ksolve = moose.Ksolve(compt.path + '/ksolve') if (solver == 'gssa') or (solver == 'Gillespie'): ksolve = moose.Gsolve(compt.path + '/gsolve') dsolve = moose.Dsolve(compt.path + '/dsolve') stoich = moose.Stoich(compt.path + '/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = compt.path + "/##" ksolveList = moose.wildcardFind(modelRoot + '/##[ISA=Ksolve]') dsolveList = moose.wildcardFind(modelRoot + '/##[ISA=Dsolve]') stoichList = moose.wildcardFind(modelRoot + '/##[ISA=Stoich]') i = 0 while (i < len(dsolveList) - 1): dsolveList[i + 1].buildMeshJunctions(dsolveList[i]) i += 1 print("Solver is added to model path %s" % modelRoot) '''
def makeSolvers(): 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')
def setCompartmentSolver(modelRoot, solver): compt = moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]') if (solver == 'gsl') or (solver == 'Runge Kutta'): ksolve = moose.Ksolve(compt[0].path + '/ksolve') if (solver == 'gssa') or (solver == 'Gillespie'): ksolve = moose.Gsolve(compt[0].path + '/gsolve') if (solver != 'ee'): stoich = moose.Stoich(compt[0].path + '/stoich') stoich.compartment = compt[0] stoich.ksolve = ksolve stoich.path = compt[0].path + "/##" for x in moose.wildcardFind(modelRoot + '/data/graph#/#'): x.tick = 18
def setup_solvers( compt, stochastic ): global args stoich = moose.Stoich( "%s/stoich" % compt.path) if stochastic: _logger.info("Setting up Stochastic solver in %s" % compt.path ) s = moose.Gsolve('%s/gsolve' % compt.path) s.useClockedUpdate = True else: s = moose.Ksolve('%s/ksolve' % compt.path) _logger.info( 'Using method %s' % s.method ) stoich.compartment = moose.element(compt.path) stoich.ksolve = s stoich.path = '%s/##' % compt.path
def setCompartmentSolver(modelRoot, solver): """ If Solver type is 'gsl' or 'gssa' do add Solver if 'ee' nothing """ if solver != 'ee': comptlist = dict( (c.volume, c) for c in moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]')) vollist = sorted(comptlist.keys()) compts = [comptlist[key] for key in vollist] #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))] if (len(compts) > 1): positionCompt(compts) fixXreacs(modelRoot) vollist = sorted(comptlist.keys()) compts = [comptlist[key] for key in vollist] #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))] for compt in compts: if solver != 'ee': if solver.lower() in ['gsl', 'runge kutta', 'lsoda']: ksolve = moose.Ksolve(compt.path + '/ksolve') elif solver.lower() in ['gssa', 'gillespie']: ksolve = moose.Gsolve(compt.path + '/gsolve') if (len(compts) > 1): dsolve = moose.Dsolve(compt.path + '/dsolve') stoich = moose.Stoich(compt.path + '/stoich') stoich.ksolve = ksolve if (len(compts) > 1): stoich.dsolve = dsolve stoich.compartment = compt stoich.path = compt.path + "/##" dsolveList = moose.wildcardFind(modelRoot + '/##[ISA=Dsolve]') i = 0 while (i < len(dsolveList) - 1): dsolveList[i + 1].buildMeshJunctions(dsolveList[i]) i += 1 if not modelRoot[:1].startswith('/'): modelRoot = '/' + modelRoot print(" Solver is added to model path `%s` with `%s` solver" % (modelRoot, solver))
def switchSolvers(solver): if (moose.exists('model/kinetics/stoich')): moose.delete('/model/kinetics/stoich') moose.delete('/model/kinetics/ksolve') compt = moose.element('/model/kinetics') if (solver == 'gsl'): ksolve = moose.Ksolve('/model/kinetics/ksolve') if (solver == 'gssa'): ksolve = moose.Gsolve('/model/kinetics/ksolve') if (solver != 'ee'): stoich = moose.Stoich('/model/kinetics/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.path = "/model/kinetics/##"
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 disableModel(self, modelPath): compt = moose.wildcardFind(modelPath + '/##[ISA=ChemCompt]') if compt: if moose.exists(compt[0].path+'/ksolve'): ksolve = moose.Ksolve( compt[0].path+'/ksolve' ) ksolve.tick = -1 if moose.exists(compt[0].path+'/gsolve'): gsolve = moose.Gsolve( compt[0].path+'/gsolve' ) gsolve.tick = -1 # if moose.exists(compt[0].path+'/stoich'): # stoich = moose.Stoich( compt[0].path+'/stoich' ) # stoich.tick = -1 else : neurons = moose.wildcardFind(modelPath + "/model/cells/##[ISA=Neuron]") for neuron in neurons: #print(neuron) solver = moose.element(neuron.path + "/hsolve") # print("Disabling => ", solver) solver.tick = -1 for table in moose.wildcardFind( modelPath+'/data/graph#/#' ): table.tick = -1
def setCompartmentSolver(modelRoot, solver): compts = moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]') if (len(compts) > 3): print "Warning: setSolverOnCompt Cannot handle ", len(compts), " chemical compartments\n" return if (len(compts) == 2): positionCompt(compts[0], compts[1].dy, True) if (len(compts) == 3): positionCompt(compts[0], compts[1].dy, True) positionCompt(compts[2], compts[1].dy, False) for compt in compts: if (solver == 'gsl') or (solver == 'Runge Kutta'): ksolve = moose.Ksolve(compt.path + '/ksolve') if (solver == 'gssa') or (solver == 'Gillespie'): ksolve = moose.Gsolve(compt.path + '/gsolve') if (solver != 'ee'): stoich = moose.Stoich(compt.path + '/stoich') stoich.compartment = compt stoich.ksolve = ksolve if moose.exists(compt.path): stoich.path = compt.path + "/##" stoichList = moose.wildcardFind(modelRoot + '/##[ISA=Stoich]') if len(stoichList) == 2: stoichList[1].buildXreacs(stoichList[0]) if len(stoichList) == 3: stoichList[1].buildXreacs(stoichList[0]) stoichList[1].buildXreacs(stoichList[2]) for i in stoichList: i.filterXreacs()
def setCompartmentSolver(modelRoot, solver): compts = moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]') for compt in compts: if (solver == 'gsl') or (solver == 'Runge Kutta'): ksolve = moose.Ksolve(compt.path + '/ksolve') if (solver == 'gssa') or (solver == 'Gillespie'): ksolve = moose.Gsolve(compt.path + '/gsolve') if (solver != 'ee'): stoich = moose.Stoich(compt.path + '/stoich') stoich.compartment = compt stoich.ksolve = ksolve if moose.exists(compt.path): stoich.path = compt.path + "/##" stoichList = moose.wildcardFind(modelRoot + '/##[ISA=Stoich]') if len(stoichList) == 2: stoichList[1].buildXreacs(stoichList[0]) if len(stoichList) == 3: stoichList[1].buildXreacs(stoichList[0]) stoichList[1].buildXreacs(stoichList[2]) for i in stoichList: i.filterXreacs() print(" Solver is added to model path %s" % modelRoot)
def main(): solver = "gssa" moose.Neutral('/model') moose.CubeMesh('/model/kinetics') moose.Pool('/model/kinetics/A') #delete if exists if (moose.exists('model/kinetics/stoich')): moose.delete('/model/kinetics/stoich') moose.delete('/model/kinetics/ksolve') #create solver compt = moose.element('/model/kinetics') ksolve = moose.Gsolve('/model/kinetics/ksolve') stoich = moose.Stoich('/model/kinetics/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.path = "/model/kinetics/##" print(" before reinit") moose.reinit() print(" After reinit") moose.start(10) print("Done")
def makeModel(): model = moose.Neutral('/model') # Make neuronal model. It has no channels, just for geometry cell = moose.loadModel('./spinyNeuron.p', '/model/cell', 'Neutral') # We don't want the cell to do any calculations. Disable everything. for i in moose.wildcardFind('/model/cell/##'): i.tick = -1 # create container for model model = moose.element('/model') chem = moose.Neutral('/model/chem') # The naming of the compartments is dicated by the places that the # chem model expects to be loaded. compt0 = moose.NeuroMesh('/model/chem/compt0') compt0.separateSpines = 1 compt0.geometryPolicy = 'cylinder' compt1 = moose.SpineMesh('/model/chem/compt1') moose.connect(compt0, 'spineListOut', compt1, 'spineList', 'OneToOne') compt2 = moose.PsdMesh('/model/chem/compt2') moose.connect(compt0, 'psdListOut', compt2, 'psdList', 'OneToOne') #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' ) makeChemModel(compt0) # Populate all 3 compts with the chem system. makeChemModel(compt1) makeChemModel(compt2) compt0.diffLength = 2e-6 # This will be over 100 compartments. # This is the magic command that configures the diffusion compartments. compt0.subTreePath = cell.path + "/##" moose.showfields(compt0) # Build the solvers. No need for diffusion in this version. ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve') ksolve1 = moose.Gsolve('/model/chem/compt1/ksolve') ksolve2 = moose.Gsolve('/model/chem/compt2/ksolve') #dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' ) #dsolve1 = moose.Dsolve( '/model/chem/compt1/dsolve' ) #dsolve2 = moose.Dsolve( '/model/chem/compt2/dsolve' ) stoich0 = moose.Stoich('/model/chem/compt0/stoich') stoich1 = moose.Stoich('/model/chem/compt1/stoich') stoich2 = moose.Stoich('/model/chem/compt2/stoich') # Configure solvers stoich0.compartment = compt0 stoich1.compartment = compt1 stoich2.compartment = compt2 stoich0.ksolve = ksolve0 stoich1.ksolve = ksolve1 stoich2.ksolve = ksolve2 #stoich0.dsolve = dsolve0 #stoich1.dsolve = dsolve1 #stoich2.dsolve = dsolve2 stoich0.path = '/model/chem/compt0/#' stoich1.path = '/model/chem/compt1/#' stoich2.path = '/model/chem/compt2/#' assert (stoich0.numVarPools == 3) assert (stoich0.numProxyPools == 0) assert (stoich0.numRates == 4) assert (stoich1.numVarPools == 3) assert (stoich1.numProxyPools == 0) #assert( stoich1.numRates == 4 ) assert (stoich2.numVarPools == 3) assert (stoich2.numProxyPools == 0) #assert( stoich2.numRates == 4 ) #dsolve0.buildNeuroMeshJunctions( dsolve1, dsolve2 ) stoich0.buildXreacs(stoich1) stoich1.buildXreacs(stoich2) stoich0.filterXreacs() stoich1.filterXreacs() stoich2.filterXreacs() moose.element('/model/chem/compt2/a[0]').concInit *= 1.5 # Create the output tables num = compt0.numDiffCompts - 1 graphs = moose.Neutral('/model/graphs') makeTab('a_soma', '/model/chem/compt0/a[0]') makeTab('b_soma', '/model/chem/compt0/b[0]') makeTab('a_apical', '/model/chem/compt0/a[' + str(num) + ']') makeTab('b_apical', '/model/chem/compt0/b[' + str(num) + ']') makeTab('a_spine', '/model/chem/compt1/a[5]') makeTab('b_spine', '/model/chem/compt1/b[5]') makeTab('a_psd', '/model/chem/compt2/a[5]') makeTab('b_psd', '/model/chem/compt2/b[5]')
def makeModel(): """ This example illustrates how to set up a diffusion/transport model with a simple reaction-diffusion system in a tapering cylinder: | Molecule **a** diffuses with diffConst of 10e-12 m^2/s. | Molecule **b** diffuses with diffConst of 5e-12 m^2/s. | Molecule **b** also undergoes motor transport with a rate of 10e-6 m/s | Thus it 'piles up' at the end of the cylinder. | Molecule **c** does not move: diffConst = 0.0 | Molecule **d** does not move: diffConst = 10.0e-12 but it is buffered. | Because it is buffered, it is treated as non-diffusing. All molecules other than **d** start out only in the leftmost (first) voxel, with a concentration of 1 mM. **d** is present throughout at 0.2 mM, except in the last voxel, where it is at 1.0 mM. The cylinder has a starting radius of 2 microns, and end radius of 1 micron. So when the molecule undergoing motor transport gets to the narrower end, its concentration goes up. There is a little reaction in all compartments: ``b + d <===> c`` As there is a high concentration of **d** in the last compartment, when the molecule **b** reaches the end of the cylinder, the reaction produces lots of **c**. Note that molecule **a** does not participate in this reaction. The concentrations of all molecules are displayed in an animation. """ # create container for model r0 = 2e-6 # m r1 = 1e-6 # m num = 100 diffLength = 1e-6 # m len = num * diffLength # m diffConst = 10e-12 #motorRate = 1e-6 #diffConst = 0 motorRate = 0 model = moose.Neutral( 'model' ) compartment = moose.CylMesh( '/model/compartment' ) compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = len compartment.diffLength = diffLength assert( compartment.numDiffCompts == num ) # create molecules and reactions a = moose.Pool( '/model/compartment/a' ) b = moose.Pool( '/model/compartment/b' ) c = moose.Pool( '/model/compartment/c' ) d = moose.Pool( '/model/compartment/d' ) r1 = moose.Reac( '/model/compartment/r1' ) moose.connect( r1, 'sub', b, 'reac' ) moose.connect( r1, 'sub', d, 'reac' ) moose.connect( r1, 'prd', c, 'reac' ) r1.Kf = 1000.0 # 1/(mM.sec) r1.Kb = 1 # 1/sec # Assign parameters a.diffConst = diffConst b.diffConst = diffConst / 2.0 b.motorConst = motorRate c.diffConst = diffConst d.diffConst = diffConst # Make solvers ksolve = moose.Gsolve( '/model/compartment/ksolve' ) dsolve = moose.Dsolve( '/model/compartment/dsolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve os.kill( PID, signal.SIGUSR1 ) stoich.path = "/model/compartment/##" print dsolve.numPools assert( dsolve.numPools == 4 ) a.vec.concInit = concA b.vec.concInit = concA / 5.0 c.vec.concInit = concA d.vec.concInit = concA / 5.0 for i in range( num ): d.vec[i].concInit = concA * 2 * i / num
def setPlugin(self, name, root='/'): """Set the current plugin to use. This - 1. sets the `plugin` attribute. 2. updates menus by clearing and reinstating menus including anything provided by the plugin. 3. sets the current view to the plugins editor view. """ busyCursor() for model in self._loadedModels: self.disableModel(model[0]) for i in range(0, len(self._loadedModels)): if self._loadedModels[i][0]== root: c = moose.Clock('/clock') compt = moose.wildcardFind(root+'/##[ISA=ChemCompt]') if compt: c.tickDt[11] = self._loadedModels[i][3] c.tickDt[16] = self._loadedModels[i][4] if moose.exists(compt[0].path+'/ksolve'): ksolve = moose.Ksolve( compt[0].path+'/ksolve' ) ksolve.tick = 16 if moose.exists(compt[0].path+'/gsolve'): gsolve = moose.Gsolve( compt[0].path+'/gsolve' ) gsolve.tick = 16 for x in moose.wildcardFind( root+'/data/graph#/#' ): x.tick = 18 else: c.tickDt[7] = self._loadedModels[i][3] c.tickDt[8] = self._loadedModels[i][4] neurons = moose.wildcardFind(root + "/model/cells/##[ISA=Neuron]") for neuron in neurons: #print(neuron) solver = moose.element(neuron.path + "/hsolve") # print("Disabling => ", solver) solver.tick = 7 for x in moose.wildcardFind( root+'/data/graph#/#' ): x.tick = 8 break self.plugin = self.loadPluginClass(str(name))(str(root), self) moose.reinit() # if root != '/' and root not in self._loadedModels: # self._loadedModels[root] = name # for k,v in self._loadedModels.items(): # compt = moose.wildcardFind(k+'/##[ISA=ChemCompt]') # if compt: # if moose.exists(compt[0].path+'/ksolve'): # ksolve = moose.Ksolve( compt[0].path+'/ksolve' ) # ksolve.tick = -1 # if moose.exists(compt[0].path+'/stoich'): # stoich = moose.Stoich( compt[0].path+'/stoich' ) # stoich.tick = -1 # for x in moose.wildcardFind( k+'/data/graph#/#' ): # x.tick = -1 # if root != '/' and root not in self._loadedModels: # self._loadedModels[root] = name # try: # self.plugin = self._plugins[str(name)] # print 'PLUGIN', self.plugin # self.plugin.setModelRoot(root) # except KeyError: # self.plugin = self.loadPluginClass(str(name))(str(root), self) # self._plugins[str(name)] = self.plugin #self.plugin.getEditorView().getCentralWidget().editObject.connect(self.objectEditSlot, QtCore.Qt.UniqueConnection) self.updateMenus() for action in self.pluginsMenu.actions(): if str(action.text()) == str(name): action.setChecked(True) elif action.isChecked(): action.setChecked(False) for subwin in self.mdiArea.subWindowList(): subwin.close() if name != "default" : self.setCurrentView('editor') self.setCurrentView('run') if name == 'kkit': self.objectEditDockWidget.objectNameChanged.connect(self.plugin.getEditorView().getCentralWidget().updateItemSlot) self.objectEditDockWidget.colorChanged.connect(self.plugin.getEditorView().getCentralWidget().updateColorSlot) self.setCurrentView('editor') freeCursor() return self.plugin
#define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool('/cylinder/pool') c.diffConst = 1e-13 # define diffusion constant # Here we set up a function calculation func = moose.Function('/cylinder/pool/func') func.expr = "(-x0 * (30e-9 - x0) * (100e-9 - x0))*0.0001" func.x.num = 1 #specify number of input variables. #Connect the molecules to the func moose.connect(c, 'nOut', func.x[0], 'input') #Connect the function to the pool moose.connect(func, 'valueOut', c, 'increment') #Set up solvers ksolve = moose.Gsolve('/cylinder/Gsolve') dsolve = moose.Dsolve('/cylinder/dsolve') stoich = moose.Stoich('/cylinder/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = '/cylinder/##' #for i in range( 10, 18 ): # moose.setClock( i, dt ) #initialize x = numpy.arange(0, compt.x1, compt.diffLength) # c.vec.nInit = [ 100.0 * (q < 0.2 * compt.x1) for q in x ] c.vec.nInit = [100 for q in x]
def makeModel(): model = moose.Neutral('/model') # Make neuronal model. It has no channels, just for geometry cell = moose.loadModel('./spinyNeuron.p', '/model/cell', 'Neutral') # We don't want the cell to do any calculations. Disable everything. for i in moose.wildcardFind('/model/cell/##'): i.tick = -1 # create container for model model = moose.element('/model') chem = moose.Neutral('/model/chem') # The naming of the compartments is dicated by the places that the # chem model expects to be loaded. compt0 = moose.NeuroMesh('/model/chem/compt0') compt0.separateSpines = 1 compt0.geometryPolicy = 'cylinder' compt1 = moose.SpineMesh('/model/chem/compt1') moose.connect(compt0, 'spineListOut', compt1, 'spineList', 'OneToOne') compt2 = moose.PsdMesh('/model/chem/compt2') moose.connect(compt0, 'psdListOut', compt2, 'psdList', 'OneToOne') #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' ) makeChemModel(compt0, True) # Populate all 3 compts with the chem system. makeChemModel(compt1, False) makeChemModel(compt2, True) compt0.diffLength = 2e-6 # This will be over 100 compartments. # This is the magic command that configures the diffusion compartments. compt0.cell = cell moose.showfields(compt0) # Build the solvers. No need for diffusion in this version. ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve') if useGssa: ksolve1 = moose.Gsolve('/model/chem/compt1/ksolve') ksolve2 = moose.Gsolve('/model/chem/compt2/ksolve') else: ksolve1 = moose.Ksolve('/model/chem/compt1/ksolve') ksolve2 = moose.Ksolve('/model/chem/compt2/ksolve') dsolve0 = moose.Dsolve('/model/chem/compt0/dsolve') dsolve1 = moose.Dsolve('/model/chem/compt1/dsolve') dsolve2 = moose.Dsolve('/model/chem/compt2/dsolve') stoich0 = moose.Stoich('/model/chem/compt0/stoich') stoich1 = moose.Stoich('/model/chem/compt1/stoich') stoich2 = moose.Stoich('/model/chem/compt2/stoich') # Configure solvers stoich0.compartment = compt0 stoich1.compartment = compt1 stoich2.compartment = compt2 stoich0.ksolve = ksolve0 stoich1.ksolve = ksolve1 stoich2.ksolve = ksolve2 stoich0.dsolve = dsolve0 stoich1.dsolve = dsolve1 stoich2.dsolve = dsolve2 stoich0.path = '/model/chem/compt0/#' stoich1.path = '/model/chem/compt1/#' stoich2.path = '/model/chem/compt2/#' assert (stoich0.numVarPools == 1) assert (stoich0.numProxyPools == 0) assert (stoich0.numRates == 1) assert (stoich1.numVarPools == 1) assert (stoich1.numProxyPools == 0) if useGssa: assert (stoich1.numRates == 2) assert (stoich2.numRates == 2) else: assert (stoich1.numRates == 1) assert (stoich2.numRates == 1) assert (stoich2.numVarPools == 1) assert (stoich2.numProxyPools == 0) dsolve0.buildNeuroMeshJunctions(dsolve1, dsolve2) stoich0.buildXreacs(stoich1) stoich1.buildXreacs(stoich2) stoich0.filterXreacs() stoich1.filterXreacs() stoich2.filterXreacs() Ca_input_dend = moose.vec('/model/chem/compt0/Ca_input') print len(Ca_input_dend) for i in range(60): Ca_input_dend[3 + i * 3].conc = 2.0 Ca_input_PSD = moose.vec('/model/chem/compt2/Ca_input') print len(Ca_input_PSD) for i in range(5): Ca_input_PSD[2 + i * 2].conc = 1.0 # Create the output tables num = compt0.numDiffCompts - 1 graphs = moose.Neutral('/model/graphs') makeTab('Ca_soma', '/model/chem/compt0/Ca[0]') makeTab('Ca_d1', '/model/chem/compt0/Ca[1]') makeTab('Ca_d2', '/model/chem/compt0/Ca[2]') makeTab('Ca_d3', '/model/chem/compt0/Ca[3]') makeTab('Ca_s3', '/model/chem/compt1/Ca[3]') makeTab('Ca_s4', '/model/chem/compt1/Ca[4]') makeTab('Ca_s5', '/model/chem/compt1/Ca[5]') makeTab('Ca_p3', '/model/chem/compt2/Ca[3]') makeTab('Ca_p4', '/model/chem/compt2/Ca[4]') makeTab('Ca_p5', '/model/chem/compt2/Ca[5]')
def makeModel(): # create container for model model = moose.Neutral( 'model' ) compt0 = moose.CubeMesh( '/model/compt0' ) compt0.volume = 1e-18 compt1 = moose.CubeMesh( '/model/compt1' ) compt1.volume = 1e-19 compt2 = moose.CubeMesh( '/model/compt2' ) compt2.volume = 1e-20 # Position containers so that they abut each other, with # compt1 in the middle. side = compt1.dy compt0.y1 += side compt0.y0 += side compt2.x1 += side compt2.x0 += side print(('Volumes = ', compt0.volume, compt1.volume, compt2.volume)) # create molecules and reactions a = moose.Pool( '/model/compt0/a' ) b = moose.Pool( '/model/compt1/b' ) c = moose.Pool( '/model/compt2/c' ) reac0 = moose.Reac( '/model/compt1/reac0' ) reac1 = moose.Reac( '/model/compt1/reac1' ) # connect them up for reactions moose.connect( reac0, 'sub', a, 'reac' ) moose.connect( reac0, 'prd', b, 'reac' ) moose.connect( reac1, 'sub', b, 'reac' ) moose.connect( reac1, 'prd', c, 'reac' ) # Assign parameters a.concInit = 1 b.concInit = 12.1 c.concInit = 1 reac0.Kf = 0.1 reac0.Kb = 0.1 reac1.Kf = 0.1 reac1.Kb = 0.1 # Create the output tables graphs = moose.Neutral( '/model/graphs' ) outputA = moose.Table2 ( '/model/graphs/concA' ) outputB = moose.Table2 ( '/model/graphs/concB' ) outputC = moose.Table2 ( '/model/graphs/concC' ) # connect up the tables moose.connect( outputA, 'requestOut', a, 'getConc' ); moose.connect( outputB, 'requestOut', b, 'getConc' ); moose.connect( outputC, 'requestOut', c, 'getConc' ); # Build the solvers. No need for diffusion in this version. ksolve0 = moose.Gsolve( '/model/compt0/ksolve0' ) ksolve1 = moose.Gsolve( '/model/compt1/ksolve1' ) ksolve2 = moose.Gsolve( '/model/compt2/ksolve2' ) stoich0 = moose.Stoich( '/model/compt0/stoich0' ) stoich1 = moose.Stoich( '/model/compt1/stoich1' ) stoich2 = moose.Stoich( '/model/compt2/stoich2' ) # Configure solvers stoich0.compartment = compt0 stoich1.compartment = compt1 stoich2.compartment = compt2 stoich0.ksolve = ksolve0 stoich1.ksolve = ksolve1 stoich2.ksolve = ksolve2 stoich0.path = '/model/compt0/#' stoich1.path = '/model/compt1/#' stoich2.path = '/model/compt2/#' stoich1.buildXreacs( stoich0 ) stoich1.buildXreacs( stoich2 ) stoich0.filterXreacs() stoich1.filterXreacs() stoich2.filterXreacs()
def main( nT ): """ This example implements a reaction-diffusion like system which is bistable and propagates losslessly. It is based on the NEURON example rxdrun.py, but incorporates more compartments and runs for a longer time. The system is implemented in a function rather than as a proper system of chemical reactions. Please see rxdReacDiffusion.py for a variant that uses a reaction plus a function object to control its rates. """ print( 'Using %d threads' % nT ) dt = 0.1 # define the geometry compt = moose.CylMesh( '/cylinder' ) compt.r0 = compt.r1 = 100e-9 compt.x1 = 200e-9 compt.diffLength = 0.2e-9 assert( compt.numDiffCompts == compt.x1/compt.diffLength ) #define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool( '/cylinder/pool' ) c.diffConst = 1e-13 # define diffusion constant # Here we set up a function calculation func = moose.Function( '/cylinder/pool/func' ) func.expr = "(-x0 * (30e-9 - x0) * (100e-9 - x0))*0.0001" func.x.num = 1 #specify number of input variables. #Connect the molecules to the func moose.connect( c, 'nOut', func.x[0], 'input' ) #Connect the function to the pool moose.connect( func, 'valueOut', c, 'increment' ) #Set up solvers ksolve = moose.Gsolve( '/cylinder/Gsolve' ) try: ksolve.numThreads = nT except Exception as e: print( 'OLD MOOSE. Does not support multithreading' ) dsolve = moose.Dsolve( '/cylinder/dsolve' ) stoich = moose.Stoich( '/cylinder/stoich' ) stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = '/cylinder/##' #initialize x = np.arange( 0, compt.x1, compt.diffLength ) c.vec.nInit = [ 1000.0 for q in x ] # Run and plot it. moose.reinit() updateDt = 50 runtime = updateDt * 10 t1 = time.time() res = [] for t in range( 0, runtime-1, updateDt ): moose.start( updateDt ) y = c.vec.n res.append( (np.mean(y), np.std(y)) ) expected = [(9.0, 0.0), (6.0, 0.0), (5.0, 0.0), (3.0, 0.0), (2.0, 0.0), (2.0, 0.0), (2.0, 0.0), (1.0, 0.0), (1.0, 0.0), (1.0, 0.0)] print(("Time = ", time.time() - t1)) print( res ) assert res == expected
def test_gsolve_paralllel(nT=4): """ This example implements a reaction-diffusion like system which is bistable and propagates losslessly. It is based on the NEURON example rxdrun.py, but incorporates more compartments and runs for a longer time. The system is implemented in a function rather than as a proper system of chemical reactions. Please see rxdReacDiffusion.py for a variant that uses a reaction plus a function object to control its rates. """ print( 'Using %d threads' % nT ) dt = 0.1 # define the geometry compt = moose.CylMesh( '/cylinder' ) compt.r0 = compt.r1 = 100e-9 compt.x1 = 200e-09 compt.diffLength = 0.2e-9 assert( compt.numDiffCompts == compt.x1/compt.diffLength) #define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool( '/cylinder/pool' ) c.diffConst = 1e-13 # define diffusion constant # Here we set up a function calculation func = moose.Function( '/cylinder/pool/func' ) func.expr = "(-x0*(30e-9-x0)*(100e-9-x0))*0.0001" # func.x.num = 1 #specify number of input variables. #Connect the molecules to the func moose.connect( c, 'nOut', func.x[0], 'input' ) #Connect the function to the pool moose.connect( func, 'valueOut', c, 'increment' ) #Set up solvers ksolve = moose.Gsolve( '/cylinder/Gsolve' ) ksolve.numThreads = nT dsolve = moose.Dsolve( '/cylinder/dsolve' ) stoich = moose.Stoich( '/cylinder/stoich' ) stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = '/cylinder/##' #initialize x = np.arange( 0, compt.x1, compt.diffLength ) c.vec.nInit = [ 1000.0 for q in x ] # Run and plot it. moose.reinit() updateDt = 50 runtime = updateDt * 10 t1 = time.time() res = [] clk = moose.element( '/clock' ) for t in range( 0, runtime-1, updateDt ): y = c.vec.n s = np.sum(y) v = (np.mean(y), np.max(y), np.min(y), s) print(v) res.append(v) moose.start( updateDt ) currTime = clk.currentTime # One molecule here and there because thread launching has undeterministic # characteristics. Even after setting moose.seed; we may not see same # numbers on all platfroms. expected = [ (1000.0, 1000.0, 1000.0, 1000000.0) , (9.908, 10.0, 8.0, 9908.0) , (6.869, 7.0, 6.0, 6869.0) , (5.354, 6.0, 5.0, 5354.0) , (4.562, 5.0, 4.0, 4562.0) , (3.483, 4.0, 3.0, 3483.0) , (3.043, 4.0, 3.0, 3043.0) , (2.261, 3.0, 2.0, 2261.0) , (1.967, 2.0, 1.0, 1967.0) , (1.997, 2.0, 1.0, 1997.0) ] print("Time = ", time.time() - t1) assert np.isclose(res, expected, atol=1, rtol=1).all(), "Got %s, expected %s" % (res, expected)
def main(): """ This example implements a reaction-diffusion like system which is bistable and propagates losslessly. It is based on the NEURON example rxdrun.py, but incorporates more compartments and runs for a longer time. The system is implemented in a function rather than as a proper system of chemical reactions. Please see rxdReacDiffusion.py for a variant that uses a reaction plus a function object to control its rates. """ dt = 0.1 # define the geometry compt = moose.CylMesh( '/cylinder' ) compt.r0 = compt.r1 = 100e-9 compt.x1 = 100e-9 compt.diffLength = 0.2e-9 assert( compt.numDiffCompts == compt.x1/compt.diffLength ) #define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool( '/cylinder/pool' ) c.diffConst = 1e-13 # define diffusion constant # Here we set up a function calculation func = moose.Function( '/cylinder/pool/func' ) func.expr = "(-x0 * (30e-9 - x0) * (100e-9 - x0))*0.0001" func.x.num = 1 #specify number of input variables. #Connect the molecules to the func moose.connect( c, 'nOut', func.x[0], 'input' ) #Connect the function to the pool moose.connect( func, 'valueOut', c, 'increment' ) #Set up solvers ksolve = moose.Gsolve( '/cylinder/Gsolve' ) dsolve = moose.Dsolve( '/cylinder/dsolve' ) stoich = moose.Stoich( '/cylinder/stoich' ) stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = '/cylinder/##' #for i in range( 10, 18 ): # moose.setClock( i, dt ) #initialize x = numpy.arange( 0, compt.x1, compt.diffLength ) # c.vec.nInit = [ 100.0 * (q < 0.2 * compt.x1) for q in x ] c.vec.nInit = [ 100 for q in x ] # Run and plot it. moose.reinit() #print((dir(compt))) updateDt = 50 runtime = updateDt * 4 plt = pylab.plot( x, c.vec.n, label='t = 0 ') t1 = time.time() for t in range( 0, runtime-1, updateDt ): moose.start( updateDt ) plt = pylab.plot( x, c.vec.n, label='t = '+str(t + updateDt) ) print(("Time = ", time.time() - t1)) pylab.ylim( 0, 105 ) pylab.legend() pylab.show()
def main(): """ The stochasticLotkaVolterra example is almost identical to the funcReacLotkaVolterra. It shows how to use function objects as part of differential equation systems in the framework of the MOOSE kinetic solvers. Here the difference is that we use a a stochastic solver. The system is interesting because it illustrates the instability of Lotka-Volterra systems in stochastic conditions. Here we see exctinction of one of the species and runaway buildup of the other. The simulation has to be halted at this point. Here the system is set up explicitly using the scripting, in normal use one would expect to use SBML. In this example we set up a Lotka-Volterra system. The equations are readily expressed as a pair of reactions each of whose rate is governed by a function:: x' = x( alpha - beta.y ) y' = -y( gamma - delta.x ) This translates into two reactions:: x ---> z Kf = beta.y - alpha y ---> z Kf = gamma - delta.x Here z is a dummy molecule whose concentration is buffered to zero. The model first runs using default Exponential Euler integration. This is not particularly accurate even with a small timestep. The model is then converted to use the deterministic Kinetic solver Ksolve. This is accurate and faster.\n Note that we cannot use the stochastic GSSA solver for this system, it cannot handle a reaction term whose rate keeps changing. """ makeModel() moose.seed(1) # A seed of 3 will give an extinction at 79 seconds. for i in range(11, 18): moose.setClock(i, 0.001) moose.setClock(18, 0.1) moose.reinit() moose.start(runtime) # Run the model # Iterate through all plots, dump their contents to data.plot. for x in moose.wildcardFind('/model/graphs/#'): #x.xplot( 'scriptKineticModel.plot', x.name ) t = numpy.arange(0, x.vector.size, 1) * x.dt # sec pylab.plot(t, x.vector, label=x.name) #pylab.ylim( 0, 2.5 ) pylab.title("Exponential Euler solution. Note slight error buildup") pylab.legend() pylab.figure() compt = moose.element('/model/lotka') ksolve = moose.Gsolve('/model/lotka/ksolve') stoich = moose.Stoich('/model/lotka/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.reacSystemPath = '/model/lotka/##' moose.reinit() moose.start(runtime) # Run the model for i in range(11, 18): moose.setClock(i, 0.1) for x in moose.wildcardFind('/model/graphs/#'): t = numpy.arange(0, x.vector.size, 1) * x.dt # sec pylab.plot(t, x.vector, label=x.name) #pylab.ylim( 0, 2.5 ) pylab.title("GSSA solution.") pylab.legend() pylab.show() quit()
def main(): """ This example illustrates how to run a model at different volumes. The key line is just to set the volume of the compartment:: compt.volume = vol If everything else is set up correctly, then this change propagates through to all reactions molecules. For a deterministic reaction one would not see any change in output concentrations. For a stochastic reaction illustrated here, one sees the level of 'noise' changing, even though the concentrations are similar up to a point. This example creates a bistable model having two enzymes and a reaction. One of the enzymes is autocatalytic. This model is set up within the script rather than using an external file. The model is set up to run using the GSSA (Gillespie Stocahstic systems algorithim) method in MOOSE. To run the example, run the script ``python scaleVolumes.py`` and hit ``enter`` every cycle to see the outcome of stochastic calculations at ever smaller volumes, keeping concentrations the same. """ makeModel() moose.seed(11111) gsolve = moose.Gsolve('/model/compartment/gsolve') stoich = moose.Stoich('/model/compartment/stoich') compt = moose.element('/model/compartment') stoich.compartment = compt stoich.ksolve = gsolve stoich.path = "/model/compartment/##" moose.setClock(5, 1.0) # clock for the solver moose.useClock(5, '/model/compartment/gsolve', 'process') a = moose.element('/model/compartment/a') for vol in (1e-19, 1e-20, 1e-21, 3e-22, 1e-22, 3e-23, 1e-23): # Set the volume compt.volume = vol print(('vol = ', vol, ', a.concInit = ', a.concInit, ', a.nInit = ', a.nInit)) 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() pylab.show(block=False) print(('vol = ', vol, 'hit enter to go to next plot')) input() quit()
# This does not. #func = moose.Function('/func') func.expr = '100*(1 + sin(0.1*t) + cos(x0) )' func.mode = 1 moose.connect( a, 'nOut', func.x[0], 'input' ) moose.connect(func, 'valueOut', a, 'setN') reac = moose.Reac('/compt/reac') moose.connect(reac, 'sub', a, 'reac') moose.connect(reac, 'prd', b, 'reac') reac.Kf = 2 reac.Kb = 1 gsolve = moose.Gsolve('/compt/gsolve') stoich = moose.Stoich('/compt/stoich') stoich.compartment = compt stoich.ksolve = gsolve stoich.path = '/compt/##' print("Reinit") moose.reinit() moose.start(100) print("Done simulation") # plots import pylab pylab.plot(atab.vector, label = 'a') pylab.plot(btab.vector, label = 'b' ) pylab.legend( framealpha=0.4)