def makeChemModel(compt, doInput): """ This function setus up a simple chemical system in which Ca input comes to the dend and to selected PSDs. There is diffusion between PSD and spine head, and between dend and spine head. Ca_input ------> Ca // in dend and spine head only. """ # create molecules and reactions Ca = moose.Pool(compt.path + '/Ca') Ca.concInit = 0.08 * 1e-3 Ca.diffConst = diffConst if doInput: Ca_input = moose.BufPool(compt.path + '/Ca_input') Ca_input.concInit = 0.08 * 1e-3 Ca_input.diffConst = diffConst rInput = moose.Reac(compt.path + '/rInput') moose.connect(rInput, 'sub', Ca, 'reac') moose.connect(rInput, 'prd', Ca_input, 'reac') rInput.Kf = 100 # 1/sec rInput.Kb = 100 # 1/sec else: Ca_sink = moose.BufPool(compt.path + '/Ca_sink') Ca_sink.concInit = 0.08 * 1e-3 rSink = moose.Reac(compt.path + '/rSink') moose.connect(rSink, 'sub', Ca, 'reac') moose.connect(rSink, 'prd', Ca_sink, 'reac') rSink.Kf = 10 # 1/sec rSink.Kb = 10 # 1/sec
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
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 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, Aexpr, Bexpr, params ): sw = params['stimWidth'] diffLength = params['diffusionLength'] dca = params['diffConstA'] * diffLength * diffLength dcb = params['diffConstB'] * diffLength * diffLength # Objects chem = moose.Neutral( '/library/' + name ) compt = moose.CubeMesh( '/library/' + name + '/' + name ) 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 = parseExpr( Aexpr, params, True ) Bdot.expr = parseExpr( Bexpr, params, False ) 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 if name[:5] == 'negFF': moose.connect( Ca, 'nOut', Bdot.x[0], 'input' ) print('Doing special msg') else: 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 makeReacs(): # Parameters volume = 1e-15 CaInitConc = 60e-6 NA = 6.022e23 tauI = 1 tauG = 0.1 model = moose.Neutral('/cells') compartment = moose.CubeMesh('/cells/compartment') compartment.volume = volume # Make pools Ca = moose.BufPool('/cells/compartment/Ca') tgtCa = moose.BufPool('/cells/compartment/tgtCa') m = moose.Pool('/cells/compartment/m') chan = moose.Pool('/cells/compartment/chan') # Make Funcs f1 = moose.Func('/cells/compartment/f1') f2 = moose.Func('/cells/compartment/f2') # connect up moose.connect(f1, 'valueOut', m, 'increment') moose.connect(f2, 'valueOut', chan, 'increment') moose.connect(Ca, 'nOut', f1, 'xIn') moose.connect(tgtCa, 'nOut', f1, 'yIn') moose.connect(m, 'nOut', f2, 'xIn') moose.connect(chan, 'nOut', f2, 'yIn') # Set params Ca.concInit = CaInitConc tgtCa.concInit = tgtCaInitConc m.concInit = 0.0 chan.concInit = 0.0 volscale = 1.0 f1.expr = str(volscale / tauI) + " * (x-y)" f2.expr = str(volscale / tauG) + " * (x-y)" #Plotting channelPlot = makePlot('channelConc', chan, 'Conc', 18) mPlot = makePlot('mConc', m, 'Conc', 18) caPlot = makePlot('Ca', Ca, 'Conc', 18) targetPlot = makePlot('tgtCa', tgtCa, 'Conc', 18) return (channelPlot, mPlot, caPlot)
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 i1_to_i1p( root ): global molecules_ global curr_subsec_ i1p_const = moose.BufPool( '%s/i1p_const' % molecules_[curr_subsec_ + '.' + 'I1'].path) i1p_const.name = pool_name( root, i1p_const.name ) molecules_[i1p_const.name] = i1p_const f = moose.Function( '%s/i12i1p' % molecules_[pool_name(root, 'I1P')].path ) f.x.num = 2 f.expr = 'x1*(1+(x0/{kh2})^3)/(x0/{kh2})^3'.format(kh2=conc_to_n(_p.K_H2)) frmName = pool_name( root, 'I1' ) toName = pool_name( root, 'I1P_' ) moose.connect( molecules_[pool_name(root,'ca')], 'nOut', f.x[0], 'input' ) moose.connect( molecules_[frmName], 'nOut', f.x[1], 'input' ) moose.connect( f, 'valueOut', molecules_[toName], 'setN' ) _logger.debug('Reaction: %s -> %s, Expr = %s' % (frmName, toName, f.expr )) # A slow reaction between I1P and I1P_ which synchornize both pools. r = add_reaction( '%s/sync' % molecules_[pool_name(root,'I1P')].path ); frmPool = molecules_[ pool_name( root, 'I1P_' ) ] toPool = molecules_[ pool_name( root, 'I1P' ) ] moose.connect( r, 'sub', frmPool, 'reac' ) moose.connect( r, 'prd', toPool, 'reac' ) r.Kf = r.Kb = 1.0 _logger.debug( 'Reaction: %s -> %s' % ( frmPool.name, toPool.name ) )
def analogStimTable(): """Example of using a StimulusTable as an analog signal source in a reaction system. It could be used similarly to give other analog inputs to a model, such as a current or voltage clamp signal. This demo creates a StimulusTable and assigns it half a sine wave. Then we assign the start time and period over which to emit the wave. The output of the StimTable is sent to a pool **a**, which participates in a trivial reaction:: table ----> a <===> b The output of **a** and **b** are recorded in a regular table for plotting. """ simtime = 150 simdt = 0.1 model = moose.Neutral('/model') data = moose.Neutral('/data') # This is the stimulus generator stimtable = moose.StimulusTable('/model/stim') a = moose.BufPool( '/model/a' ) b = moose.Pool( '/model/b' ) reac = moose.Reac( '/model/reac' ) reac.Kf = 0.1 reac.Kb = 0.1 moose.connect( stimtable, 'output', a, 'setConcInit' ) moose.connect( reac, 'sub', a, 'reac' ) moose.connect( reac, 'prd', b, 'reac' ) aPlot = moose.Table('/data/aPlot') moose.connect(aPlot, 'requestOut', a, 'getConc') bPlot = moose.Table('/data/bPlot') moose.connect(bPlot, 'requestOut', b, 'getConc') moose.setClock( stimtable.tick, simdt ) moose.setClock( a.tick, simdt ) moose.setClock( aPlot.tick, simdt ) #################################################### # Here we set up the stimulus table. It is half a sine-wave. stim = [ np.sin(0.01 * float(i) ) for i in range( 314 )] stimtable.vector = stim stimtable.stepSize = 0 # This forces use of current time as x value # The table will interpolate its contents over the time start to stop: # At values less than startTime, it emits the first value in table stimtable.startTime = 5 # At values more than stopTime, it emits the last value in table stimtable.stopTime = 60 stimtable.doLoop = 1 # Enable repeat playbacks. stimtable.loopTime = 10 + simtime / 2.0 # Repeat playback over this time moose.reinit() moose.start(simtime) t = [ x * simdt for x in range( len( aPlot.vector ) )] pylab.plot( t, aPlot.vector, label='Stimulus waveform' ) pylab.plot( t, bPlot.vector, label='Reaction product b' ) pylab.legend() pylab.show()
def makeModel(): # create container for model r0 = 2e-6 # m r1 = 1e-6 # m num = 100 diffLength = 1e-6 # m len = num * diffLength # m diffConst = 10e-12 # m^2/sec motorRate = 10e-6 # m/sec concA = 1 # millimolar model = moose.Neutral( 'model' ) compartment = moose.CylMesh( '/model/compartment' ) compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = len compartment.diffLength = diffLength assert( compartment.numDiffCompts == num ) # create molecules and reactions a = moose.Pool( '/model/compartment/a' ) b = moose.Pool( '/model/compartment/b' ) c = moose.Pool( '/model/compartment/c' ) d = moose.BufPool( '/model/compartment/d' ) r1 = moose.Reac( '/model/compartment/r1' ) moose.connect( r1, 'sub', b, 'reac' ) moose.connect( r1, 'sub', d, 'reac' ) moose.connect( r1, 'prd', c, 'reac' ) r1.Kf = 1.0 # 1/(mM.sec) r1.Kb = 1.0 # 1/sec # Assign parameters a.diffConst = diffConst b.diffConst = diffConst / 2.0 b.motorConst = motorRate c.diffConst = 0 d.diffConst = diffConst # Make solvers ksolve = moose.Ksolve( '/model/compartment/ksolve' ) dsolve = moose.Dsolve( '/model/compartment/dsolve' ) stoich = moose.Stoich( '/model/compartment/stoich' ) stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve os.kill( PID, signal.SIGUSR1 ) stoich.path = "/model/compartment/##" print((dsolve.numPools)) assert( dsolve.numPools == 3 ) a.vec[0].concInit = concA b.vec[0].concInit = concA c.vec[0].concInit = concA d.vec.concInit = concA / 5.0 d.vec[num-1].concInit = concA
def makeModel(): """ This function creates a bistable reaction system using explicit MOOSE calls rather than load from a file. The reaction is:: a ---b---> 2b # b catalyzes a to form more of b. 2b ---c---> a # c catalyzes b to form a. a <======> 2b # a interconverts to b. """ # 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 = moose.BufPool( '/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, 'prd', b, 'reac' ) # Note 2 molecules of b. moose.connect( enz1, 'enz', b, 'reac' ) moose.connect( enz1, 'cplx', cplx1, 'reac' ) moose.connect( enz2, 'sub', b, 'reac' ) moose.connect( enz2, 'sub', b, 'reac' ) # Note 2 molecules of b. 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' ) moose.connect( reac, 'prd', b, 'reac' ) # Note 2 order in b. # 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 return compartment
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 make_kca(): """Ported from NEURON code. - Subhasis Ray, Thu Jun 5 16:18:14 IST 2014 original file comment: COMMENT 26 Ago 2002 Modification of original channel to allow variable time step and to correct an initialization error. Done by Michael Hines([email protected]) and Ruggero Scorcioni([email protected]) at EU Advance Course in Computational Neuroscience. Obidos, Portugal kca.mod Calcium-dependent potassium channel Based on Pennefather (1990) -- sympathetic ganglion cells taken from Reuveni et al (1993) -- neocortical cells Author: Zach Mainen, Salk Institute, 1995, [email protected] ENDCOMMENT """ gbar = 10 # (pS/um2) : 0.03 mho/cm2 caix = 1 # Ra = 0.01 # (/ms) : max act rate Rb = 0.02 # (/ms) : max deact rate vmin = -120 # (mV) vmax = 100 # (mV) # In MOOSE we set up lookup tables beforehand camin = 0.0 camax = 500.0 cai = np.linspace(camin, camax) a = Ra * cai**caix b = Rb ntau = 1 / tadj / (a + b) ninf = a / (a + b) channel = moose.HHChannel('/library/KCa') channel.Zpower = 1 channel.useConcentration = 1 channel.gateZ[0].min = camin channel.gateZ[0].max = camax channel.gateZ[0].tableA = 1e3 * ninf / ntau channel.gateZ[0].tableB = 1e3 / ntau channel.Gbar = 0.0 channel.Ek = -90e-3 # addmsg1 = moose.Mstring('%s/addmsg1' % (channel.path)) # addmsg1.value = '../Ca_conc concOut . concen' capool = moose.BufPool( '%s/CaPool' % (channel.path)) # send a constant [Ca2+] to this channel capool.n = 5e-5 # n is actually number of molecules (in # floating point though, but I am using it for # conc, because only nOut src msg is available moose.connect(capool, 'nOut', channel, 'concen')
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 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 analogStimTable(): simtime = 150 simdt = 0.1 model = moose.Neutral('/model') data = moose.Neutral('/data') # This is the stimulus generator stimtable = moose.StimulusTable('/model/stim') a = moose.BufPool('/model/a') b = moose.Pool('/model/b') reac = moose.Reac('/model/reac') reac.Kf = 0.1 reac.Kb = 0.1 moose.connect(stimtable, 'output', a, 'setConcInit') moose.connect(reac, 'sub', a, 'reac') moose.connect(reac, 'prd', b, 'reac') aPlot = moose.Table('/data/aPlot') moose.connect(aPlot, 'requestOut', a, 'getConc') bPlot = moose.Table('/data/bPlot') moose.connect(bPlot, 'requestOut', b, 'getConc') moose.setClock(stimtable.tick, simdt) moose.setClock(a.tick, simdt) moose.setClock(aPlot.tick, simdt) #################################################### # Here we set up the stimulus table. It is half a sine-wave. stim = [np.sin(0.01 * float(i)) for i in range(314)] stimtable.vector = stim stimtable.stepSize = 0 # This forces use of current time as x value # The table will interpolate its contents over the time start to stop: # At values less than startTime, it emits the first value in table stimtable.startTime = 5 # At values more than stopTime, it emits the last value in table stimtable.stopTime = 60 stimtable.doLoop = 1 # Enable repeat playbacks. stimtable.loopTime = 10 + simtime / 2.0 # Repeat playback over this time moose.reinit() moose.start(simtime) t = [x * simdt for x in range(len(aPlot.vector))] pylab.plot(t, aPlot.vector, label='Stimulus waveform') pylab.plot(t, bPlot.vector, label='Reaction product b') pylab.legend() pylab.show()
def makeChemyOscillator(name='osc', parent='/library'): model = moose.Neutral(parent + '/' + name) compt = moose.CubeMesh(model.path + '/kinetics') """ This function sets up a simple oscillatory chemical system within the script. The reaction system is:: s ---a---> a // s goes to a, catalyzed by a. s ---a---> b // s goes to b, catalyzed by a. a ---b---> s // a goes to s, catalyzed by b. b -------> s // b is degraded irreversibly to s. in sum, **a** has a positive feedback onto itself and also forms **b**. **b** has a negative feedback onto **a**. Finally, the diffusion constant for **a** is 1/10 that of **b**. """ # create container for model diffConst = 1e-11 # m^2/sec motorRate = 1e-6 # m/sec concA = 1 # millimolar # create molecules and reactions a = moose.Pool(compt.path + '/a') c = moose.Pool(compt.path + '/c') d = moose.BufPool(compt.path + '/d') r2 = moose.Reac(compt.path + '/r2') moose.connect(r2, 'sub', a, 'reac') moose.connect(r2, 'sub', c, 'reac') moose.connect(r2, 'prd', d, 'reac') r2.Kf = 1 r2.Kb = 10 # Assign parameters a.diffConst = diffConst / 10 # b.diffConst = diffConst # s.diffConst = diffConst c.diffConst = diffConst d.diffConst = 0 return compt
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 init_pools(compt): global args # Ring with 6 subunits. for st in range(7): state = 'x%dy%d' % (st, 6 - st) p = add_pool(compt, state) p.nInit = 0 if args['enable_subunit_exchange']: # Ring with 7 subunits for st in range(8): state = 'x%dy%d' % (st, 7 - st) p = add_pool(compt, state) p.nInit = 0 molecules_[p.name] = p if args['enable_subunit_exchange']: # Add subunit x and y. # NOTE: These guys are shared across multiple sub_sections.. x = add_pool(compt, 'x') x.nInit = 0 molecules_[x.name] = x y = add_pool(compt, 'y') y.nInit = 0 molecules_[y.name] = y # In this version, we immediately convert x to y instead of converting # to 'xs'. This way we maintain the mass-conservation in system. In most # likely scenario, when we loose 'x', it is likely to be compenstated by # 'x' or 'y' from other system. # NOTE: A hypothetical species to convert x -> xs. x converts to xs to # mimic diffusion. xs = add_pool(compt, 'xs') xs.nInit = 0 molecules_[xs.name] = xs else: _logger.info("Subunit exchange is disabled") for p in ['I1', 'PP1', 'I1P', 'I1P_']: if p in ['I1']: c = moose.BufPool('%s/%s' % (compt.path, p)) c.name = pool_name(compt, p) molecules_[c.name] = c else: c = moose.Pool('%s/%s' % (compt.path, p)) c.name = pool_name(compt, p) molecules_[c.name] = c molecules_[c.name].nInit = 0 if args['enable_subunit_exchange']: # Here we are using concInit rather than nInit to setup the number of # molecules. This is because when Dsolve is used, setting nInit causes # problem: they don't get divided into different voxels. molecules_[pool_name(compt, 'x0y7')].concInit = args['camkii_conc'] / 2.0 molecules_[pool_name(compt, 'x0y6')].concInit = args['camkii_conc'] / 2.0 else: molecules_[pool_name(compt, 'x0y6')].concInit = args['camkii_conc'] if args['enable_subunit_exchange']: _logger.debug('CaMKII = %f (6sym) %f (7sym)' % (molecules_[pool_name( compt, 'x0y6')].nInit, molecules_[pool_name(compt, 'x0y7')].nInit)) else: _logger.debug('CaMKII = %d (6sym)' % (molecules_[pool_name(compt, 'x0y6')].nInit)) molecules_[pool_name(compt, 'PP1')].concInit = args['pp1_conc'] _logger.debug('Total PP1 %s' % molecules_[pool_name(compt, 'PP1')].nInit) # TODO: Much of it only make sense if stochastic solver is used. molecules_[pool_name(compt, 'I1')].concInit = _p.conc_i1_free pp1CamKIICplx = moose.Pool('%s/camkii_pp1_cplx' % compt.path) pp1CamKIICplx.name = pool_name(compt, pp1CamKIICplx.name) pp1CamKIICplx.concInit = 0 molecules_[pp1CamKIICplx.name] = pp1CamKIICplx for k in sorted(molecules_): _logger.debug('Molecule: %s (%f)' % (k, molecules_[k].nInit))
from __future__ import print_function import moose moose.Neutral('/model') compt = moose.CubeMesh('/model/Compart') compt.volume = 1.6667e-21 s = moose.Pool('/model/Compart/S') s.concInit = 0.3 p = moose.Pool('/model/Compart/P') r = moose.Reac('/model/Compart/Reac') moose.connect(r, 'sub', s, 'reac') moose.connect(r, 'prd', p, 'reac') bf = moose.BufPool('/model/Compart/BufPool') f = moose.Function('/model/Compart/BufPool/function') moose.connect(f, 'valueOut', bf, 'setN') numVariables = f.numVars f.numVars += 1 expr = "" expr = (f.expr + '+' + 'x' + str(numVariables)) expr = expr.lstrip("0 +") expr = expr.replace(" ", "") f.expr = expr moose.connect(s, 'nOut', f.x[numVariables], 'input') bf1 = moose.BufPool('/model/Compart/BufPool1') f1 = moose.Function('/model/Compart/BufPool1/func') moose.connect(f1, 'valueOut', bf1, 'setN')
def makeModel(): """ This example illustrates how to set up a diffusion/transport model with a simple reaction-diffusion system in a tapering cylinder: | Molecule **a** diffuses with diffConst of 10e-12 m^2/s. | Molecule **b** diffuses with diffConst of 5e-12 m^2/s. | Molecule **b** also undergoes motor transport with a rate of 10e-6 m/s | Thus it 'piles up' at the end of the cylinder. | Molecule **c** does not move: diffConst = 0.0 | Molecule **d** does not move: diffConst = 10.0e-12 but it is buffered. | Because it is buffered, it is treated as non-diffusing. All molecules other than **d** start out only in the leftmost (first) voxel, with a concentration of 1 mM. **d** is present throughout at 0.2 mM, except in the last voxel, where it is at 1.0 mM. The cylinder has a starting radius of 2 microns, and end radius of 1 micron. So when the molecule undergoing motor transport gets to the narrower end, its concentration goes up. There is a little reaction in all compartments: ``b + d <===> c`` As there is a high concentration of **d** in the last compartment, when the molecule **b** reaches the end of the cylinder, the reaction produces lots of **c**. Note that molecule **a** does not participate in this reaction. The concentrations of all molecules are displayed in an animation. """ # create container for model r0 = 2e-6 # m r1 = 1e-6 # m num = 100 diffLength = 1e-6 # m len = num * diffLength # m diffConst = 10e-12 # m^2/sec motorRate = 10e-6 # m/sec concA = 1 # millimolar model = moose.Neutral('model') compartment = moose.CylMesh('/model/compartment') compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = len compartment.diffLength = diffLength assert (compartment.numDiffCompts == num) # create molecules and reactions a = moose.Pool('/model/compartment/a') b = moose.Pool('/model/compartment/b') c = moose.Pool('/model/compartment/c') d = moose.BufPool('/model/compartment/d') r1 = moose.Reac('/model/compartment/r1') moose.connect(r1, 'sub', b, 'reac') moose.connect(r1, 'sub', d, 'reac') moose.connect(r1, 'prd', c, 'reac') r1.Kf = 1.0 # 1/(mM.sec) r1.Kb = 1.0 # 1/sec # Assign parameters a.diffConst = diffConst b.diffConst = diffConst / 2.0 b.motorConst = motorRate c.diffConst = 0 d.diffConst = diffConst # Make solvers ksolve = moose.Ksolve('/model/compartment/ksolve') dsolve = moose.Dsolve('/model/compartment/dsolve') stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve os.kill(PID, signal.SIGUSR1) stoich.path = "/model/compartment/##" print((dsolve.numPools)) assert (dsolve.numPools == 3) a.vec[0].concInit = concA b.vec[0].concInit = concA c.vec[0].concInit = concA d.vec.concInit = concA / 5.0 d.vec[num - 1].concInit = concA
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 createSpecies(basePath, model, comptSbmlidMooseIdMap, specInfoMap, modelAnnotaInfo): # ToDo: # - Need to add group name if exist in pool # - Notes # print "species " if not (model.getNumSpecies()): return (False, "number of species is zero") else: for sindex in range(0, model.getNumSpecies()): spe = model.getSpecies(sindex) group = "" specAnnoInfo = {} specAnnoInfo = getObjAnnotation(spe, modelAnnotaInfo) if "Group" in specAnnoInfo: group = specAnnoInfo["Group"] sName = None sId = spe.getId() if spe.isSetName(): sName = spe.getName() sName = sName.replace(" ", "_space_") if spe.isSetCompartment(): comptId = spe.getCompartment() if not (sName): sName = sId constant = spe.getConstant() boundaryCondition = spe.getBoundaryCondition() comptEl = comptSbmlidMooseIdMap[comptId]["MooseId"].path hasonlySubUnit = spe.getHasOnlySubstanceUnits() # "false": is {unit of amount}/{unit of size} (i.e., concentration or density). # "true": then the value is interpreted as having a unit of amount only. if group: if moose.exists(comptEl + '/' + group): comptEl = comptEl + '/' + group else: comptEl = (moose.Neutral(comptEl + '/' + group)).path if (boundaryCondition): poolId = moose.BufPool(comptEl + '/' + sName) else: poolId = moose.Pool(comptEl + '/' + sName) if (spe.isSetNotes): pullnotes(spe, poolId) if specAnnoInfo: if not moose.exists(poolId.path + '/info'): poolInfo = moose.Annotator(poolId.path + '/info') else: poolInfo = moose.element(poolId.path + '/info') for k, v in list(specAnnoInfo.items()): if k == 'xCord': poolInfo.x = float(v) elif k == 'yCord': poolInfo.y = float(v) elif k == 'bgColor': poolInfo.color = v else: poolInfo.textColor = v specInfoMap[sId] = { "Mpath": poolId, "const": constant, "bcondition": boundaryCondition, "hassubunit": hasonlySubUnit, "comptId": comptSbmlidMooseIdMap[comptId]["MooseId"] } initvalue = 0.0 unitfactor, unitset, unittype = transformUnit(spe, hasonlySubUnit) if hasonlySubUnit == True: if spe.isSetInitialAmount(): initvalue = spe.getInitialAmount() # populating nInit, will automatically calculate the # concInit. if not (unitset): # if unit is not set, # default unit is assumed as Mole in SBML unitfactor = pow(6.0221409e23, 1) unittype = "Mole" initvalue = initvalue * unitfactor elif spe.isSetInitialConcentration(): initvalue = spe.getInitialConcentration() print( " Since hasonlySubUnit is true and concentration is set units are not checked" ) poolId.nInit = initvalue elif hasonlySubUnit == False: # ToDo : check 00976 if spe.isSetInitialAmount(): initvalue = spe.getInitialAmount() # initAmount is set we need to convert to concentration initvalue = initvalue / comptSbmlidMooseIdMap[comptId][ "size"] elif spe.isSetInitialConcentration(): initvalue = spe.getInitialConcentration() if not unitset: # print " unit is not set" unitfactor = pow(10, -3) initvalue = initvalue * unitfactor poolId.concInit = initvalue else: nr = model.getNumRules() found = False for nrItem in range(0, nr): rule = model.getRule(nrItem) assignRule = rule.isAssignment() if (assignRule): rule_variable = rule.getVariable() if (rule_variable == sId): found = True break if not (found): print( "Invalid SBML: Either initialConcentration or initialAmount must be set or it should be found in assignmentRule but non happening for ", sName) return ( False, "Invalid SBML: Either initialConcentration or initialAmount must be set or it should be found in assignmentRule but non happening for ", sName) return (True, " ")
def makeModel(): """ This example illustrates how to set up a oscillatory Turing pattern in 1-D using reaction diffusion calculations. Reaction system is:: s ---a---> a // s goes to a, catalyzed by a. s ---a---> b // s goes to b, catalyzed by a. a ---b---> s // a goes to s, catalyzed by b. b -------> s // b is degraded irreversibly to s. in sum, **a** has a positive feedback onto itself and also forms **b**. **b** has a negative feedback onto **a**. Finally, the diffusion constant for **a** is 1/10 that of **b**. This chemical system is present in a 1-dimensional (cylindrical) compartment. The entire reaction-diffusion system is set up within the script. """ # create container for model r0 = 1e-6 # m r1 = 1e-6 # m num = 100 diffLength = 1e-7 # m len = num * diffLength # m diffConst = 1e-13 # m^2/sec motorRate = 1e-6 # m/sec concA = 1 # millimolar dt4 = 0.002 # for the diffusion dt5 = 0.2 # for the reaction model = moose.Neutral('model') compartment = moose.CylMesh('/model/compartment') compartment.r0 = r0 compartment.r1 = r1 compartment.x0 = 0 compartment.x1 = len compartment.diffLength = diffLength assert (compartment.numDiffCompts == num) # create molecules and reactions a = moose.Pool('/model/compartment/a') b = moose.Pool('/model/compartment/b') s = moose.Pool('/model/compartment/s') e1 = moose.MMenz('/model/compartment/e1') e2 = moose.MMenz('/model/compartment/e2') e3 = moose.MMenz('/model/compartment/e3') r1 = moose.Reac('/model/compartment/r1') c = moose.Pool('/model/compartment/c') d = moose.BufPool('/model/compartment/d') r2 = moose.Reac('/model/compartment/r2') moose.connect(r2, 'sub', a, 'reac') moose.connect(r2, 'sub', c, 'reac') moose.connect(r2, 'prd', d, 'reac') r2.Kf = 1 r2.Kb = 10 #moose.connect( e1, 'sub', s, 'reac' ) #moose.connect( e1, 'prd', a, 'reac' ) #moose.connect( a, 'nOut', e1, 'enzDest' ) #e1.Km = 1 #e1.kcat = 1 #moose.connect( e2, 'sub', s, 'reac' ) #moose.connect( e2, 'prd', b, 'reac' ) #moose.connect( a, 'nOut', e2, 'enzDest' ) #e2.Km = 1 #e2.kcat = 0.5 #moose.connect( e3, 'sub', a, 'reac' ) #moose.connect( e3, 'prd', s, 'reac' ) #moose.connect( b, 'nOut', e3, 'enzDest' ) #e3.Km = 0.1 #e3.kcat = 1 #moose.connect( r1, 'sub', b, 'reac' ) #moose.connect( r1, 'prd', s, 'reac' ) #r1.Kf = 0.3 # 1/sec #r1.Kb = 0. # 1/sec # Assign parameters a.diffConst = diffConst / 10 b.diffConst = 0 s.diffConst = 0 c.diffConst = diffConst d.diffConst = 0 # Make solvers ksolve = moose.Ksolve('/model/compartment/ksolve') dsolve = moose.Dsolve('/model/dsolve') # Set up clocks. The dsolver to know before assigning stoich moose.setClock(4, dt4) moose.setClock(5, dt5) moose.useClock(4, '/model/dsolve', 'process') # Ksolve must be scheduled after dsolve. moose.useClock(5, '/model/compartment/ksolve', 'process') stoich = moose.Stoich('/model/compartment/stoich') stoich.compartment = compartment stoich.ksolve = ksolve stoich.dsolve = dsolve stoich.path = "/model/compartment/##" assert (dsolve.numPools == 4) #a.vec.concInit = [0.1]*num # a.vec[50].concInit *= 1.2 # slight perturbation at one end. #a.vec[60].concInit *= 1.2 #a.vec[40].concInit *= 1.2 a.vec[25].concInit *= 1.2 #a.vec[30].concInit *= 1.2 #a.vec[50].concInit *= 1.2 #b.vec[99].concInit *= 0.5 b.vec.concInit = [0.1] * num s.vec.concInit = [1] * num for i in range(0, num - 1, 10): #c.vec[i].concInit = 0.1 c.vec[i].concInit = 0.5 d.vec[i].concInit = 0.5
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
import moose print('Using moose from %s' % moose.__file__) modelRoot = moose.Neutral('/model') compt = moose.CubeMesh('/model/kinetics') p1 = moose.BufPool('/model/kinetics/Ca') function = moose.Function('/model/kinetics/Ca/func') #function out to pool moose.connect(function, 'valueOut', p1, 'setConc') #input pools to be connected to fuction S1 = moose.BufPool('/model/kinetics/s1') S2 = moose.BufPool('/model/kinetics/s2') initiexpr = function.expr #S1 connected to function numVariables = function.numVars expr = "" expr = (function.expr + '+' + 'x' + str(numVariables)) expr = expr.lstrip("0 +") expr = expr.replace(" ", "") function.expr = expr s1msg = moose.connect(S1, 'nOut', function.x[numVariables], 'input') #S2 connected to function numVariables = function.numVars expr = "" expr = (function.expr + '+' + 'x' + str(numVariables)) expr = expr.lstrip("0 +") expr = expr.replace(" ", "") function.expr = expr s2msg = moose.connect(S2, 'nOut', function.x[numVariables], 'input')
def init_pools( compt ): global args # Ring with 6 subunits. for st in range(7): state = 'x%dy%d' % (st, 6 - st ) p = add_pool( compt, state ) p.nInit = 0 if args['enable_subunit_exchange']: # Ring with 7 subunits for st in range(8): state = 'x%dy%d' % (st, 7 - st ) p = add_pool( compt, state ) p.nInit = 0 molecules_[p.name] = p if args['enable_subunit_exchange']: # Add subunit x and y. # NOTE: These guys are shared across multiple sub_sections.. x = add_pool( compt, 'x' ) x.nInit = 0 molecules_[x.name] = x y = add_pool( compt, 'y' ) y.nInit = 0 molecules_[y.name] = y else: _logger.info( "Subunit exchange is disabled" ) for p in [ 'I1', 'PP1', 'PP1_', 'I1P', 'I1P_', 'I1PPP1' ]: if p in [ 'I1' ]: c = moose.BufPool( '%s/%s' % (compt.path, p) ) c.name = pool_name( compt, p ) molecules_[c.name] = c else: c = moose.Pool( '%s/%s' % (compt.path, p) ) c.name = pool_name( compt, p ) molecules_[c.name] = c molecules_[c.name].nInit = 0 if args['enable_subunit_exchange']: # Here we are using concInit rather than nInit to setup the number of # molecules. This is because when Dsolve is used, setting nInit causes # problem: they don't get divided into different voxels. a, b = split_in_two(args['camkii']/args['num_voxels']) assert a+b == args['camkii'] / args['num_voxels'] molecules_[pool_name(compt,'x0y7')].nInit = a molecules_[pool_name(compt,'x0y6')].nInit = b else: molecules_[ pool_name(compt, 'x0y6') ].nInit = args['camkii']/args['num_voxels'] if args['enable_subunit_exchange']: _logger.info('CaMKII = %f (6sym) %f (7sym)' % ( molecules_[ pool_name(compt,'x0y6')].nInit, molecules_[pool_name(compt,'x0y7')].nInit ) ) else: _logger.info('CaMKII = %d (6sym)' % ( molecules_[pool_name(compt,'x0y6')].nInit ) ) # NOTE: Note add 10% of PP1 to initConc. 90% of initConc goes to # inactivePP1. It helps speed up the first step of simiulation. molecules_[ pool_name(compt, 'PP1') ].nInit = 0.1*args['pp1']/args['num_voxels'] molecules_[ pool_name(compt, 'I1PPP1') ].nInit = 0.9*args['pp1']/args['num_voxels'] _logger.debug('Total PP1 %s' % molecules_[pool_name(compt,'PP1')].nInit ) _logger.debug('Total I1PPP1 %s' % molecules_[pool_name(compt,'I1PPP1')].nInit ) # TODO: Much of it only make sense if stochastic solver is used. molecules_[ pool_name(compt,'I1') ].nInit = conc_to_n(_p.conc_i1_free) pp1CamKIICplx = moose.Pool( '%s/camkii_pp1_cplx' % compt.path ) pp1CamKIICplx.name = pool_name( compt, pp1CamKIICplx.name ) pp1CamKIICplx.nInit = 0 molecules_[ pp1CamKIICplx.name ] = pp1CamKIICplx for k in sorted(molecules_): _logger.debug( 'Molecule: %s (%f)' % (k, molecules_[k].nInit ) )
import numpy import pylab import moose # define the geometry compt = moose.CylMesh( '/cylinder' ) compt.r0 = compt.r1 = 1 compt.x1 = 1000 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' )
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 logger_.debug( "checkCreate is called") if moose.exists(modelpath + '/info'): 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 qGItem = kkitQGraphics.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) layoutPt.qGraCompt[mobj] = qGItem # Attach a drop signal. qGItem.dropped.emit() 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') qGItem = kkitQGraphics.PoolItem(poolObj, itemAtView) layoutPt.mooseId_GObj[poolObj] = qGItem posWrtComp = (itemAtView.mapFromScene(pos)).toPoint() bgcolor = kkitUtil.getRandColor() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('green'), bgcolor) poolinfo.color = str(bgcolor.getRgb()) qGItem.dropped.emit() kkitUtil.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 = kkitQGraphics.ReacItem(reacObj, itemAtView) qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), "white", "white") layoutPt.mooseId_GObj[reacObj] = qGItem qGItem.dopped.emit() # view.emit(QtCore.SIGNAL("dropped"), reacObj) kkitUtil.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 = kkitQGraphics.TableItem(tabObj, itemAtView) qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('white'), QtGui.QColor('white')) layoutPt.mooseId_GObj[tabObj] = qGItem qGItem.dropped.emit() # view.emit(QtCore.SIGNAL("dropped"), tabObj) kkitUtil.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[moose.element(mobj.path)] elif mobj.className in comptclass: funcParent = layoutPt.qGraCompt[moose.element(mobj)] posWrtComp = funcParent.mapFromScene(pos).toPoint() elif mobj.className in "Neutral": funcParent = layoutPt.qGraGrp[moose.element(mobj)] qGItem = kkitQGraphics.FuncItem(funcObj, funcParent) qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y(), QtGui.QColor('red'), QtGui.QColor('green')) layoutPt.mooseId_GObj[funcObj] = qGItem qGItem.dropped.emit() # view.emit(QtCore.SIGNAL("dropped"), funcObj) kkitUtil.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": # FIXME: 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 if ((mobj.parent).className == "Enz"): QMessageBox.information( None, "Drop Not possible", "'{}' has to have Pool as its parent and not Enzyme Complex". format(string), QMessageBox.Ok) return None 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 = kkitQGraphics.EnzItem(enzObj, parentcompt) layoutPt.mooseId_GObj[enzObj] = qGItem posWrtComp = pos bgcolor = kkitUtil.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()) moose.Annotator(enzinfo) Enz_cplx = enzObj.path + '/' + string_num + '_cplx' cplxItem = moose.Pool(Enz_cplx) moose.Annotator(cplxItem.path + '/info') qGEnz = layoutPt.mooseId_GObj[enzObj] kkitQGraphics.CplxItem(cplxItem, qGEnz) layoutPt.mooseId_GObj[cplxItem] = qGItem enzboundingRect = qGEnz.boundingRect() moose.connect(enzObj, 'cplx', cplxItem, 'reac') qGItem.setDisplayProperties(int(enzboundingRect.height() / 2), enzboundingRect.height() - 40, QtGui.QColor('white'), QtGui.QColor('white')) qGItem.dropped.emit() # 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 = kkitQGraphics.MMEnzItem(enzObj, parentcompt) posWrtComp = pos bgcolor = kkitUtil.getRandColor() qGItem.setDisplayProperties(posWrtComp.x(), posWrtComp.y() - 30, QtGui.QColor('green'), bgcolor) enzinfo.color = str(bgcolor.name()) layoutPt.mooseId_GObj[enzObj] = qGItem qGItem.dropped.emit() # view.emit(QtCore.SIGNAL("dropped"), enzObj) x, y = roundoff(qGItem.scenePos(), layoutPt) enzinfo.x = x enzinfo.y = y kkitUtil.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)