def makeChemProto(name='hydra'): chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh('/library/' + name + '/' + name) A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') C = moose.Pool(compt.path + '/C') #A.diffConst=params['diffA'] #B.diffConst=params['diffB'] Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') Cdot = moose.Function(C.path + '/Cdot') #Adot.expr="0.001*((x0^2/x1)+1)-1*x0+0.5*x0" #Bdot.expr="0*x0+0.001*x0^2-1*x1+1*x1" Adot.expr = "-0.1*x0+((0.1*x0^2)/(x1+x2))" Bdot.expr = "0*x0-0.1*x1+0.1*x2+0.1*x0^2-0.1*(x1+x2)" Cdot.expr = "0*x0+0.1*x1-0.1*x2+0.1*x0^2-0.1*(x1+x2)" print "$$$$> ", Adot, Bdot, Cdot print Adot.expr, Bdot.expr, Cdot.expr print moose.showmsg(Adot) Adot.x.num = 3 #2 Bdot.x.num = 3 #2 Cdot.x.num = 3 #A.nInit=10 #B.nInit=5 A.nInit = 1 B.nInit = 1 C.nInit = 1 moose.connect(A, 'nOut', Adot.x[0], 'input') moose.connect(B, 'nOut', Adot.x[1], 'input') moose.connect(C, 'nOut', Adot.x[2], 'input') moose.connect(Adot, 'valueOut', A, 'increment') moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') moose.connect(C, 'nOut', Bdot.x[2], 'input') moose.connect(Bdot, 'valueOut', B, 'increment') moose.connect(A, 'nOut', Cdot.x[0], 'input') moose.connect(B, 'nOut', Cdot.x[1], 'input') moose.connect(C, 'nOut', Cdot.x[2], 'input') moose.connect(Cdot, 'valueOut', C, 'increment') return compt
def test_print(): a = moose.Function('f', expr='sqrt(sin(x0))+cos(x1)^2+ln(20+sin(t))') # Get equivalent sympy expression. And do whatever you like with it. try: sympyExpr = a.sympyExpr() print('Sympy expression is:', sympyExpr) # Or pretty-print using sympy a.printUsingSympy() except ImportError: pass
def test_var_order(): """The y values are one step behind the x values because of scheduling sequences""" moose.delete( '/' ) nsteps = 5 simtime = nsteps dt = 1.0 # fn0 = moose.Function('/fn0') fn1 = moose.Function('/fn1') fn1.x.num = 2 fn1.expr = 'y1+y0+x1+x0' fn1.mode = 1 inputs = np.arange(0, nsteps+1, 1.0) x0 = moose.StimulusTable('/x0') x0.vector = inputs x0.startTime = 0.0 x0.stopTime = simtime x0.stepPosition = 0.0 inputs /= 10 x1 = moose.StimulusTable('/x1') x1.vector = inputs x1.startTime = 0.0 x1.stopTime = simtime x1.stepPosition = 0.0 inputs /= 10 y0 = moose.StimulusTable('/y0') y0.vector = inputs y0.startTime = 0.0 y0.stopTime = simtime y0.stepPosition = 0.0 inputs /= 10 y1 = moose.StimulusTable('/y1') y1.vector = inputs y1.startTime = 0.0 y1.startTime = 0.0 y1.stopTime = simtime y1.stepPosition = 0.0 # print( fn1, type(fn1) ) # print( moose.showmsg(fn1.x) ) moose.connect(x0, 'output', fn1.x[0], 'input') moose.connect(x1, 'output', fn1.x[1], 'input') moose.connect(fn1, 'requestOut', y0, 'getOutputValue') moose.connect(fn1, 'requestOut', y1, 'getOutputValue') z1 = moose.Table('/z1') moose.connect(z1, 'requestOut', fn1, 'getValue') for ii in range(32): moose.setClock(ii, dt) moose.reinit() moose.start(simtime) expected = [0, 1.1, 2.211, 3.322, 4.433, 5.544] assert np.allclose(z1.vector, expected), "Excepted %s, got %s" % (expected, z1.vector ) print( 'Passed order vars' )
def remove_extra( pool, limit ): null = moose.BufPool( '%s/null' % pool.path ) null.nInit = 0.0 nullReac = moose.Reac( '%s/null_reac' % pool.path ) nullReac.numKb = 0.0 moose.connect( nullReac, 'sub', pool, 'reac' ) moose.connect( nullReac, 'prd', null, 'reac' ) nullF = moose.Function( '%s/func_null' % pool.path ) nullF.expr = '(x0 > %f)?1e-2:0' % limit _logger.debug( 'Removing extra from pool %s' % pool.path ) _logger.debug( '\tExpression on nullR %s' % nullF.expr ) moose.connect( pool, 'nOut', nullF.x[0], 'input' ) moose.connect( nullF, 'valueOut', nullReac, 'setNumKf' )
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 test_var_order(): """The y values are one step behind the x values because of scheduling sequences""" nsteps = 5 simtime = nsteps dt = 1.0 # fn0 = moose.Function('/fn0') # fn0.x.num = 2 # fn0.expr = 'x0 + x1' # fn0.mode = 1 fn1 = moose.Function('/fn1') fn1.x.num = 2 fn1.expr = 'y1 + y0 + x1 + x0' fn1.mode = 1 inputs = np.arange(0, nsteps+1, 1.0) x0 = moose.StimulusTable('/x0') x0.vector = inputs x0.startTime = 0.0 x0.stopTime = simtime x0.stepPosition = 0.0 inputs /= 10 x1 = moose.StimulusTable('/x1') x1.vector = inputs x1.startTime = 0.0 x1.stopTime = simtime x1.stepPosition = 0.0 inputs /= 10 y0 = moose.StimulusTable('/y0') y0.vector = inputs y0.startTime = 0.0 y0.stopTime = simtime y0.stepPosition = 0.0 inputs /= 10 y1 = moose.StimulusTable('/y1') y1.vector = inputs y1.startTime = 0.0 y1.startTime = 0.0 y1.stopTime = simtime y1.stepPosition = 0.0 moose.connect(x0, 'output', fn1.x[0], 'input') moose.connect(x1, 'output', fn1.x[1], 'input') moose.connect(fn1, 'requestOut', y0, 'getOutputValue') moose.connect(fn1, 'requestOut', y1, 'getOutputValue') z1 = moose.Table('/z1') moose.connect(z1, 'requestOut', fn1, 'getValue') for ii in range(32): moose.setClock(ii, dt) moose.reinit() moose.start(simtime) for ii in range(len(z1.vector)): print ii, z1.vector[ii]
def makeChemProto(name='hydra'): chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh('/library/' + name + '/' + name) A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') C = moose.Pool(compt.path + '/C') space = moose.Pool(compt.path + '/space') #A.diffConst=params['diffA'] #B.diffConst=params['diffB'] Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') Cdot = moose.Function(C.path + '/Cdot') #Adot.expr="0.001*((x0^2/x1)+1)-1*x0+0.5*x0" #Bdot.expr="0*x0+0.001*x0^2-1*x1+1*x1" #Adot.expr="0.5*exp(-1.5*x2/(50*1e-06))*x0^2*x1-(0.1+0.01)*x0+0.01*x1" #Bdot.expr="-0.5*exp(-1.5*x2/(50*1e-06))*x0^2*x1+0.1*x0-0.01*x1+0.01" Adot.expr = "0.1*x0^2*x1-(0.1+0.01)*x0+0.01*x1" Bdot.expr = "-0.1*x0^2*x1+0.1*x0-0.01*x1+0.01" print moose.showmsg(Adot) Adot.x.num = 2 #2 Bdot.x.num = 2 #2 #A.nInit=10 #B.nInit=5 A.nInit = 0 B.nInit = 0 moose.connect(A, 'nOut', Adot.x[0], 'input') moose.connect(B, 'nOut', Adot.x[1], 'input') #moose.connect( space, 'nOut', Adot.x[2], 'input' ) moose.connect(Adot, 'valueOut', A, 'increment') moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') #moose.connect( space, 'nOut', Bdot.x[2], 'input' ) moose.connect(Bdot, 'valueOut', B, 'increment') return compt
def makeChemProto(name='hydra'): chem=moose.Neutral('/library/'+name) compt=moose.CubeMesh('/library/'+name + '/' + name) A=moose.Pool(compt.path+'/A') B=moose.Pool(compt.path+'/B') A.diffConst=params['diffA'] B.diffConst=params['diffB'] Adot = moose.Function( A.path + '/Adot' ) Bdot = moose.Function( B.path + '/Bdot' ) Adot.expr="-0.28*x0*x1" Bdot.expr="0.28*x0*x1-0.03*x0" Adot.x.num = 2 #2 Bdot.x.num = 2 moose.connect( A, 'nOut', Adot.x[0], 'input' ) moose.connect( B, 'nOut', Adot.x[1], 'input' ) moose.connect( Adot, 'valueOut', A, 'increment' ) moose.connect( A, 'nOut', Bdot.x[0], 'input' ) moose.connect( B, 'nOut', Bdot.x[1], 'input' ) moose.connect( Bdot, 'valueOut', B, 'increment' ) return compt
def test_var_order(): nsteps = 5 simtime = nsteps dt = 1.0 fn1 = moose.Function('/fn1') fn1.expr = 'B+A+y0+y1' inputs = np.arange(0, nsteps + 1, 1.0) x0 = moose.StimulusTable('/x0') x0.vector = inputs x0.startTime = 0.0 x0.stopTime = simtime x0.stepPosition = 0.0 print('x0', x0.vector) inputs /= 10 x1 = moose.StimulusTable('/x1') x1.vector = inputs x1.startTime = 0.0 x1.stopTime = simtime x1.stepPosition = 0.0 print('x1', x1.vector) inputs /= 10 y0 = moose.StimulusTable('/y0') y0.vector = inputs y0.startTime = 0.0 y0.stopTime = simtime y0.stepPosition = 0.0 print('y0', y0.vector) inputs /= 10 y1 = moose.StimulusTable('/y1') y1.vector = inputs print('y1', y1.vector) y1.startTime = 0.0 y1.startTime = 0.0 y1.stopTime = simtime y1.stepPosition = 0.0 moose.connect(x0, 'output', fn1['A'], 'input') moose.connect(x1, 'output', fn1['B'], 'input') moose.connect(fn1, 'requestOut', y0, 'getOutputValue') moose.connect(fn1, 'requestOut', y1, 'getOutputValue') z1 = moose.Table('/z1') moose.connect(z1, 'requestOut', fn1, 'getValue') for ii in range(32): moose.setClock(ii, dt) moose.reinit() moose.start(simtime) expected = [0, 1.1, 2.211, 3.322, 4.433, 5.544] assert np.allclose(z1.vector, expected), "Excepted %s, got %s" % (expected, z1.vector) print('Passed order vars')
def makeChemProto(name='hydra'): chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh('/library/' + name + '/' + name) A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') #A.diffConst=params['diffA'] #B.diffConst=params['diffB'] Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') Adot.expr = "-x0+(x0^2/(1+0.01*x0^2))*x1" Bdot.expr = "x0-(x0^2/(1+0.01*x0^2))*x1" print moose.showmsg(Adot) Adot.x.num = 2 #2 Bdot.x.num = 2 #2 moose.connect(A, 'nOut', Adot.x[0], 'input') moose.connect(B, 'nOut', Adot.x[1], 'input') moose.connect(Adot, 'valueOut', A, 'increment') moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') moose.connect(Bdot, 'valueOut', B, 'increment')
def attachStimulus( fname, rdes ): compts = rdes.elecid.compartments heads = [] lookupSpineIndexFromCompt = [] for i in compts: sl = rdes.elecid.spinesOnCompartment[i] lookupSpineIndexFromCompt.append( len( heads ) ) heads.extend( sl[1::2] ) ampar = moose.wildcardFind( '/model/elec/#/glu' ) assert( len(ampar) == len( heads ) ) moose.RandSpike( '/model/elec/spike', len( heads ) ) spikes = moose.vec( '/model/elec/spike' ) spikes.rate = params['meanSpikeRate'] spikes.refractT = params['refractoryPeriod'] amparSynWeight = params['amparSynapseWeight'] nmdarSynWeight = params['nmdarSynapseWeight'] for j in zip( heads, range( len( heads ) ) ): sh = moose.element( j[0].path + '/glu/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = amparSynWeight moose.connect( spikes[j[1]], 'spikeOut', sh.synapse[0], 'addSpike' ) sh = moose.element( j[0].path + '/NMDA/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = nmdarSynWeight moose.connect( spikes[j[1]], 'spikeOut', sh.synapse[0], 'addSpike' ) thetaGaba = moose.Function( '/model/elec/thetaGabaRhythm' ) timeExpr = 'cos( 6.283 * t * ' + str(params['thetaFreq']/2.0) + ' )^2' rateExpr = str( 2.0 * params['thetaGabaSpikeRate']) thetaGaba.expr = str( params['baseGabaSpikeRate']) + ' + ' + rateExpr + ' * ' + timeExpr print thetaGaba.expr, gabar = moose.wildcardFind( '/model/elec/#/GABA' ) print " NUM-GABA = ", len(gabar) rsGabar = moose.RandSpike( '/model/elec/gabaSpike', len( gabar ) ) moose.connect( thetaGaba, 'valueOut', rsGabar, 'setRate', 'OneToAll' ) gabaSpikes = moose.vec( '/model/elec/gabaSpike' ) #spikes.rate = params['meanSpikeRate'] gabaSpikes.refractT = params['refractoryPeriod'] gabarSynWeight = params['gabarSynapseWeight'] for i in range( len(gabar) ): sh = moose.element( gabar[i].path + '/sh' ) sh.numSynapses = 1 sh.synapse[0].weight = gabarSynWeight moose.connect( gabaSpikes[i], 'spikeOut', sh.synapse[0], 'addSpike' ) return lookupSpineIndexFromCompt
def phosphorylation_first_step(root, nc): # CaMKII to x1y0 is slow. subPool = molecules_[pool_name(root, 'x0y%d' % nc)] prdPool = molecules_[pool_name(root, 'x1y%d' % (nc - 1))] r0 = add_reaction('%s/reac_0to1_%d' % (subPool.path, nc)) r0.numKb = 0 moose.connect(r0, 'sub', subPool, 'reac') moose.connect(r0, 'prd', prdPool, 'reac') # The rate expression of this reaction depends on Ca++ f = moose.Function('%s/func_kf' % r0.path) f.expr = '{nc}*{k1}*(x0/{kh1})^6/(1 + (x0/{kh1})^3)^2'.format( k1=_p.k_1, kh1=conc_to_n(_p.K_H1), nc=nc) f.x.num = 1 moose.connect(molecules_[pool_name(root, 'ca')], 'nOut', f.x[0], 'input') moose.connect(f, 'valueOut', r0, 'setNumKf') _logger.debug('Reaction: %s -> %s' % (subPool.name, prdPool.name))
def ca_input( root ): """Input calcium pulse When using stochastic solver, any event less than 100 or so seconds would not work. """ global args # Input calcium ca = moose.BufPool( '%s/ca' % root.path ) ca.nInit = conc_to_n( _p.ca_basal ) ca.name = pool_name( root, ca.name ) molecules_[ ca.name ] = ca _logger.info("Setting up input calcium : init = %s" % ca.nInit ) # _logger.debug("Baselevel ca conc = %s" % _p.resting_ca_conc) concFunc = moose.Function( "%s/cafunc" % ca.path ) concFunc.expr = args[ 'ca_expr' ] moose.connect( concFunc, 'valueOut', ca, 'setConc' ) _logger.info( "Ca conc expression = %s " % concFunc.expr )
def createFunction(fb, inputB, objB, objA): fapath1 = fb.path.replace(objB, objA) fapath = fapath1.replace('[0]', '') if not moose.exists(fapath): # if fb.parent.className in ['CubeMesh','CyclMesh']: # des = moose.Function('/'+objA+'/'+fb.parent.name+'/'+fb.name) # elif fb.parent.className in ['Pool','ZombiePool','BufPool','ZombieBufPool']: # for akey in list(poolListina[findCompartment(fb).name]): # if fb.parent.name == akey.name: # des = moose.Function(akey.path+'/'+fb.name) des = moose.Function(fapath) moose.connect(des, 'valueOut', moose.element(fapath).parent, 'setN') for src in inputB: pool = ((src.path).replace(objB, objA)).replace('[0]', '') numVariables = des.numVars expr = "" expr = (des.expr + '+' + 'x' + str(numVariables)) expr = expr.lstrip("0 +") expr = expr.replace(" ", "") des.expr = expr moose.connect(pool, 'nOut', des.x[numVariables], 'input')
def makeFuncRate(): model = moose.Neutral('/library') model = moose.Neutral('/library/chem') compt = moose.CubeMesh('/library/chem/compt') compt.volume = 1e-15 A = moose.Pool('/library/chem/compt/A') B = moose.Pool('/library/chem/compt/B') C = moose.Pool('/library/chem/compt/C') reac = moose.Reac('/library/chem/compt/reac') func = moose.Function('/library/chem/compt/reac/func') func.x.num = 1 func.expr = "(x0/1e8)^2" moose.connect(C, 'nOut', func.x[0], 'input') moose.connect(func, 'valueOut', reac, 'setNumKf') moose.connect(reac, 'sub', A, 'reac') moose.connect(reac, 'prd', B, 'reac') A.concInit = 1 B.concInit = 0 C.concInit = 0 reac.Kb = 1
def pp1_activation( root ): """Here we setup the reactions PP1 I1P binds with PP1 and give rise to complex I1PPP1 (which is inavtivated PP1) I1P + PP1 <- -> I1PPP1 """ activePP1 = molecules_[pool_name(root, 'PP1')] i1pPool = molecules_[ pool_name( root, 'I1P' ) ] inactive_pp1 = molecules_[ pool_name( root, 'I1PPP1' ) ] r = add_reaction( '%s/reac_inactivate_pp1' % activePP1.path ) moose.connect( r, 'sub', activePP1, 'reac' ) moose.connect( r, 'prd', inactive_pp1, 'reac') k3, k4, s = 1e5, 0.0001, 1 kfFun = moose.Function( '%s/kffunc' % r.path ) kfFun.expr = '{scale}*{k3}*x0'.format( k3 = k3, scale = s ) moose.connect( i1pPool, 'nOut', kfFun.x[0], 'input' ) moose.connect( kfFun, 'valueOut', r, 'setNumKf' ) r.numKb = s * k4 _logger.debug( 'Reaction: %s + %s -> %s' % ( activePP1.name, i1pPool.name, inactive_pp1.name ) )
def ShortTermPlas(synapse, index, stp_params, simdt, presyn, msg): #implements short term plasticity - depression and/or facilitation synchan = synapse.parent.parent num_inputs = 0 if stp_params.depress is not None: dep = facil_depress(synchan.path + NAME_DEPRESS + str(index), stp_params.depress, simdt, presyn, msg) log.debug(' ***depress={} {} presyn {}', dep.path, dep.expr, presyn.path) num_inputs += 1 source0 = dep plas_expr = '(init*x0)' if stp_params.facil is not None: fac = facil_depress(synchan.path + NAME_FACIL + str(index), stp_params.facil, simdt, presyn, msg) log.debug(' ***facil={} {} presyn {}', fac.path, fac.expr, presyn.path) num_inputs += 1 if num_inputs == 1: source0 = fac plas_expr = '(init*x0)' else: source1 = fac plas_expr = '(init*x0*x1)' # log.debug('**** STP={} x[0]={} ****', plas_expr, source0.path) plaspath = synchan.path + NAME_STP + str(index) plas_func = moose.Function(plaspath) plas_func.c['init'] = synapse.weight plas_func.c['dt'] = simdt plas_func.expr = '(t<2*dt) ? (init) :' + plas_expr plas_func.x.num = num_inputs moose.connect(source0, 'valueOut', plas_func.x[0], 'input') if num_inputs == 2: moose.connect(source1, 'valueOut', plas_func.x[1], 'input') # Output the updated weight computed by plasticity function to the synapse moose.connect(plas_func, 'valueOut', synapse, 'setWeight') return
def example(): """Function objects can be used to evaluate expressions with arbitrary number of variables and constants. We can assign expression of the form:: f(c0, c1, ..., cM, x0, x1, ..., xN, y0,..., yP ) where `c_i`'s are constants and `x_i`'s and `y_i`'s are variables. The constants must be defined before setting the expression and variables are connected via messages. The constants can have any name, but the variable names must be of the form x{i} or y{i} where i is increasing integer starting from 0. The `x_i`'s are field elements and you have to set their number first (function.x.num = N). Then you can connect any source field sending out double to the 'input' destination field of the `x[i]`. The `y_i`'s are useful when the required variable is a value field and is not available as a source field. In that case you connect the `requestOut` source field of the function element to the `get{Field}` destination field on the target element. The `y_i`'s are automatically added on connecting. Thus, if you call:: moose.connect(function, 'requestOut', a, 'getSomeField') moose.connect(function, 'requestOut', b, 'getSomeField') then ``a.someField`` will be assigned to ``y0`` and ``b.someField`` will be assigned to ``y1``. In this example we evaluate the expression: ``z = c0 * exp(c1 * x0) * cos(y0)`` with x0 ranging from -1 to +1 and y0 ranging from -pi to +pi. These values are stored in two stimulus tables called xtab and ytab respectively, so that at each timestep the next values of x0 and y0 are assigned to the function. Along with the value of the expression itself we also compute its derivative with respect to y0 and its derivative with respect to time (rate). The former uses a five-point stencil for the numerical differentiation and has a glitch at y=0. The latter uses backward difference divided by dt. Unlike Func class, the number of variables and constants are unlimited in Function and you can set all the variables via messages. """ demo = moose.Neutral('/model') function = moose.Function('/model/function') function.c['c0'] = 1.0 function.c['c1'] = 2.0 function.x.num = 1 function.expr = 'c0 * exp(c1*x0) * cos(y0) + sin(t)' # mode 0 - evaluate function value, derivative and rate # mode 1 - just evaluate function value, # mode 2 - evaluate derivative, # mode 3 - evaluate rate function.mode = 0 function.independent = 'y0' nsteps = 10000 xarr = np.linspace(0.0, 1.0, nsteps) # Stimulus tables allow you to store sequences of numbers which # are delivered via the 'output' message at each time step. This # is a placeholder and in real scenario you will be using any # sourceFinfo that sends out a double value. input_x = moose.StimulusTable('/xtab') input_x.vector = xarr input_x.startTime = 0.0 input_x.stepPosition = xarr[0] input_x.stopTime = simtime moose.connect(input_x, 'output', function.x[0], 'input') yarr = np.linspace(-np.pi, np.pi, nsteps) input_y = moose.StimulusTable('/ytab') input_y.vector = yarr input_y.startTime = 0.0 input_y.stepPosition = yarr[0] input_y.stopTime = simtime moose.connect(function, 'requestOut', input_y, 'getOutputValue') # data recording result = moose.Table('/ztab') moose.connect(result, 'requestOut', function, 'getValue') derivative = moose.Table('/zprime') moose.connect(derivative, 'requestOut', function, 'getDerivative') rate = moose.Table('/dz_by_dt') moose.connect(rate, 'requestOut', function, 'getRate') x_rec = moose.Table('/xrec') moose.connect(x_rec, 'requestOut', input_x, 'getOutputValue') y_rec = moose.Table('/yrec') moose.connect(y_rec, 'requestOut', input_y, 'getOutputValue') dt = simtime / nsteps for ii in range(32): moose.setClock(ii, dt) moose.reinit() moose.start(simtime) # Uncomment the following lines and the import matplotlib.pyplot as plt on top # of this file to display the plot. if plot_: plt.plot(x_rec.vector, result.vector, 'r-', label='z = {}'.format(function.expr)) plt.subplot(4, 1, 1) z = function.c['c0'] * np.exp( function.c['c1'] * xarr) * np.cos(yarr) + np.sin( np.arange(len(xarr)) * dt) zz = result.vector[1:] err = z[1:] - zz[1:] assert (np.abs(err) <= 0.05).all(), err assert (np.mean(err) <= 0.001), np.mean(err) if plot_: plt.plot(xarr, z, 'b--', label='numpy computed') plt.xlabel('x') plt.ylabel('z') plt.legend() if plot_: plt.subplot(4, 1, 2) plt.plot(y_rec.vector, derivative.vector, 'r-', label='dz/dy0') # derivatives computed by putting x values in the analytical formula dzdy = function.c['c0'] * np.exp(function.c['c1'] * xarr) * (-np.sin(yarr)) err = np.abs(dzdy - derivative.vector[1:]) assert (err < 1e-2).all(), err assert (np.mean(err) < 1e-3), np.mean(err) if plot_: plt.plot(yarr, dzdy, 'b--', label='numpy computed') plt.xlabel('y') plt.ylabel('dz/dy') plt.legend() if plot_: plt.subplot(4, 1, 3) # *** BEWARE *** The first two entries are spurious. Entry 0 is # *** from reinit sending out the defaults. Entry 2 is because # *** there is no lastValue for computing real forward difference. plt.plot(np.arange(2, len(rate.vector), 1) * dt, rate.vector[2:], 'r-', label='dz/dt') dzdt = np.diff(z) / dt plt.plot(np.arange(0, len(dzdt), 1.0) * dt, dzdt, 'b--', label='numpy computed') plt.xlabel('t') plt.ylabel('dz/dt') plt.legend() plt.tight_layout() plt.show()
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 test_wrapper(): a = moose.Pool('/dadadada', concInit=9.99, nInit=10) assert a.nInit == 10 f = moose.Function('/fun1', expr='x0+x1+A+B') assert f.expr == 'x0+x1+A+B' assert f.numVars == 4, f.numVars
def checkCreate(scene, view, modelpath, mobj, string, ret_string, num, event_pos, layoutPt): # The variable 'compt' will be empty when dropping cubeMesh,cyclMesh, but rest it shd be # compartment # if modelpath.find('/',1) > -1: # modelRoot = modelpath[0:modelpath.find('/',1)] # else: # modelRoot = modelpath print "28 ", modelpath if moose.exists(modelpath + '/info'): mType = moose.Annotator((moose.element(modelpath + '/info'))).modeltype itemAtView = view.sceneContainerPt.itemAt(view.mapToScene(event_pos)) pos = view.mapToScene(event_pos) modelpath = moose.element(modelpath) if num: string_num = ret_string + str(num) else: string_num = ret_string if string == "CubeMesh" or string == "CylMesh": if string == "CylMesh": mobj = moose.CylMesh(modelpath.path + '/' + string_num) else: mobj = moose.CubeMesh(modelpath.path + '/' + string_num) mobj.volume = 1e-15 mesh = moose.element(mobj.path + '/mesh') qGItem = ComptItem(scene, pos.toPoint().x(), pos.toPoint().y(), 100, 100, mobj) qGItem.setPen( QtGui.QPen(Qt.QColor(66, 66, 66, 100), 1, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) view.sceneContainerPt.addItem(qGItem) qGItem.cmptEmitter.connect( qGItem.cmptEmitter, QtCore.SIGNAL("qgtextPositionChange(PyQt_PyObject)"), layoutPt.positionChange1) qGItem.cmptEmitter.connect( qGItem.cmptEmitter, QtCore.SIGNAL("qgtextItemSelectedChange(PyQt_PyObject)"), layoutPt.objectEditSlot) compartment = qGItem layoutPt.qGraCompt[mobj] = qGItem view.emit(QtCore.SIGNAL("dropped"), mobj) elif string == "Pool" or string == "BufPool": #getting pos with respect to compartment otherwise if compartment is moved then pos would be wrong posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() if string == "Pool": poolObj = moose.Pool(mobj.path + '/' + string_num) else: poolObj = moose.BufPool(mobj.path + '/' + string_num) poolinfo = moose.Annotator(poolObj.path + '/info') #Compartment's one Pool object is picked to get the font size qGItem = PoolItem(poolObj, itemAtView) layoutPt.mooseId_GObj[poolObj] = qGItem posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() bgcolor = getRandColor() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('green'), bgcolor) poolinfo.color = str(bgcolor.getRgb()) view.emit(QtCore.SIGNAL("dropped"), poolObj) setupItem(modelpath.path, layoutPt.srcdesConnection) layoutPt.drawLine_arrow(False) x, y = roundoff(qGItem.scenePos(), layoutPt) poolinfo.x = x poolinfo.y = y #Dropping is on compartment then update Compart size if isinstance(mobj, moose.ChemCompt): compt = layoutPt.qGraCompt[moose.element(mobj)] updateCompartmentSize(compt) elif string == "Reac": posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() reacObj = moose.Reac(mobj.path + '/' + string_num) reacinfo = moose.Annotator(reacObj.path + '/info') qGItem = ReacItem(reacObj, itemAtView) qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), "white", "white") #if mType == "new_kkit": # reacinfo.x = posWrtComp.x() # reacinfo.y = posWrtComp.y() layoutPt.mooseId_GObj[reacObj] = qGItem view.emit(QtCore.SIGNAL("dropped"), reacObj) setupItem(modelpath.path, layoutPt.srcdesConnection) layoutPt.drawLine_arrow(False) #Dropping is on compartment then update Compart size if isinstance(mobj, moose.ChemCompt): compt = layoutPt.qGraCompt[moose.element(mobj)] updateCompartmentSize(compt) x, y = roundoff(qGItem.scenePos(), layoutPt) reacinfo.x = x reacinfo.y = y elif string == "StimulusTable": posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() tabObj = moose.StimulusTable(mobj.path + '/' + string_num) tabinfo = moose.Annotator(tabObj.path + '/info') qGItem = TableItem(tabObj, itemAtView) qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('white'), QtGui.QColor('white')) #if mType == "new_kkit": #tabinfo.x = posWrtComp.x() #tabinfo.y = posWrtComp.y() layoutPt.mooseId_GObj[tabObj] = qGItem view.emit(QtCore.SIGNAL("dropped"), tabObj) setupItem(modelpath.path, layoutPt.srcdesConnection) layoutPt.drawLine_arrow(False) #Dropping is on compartment then update Compart size if isinstance(mobj, moose.ChemCompt): compt = layoutPt.qGraCompt[moose.element(mobj)] updateCompartmentSize(compt) x, y = roundoff(qGItem.scenePos(), layoutPt) tabinfo.x = x tabinfo.y = y elif string == "Function": posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() funcObj = moose.Function(mobj.path + '/' + string_num) funcinfo = moose.Annotator(funcObj.path + '/info') #moose.connect( funcObj, 'valueOut', mobj ,'setN' ) poolclass = ["ZombieBufPool", "BufPool"] comptclass = ["CubeMesh", "cyclMesh"] if mobj.className in poolclass: funcParent = layoutPt.mooseId_GObj[element(mobj.path)] elif mobj.className in comptclass: funcParent = layoutPt.qGraCompt[moose.element(mobj)] posWrtComp = funcParent.mapFromScene(pos).toPoint() #posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() qGItem = FuncItem(funcObj, funcParent) #print " function ", posWrtComp.x(),posWrtComp.y() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('red'), QtGui.QColor('green')) layoutPt.mooseId_GObj[funcObj] = qGItem #if mType == "new_kkit": #funcinfo.x = posWrtComp.x() #funcinfo.y = posWrtComp.y() view.emit(QtCore.SIGNAL("dropped"), funcObj) setupItem(modelpath.path, layoutPt.srcdesConnection) layoutPt.drawLine_arrow(False) #Dropping is on compartment then update Compart size mooseCmpt = findCompartment(mobj) if isinstance(mooseCmpt, moose.ChemCompt): compt = layoutPt.qGraCompt[moose.element(mooseCmpt)] updateCompartmentSize(compt) x, y = roundoff(qGItem.scenePos(), layoutPt) funcinfo.x = x funcinfo.y = y elif string == "Enz" or string == "MMenz": #If 2 enz has same pool parent, then pos of the 2nd enz shd be displaced by some position, need to check how to deal with it posWrtComp = pos enzPool = layoutPt.mooseId_GObj[mobj] if ((mobj.parent).className == "Enz"): QtGui.QMessageBox.information( None, 'Drop Not possible', '\'{newString}\' has to have Pool as its parent and not Enzyme Complex' .format(newString=string), QtGui.QMessageBox.Ok) return else: enzparent = findCompartment(mobj) parentcompt = layoutPt.qGraCompt[enzparent] if string == "Enz": enzObj = moose.Enz(moose.element(mobj).path + '/' + string_num) enzinfo = moose.Annotator(enzObj.path + '/info') moose.connect(enzObj, 'enz', mobj, 'reac') qGItem = EnzItem(enzObj, parentcompt) layoutPt.mooseId_GObj[enzObj] = qGItem posWrtComp = pos bgcolor = getRandColor() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y() - 40, QtGui.QColor('green'), bgcolor) x, y = roundoff(qGItem.scenePos(), layoutPt) enzinfo.x = x enzinfo.y = y enzinfo.color = str(bgcolor.name()) enzinfo.textColor = str(QtGui.QColor('green').name()) #if mType == "new_kkit": #enzinfo.x = posWrtComp.x() #enzinfo.y = posWrtComp.y() #enzinfo.color = str(bgcolor.name()) e = moose.Annotator(enzinfo) #e.x = posWrtComp.x() #e.y = posWrtComp.y() Enz_cplx = enzObj.path + '/' + string_num + '_cplx' cplxItem = moose.Pool(Enz_cplx) cplxinfo = moose.Annotator(cplxItem.path + '/info') qGEnz = layoutPt.mooseId_GObj[enzObj] qGItem = CplxItem(cplxItem, qGEnz) layoutPt.mooseId_GObj[cplxItem] = qGItem enzboundingRect = qGEnz.boundingRect() moose.connect(enzObj, 'cplx', cplxItem, 'reac') qGItem.setDisplayProperties(enzboundingRect.height() / 2, enzboundingRect.height() - 40, QtGui.QColor('white'), QtGui.QColor('white')) #cplxinfo.x = enzboundingRect.height()/2 #cplxinfo.y = enzboundingRect.height()-60 view.emit(QtCore.SIGNAL("dropped"), enzObj) else: enzObj = moose.MMenz(mobj.path + '/' + string_num) enzinfo = moose.Annotator(enzObj.path + '/info') moose.connect(mobj, "nOut", enzObj, "enzDest") qGItem = MMEnzItem(enzObj, parentcompt) posWrtComp = pos bgcolor = getRandColor() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y() - 30, QtGui.QColor('green'), bgcolor) #enzinfo.x = posWrtComp.x() #enzinfo.y = posWrtComp.y() enzinfo.color = str(bgcolor.name()) layoutPt.mooseId_GObj[enzObj] = qGItem view.emit(QtCore.SIGNAL("dropped"), enzObj) x, y = roundoff(qGItem.scenePos(), layoutPt) enzinfo.x = x enzinfo.y = y setupItem(modelpath.path, layoutPt.srcdesConnection) layoutPt.drawLine_arrow(False) #Dropping is on compartment then update Compart size if isinstance(enzparent, moose.ChemCompt): updateCompartmentSize(parentcompt) if view.iconScale != 1: view.updateScale(view.iconScale)
def makeChemProto(name, stimAmpl=1, diffLength=1e-6, preStim=10.0): # Parameters sw = params['stimWidth'] dca = params['diffConstA'] * diffLength * diffLength dcb = params['diffConstB'] * diffLength * diffLength num = params['dendLength'] / diffLength # Objects chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh(chem.path + '/dend') # compt = moose.CylMesh( chem.path + '/dend') # # for i in range(int(num)): # compt.x0 = 0 # compt.x1 = params['dendLength'] # compt.r0 = 2*params['dendDiameter'] # compt.r1 = params['dendDiameter'] # compt.diffLength = diffLength A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') Z = moose.BufPool(compt.path + '/Z') Ca = moose.BufPool(compt.path + '/Ca') phase = moose.BufPool(compt.path + '/phase') vel = moose.BufPool(compt.path + '/vel') ampl = moose.BufPool(compt.path + '/ampl') Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') CaStim = moose.Function(Ca.path + '/CaStim') A.diffConst = dca B.diffConst = dcb # Equations Adot.expr = 'x3*(' + sp('k0a', '+ ') + sp('k1a', '*x1 + ') + sp( 'k2a', '*x1*x1 + ') + sp('k3a', '*x1*x1*x1 + ') + sp( 'k4a', '*x0*x1/(1+x1+10*x2) + ') + sp('k5a', '*x1*x2') + ')' Bdot.expr = 'x2*(' + sp('k1b', '*x0*x0 + ') + sp('k2b', '*x1') + ')' CaStim.expr = 'x2 * exp( -((x0 - t)^2)/(2* ' + str(sw * sw) + ') )' print Adot.expr print Bdot.expr print CaStim.expr # Connections Adot.x.num = 4 moose.connect(Ca, 'nOut', Adot.x[0], 'input') moose.connect(A, 'nOut', Adot.x[1], 'input') moose.connect(B, 'nOut', Adot.x[2], 'input') moose.connect(Z, 'nOut', Adot.x[3], 'input') moose.connect(Adot, 'valueOut', A, 'increment') Bdot.x.num = 3 moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') moose.connect(Z, 'nOut', Bdot.x[2], 'input') moose.connect(Bdot, 'valueOut', B, 'increment') CaStim.x.num = 3 moose.connect(phase, 'nOut', CaStim.x[0], 'input') moose.connect(vel, 'nOut', CaStim.x[1], 'input') moose.connect(ampl, 'nOut', CaStim.x[2], 'input') moose.connect(CaStim, 'valueOut', Ca, 'setN') return compt
def makeChemProto(name='hydra'): chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh('/library/' + name + '/' + name) A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') C = moose.Pool(compt.path + '/C') D = moose.Pool(compt.path + '/D') E = moose.Pool(compt.path + '/E') F = moose.Pool(compt.path + '/F') Z1 = moose.Pool(compt.path + '/Z1') Z2 = moose.Pool(compt.path + '/Z2') #A.diffConst=params['diffA'] #B.diffConst=params['diffB'] Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') Cdot = moose.Function(C.path + '/Cdot') Ddot = moose.Function(D.path + '/Ddot') Edot = moose.Function(E.path + '/Edot') Fdot = moose.Function(F.path + '/Fdot') #Zdot = moose.Function( Z.path + '/Zdot' ) #Adot.expr="x6*(1+x7)*(-x0+(5/(1+x1^3))*(2-x0-x3))" #Bdot.expr="x6*(1+x7)*(0*x0-x1+(3+2*(x2^3/(1+x1^3)))*(1/(1+x0^3))*(2-x1-x4))" #Cdot.expr="x6*(1+x7)*(0*x0+0*x1-0*x2+0.1*((0.2+0.3*(x0^3/(0.85^3+x0^3)))-x2^2*(0.2+1*x1^3/(0.85^3+x1^3))))" Adot.expr = "x6*(1+x7)*(-x0+(4.5/(1+x1^3))*(2-x0-x3))" Bdot.expr = "x6*(1+x7)*(0*x0-x1+(3+0.5*(x2^3/(1+x1^3)))*(1/(1+x0^3))*(2-x1-x4))" Cdot.expr = "x6*(1+x7)*(0*x0+0*x1-0*x2+0.5*((0.2+0.3*(x0^3/(0.85^3+x0^3)))-x2^2*(0.2+1*x1^3/(0.85^3+x1^3))))" #Ddot.expr="(1+x6)*x7*(0*x0+0*x1+0*x2-x3+(5/(1+x4^3))*(2-x0-x3))" #Edot.expr="(1+x6)*x7*(0*x0+0*x1+0*x2+0*x3-x4+(3+2*(x5^3/(1+x4^3)))*(1/(1+x3^3))*(2-x1-x4))" #Fdot.expr="(1+x6)*x7*(0*x0+0*x1+0*x2+0*x3+0*x4-0*x5+0.1*((0.2+0.3*(x3^3/(0.85^3+x3^3)))-x5^2*(0.2+1*x4^3/(0.85^3+x4^3))))" Ddot.expr = "(1+x6)*x7*(0*x0+0*x1+0*x2-x3+(4.5/(1+x4^3))*(2-x0-x3))" Edot.expr = "(1+x6)*x7*(0*x0+0*x1+0*x2+0*x3-x4+(3+0.5*(x5^3/(1+x4^3)))*(1/(1+x3^3))*(2-x1-x4))" Fdot.expr = "(1+x6)*x7*(0*x0+0*x1+0*x2+0*x3+0*x4-0*x5+0.5*((0.2+0.3*(x3^3/(0.85^3+x3^3)))-x5^2*(0.2+1*x4^3/(0.85^3+x4^3))))" print moose.showmsg(Adot) Adot.x.num = 8 #2 Bdot.x.num = 8 #2 Cdot.x.num = 8 #2 Ddot.x.num = 8 #2 Edot.x.num = 8 #2 Fdot.x.num = 8 #2 #A.nInit=10 #B.nInit=5 moose.connect(A, 'nOut', Adot.x[0], 'input') moose.connect(B, 'nOut', Adot.x[1], 'input') moose.connect(C, 'nOut', Adot.x[2], 'input') moose.connect(D, 'nOut', Adot.x[3], 'input') moose.connect(E, 'nOut', Adot.x[4], 'input') moose.connect(F, 'nOut', Adot.x[5], 'input') moose.connect(Z1, 'nOut', Adot.x[6], 'input') moose.connect(Z2, 'nOut', Adot.x[7], 'input') moose.connect(Adot, 'valueOut', A, 'increment') moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') moose.connect(C, 'nOut', Bdot.x[2], 'input') moose.connect(D, 'nOut', Bdot.x[3], 'input') moose.connect(E, 'nOut', Bdot.x[4], 'input') moose.connect(F, 'nOut', Bdot.x[5], 'input') moose.connect(Z1, 'nOut', Bdot.x[6], 'input') moose.connect(Z2, 'nOut', Bdot.x[7], 'input') moose.connect(Bdot, 'valueOut', B, 'increment') moose.connect(A, 'nOut', Cdot.x[0], 'input') moose.connect(B, 'nOut', Cdot.x[1], 'input') moose.connect(C, 'nOut', Cdot.x[2], 'input') moose.connect(D, 'nOut', Cdot.x[3], 'input') moose.connect(E, 'nOut', Cdot.x[4], 'input') moose.connect(F, 'nOut', Cdot.x[5], 'input') moose.connect(Z1, 'nOut', Cdot.x[6], 'input') moose.connect(Z2, 'nOut', Cdot.x[7], 'input') moose.connect(Cdot, 'valueOut', C, 'increment') moose.connect(A, 'nOut', Ddot.x[0], 'input') moose.connect(B, 'nOut', Ddot.x[1], 'input') moose.connect(C, 'nOut', Ddot.x[2], 'input') moose.connect(D, 'nOut', Ddot.x[3], 'input') moose.connect(E, 'nOut', Ddot.x[4], 'input') moose.connect(F, 'nOut', Ddot.x[5], 'input') moose.connect(Z1, 'nOut', Ddot.x[6], 'input') moose.connect(Z2, 'nOut', Ddot.x[7], 'input') moose.connect(Ddot, 'valueOut', D, 'increment') moose.connect(A, 'nOut', Edot.x[0], 'input') moose.connect(B, 'nOut', Edot.x[1], 'input') moose.connect(C, 'nOut', Edot.x[2], 'input') moose.connect(D, 'nOut', Edot.x[3], 'input') moose.connect(E, 'nOut', Edot.x[4], 'input') moose.connect(F, 'nOut', Edot.x[5], 'input') moose.connect(Z1, 'nOut', Edot.x[6], 'input') moose.connect(Z2, 'nOut', Edot.x[7], 'input') moose.connect(Edot, 'valueOut', E, 'increment') moose.connect(A, 'nOut', Fdot.x[0], 'input') moose.connect(B, 'nOut', Fdot.x[1], 'input') moose.connect(C, 'nOut', Fdot.x[2], 'input') moose.connect(D, 'nOut', Fdot.x[3], 'input') moose.connect(E, 'nOut', Fdot.x[4], 'input') moose.connect(F, 'nOut', Fdot.x[5], 'input') moose.connect(Z1, 'nOut', Fdot.x[6], 'input') moose.connect(Z2, 'nOut', Fdot.x[7], 'input') moose.connect(Fdot, 'valueOut', F, 'increment') return compt
def makeChemProto(name='hydra'): moose.Neutral('/library/') meshName = '/library/' + name moose.SBML.mooseReadSBML(os.path.join(sdir_, '..', 'data', 'c_m.xml'), meshName) Rad = moose.element('/library/hydra/dend/IRSpGr/Rad') I_C = moose.element(meshName + '/dend/IRSpGr/IRSp53') Ca = moose.element(meshName + '/dend/Ca') rec = moose.Pool(meshName + '/dend/IRSpGr/rec') conv = moose.Pool(meshName + '/dend/conv') Cdc42 = moose.element(meshName + '/dend/IRSpGr/Cdc42') Cdc42_m = moose.element(meshName + '/dend/IRSpGr/Cdc42_m') Cdc42_GDP = moose.element(meshName + '/dend/Cdc42_GDP') Rac_GTP = moose.element(meshName + '/dend/Rac_GTP') Rac_m = moose.element(meshName + '/dend/IRSpGr/Rac_m') Rac_GDP = moose.element(meshName + '/dend/Rac_GDP') Eps8 = moose.element(meshName + '/dend/IRSpGr/Eps8') I_Cact = moose.element(meshName + '/dend/IRSpGr/IRSp53_a') I_M = moose.element(meshName + '/dend/IRSpGr/IRSp53_m') Idimer = moose.element(meshName + '/dend/IRSpGr/IRSp53_dimer') recBAR = moose.Function(meshName + '/dend/IRSpGr/recBAR') gradBAR = moose.Function(meshName + '/dend/IRSpGr/gradBAR') Radfun = moose.Function(meshName + '/dend/IRSpGr/Radfun') Ipool = moose.element(meshName + '/dend/IRSpGr/Ipool') sort = moose.element(meshName + '/dend/IRSpGr/sort') detach = moose.element(meshName + '/dend/IRSpGr/detach') curv_IRSp53 = moose.element(meshName + '/dend/IRSpGr/curv_IRSp53') tube_IRSp53 = moose.element(meshName + '/dend/IRSpGr/tube_IRSp53') to_tube_Reac = moose.element(meshName + '/dend/IRSpGr/to_tube_Reac') Cdc42_breac = moose.element(meshName + '/dend/Cdc42_GTP_GDP_Reac') Tiam_breac = moose.element(meshName + '/dend/Tiam_Rev_Reac') store_tube = moose.Pool(meshName + '/dend/IRSpGr/store_tube') IRSp53_temp = moose.element(meshName + '/dend/IRSpGr/IRSp53_temp') sigma = moose.Pool(meshName + '/dend/IRSpGr/sigma') Kv = moose.Pool(meshName + '/dend/IRSpGr/Kv') dend_vasp = moose.element(meshName + '/dend/IRSpGr/VASP') dend_gactin = moose.element(meshName + '/dend/IRSpGr/Gactin') dend_factin = moose.element(meshName + '/dend/IRSpGr/Factin') GF_Reac = moose.element(meshName + '/dend/IRSpGr/GF_Reac') sort_func = moose.element(meshName + '/dend/IRSpGr/sort_func') breacT_fun = moose.Function(meshName + '/dend/breacT_fun') breacC_fun = moose.Function(meshName + '/dend/breacC_fun') simpleFun = moose.Function(meshName + '/dend/IRSpGr/simpleFun') simpleFun1 = moose.Function(meshName + '/dend/IRSpGr/simpleFun1') simpleFun2 = moose.Function(meshName + '/dend/IRSpGr/simpleFun2') Kvfun = moose.Function(meshName + '/dend/IRSpGr/Kvfun') recFun = moose.Function(meshName + '/dend/IRSpGr/recFun') simpleFun2 = moose.Function(meshName + '/dend/IRSpGr/simpleFun2') simpleFun3 = moose.Function(meshName + '/dend/IRSpGr/simpleFun3') mod_sort = moose.element(meshName + '/dend/IRSpGr/mod_sort') mod_detach = moose.element(meshName + '/dend/IRSpGr/mod_detach') to_tube_Reac = moose.element(meshName + '/dend/IRSpGr/to_tube_Reac') conv_fun = moose.Function(meshName + '/dend/IRSpGr/conv_fun') conv_fun.expr = "1*x0*(x1-1.89191155)+1.89191155" Kvfun.expr = "1.0" moose.connect(Kvfun, 'valueOut', Kv, 'setN') simpleFun.expr = "1.0*x0" simpleFun1.expr = "1.0*x0" simpleFun2.expr = "0.1*x0" simpleFun3.expr = "1.0*x0" breacT_fun.expr = "5*x0" breacC_fun.expr = "5*x0" moose.connect(curv_IRSp53, 'nOut', simpleFun2.x[0], 'input') moose.connect(simpleFun2, 'valueOut', GF_Reac, 'setNumKf') moose.connect(sort_func, 'nOut', simpleFun.x[0], 'input') moose.connect(detach, 'nOut', simpleFun1.x[0], 'input') moose.connect(store_tube, 'nOut', simpleFun3.x[0], 'input') recFun.expr = "0.0*x0+(exp(45*54*((" + str( args_[14]) + "/(x0*1e9))-(1/(2.0*(x0*1e9)*(x0*1e9))))))" Radfun.expr = "sqrt(((45+12)*4*1e-18)/(2*(x2-0.08*(ln((((1.0*x0+1.0*x1)/(2*3.14*(0.45*0.05)))*1e-6*54))))))*((3*" + str( float(args_[2])) + "*x3*(x0+1.0*x1)^2)/(1.+3*" + str(float( args_[2])) + "*x3*(x0+1.0*x1)^2))" mod_sort.Kf = 0. mod_sort.Kb = 0. mod_detach.Kf = 0. mod_detach.Kb = 0. moose.connect(curv_IRSp53, 'nOut', Radfun.x[0], 'input') moose.connect(I_M, 'nOut', Radfun.x[1], 'input') #moose.connect(tube_IRSp53,'nOut',Radfun.x[2],'input') moose.connect(sigma, 'nOut', Radfun.x[2], 'input') moose.connect(Kv, 'nOut', Radfun.x[3], 'input') moose.connect(Radfun, 'valueOut', Rad, 'setN') moose.connect(rec, 'nOut', conv_fun.x[0], 'input') moose.connect(conv, 'nOut', conv_fun.x[1], 'input') moose.connect(conv_fun, 'valueOut', Ca, 'setN') moose.connect(simpleFun, 'valueOut', mod_sort, 'setNumKf') moose.connect(simpleFun1, 'valueOut', mod_detach, 'setNumKf') moose.connect(Rad, 'nOut', recFun.x[0], 'input') moose.connect(recFun, 'valueOut', Ipool, 'setN') ### Ipool is further copied to sort to participate in the reaction tube_reac or enz (model version 2.5.3) I_C.concInit = 0.0012 file_molWt = os.path.join(sdir_, '..', 'data', 'prot_wt.xml') den = 6.0 * 3.14 * np.cbrt(3.0 / (4.0 * 3.14 * 0.73 * 6.02 * 1e23)) num = 1e3 * 1e6 * 1.38 * 1e-23 co = num / den # Diffconsts are set here if int(args_[3]) == 1: for prot in moose.wildcardFind(meshName + '/dend/#[ISA=Pool]'): mol_name = ET.parse(file_molWt).find(str(prot.name)) print('Name is %s' % mol_name, end='. ') molWt = mol_name.text.split() if float(molWt[1]) <= 0.0: continue moose.element(prot).diffConst = co * ( 300 / (200.0 * np.cbrt(float(molWt[1]) * 1e3))) * 1e-4 print('-- D', prot.name, moose.element(prot).diffConst) for prot in moose.wildcardFind(meshName + '/dend/CaMKII_gr/#[ISA=Pool]'): mol_name = ET.parse(file_molWt).find(str(prot.name)) print('Name is %s' % mol_name, end='. ') molWt = mol_name.text.split() if float(molWt[1]) <= 0.0: continue moose.element(prot).diffConst = co * ( 300 / (200.0 * np.cbrt(float(molWt[1]) * 1e3))) * 1e-4 print('-- D', prot.name, moose.element(prot).diffConst) for prot in moose.wildcardFind(meshName + '/dend/Ras_gr/#[ISA=Pool]'): mol_name = ET.parse(file_molWt).find(str(prot.name)) print('Name is %s' % mol_name, end='. ') molWt = mol_name.text.split() if float(molWt[1]) <= 0.0: continue moose.element(prot).diffConst = co * ( 300 / (200.0 * np.cbrt(float(molWt[1]) * 1e3))) * 1e-4 print('-- D', prot.name, moose.element(prot).diffConst) Ca.diffConst = float(args_[4]) print('-- D', Ca.name, Ca.diffConst) print('\t==================== diffConst updated') print('DIFFUSION FOR IRSp53 GROUP') I_C.diffConst = co * (300 / (8.0 * np.cbrt(120.0 * 1e3))) * 1e-4 print(I_C.diffConst, end=' + ') I_Cact.diffConst = co * (300 / (8.0 * np.cbrt(208.0 * 1e3))) * 1e-4 print(I_Cact.diffConst) Eps8.diffConst = co * (300 / (200.0 * np.cbrt(92.0 * 1e3))) * 1e-4 print(Eps8.diffConst, end=' + ') Cdc42.diffConst = co * (300 / (8.0 * np.cbrt(22.0 * 1e3))) * 1e-4 Cdc42_m.diffConst = co * (300 / (200.0 * np.cbrt(22.0 * 1e3))) * 1e-4 Cdc42_GDP.diffConst = co * (300 / (8.0 * np.cbrt(22.0 * 1e3))) * 1e-4 print(Cdc42.diffConst, end=' + ') Rac_GTP.diffConst = co * (300 / (8.0 * np.cbrt(22.0 * 1e3))) * 1e-4 Rac_m.diffConst = co * (300 / (200.0 * np.cbrt(22.0 * 1e3))) * 1e-4 Rac_GDP.diffConst = co * (300 / (8.0 * np.cbrt(22.0 * 1e3))) * 1e-4 I_M.diffConst = 1.0 * co * (300 / (200.0 * np.cbrt(392.0 * 1e3))) * 1e-4 print(I_M.diffConst, end=' + ') Idimer.diffConst = co * (300 / (8.0 * np.cbrt(120.0 * 1e3))) * 1e-4 print(Idimer.diffConst) curv_IRSp53.diffConst = float(args_[17]) conv.diffConst = 0.0 rec.diffConst = 0.0 dend_gactin.diffConst = 1e-13 dend_vasp.diffConst = 1e-13 return meshName
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 as a hybrid of a reaction and a function which sets its rates. Please see rxdFuncDiffusion.py for a variant that uses just a function object to set up the system. """ dt = 0.1 # define the geometry compt = moose.CylMesh( '/cylinder' ) compt.r0 = compt.r1 = 1 compt.diffLength = 0.2 compt.x1 = 100 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 = 1 # define diffusion constant # There is an implicit reaction substrate/product. MOOSE makes it explicit. buf = moose.BufPool( '/cylinder/buf' ) buf.nInit = 1 # The reaction is something entirely peculiar, not a chemical thing. reaction = moose.Reac( '/cylinder/reac' ) reaction.Kb = 0 # so here we set up a function calculation to do the same thing. func = moose.Function( '/cylinder/reac/func' ) func.expr = "(1 - x0) * (0.3 - x0)" func.x.num = 1 #specify number of input variables. #Connect the reaction to the pools moose.connect( reaction, 'sub', c, 'reac' ) moose.connect( reaction, 'prd', buf, 'reac' ) #Connect the function to the reaction moose.connect( func, 'valueOut', reaction, 'setNumKf' ) #Connect the molecules to the func moose.connect( c, 'nOut', func.x[0], 'input' ) #Set up solvers ksolve = moose.Ksolve( '/cylinder/ksolve' ) 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 = [ (q < 0.2 * compt.x1) for q in x ] # Run and plot it. moose.reinit() 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, 1.05 ) pylab.legend() pylab.show()
def makeChemProto(name, stimAmpl=1, diffLength=1e-6, preStim=10.0): # Parameters sw = params['stimWidth'] dca = params['diffConstA'] * diffLength * diffLength dcb = params['diffConstB'] * diffLength * diffLength # Objects chem = moose.Neutral('/library/' + name) compt = moose.CubeMesh(chem.path + '/dend') A = moose.Pool(compt.path + '/A') B = moose.Pool(compt.path + '/B') Z = moose.BufPool(compt.path + '/Z') Ca = moose.BufPool(compt.path + '/Ca') phase = moose.BufPool(compt.path + '/phase') vel = moose.BufPool(compt.path + '/vel') ampl = moose.BufPool(compt.path + '/ampl') Adot = moose.Function(A.path + '/Adot') Bdot = moose.Function(B.path + '/Bdot') CaStim = moose.Function(Ca.path + '/CaStim') A.diffConst = dca B.diffConst = dcb # Equations xv0 = '(x0-' + str(params['offsetV']) + ')' xv1 = '(x1-' + str(params['offsetV']) + ')' xw1 = '(x1-' + str(params['offsetW']) + ')' xw2 = '(x2-' + str(params['offsetW']) + ')' Adot.expr = '5*x3*( 0.0 +' + xv1 + ' - (' + xv1 + '^3)/3 -' + xw2 + ' + x0 )' # x0=Ca, x1=A, x2=B #Adot.expr = 'x3*( 0.5 + x1 - x1*x1*x1/3 - x2 + x0 )' # x0=Ca, x1=A, x2=B #Bdot.expr = 'x2*' + str(1.0/params['tau']) + '*(x0 + ' + sp('a', ' - ') + sp( 'b', ' * x1 ' ) + ')' Bdot.expr = 'x2*' + str(1.0 / params['tau']) + '*(' + xv0 + '+' + sp( 'a', ' - ') + sp('b', ' * ' + xw1) + ')' CaStim.expr = 'x2 * exp( -((x0 - t)^2)/(2* ' + str(sw * sw) + ') )' print Adot.expr print Bdot.expr print CaStim.expr # Connections Adot.x.num = 4 moose.connect(Ca, 'nOut', Adot.x[0], 'input') moose.connect(A, 'nOut', Adot.x[1], 'input') moose.connect(B, 'nOut', Adot.x[2], 'input') moose.connect(Z, 'nOut', Adot.x[3], 'input') moose.connect(Adot, 'valueOut', A, 'increment') Bdot.x.num = 3 moose.connect(A, 'nOut', Bdot.x[0], 'input') moose.connect(B, 'nOut', Bdot.x[1], 'input') moose.connect(Z, 'nOut', Bdot.x[2], 'input') moose.connect(Bdot, 'valueOut', B, 'increment') CaStim.x.num = 3 moose.connect(phase, 'nOut', CaStim.x[0], 'input') moose.connect(vel, 'nOut', CaStim.x[1], 'input') moose.connect(ampl, 'nOut', CaStim.x[2], 'input') moose.connect(CaStim, 'valueOut', Ca, 'setN') return compt
compt.diffLength = 1 assert( compt.numDiffCompts == 1000 ) #define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool( '/cylinder/pool' ) c.diffConst = 1 # define diffusion constant # There is an implicit reaction substrate/product. MOOSE makes it explicit. buf = moose.BufPool( '/cylinder/buf' ) buf.nInit = 1 # The reaction is something entirely peculiar, not a chemical thing. reaction = moose.Reac( '/cylinder/reac' ) reaction.Kb = 0 # so here we set up a function calculation to do the same thing. func = moose.Function( '/cylinder/reac/func' ) func.expr = "(0.3 - x0) * (1 - x0)" func.x.num = 1 #specify number of input variables. #Connect the reaction to the pools moose.connect( reaction, 'sub', c, 'reac' ) moose.connect( reaction, 'prd', buf, 'reac' ) #Connect the function to the reaction moose.connect( func, 'valueOut', reaction, 'setNumKf' ) #Connect the molecules to the func moose.connect( c, 'nOut', func.x[0], 'input' ) #Set up solvers
def test_ksolver_parallel(nthreads=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 as a hybrid of a reaction and a function which sets its rates. Please see rxdFuncDiffusion.py for a variant that uses just a function object to set up the system. """ dt = 0.1 # define the geometry compt = moose.CylMesh('/cylinder') compt.r0 = compt.r1 = 1 # compt.diffLength = 1e-6 compt.x1 = 1e-2 assert compt.numDiffCompts == int( compt.x1 / compt.diffLength), (compt.numDiffCompts, compt.x1 / compt.diffLength) print('No of compartment %d' % compt.numDiffCompts) #define the molecule. Its geometry is defined by its parent volume, cylinder c = moose.Pool('/cylinder/pool') c.diffConst = 1 # define diffusion constant # There is an implicit reaction substrate/product. MOOSE makes it explicit. buf = moose.BufPool('/cylinder/buf') buf.nInit = 1 # The reaction is something entirely peculiar, not a chemical thing. reaction = moose.Reac('/cylinder/reac') reaction.Kb = 0 # so here we set up a function calculation to do the same thing. func = moose.Function('/cylinder/reac/func') func.expr = "(1 - x0) * (0.3 - x0)" func.x.num = 1 #specify number of input variables. #Connect the reaction to the pools moose.connect(reaction, 'sub', c, 'reac') moose.connect(reaction, 'prd', buf, 'reac') #Connect the function to the reaction moose.connect(func, 'valueOut', reaction, 'setNumKf') #Connect the molecules to the func moose.connect(c, 'nOut', func.x[0], 'input') #Set up solvers ksolve = moose.Ksolve('/cylinder/ksolve') ksolve.numThreads = nthreads dsolve = moose.Dsolve('/cylinder/dsolve') stoich = moose.Stoich('/cylinder/stoich') stoich.compartment = compt stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.reacSystemPath = '/cylinder/##' assert stoich.reacSystemPath == '/cylinder/##' for i in range(10, 18): moose.setClock(i, dt) #initialize x = np.arange(0, compt.x1, compt.diffLength) assert len(c.vec) == 10000, len(c.vec) nInit = [(float(q < 0.2) * compt.x1) for q in x] c.vec.nInit = nInit assert np.allclose(c.vec.nInit, nInit), (c.vec.nInit, nInit) expected = [(0.01, 0.0), (2.6704795776286974e-07, 1.2678976830753021e-17), (8.167639617309419e-14, 3.8777269301457245e-24), (2.498062905267963e-20, 1.1860363878961374e-30), (7.64029581501609e-27, 3.6273808003690943e-37)] # Run and plot it. moose.reinit() updateDt = 50 runtime = updateDt * 4 yvec = c.vec.n u1, m1 = np.mean(yvec), np.std(yvec) print(u1, m1) assert np.isclose((u1, m1), expected[0], atol=1e-5).all(), ((u1, m1), expected[0]) t1 = time.time() for i, t in enumerate(range(0, runtime - 1, updateDt)): moose.start(updateDt) yvec = c.vec.n u1, m1 = np.mean(yvec), np.std(yvec) print(u1, m1) np.isclose((u1, m1), expected[i + 1], atol=1e-5).all(), expected[i + 1] return time.time() - t1
dt = 0.1 # define the geometry compt = moose.CylMesh('/cylinder') compt.r0 = compt.r1 = 1 compt.x1 = 100 compt.diffLength = 0.2 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 = 1 # define diffusion constant # Here we set up a function calculation func = moose.Function('/cylinder/pool/func') func.expr = "-x0 * (0.3 - x0) * (1 - x0)" 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.Ksolve('/cylinder/ksolve') dsolve = moose.Dsolve('/cylinder/dsolve') stoich = moose.Stoich('/cylinder/stoich') stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.compartment = compt
def createRules(model, specInfoMap, globparameterIdValue): for r in range(0, model.getNumRules()): rule = model.getRule(r) comptvolume = [] if (rule.isAssignment()): rule_variable = rule.getVariable() rule_variable = parentSp = str(idBeginWith(rule_variable)) poolList = specInfoMap[rule_variable]["Mpath"].path poolsCompt = findCompartment(moose.element(poolList)) if not isinstance(moose.element(poolsCompt), moose.ChemCompt): return -2 else: if poolsCompt.name not in comptvolume: comptvolume.append(poolsCompt.name) funcId = moose.Function(poolList + '/func') objclassname = moose.element(poolList).className if objclassname == "BufPool" or objclassname == "ZombieBufPool": moose.connect(funcId, 'valueOut', poolList, 'setN') elif objclassname == "Pool" or objclassname == "ZombiePool": # moose.connect( funcId, 'valueOut', poolList ,'increament' ) moose.connect(funcId, 'valueOut', poolList, 'setN') elif objclassname == "Reac" or objclassname == "ZombieReac": moose.connect(funcId, 'valueOut', poolList, 'setNumkf') ruleMath = rule.getMath() ruleMemlist = [] speFunXterm = {} getMembers(ruleMath, ruleMemlist) for i in ruleMemlist: if (i in specInfoMap): i = str(idBeginWith(i)) specMapList = specInfoMap[i]["Mpath"] poolsCompt = findCompartment(moose.element(specMapList)) if not isinstance(moose.element(poolsCompt), moose.ChemCompt): return -2 else: if poolsCompt.name not in comptvolume: comptvolume.append(poolsCompt.name) numVars = funcId.numVars x = funcId.path + '/x[' + str(numVars) + ']' speFunXterm[i] = 'x' + str(numVars) moose.connect(specMapList, 'nOut', x, 'input') funcId.numVars = numVars + 1 elif not (i in globparameterIdValue): print("check the variable type ", i) exp = rule.getFormula() for mem in ruleMemlist: if (mem in specInfoMap): #exp1 = exp.replace(mem, str(speFunXterm[mem])) exp1 = re.sub(r'\b%s\b' % (mem), speFunXterm[mem], exp) exp = exp1 elif (mem in globparameterIdValue): #exp1 = exp.replace(mem, str(globparameterIdValue[mem])) exp1 = re.sub(r'\b%s\b' % (mem), globparameterIdValue[mem], exp) exp = exp1 else: print("Math expression need to be checked") exp = exp.replace(" ", "") funcId.expr = exp.strip(" \t\n\r") # return True elif (rule.isRate()): print("Warning : For now this \"", rule.getVariable(), "\" rate Rule is not handled in moose ") # return False elif (rule.isAlgebraic()): print("Warning: For now this ", rule.getVariable(), " Algebraic Rule is not handled in moose") # return False if len(comptvolume) > 1: warning = "\nFunction ", moose.element( poolList ).name, " has input from different compartment which is depricated in moose and running this model cause moose to crash" return True