def main(): """ This example illustrates loading, running of an SBML model defined in XML format.\n The model 00001-sbml-l3v1.xml is taken from l3v1 SBML testcase.\n Plots are setup.\n Model is run for 20sec.\n As a general rule we created model under '/path/model' and plots under '/path/graphs'.\n """ mfile = os.path.join(script_dir, 'chem_models/00001-sbml-l3v1.xml') runtime = 20.0 # Loading the sbml file into MOOSE, models are loaded in path/model sbmlId = moose.readSBML(mfile, 'sbml') s1 = moose.element('/sbml/model/compartment/S1') s2 = moose.element('/sbml/model/compartment/S2') # Creating MOOSE Table, Table2 is for the chemical model graphs = moose.Neutral('/sbml/graphs') outputs1 = moose.Table2('/sbml/graphs/concS1') outputs2 = moose.Table2('/sbml/graphs/concS2') # connect up the tables moose.connect(outputs1, 'requestOut', s1, 'getConc') moose.connect(outputs2, 'requestOut', s2, 'getConc') # Reset and Run moose.reinit() moose.start(runtime)
def makeModel(): # create container for model num = 1 # number of compartments model = moose.Neutral( '/model' ) compartment = moose.CylMesh( '/model/compartment' ) compartment.x1 = 1.0e-6 # Set it to a 1 micron single-voxel cylinder # create molecules and reactions s = moose.Pool( '/model/compartment/s' ) ##################################################################### # Put in endo compartment. Add molecule s endo = moose.EndoMesh( '/model/endo' ) endo.isMembraneBound = True endo.surround = compartment es = moose.Pool( '/model/endo/s' ) rXfer = moose.Reac( '/model/endo/rXfer' ) ##################################################################### moose.connect( rXfer, 'sub', s, 'reac' ) moose.connect( rXfer, 'prd', es, 'reac' ) volRatio = compartment.volume / endo.volume rXfer.Kf = 0.04 # 0.04/sec rXfer.Kb = 0.02 # 0.02/sec ##################################################################### fixXreacs.fixXreacs( '/model' ) #fixXreacs.restoreXreacs( '/model' ) #fixXreacs.fixXreacs( '/model' ) ##################################################################### # Make solvers ksolve = moose.Ksolve( '/model/compartment/ksolve' ) dsolve = moose.Dsolve( '/model/dsolve' ) eksolve = moose.Ksolve( '/model/endo/ksolve' ) edsolve = moose.Dsolve( '/model/endo/dsolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = "/model/compartment/##" assert( dsolve.numPools == 1 ) s.vec.concInit = [1]*num estoich = moose.Stoich( '/model/endo/stoich' ) estoich.compartment = endo estoich.ksolve = eksolve estoich.dsolve = edsolve estoich.path = "/model/endo/##" assert( edsolve.numPools == 2 ) edsolve.buildMeshJunctions( dsolve ) plot1 = moose.Table2( '/model/plot1' ) plot2 = moose.Table2( '/model/plot2' ) moose.connect( '/model/plot1', 'requestOut', s, 'getN' ) moose.connect( '/model/plot2', 'requestOut', es, 'getN' ) plot3 = moose.Table2( '/model/plot3' ) plot4 = moose.Table2( '/model/plot4' ) moose.connect( '/model/plot3', 'requestOut', s, 'getConc' ) moose.connect( '/model/plot4', 'requestOut', es, 'getConc' )
def makeModel(): # create container for model model = moose.Neutral('model') compartment = moose.CubeMesh('/model/compartment') compartment.volume = 1e-15 # the mesh is created automatically by the compartment mesh = moose.element('/model/compartment/mesh') # create molecules and reactions # a <----> b # b + 10c ---func---> d a = moose.Pool('/model/compartment/a') b = moose.Pool('/model/compartment/b') c = moose.Pool('/model/compartment/c') d = moose.BufPool('/model/compartment/d') reac = moose.Reac('/model/compartment/reac') func = moose.Function('/model/compartment/d/func') func.numVars = 2 #func.x.num = 2 # connect them up for reactions moose.connect(reac, 'sub', a, 'reac') moose.connect(reac, 'prd', b, 'reac') if useY: moose.connect(func, 'requestOut', b, 'getN') moose.connect(func, 'requestOut', c, 'getN') else: moose.connect(b, 'nOut', func.x[0], 'input') moose.connect(c, 'nOut', func.x[1], 'input') moose.connect(func, 'valueOut', d, 'setN') if useY: func.expr = "y0 + 10*y1" else: func.expr = "x0 + 10*x1" # connect them up to the compartment for volumes #for x in ( a, b, c, cplx1, cplx2 ): # moose.connect( x, 'mesh', mesh, 'mesh' ) # Assign parameters a.concInit = 1 b.concInit = 0.5 c.concInit = 0.1 reac.Kf = 0.001 reac.Kb = 0.01 # 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') outputD = moose.Table2('/model/graphs/concD') # connect up the tables moose.connect(outputA, 'requestOut', a, 'getConc') moose.connect(outputB, 'requestOut', b, 'getConc') moose.connect(outputC, 'requestOut', c, 'getConc') moose.connect(outputD, 'requestOut', d, 'getConc')
def main(): """ This example illustrates loading, running of an SBML model defined in XML format. Default this file load's 00001-sbml-l3v1.xml which is taken from l3v1 SBML testcase. Plots are setup. Model is run for 20sec. As a general rule we created model under '/path/model' and plots under '/path/graphs'. If someone wants to load anyother file then `python loadSbmlmodel filepath runtime` """ dfilepath = "../genesis/00001-sbml-l3v1.xml" druntime = 20.0 msg = "" try: sys.argv[1] except IndexError: filepath = dfilepath else: filepath = sys.argv[1] if not os.path.exists(filepath): msg = "Filename or path does not exist", filepath, "loading default file", dfilepath filepath = dfilepath try: sys.argv[2] except: runtime = druntime else: runtime = float(sys.argv[2]) sbmlId = moose.element('/') # Loading the sbml file into MOOSE, models are loaded in path/model sbmlId = moose.mooseReadSBML(filepath, '/sbml') if isinstance(sbmlId, (list, tuple)): print(sbmlId) elif sbmlId.path != '/': s1 = moose.element('/sbml/model/compartment/S1') s2 = moose.element('/sbml/model/compartment/S2') # Creating MOOSE Table, Table2 is for the chemical model graphs = moose.Neutral('/sbml/graphs') outputs1 = moose.Table2('/sbml/graphs/concS1') outputs2 = moose.Table2('/sbml/graphs/concS2') # connect up the tables moose.connect(outputs1, 'requestOut', s1, 'getConc') moose.connect(outputs2, 'requestOut', s2, 'getConc') # gsl solver is added, default is ee moose.mooseaddChemSolver(sbmlId.path, "ee") # Reset and Run moose.reinit() moose.start(runtime) return sbmlId, True, msg return sbmlId, False, msg
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 test_streamer(): compt = moose.CubeMesh('/compt') assert compt r = moose.Reac('/compt/r') a = moose.Pool('/compt/a') a.concInit = 1 b = moose.Pool('/compt/b') b.concInit = 2 c = moose.Pool('/compt/c') c.concInit = 0.5 moose.connect(r, 'sub', a, 'reac') moose.connect(r, 'prd', b, 'reac') moose.connect(r, 'prd', c, 'reac') r.Kf = 0.1 r.Kb = 0.01 outfile = 'streamer_test.csv' if os.path.exists(outfile): os.remove(outfile) tabA = moose.Table2('/compt/a/tab') tabB = moose.Table2('/compt/tabB') tabC = moose.Table2('/compt/tabB/tabC') print(tabA, tabB, tabC) moose.connect(tabA, 'requestOut', a, 'getConc') moose.connect(tabB, 'requestOut', b, 'getConc') moose.connect(tabC, 'requestOut', c, 'getConc') # Now create a streamer and use it to write to a stream st = moose.Streamer('/compt/streamer') st.outfile = outfile print("outfile set to: %s " % st.outfile) st.addTable(tabA) st.addTables([tabB, tabC]) assert st.numTables == 3 moose.reinit() t = 100 print('[INFO] Running for %d seconds' % t) moose.start(t) outfile = st.outfile moose.quit() # Otherwise Streamer won't flush the rest of entries. print('Moose is done. Waiting for monitor to shut down...') # Now read the table and verify that we have written print('[INFO] Reading file %s' % outfile) if 'csv' in outfile: data = np.loadtxt(outfile, skiprows=1) else: data = np.load(outfile) # Total rows should be 58 (counting zero as well). # print(data) # print( data.dtype ) assert data.shape >= (101, ), data.shape print('[INFO] Test 2 passed') return 0
def makeModel(): # create container for model model = moose.Neutral( 'model' ) compartment = moose.CubeMesh( '/model/compartment' ) compartment.volume = 1e-20 # the mesh is created automatically by the compartment mesh = moose.element( '/model/compartment/mesh' ) # create molecules and reactions a = moose.Pool( '/model/compartment/a' ) b = moose.Pool( '/model/compartment/b' ) c = moose.Pool( '/model/compartment/c' ) enz1 = moose.Enz( '/model/compartment/b/enz1' ) enz2 = moose.Enz( '/model/compartment/c/enz2' ) cplx1 = moose.Pool( '/model/compartment/b/enz1/cplx' ) cplx2 = moose.Pool( '/model/compartment/c/enz2/cplx' ) reac = moose.Reac( '/model/compartment/reac' ) # connect them up for reactions moose.connect( enz1, 'sub', a, 'reac' ) moose.connect( enz1, 'prd', b, 'reac' ) moose.connect( enz1, 'enz', b, 'reac' ) moose.connect( enz1, 'cplx', cplx1, 'reac' ) moose.connect( enz2, 'sub', b, 'reac' ) moose.connect( enz2, 'prd', a, 'reac' ) moose.connect( enz2, 'enz', c, 'reac' ) moose.connect( enz2, 'cplx', cplx2, 'reac' ) moose.connect( reac, 'sub', a, 'reac' ) moose.connect( reac, 'prd', b, 'reac' ) # connect them up to the compartment for volumes #for x in ( a, b, c, cplx1, cplx2 ): # moose.connect( x, 'mesh', mesh, 'mesh' ) # Assign parameters a.concInit = 1 b.concInit = 0 c.concInit = 0.01 enz1.kcat = 0.4 enz1.Km = 4 enz2.kcat = 0.6 enz2.Km = 0.01 reac.Kf = 0.001 reac.Kb = 0.01 # Create the output tables graphs = moose.Neutral( '/model/graphs' ) outputA = moose.Table2( '/model/graphs/concA' ) outputB = moose.Table2( '/model/graphs/concB' ) # connect up the tables moose.connect( outputA, 'requestOut', a, 'getConc' ); moose.connect( outputB, 'requestOut', b, 'getConc' ); '''
def test( ): compt = moose.CubeMesh( '/compt' ) r = moose.Reac( '/compt/r' ) a = moose.Pool( '/compt/a' ) a.concInit = 1 b = moose.Pool( '/compt/b' ) b.concInit = 2 c = moose.Pool( '/compt/c' ) c.concInit = 0.5 moose.connect( r, 'sub', a, 'reac' ) moose.connect( r, 'prd', b, 'reac' ) moose.connect( r, 'prd', c, 'reac' ) r.Kf = 0.1 r.Kb = 0.01 tabA = moose.Table2( '/compt/a/tab' ) tabB = moose.Table2( '/compt/tabB' ) tabC = moose.Table2( '/compt/tabB/tabC' ) print(tabA, tabB, tabC) moose.connect( tabA, 'requestOut', a, 'getConc' ) moose.connect( tabB, 'requestOut', b, 'getConc' ) moose.connect( tabC, 'requestOut', c, 'getConc' ) # Now create a streamer and use it to write to a stream st = moose.Streamer( '/compt/streamer' ) st.outfile = os.path.join( os.getcwd(), 'temp.npy' ) print(("outfile set to: %s " % st.outfile )) assert st.outfile == os.path.join( os.getcwd(), 'temp.npy' ), st.outfile st.addTable( tabA ) st.addTables( [ tabB, tabC ] ) assert st.numTables == 3 moose.reinit( ) print( '[INFO] Running for 57 seconds' ) moose.start( 57 ) outfile = st.outfile moose.quit() # Otherwise Streamer won't flush the rest of entries. # Now read the table and verify that we have written print( '[INFO] Reading file %s' % outfile ) if 'csv' in outfile: data = np.loadtxt(outfile, skiprows=1 ) else: data = np.load( outfile ) # Total rows should be 58 (counting zero as well). # print(data) # print( data.dtype ) time = data['time'] print( time ) assert data.shape >= (58,), data.shape print( '[INFO] Test 2 passed' ) return 0
def main(): """ This example illustrates loading, running of an SBML model defined in XML format. The model 00001-sbml-l3v1.xml is taken from l3v1 SBML testcase. Plots are setup. Model is run for 20sec. As a general rule we created model under '/path/model' and plots under '/path/graphs'. """ mfile = "../genesis/00001-sbml-l3v1.xml" try: sys.argv[1] except: pass else: mfile = sys.argv[1] try: sys.argv[2] except: runtime = 20.0 else: runtime = float(sys.argv[2]) # Loading the sbml file into MOOSE, models are loaded in path/model sbmlId = moose.SBML.readSBML.mooseReadSBML(mfile, 'sbml') # Loading the sbml file into MOOSE, models are loaded in path/model sbmlId = mooseReadSBML(mfile, '/sbml') if isinstance(sbmlId, (list, tuple)): print(sbmlId) elif sbmlId.path != '/': s1 = moose.element('/sbml/model/compartment/S1') s2 = moose.element('/sbml/model/compartment/S2') # Creating MOOSE Table, Table2 is for the chemical model graphs = moose.Neutral('/sbml/graphs') outputs1 = moose.Table2('/sbml/graphs/concS1') outputs2 = moose.Table2('/sbml/graphs/concS2') # connect up the tables moose.connect(outputs1, 'requestOut', s1, 'getConc') moose.connect(outputs2, 'requestOut', s2, 'getConc') # gsl solver is added, default is ee mooseaddChemSolver(sbmlId.path, "ee") # Reset and Run moose.reinit() moose.start(runtime) return sbmlId, True return sbmlId, False
def makeModel(): # create container for model model = moose.Neutral('model') harmonic = moose.CubeMesh('/model/harmonic') harmonic.volume = 1e-15 lotka = moose.CubeMesh('/model/lotka') lotka.volume = 1e-15 # create molecules and reactions x = moose.Pool('/model/lotka/x') y = moose.Pool('/model/lotka/y') z = moose.BufPool('/model/lotka/z') # Dummy molecule. xreac = moose.Reac('/model/lotka/xreac') yreac = moose.Reac('/model/lotka/yreac') xrate = moose.Function('/model/lotka/xreac/func') yrate = moose.Function('/model/lotka/yreac/func') # Parameters alpha = 1.0 beta = 1.0 gamma = 1.0 delta = 1.0 k = 1.0 x.nInit = 2.0 y.nInit = 1.0 z.nInit = 0.0 xrate.x.num = 1 yrate.x.num = 1 xrate.expr = "x0 * " + str(beta) + " - " + str(alpha) yrate.expr = str(gamma) + " - x0 * " + str(delta) xreac.Kf = k yreac.Kf = k xreac.Kb = 0 yreac.Kb = 0 # connect them up for reactions moose.connect(y, 'nOut', xrate.x[0], 'input') moose.connect(x, 'nOut', yrate.x[0], 'input') moose.connect(xrate, 'valueOut', xreac, 'setNumKf') moose.connect(yrate, 'valueOut', yreac, 'setNumKf') moose.connect(xreac, 'sub', x, 'reac') moose.connect(xreac, 'prd', z, 'reac') moose.connect(yreac, 'sub', y, 'reac') moose.connect(yreac, 'prd', z, 'reac') # Create the output tables graphs = moose.Neutral('/model/graphs') xplot = moose.Table2('/model/graphs/x') yplot = moose.Table2('/model/graphs/y') # connect up the tables moose.connect(xplot, 'requestOut', x, 'getN') moose.connect(yplot, 'requestOut', y, 'getN')
def _init_plots(self): ExcInhNetBase._init_plots(self) self.recN = 50 # number of neurons for which to record weights and Ca if CaPlasticity: ## make tables to store weights of recN exc synapses ## for each post-synaptic exc neuron self.weights = moose.Table2( '/plotWeights', self.excC*self.recN ) for i in range(self.recN): # range(self.N) is too large for j in range(self.excC): moose.connect( self.weights.vec[self.excC*i+j], 'requestOut', self.synsEE.vec[i*self.excC+j].synapse[0], 'getWeight') self.CaTables = moose.Table2( '/plotCa', self.recN ) for i in range(self.recN): # range(self.N) is too large moose.connect( self.CaTables.vec[i], 'requestOut', self.synsEE.vec[i*self.excC+j], 'getCa')
def buildNeuronPlots( rdes ): if not moose.exists( '/graphs' ): graphs = moose.Neutral( '/graphs' ) vtab = moose.Table( '/graphs/vtab' ) catab = moose.Table( '/graphs/catab' ) moose.connect( vtab, "requestOut", rdes.soma, "getVm" ) caSoma = moose.element( rdes.soma.path + "/Ca_conc" ) moose.connect( catab, "requestOut", caSoma, "getCa" ) elist = moose.wildcardFind( '/model/chem/psd/tot_PSD_R[]' ) rtab = moose.Table2( '/graphs/rtab', len( elist ) ).vec for i in zip( elist, rtab ): moose.connect( i[1], "requestOut", i[0], "getN" ) elist = moose.wildcardFind( '/model/chem/spine/Ca[]' ) pcatab = moose.Table2( '/graphs/pcatab', len( elist ) ).vec for i in zip( elist, pcatab ): moose.connect( i[1], "requestOut", i[0], "getConc" )
def singleCompt(name, params): mod = moose.copy('/library/' + name + '/' + name, '/model') A = moose.element(mod.path + '/A') Z = moose.element(mod.path + '/Z') Z.nInit = 1 Ca = moose.element(mod.path + '/Ca') CaStim = moose.element(Ca.path + '/CaStim') runtime = params['preStimTime'] + params['stimWidth'] + params[ 'postStimTime'] steptime = 100 CaStim.expr += ' + x2 * (t > ' + str(runtime) + ' ) * ( t < ' + str( runtime + steptime) + ' )' print CaStim.expr tab = moose.Table2('/model/' + name + '/Atab') #for i in range( 10, 19 ): #moose.setClock( i, 0.01 ) ampl = moose.element(mod.path + '/ampl') phase = moose.element(mod.path + '/phase') moose.connect(tab, 'requestOut', A, 'getN') ampl.nInit = params['stimAmplitude'] * 1 phase.nInit = params['preStimTime'] ksolve = moose.Ksolve(mod.path + '/ksolve') stoich = moose.Stoich(mod.path + '/stoich') stoich.compartment = mod stoich.ksolve = ksolve stoich.path = mod.path + '/##' runtime += 2 * steptime moose.reinit() moose.start(runtime) t = np.arange(0, runtime + 1e-9, tab.dt) return name, t, tab.vector
def singleCompt(name, params): print('=============') print('[INFO] Making compartment %s' % name) mod = moose.copy('/library/' + name + '/' + name, '/model') A = moose.element(mod.path + '/A') Z = moose.element(mod.path + '/Z') Z.nInit = 1 Ca = moose.element(mod.path + '/Ca') CaStim = moose.element(Ca.path + '/CaStim') print('\n\n[INFO] CaStim %s' % CaStim.path) runtime = params['preStimTime'] + params['postStimTime'] steptime = 50 CaStim.expr += '+x2*(t>100+' + str(runtime) + ')*(t<100+' + str( runtime + steptime) + ')' print("[INFO] CaStim.expr = %s" % CaStim.expr) tab = moose.Table2('/model/' + name + '/Atab') ampl = moose.element(mod.path + '/ampl') phase = moose.element(mod.path + '/phase') moose.connect(tab, 'requestOut', A, 'getN') ampl.nInit = params['stimAmplitude'] * 1 phase.nInit = params['preStimTime'] ksolve = moose.Ksolve(mod.path + '/ksolve') stoich = moose.Stoich(mod.path + '/stoich') stoich.compartment = mod stoich.ksolve = ksolve stoich.path = mod.path + '/##' print('REINIT AND START') moose.reinit() runtime += 100 + steptime * 2 moose.start(runtime) t = np.arange(0, runtime + 1e-9, tab.dt) return name, t, tab.vector
def test(): compt = moose.CubeMesh('/compt') r = moose.Reac('/compt/r') a = moose.Pool('/compt/a') a.concInit = 1 b = moose.Pool('/compt/b') b.concInit = 2 c = moose.Pool('/compt/c') c.concInit = 0.5 moose.connect(r, 'sub', a, 'reac') moose.connect(r, 'prd', b, 'reac') moose.connect(r, 'prd', c, 'reac') r.Kf = 0.1 r.Kb = 0.01 tabA = moose.Table2('/compt/a/tabA') tabA.format = 'npy' tabA.useStreamer = 1 # Setting format alone is not good enough tabB = moose.Table2('/compt/b/tabB') tabB.outfile = 'table2.npy' tabC = moose.Table2('/compt/c/tabC') tabC.outfile = 'tablec.csv' moose.connect(tabA, 'requestOut', a, 'getConc') moose.connect(tabB, 'requestOut', b, 'getConc') moose.connect(tabC, 'requestOut', c, 'getConc') moose.reinit() [print_table(x) for x in [tabA, tabB, tabC]] runtime = 1000 print('Starting moose for %d secs' % runtime) moose.start(runtime, 1) print(' MOOSE is done') # Now read the numpy and csv and check the results. a = np.load('_tables/compt/a/tabA.npy') b = np.load('table2.npy') c = np.loadtxt('tablec.csv', skiprows=1) print(a) print(b) print(c) print(a['time']) print(b['time']) assert len(a['time']) == len(a['/compt/a/tabA'])
def create_model(compt, sec): global pools_ for s in ['A']: x = moose.Pool('%s/%s.%s' % (compt.path, sec, s)) pools_[x.name] = x t = moose.Table2('%s/tab%s.%s' % (compt.path, sec, s)) moose.connect(t, 'requestOut', x, 'getConc') tables_[x.name] = t
def getModelAnnotation(obj, baseId, basepath): annotationNode = obj.getAnnotation() if annotationNode is not None: numchild = annotationNode.getNumChildren() for child_no in range(0, numchild): childNode = annotationNode.getChild(child_no) if (childNode.getPrefix() == "moose" and childNode.getName() == "ModelAnnotation"): num_gchildren = childNode.getNumChildren() for gchild_no in range(0, num_gchildren): grandChildNode = childNode.getChild(gchild_no) nodeName = grandChildNode.getName() if (grandChildNode.getNumChildren() == 1): baseinfo = moose.Annotator(baseId.path + '/info') baseinfo.modeltype = "xml" if nodeName == "runTime": runtime = float( (grandChildNode.getChild(0).toXMLString())) baseinfo.runtime = runtime if nodeName == "solver": solver = (grandChildNode.getChild(0).toXMLString()) baseinfo.solver = solver if (nodeName == "plots"): plotValue = ( grandChildNode.getChild(0).toXMLString()) p = moose.element(baseId) datapath = moose.element(baseId).path + "/data" if not moose.exists(datapath): datapath = moose.Neutral(baseId.path + "/data") graph = moose.Neutral(datapath.path + "/graph_0") plotlist = plotValue.split(";") tablelistname = [] for plots in plotlist: plots = plots.replace(" ", "") plotorg = plots if (moose.exists(basepath.path + plotorg) and isinstance( moose.element(basepath.path + plotorg), moose.PoolBase)): plotSId = moose.element(basepath.path + plotorg) # plotorg = convertSpecialChar(plotorg) plot2 = plots.replace('/', '_') plot3 = plot2.replace('[', '_') plotClean = plot3.replace(']', '_') plotName = plotClean + ".conc" fullPath = graph.path + '/' + \ plotName.replace(" ", "") # If table exist with same name then # its not created if not fullPath in tablelistname: tab = moose.Table2(fullPath) tablelistname.append(fullPath) moose.connect( tab, "requestOut", plotSId, "getConc")
def add_table( moose_elem, field, tableName = None): global tables_ tablePath = '%s/tab%s' % (moose_elem.path, field) if moose.exists( tablePath ): return None t = moose.Table2( tablePath ) moose.connect( t, 'requestOut', moose_elem, 'get'+field[0].upper()+field[1:]) tables_[ moose_elem.name ].append( t ) _logger.debug( 'Added table on %s' % moose_elem.path )
def updatePlots(self): for path, lines in list(self.pathToLine.items()): element = moose.element(path) if isinstance(element, moose.Table2): tab = moose.Table2(path) else: tab = moose.Table(path) data = tab.vector ts = np.linspace(0, moose.Clock('/clock').currentTime, len(data)) for line in lines: line.set_data(ts, data) self.canvas.draw()
def makeModel(): # create container for model model = moose.Neutral('model') harmonic = moose.CubeMesh('/model/harmonic') harmonic.volume = 1e-15 lotka = moose.CubeMesh('/model/lotka') lotka.volume = 1e-15 # create molecules and reactions p = moose.Pool('/model/harmonic/p') v = moose.Pool('/model/harmonic/v') pdot = moose.Function('/model/harmonic/p/func') vdot = moose.Function('/model/harmonic/v/func') # Parameters offset1 = 1.0 offset2 = 1.0 k = 0.1 p.nInit = offset1 v.nInit = offset2 + 0.1 pdot.x.num = 1 vdot.x.num = 1 pdot.expr = "x0 - " + str(offset1) vdot.expr = "-" + str(k) + " * (x0 - " + str(offset2) + ")" # connect them up for reactions moose.connect(p, 'nOut', vdot.x[0], 'input') moose.connect(v, 'nOut', pdot.x[0], 'input') moose.connect(vdot, 'valueOut', v, 'increment') moose.connect(pdot, 'valueOut', p, 'increment') # Create the output tables graphs = moose.Neutral('/model/graphs') pplot = moose.Table2('/model/graphs/p') vplot = moose.Table2('/model/graphs/v') # connect up the tables moose.connect(pplot, 'requestOut', p, 'getN') moose.connect(vplot, 'requestOut', v, 'getN')
def buildLargeSystem(useStreamer=False): # create a huge system. if moose.exists('/comptB'): moose.delete('/comptB') moose.CubeMesh('/comptB') tables = [] for i in range(300): r = moose.Reac('/comptB/r%d' % i) a = moose.Pool('/comptB/a%d' % i) a.concInit = 10.0 b = moose.Pool('/comptB/b%d' % i) b.concInit = 2.0 c = moose.Pool('/comptB/c%d' % i) c.concInit = 0.5 moose.connect(r, 'sub', a, 'reac') moose.connect(r, 'prd', b, 'reac') moose.connect(r, 'prd', c, 'reac') r.Kf = 0.1 r.Kb = 0.01 # Make table name large enough such that the header is larger than 2^16 # . Numpy version 1 can't handle such a large header. If format 1 is # then this test will fail. t = moose.Table2('/comptB/TableO1%d' % i + 'abc' * 100) moose.connect(t, 'requestOut', a, 'getConc') tables.append(t) if useStreamer: s = moose.Streamer('/comptB/streamer') s.datafile = 'data2.npy' print("[INFO ] Total tables %d" % len(tables)) # Add tables using wilcardFind. s.addTables(moose.wildcardFind('/comptB/##[TYPE=Table2]')) print("Streamer has %d table" % s.numTables) assert s.numTables == len(tables), (s.numTables, len(tables)) moose.reinit() moose.start(10) if useStreamer: # load the data data = np.load(s.datafile) header = str(data.dtype.names) assert len(header) > 2**16 else: data = {x.columnName: x.vector for x in tables} return data
def simple_model_a(): compt = moose.CubeMesh( '/compt' ) r = moose.Reac( '/compt/r' ) a = moose.Pool( '/compt/a' ) a.concInit = 1 b = moose.Pool( '/compt/b' ) b.concInit = 2 c = moose.Pool( '/compt/c' ) c.concInit = 0.5 moose.connect( r, 'sub', a, 'reac' ) moose.connect( r, 'prd', b, 'reac' ) moose.connect( r, 'prd', c, 'reac' ) r.Kf = 0.1 r.Kb = 0.01 tabA = moose.Table2( '/compt/a/tab' ) tabB = moose.Table2( '/compt/tabB' ) tabC = moose.Table2( '/compt/tabB/tabC' ) print(tabA, tabB, tabC) moose.connect( tabA, 'requestOut', a, 'getConc' ) moose.connect( tabB, 'requestOut', b, 'getConc' ) moose.connect( tabC, 'requestOut', c, 'getConc' ) return [tabA, tabB, tabC]
def buildSystem(outfile): if moose.exists('/compt'): moose.delete('/compt') compt = moose.CubeMesh('/compt') assert compt r = moose.Reac('/compt/r') a = moose.Pool('/compt/a') a.concInit = 1 b = moose.Pool('/compt/b') b.concInit = 2 c = moose.Pool('/compt/c') c.concInit = 0.5 moose.connect(r, 'sub', a, 'reac') moose.connect(r, 'prd', b, 'reac') moose.connect(r, 'prd', c, 'reac') r.Kf = 0.1 r.Kb = 0.01 tabA = moose.Table2('/compt/a/tab') tabB = moose.Table2('/compt/tabB') tabC = moose.Table2('/compt/tabB/tabC') print(tabA, tabB, tabC) moose.connect(tabA, 'requestOut', a, 'getConc') moose.connect(tabB, 'requestOut', b, 'getConc') moose.connect(tabC, 'requestOut', c, 'getConc') # Now create a streamer and use it to write to a stream st = moose.Streamer('/compt/streamer') st.outfile = outfile print("outfile set to: %s " % st.outfile) st.addTable(tabA) st.addTables([tabB, tabC]) assert st.numTables == 3 return st
def _init_plots(self): ## make a few tables to store a few Vm-s numVms = 10 self.plots = moose.Table2( '/plotVms', numVms ) ## draw numVms out of N neurons nrnIdxs = random.sample(list(range(self.N)),numVms) for i in range( numVms ): moose.connect( self.network.vec[nrnIdxs[i]], 'VmOut', \ self.plots.vec[i], 'input') ## make self.N tables to store spikes of all neurons self.spikes = moose.Table2( '/plotSpikes', self.N ) moose.connect( self.network, 'spikeOut', \ self.spikes, 'input', 'OneToOne' ) ## make 2 tables to store spikes of all exc and all inh neurons self.spikesExc = moose.Table2( '/plotSpikesAllExc' ) for i in range(self.NmaxExc): moose.connect( self.network.vec[i], 'spikeOut', \ self.spikesExc, 'input' ) self.spikesInh = moose.Table2( '/plotSpikesAllInh' ) for i in range(self.NmaxExc,self.N): moose.connect( self.network.vec[i], 'spikeOut', \ self.spikesInh, 'input' )
def nand( a, b ): compt = moose.CubeMesh( '/compt' ) compt.volume = 1 species = {} tables = { } concInit = { 'a' : a, 'b' : b, 'r' : 1, 'x' : 1 } for s in [ 'a', 'b', 'r', 'x', 'x*', 'ab', 'xab' ] : p = moose.Pool( '%s/%s' % (compt.path, s) ) t = moose.Table2( '%s/%s_table' % (compt.path, s ) ) moose.connect( t, 'requestOut', p, 'getConc' ) tables[ s ] = t p.concInit = concInit.get( s, 0.0 ) species[ s ] = p # Now the reactions. r1 = moose.Reac( '%s/reac1' % compt.path ) moose.connect( r1, 'sub', species[ 'a' ], 'reac' ) moose.connect( r1, 'sub', species[ 'b' ], 'reac' ) moose.connect( r1, 'prd', species[ 'ab' ], 'reac' ) r1.Kf = 1 r1.Kb = 0 r2 = moose.Reac( '%s/reac2' % compt.path ) moose.connect( r2, 'sub', species[ 'r' ], 'reac' ) moose.connect( r2, 'sub', species[ 'x' ], 'reac' ) moose.connect( r2, 'prd', species[ 'x*' ], 'reac' ) moose.connect( r2, 'prd', species[ 'r' ], 'reac' ) r2.Kf = 1 r2.Kb = 0 r3 = moose.Reac( '%s/reac3' % compt.path ) moose.connect( r3, 'sub', species[ 'x*' ], 'reac' ) moose.connect( r3, 'sub', species[ 'ab' ], 'reac' ) moose.connect( r3, 'prd', species[ 'xab' ], 'reac' ) r3.Kf = 100 r3.Kb = 0.01 stoich = moose.Stoich( '%s/stoich' % compt.path ) ksolve = moose.Ksolve( '%s/ksolve' % compt.path ) stoich.ksolve = ksolve stoich.compartment = compt stoich.path = '%s/#' % compt.path moose.reinit( ) moose.start( 20 ) return tables['x*'].vector[-1]
def create_table(tablePath, element, field, tableType): """Create table to record `field` from element `element` Tables are created under `dataRoot`, the names are generally created by removing `/model` in the beginning of `elementPath` and replacing `/` with `_`. If this conflicts with an existing table, the id value of the target element (elementPath) is appended to the name. """ if moose.exists(tablePath): table = moose.element(tablePath) else: if tableType == "Table2": table = moose.Table2(tablePath) elif tableType == "Table": table = moose.Table(tablePath) moose.connect(table, "requestOut", element, "get%s" % (field)) return table
def runMoose(chem, stimVec, outMols): filename, file_extension = os.path.splitext(chem) if file_extension == ".g": modelId = moose.loadModel(chem, 'model', 'gsl') elif file_extension == ".xml": #modelId = mu.mooseReadSBML( chem, 'model', 'gsl' ) modelId = moose.readSBML(chem, 'model', 'gsl') ''' moose.le( "/model/kinetics" ) for i in moose.wildcardFind ( "/model/kinetics/##[ISA=PoolBase]" ): print( i.name, i.concInit ) for i in moose.wildcardFind ( "/model/kinetics/##[ISA=Reac]" ): print( i.name, i.Kf, i.Kb ) ''' tabs = moose.Neutral("/model/tabs") mooseMols = [getMooseName(i) for i in outMols] for i in mooseMols: el = moose.wildcardFind("/model/kinetics/" + i + ",/model/kinetics/##/" + i) if len(el) > 0: # Make an output table tab = moose.Table2("/model/tabs/" + i) moose.connect(tab, "requestOut", el[0], "getConc") for i in range(10, 20): moose.setClock(i, plotDt) moose.reinit() lastt = 0.0 for stim in stimVec: #print( "STIM = ", stim.mol, " ", stim.conc, " ", stim.time ) el = moose.wildcardFind("/model/kinetics/" + stim.mooseMol + ",/model/kinetics/##/" + stim.mooseMol) if len(el) > 0: if stim.time > lastt: moose.start(stim.time - lastt) lastt = stim.time el[0].concInit = stim.conc # assign conc even if no sim advance else: print("Warning: Stimulus molecule '{}' not found in MOOSE".format( stim.mooseMol)) vecs = {i.name: i.vector for i in moose.wildcardFind("/model/tabs/#")} return vecs
def _buildPlots(self): knownFields = { 'Vm': ('CompartmentBase', 'getVm', 1000, 'Memb. Potential (mV)'), 'Im': ('CompartmentBase', 'getIm', 1e9, 'Memb. current (nA)'), 'inject': ('CompartmentBase', 'getInject', 1e9, 'inject current (nA)'), 'Gbar': ('ChanBase', 'getGbar', 1e9, 'chan max conductance (nS)'), 'Gk': ('ChanBase', 'getGk', 1e9, 'chan conductance (nS)'), 'Ik': ('ChanBase', 'getIk', 1e9, 'chan current (nA)'), 'Ca': ('CaConcBase', 'getCa', 1e3, 'Ca conc (uM)'), 'n': ('PoolBase', 'getN', 1, '# of molecules'), 'conc': ('PoolBase', 'getConc', 1000, 'Concentration (uM)') } graphs = moose.Neutral(self.modelPath + '/graphs') dummy = moose.element('/') k = 0 for i in self.plotList: pair = i[0] + " " + i[1] dendCompts = self.elecid.compartmentsFromExpression[pair] spineCompts = self.elecid.spinesFromExpression[pair] plotObj, plotField = self._parseComptField(dendCompts, i, knownFields) plotObj2, plotField2 = self._parseComptField( spineCompts, i, knownFields) assert (plotField == plotField2) plotObj3 = plotObj + plotObj2 numPlots = sum(i != dummy for i in plotObj3) if numPlots > 0: tabname = graphs.path + '/plot' + str(k) scale = knownFields[i[3]][2] units = knownFields[i[3]][3] self.plotNames.append((tabname, i[4], k, scale, units)) k += 1 if i[3] == 'n' or i[3] == 'conc': tabs = moose.Table2(tabname, numPlots) else: tabs = moose.Table(tabname, numPlots) vtabs = moose.vec(tabs) q = 0 for p in [x for x in plotObj3 if x != dummy]: moose.connect(vtabs[q], 'requestOut', p, plotField) q += 1
def buildPlots(rdes): if not moose.exists('/graphs'): moose.Neutral('/graphs') numPlots = 10 caPsd = moose.vec('/model/chem/psd/Ca') caHead = moose.vec('/model/chem/spine/Ca') caDend = moose.vec('/model/chem/dend/Ca_dend_input') psdR = moose.vec('/model/chem/psd/tot_PSD_R') numSpines = rdes.spineCompt.mesh.num assert (2 * numSpines == len(rdes.spineComptElist)) assert (len(caPsd) == numSpines) assert (len(caHead) == numSpines) if numSpines < numPlots: caPsdTab = moose.Table2('/graphs/caPsdTab', numSpines).vec caHeadTab = moose.Table2('/graphs/caHeadTab', numSpines).vec psdRtab = moose.Table2('/graphs/psdRtab', numSpines).vec for i in range(numSpines): moose.connect(caPsdTab[i], 'requestOut', caPsd[i], 'getConc') moose.connect(caHeadTab[i], 'requestOut', caHead[i], 'getConc') moose.connect(psdRtab[i], 'requestOut', psdR[i], 'getN') else: caPsdTab = moose.Table2('/graphs/caPsdTab', numPlots).vec caHeadTab = moose.Table2('/graphs/caHeadTab', numPlots).vec psdRtab = moose.Table2('/graphs/psdRtab', numPlots).vec dx = numSpines / numPlots for i in range(numPlots): moose.connect(caPsdTab[i], 'requestOut', caPsd[i * dx], 'getConc') moose.connect(caHeadTab[i], 'requestOut', caHead[i * dx], 'getConc') moose.connect(psdRtab[i], 'requestOut', psdR[i * dx], 'getN') caDendTab = moose.Table2('/graphs/caDendTab', len(caDend)).vec for i in zip(caDendTab, caDend): moose.connect(i[0], 'requestOut', i[1], 'getConc') vtab = moose.Table('/graphs/VmTab') moose.connect(vtab, 'requestOut', rdes.soma, 'getVm') eSpineCaTab = moose.Table('/graphs/eSpineCaTab') path = rdes.spineComptElist[1].path + "/Ca_conc" moose.connect(eSpineCaTab, 'requestOut', path, 'getCa') eSpineVmTab = moose.Table('/graphs/eSpineVmTab') moose.connect(eSpineVmTab, 'requestOut', rdes.spineComptElist[1], 'getVm') eSpineGkTab = moose.Table('/graphs/eSpineGkTab') path = rdes.spineComptElist[1].path + "/NMDA" moose.connect(eSpineGkTab, 'requestOut', path, 'getGk')
def test_inheritance(): ta = moose.Table2('/tab2', 10) tb = moose.wildcardFind('/##[TYPE=Table2]') assert len(tb) == len(ta.vec) for i, (t1, t2) in enumerate(zip(tb, ta.vec)): assert t1 == t2, (t1, t2) assert t1.id == t2.id assert t1.dataIndex == t2.dataIndex assert t1.path == t2.path a = moose.CubeMesh('/dadada') isinstance(a, moose.CubeMesh) assert isinstance(a, moose.CubeMesh) aa = moose.wildcardFind('/##[TYPE=CubeMesh]')[0] assert a == aa # This must be true for isinstance to work. assert isinstance(aa, moose.CubeMesh), (a.__class__, aa.__class__) a = moose.CubeMesh('yapf') assert a.isA['CubeMesh'] assert a.isA['ChemCompt']