def main():
    global compt_
    compt_ = moose.CylMesh('/compt')
    compt_.r0 = compt_.r1 = 1e-6
    compt_.x1 = 100e-6
    print('[INFO] Compartment volume is %g' % compt_.volume)

    # Create n subcompartment in this compartment.
    subsecs = ['sec%d' % x for x in range(10)]
    for subsec in subsecs:
        create_model(compt_, subsec)

    # Put 1000 molecules of A in first subsection.
    pools_['sec0.A'].concInit = A0_

    # Putt diffusion between subsections.
    for i, s2 in enumerate(subsecs[1:]):
        s1 = subsecs[i]
        kfkb = D_ / (compt_.x1 / len(subsecs))**2.0  # D/L^2
        enable_diffusion(s1, s2, 'A', kfkb)

    setup_solvers()
    moose.reinit()
    moose.start(100, 1)
    # make_plot( tables_ )
    concA = diff_analytical()
    print(concA)
示例#2
0
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 = 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

    # 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
    stoich.reacSystemPath = '/cylinder/##'

    #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 = %f " % (time.time() - t1)))

    print(("Time = %s " % (time.time() - t1)))
    pylab.ylim(0, 1.05)
    pylab.legend()
    pylab.show()
示例#3
0
def makeModel():
    # create container for model
    num = 1 # number of compartments
    model = moose.Neutral( '/model' )
    compartment = moose.CylMesh( '/model/compartment' )
    compartment.x1 = 1.0e-6 # Set it to a 1 micron single-voxel cylinder

    # create molecules and reactions
    s = moose.Pool( '/model/compartment/s' )
    #####################################################################
    # Put in endo compartment. Add molecule s
    endo = moose.EndoMesh( '/model/endo' )
    endo.isMembraneBound = True
    endo.surround = compartment
    es = moose.Pool( '/model/endo/s' )
    rXfer = moose.Reac( '/model/endo/rXfer' )
    #####################################################################
    moose.connect( rXfer, 'sub', s, 'reac' )
    moose.connect( rXfer, 'prd', es, 'reac' )
    volRatio = compartment.volume / endo.volume
    rXfer.Kf = 0.04 # 0.04/sec
    rXfer.Kb = 0.02 # 0.02/sec

    #####################################################################
    fixXreacs.fixXreacs( '/model' )
    #fixXreacs.restoreXreacs( '/model' )
    #fixXreacs.fixXreacs( '/model' )
    #####################################################################

    # Make solvers
    ksolve = moose.Ksolve( '/model/compartment/ksolve' )
    dsolve = moose.Dsolve( '/model/dsolve' )
    eksolve = moose.Ksolve( '/model/endo/ksolve' )
    edsolve = moose.Dsolve( '/model/endo/dsolve' )

    stoich = moose.Stoich( '/model/compartment/stoich' )
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = "/model/compartment/##"
    assert( dsolve.numPools == 1 )
    s.vec.concInit = [1]*num

    estoich = moose.Stoich( '/model/endo/stoich' )
    estoich.compartment = endo
    estoich.ksolve = eksolve
    estoich.dsolve = edsolve
    estoich.path = "/model/endo/##"
    assert( edsolve.numPools == 2 )

    edsolve.buildMeshJunctions( dsolve )

    plot1 = moose.Table2( '/model/plot1' )
    plot2 = moose.Table2( '/model/plot2' )
    moose.connect( '/model/plot1', 'requestOut', s, 'getN' )
    moose.connect( '/model/plot2', 'requestOut', es, 'getN' )
    plot3 = moose.Table2( '/model/plot3' )
    plot4 = moose.Table2( '/model/plot4' )
    moose.connect( '/model/plot3', 'requestOut', s, 'getConc' )
    moose.connect( '/model/plot4', 'requestOut', es, 'getConc' )
示例#4
0
def makeModel():
    # create container for model
    r0 = 2e-6  # m
    r1 = 1e-6  # m
    num = 100
    diffLength = 1e-6  # m
    len = num * diffLength  # m
    diffConst = 10e-12
    #motorRate = 1e-6
    #diffConst = 0
    motorRate = 0

    model = moose.Neutral('model')
    compartment = moose.CylMesh('/model/compartment')
    compartment.r0 = r0
    compartment.r1 = r1
    compartment.x0 = 0
    compartment.x1 = len
    compartment.diffLength = diffLength

    assert (compartment.numDiffCompts == num)

    # create molecules and reactions
    a = moose.Pool('/model/compartment/a')
    b = moose.Pool('/model/compartment/b')
    c = moose.Pool('/model/compartment/c')
    d = moose.Pool('/model/compartment/d')
    r1 = moose.Reac('/model/compartment/r1')
    moose.connect(r1, 'sub', b, 'reac')
    moose.connect(r1, 'sub', d, 'reac')
    moose.connect(r1, 'prd', c, 'reac')
    r1.Kf = 1000.0  # 1/(mM.sec)
    r1.Kb = 1  # 1/sec

    # Assign parameters
    a.diffConst = diffConst
    b.diffConst = diffConst / 2.0
    b.motorConst = motorRate
    c.diffConst = diffConst
    d.diffConst = diffConst

    # Make solvers
    ksolve = moose.Gsolve('/model/compartment/ksolve')
    dsolve = moose.Dsolve('/model/compartment/dsolve')
    stoich = moose.Stoich('/model/compartment/stoich')
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    os.kill(PID, signal.SIGUSR1)
    stoich.path = "/model/compartment/##"

    print((dsolve.numPools))
    assert (dsolve.numPools == 4)
    a.vec.concInit = concA
    b.vec.concInit = concA / 5.0
    c.vec.concInit = concA
    d.vec.concInit = concA / 5.0
    for i in range(num):
        d.vec[i].concInit = concA * 2 * i / num
示例#5
0
def makeModel():
                # create container for model
                r0 = 1e-6        # m
                r1 = 0.5e-6        # m. Note taper.
                num = 200
                diffLength = 1e-6 # m
                comptLength = num * diffLength        # m
                diffConst = 20e-12 # m^2/sec
                concA = 1 # millimolar
                diffDt = 0.02  # for the diffusion
                chemDt = 0.2   # for the reaction
                mfile = '../../genesis/M1719.g'

                model = moose.Neutral( 'model' )
                compartment = moose.CylMesh( '/model/kinetics' )

                # load in model
                modelId = moose.loadModel( mfile, '/model', 'ee' )
                a = moose.element( '/model/kinetics/a' )
                b = moose.element( '/model/kinetics/b' )
                c = moose.element( '/model/kinetics/c' )

                ac = a.concInit
                bc = b.concInit
                cc = c.concInit

                compartment.r0 = r0
                compartment.r1 = r1
                compartment.x0 = 0
                compartment.x1 = comptLength
                compartment.diffLength = diffLength
                assert( compartment.numDiffCompts == num )

                # Assign parameters
                for x in moose.wildcardFind( '/model/kinetics/##[ISA=PoolBase]' ):
                    #print 'pools: ', x, x.name
                    x.diffConst = diffConst

                # Make solvers
                ksolve = moose.Ksolve( '/model/kinetics/ksolve' )
                dsolve = moose.Dsolve( '/model/dsolve' )
                # Set up clocks.
                moose.setClock( 10, diffDt )
                for i in range( 11, 17 ):
                    moose.setClock( i, chemDt )

                stoich = moose.Stoich( '/model/kinetics/stoich' )
                stoich.compartment = compartment
                stoich.ksolve = ksolve
                stoich.dsolve = dsolve
                stoich.path = "/model/kinetics/##"
                print(('dsolve.numPools, num = ', dsolve.numPools, num))
                b.vec[num-1].concInit *= 1.01 # Break symmetry.
def makeCyl(num, concInit, radius, x0, x1):
    compt = moose.CylMesh('/model/compt' + num)
    compt.x0 = x0
    compt.x1 = x1
    compt.y0 = 0
    compt.y1 = 0
    compt.z0 = 0
    compt.z1 = 0
    compt.r0 = radius
    compt.r1 = radius
    compt.diffLength = x1 - x0
    a = moose.Pool(compt.path + '/a')
    b = moose.Pool(compt.path + '/b' + num)
    reac = moose.Reac(compt.path + '/reac')
    moose.connect(reac, 'sub', a, 'reac')
    moose.connect(reac, 'prd', b, 'reac')
    a.diffConst = diffConst
    a.concInit = concInit
    b.concInit = concInit
    reac.Kf = 0.1
    reac.Kb = 0.1
    return a, b, compt
示例#7
0
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()
示例#8
0
def main( compt_name, **kwargs ):
    global args
    global model_path_
    global curr_subsec_
    global compt_
    moose.Neutral( model_path_ )
    args = kwargs

    # NOTE: Try to keep volumne of all voxels close to 3.1416e-22m^3. In these
    # experiments, the length of compartment is set to 180nM and volumne math
    # Πe-22 m^3.
    voxels = [ ]
    nVoxels = int(args['num_voxels'])
    voxelL = args['voxel_length']
    assert nVoxels > 0, nVoxels
    assert voxelL > 0, voxelL
    radius = 23.56e-9
    args[ 'voxel_volume' ] = math.pi * radius * radius * voxelL
    args[ 'camkii_conc' ] = n_to_conc( args[ 'camkii' ] / nVoxels  )
    args[ 'pp1_conc' ] = n_to_conc( args[ 'pp1' ] / nVoxels )

    if isinstance( args['diff_dict'], str ):
        args[ 'diff_dict' ] = eval( args[ 'diff_dict' ] )
        _logger.info( 'Diffusion dict %s' % args[ 'diff_dict' ] )

    compt_ = moose.CylMesh( '%s/%s' % (model_path_, compt_name ) )
    compt_.x1 = nVoxels * voxelL
    compt_.r0 = compt_.r1 = radius
    _logger.info( '++ Volume of compt %g' % compt_.volume )

    for i in range( args[ 'num_voxels' ] ):
        curr_subsec_ = 'sw%d' % i
        voxel = moose.Neutral( '%s/%s' % ( compt_.path, curr_subsec_ ) )
        _logger.info( "== Creating voxles %d" % i )
        _logger.debug( '=== Created subsystem inside %s' % voxel.name )
        make_model( voxel, **kwargs )
        voxels.append( voxel )

    if args[ 'enable_subunit_exchange' ]:
        for x in args[ 'diff_dict' ].keys( ):
            _logger.info( "Setting up diffusion for %s" % x )
            try:
                setup_diffusion( voxels, x )
            except Exception as e:
                _logger.warn( 'Could not enable diffusion for %s' % x )
                _logger.warn( '\tError was %s' % e )


    setup_solvers( compt_, stochastic = True )
    print_compt( compt_ )

    # Now add solvers and other goodies in compartment.
    moose.setClock(18, args['record_dt'] ) # Table2
    tables = setupTables( )

    st = moose.Streamer( '/model/streamer' )
    st.outfile = args['outfile']
    _logger.info( 'Added streamer with outfile  %s' % st.outfile )
    st.addTables( tables )
    t1 = time.time()
    stamp = datetime.datetime.now().isoformat()
    # moose.setClock( 10, 0.003 )
    # moose.setClock( 15, 0.03 )
    # moose.setClock( 16, 0.03 )
    moose.reinit()
    print( '== Gainers' )
    print( sorted( gainers_ ) )
    print( '== Loosers' )
    print( sorted( loosers_ ) )
    print( '== Dephosphorylated' )
    print( sorted( dephospho_ ) )

    # sanity tests
    verify( )
    runtime = 24 * 3600 * float( args[ 'simtime' ] )
    _logger.info('Running for %d seconds' %  runtime )
    t = time.time( )
    #compartment_to_graph( '' )

    moose.start( runtime, 1 )
    print( '[INFO] Time taken %f' % (time.time() - t ) )

    # append parameters to streamer file.
    with open( st.outfile, 'a' ) as f:
        f.write( "# %s" % str( args ) )
    print( '[INFO] Appended simulation parameters to file' )

    _logger.info( 'Total time taken %s' % (time.time() - t1 ) )
示例#9
0
def makeModel():
    # create container for model
    num = 1  # number of compartments
    model = moose.Neutral('/model')
    compartment = moose.CylMesh('/model/compartment')
    compartment.x1 = 1.0e-6  # Set it to a 1 micron single-voxel cylinder

    # create molecules and reactions
    s = moose.Pool('/model/compartment/s')
    rXfer = moose.Reac('/model/compartment/rXfer')
    #####################################################################
    # Put in endo compartment. Add molecule s
    endo = moose.EndoMesh('/model/endo')
    # Note that the chanPool must be on the 'In' compartment.
    #chanPool = moose.Pool( '/model/compartment/chanPool' )
    #chan = moose.ConcChan( '/model/compartment/chanPool/chan' )
    chanPool = moose.Pool('/model/endo/chanPool')
    chan = moose.ConcChan('/model/endo/chanPool/chan')
    endo.isMembraneBound = True
    endo.surround = compartment
    es = moose.Pool('/model/endo/s')
    #####################################################################
    moose.connect(rXfer, 'sub', s, 'reac')
    moose.connect(rXfer, 'prd', es, 'reac')
    moose.connect(chanPool, 'nOut', chan, 'setNumChan')
    moose.connect(chan, 'out', s, 'reac')
    moose.connect(chan, 'in', es, 'reac')
    volRatio = compartment.volume / endo.volume
    rXfer.Kf = 0.0  # 0.02/sec
    rXfer.Kb = 0.0  #
    s.concInit = 0.001
    chanPool.nInit = 1000.0
    # Flux (mM/s) = permeability * N * (conc_out - conc_in )
    chan.permeability = 0.1 * chanPool.volume * 6.022e23 / chanPool.nInit

    #####################################################################
    fixXreacs.fixXreacs('/model')
    #fixXreacs.restoreXreacs( '/model' )
    #fixXreacs.fixXreacs( '/model' )
    #####################################################################

    # Make solvers
    ksolve = moose.Ksolve('/model/compartment/ksolve')
    dsolve = moose.Dsolve('/model/dsolve')
    eksolve = moose.Ksolve('/model/endo/ksolve')
    edsolve = moose.Dsolve('/model/endo/dsolve')

    stoich = moose.Stoich('/model/compartment/stoich')
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = "/model/compartment/##"
    assert (dsolve.numPools == 2)

    estoich = moose.Stoich('/model/endo/stoich')
    estoich.compartment = endo
    estoich.ksolve = eksolve
    estoich.dsolve = edsolve
    estoich.path = "/model/endo/##"
    assert (edsolve.numPools == 2)

    edsolve.buildMeshJunctions(dsolve)

    plot1 = moose.Table2('/model/plot1')
    plot2 = moose.Table2('/model/plot2')
    plot3 = moose.Table2('/model/plot3')
    moose.connect('/model/plot1', 'requestOut', s, 'getN')
    moose.connect('/model/plot2', 'requestOut', es, 'getN')
    moose.connect('/model/plot3', 'requestOut',
                  '/model/compartment/s_xfer_endo', 'getN')
    plot4 = moose.Table2('/model/plot4')
    plot5 = moose.Table2('/model/plot5')
    plot6 = moose.Table2('/model/plot6')
    moose.connect('/model/plot4', 'requestOut', s, 'getConc')
    moose.connect('/model/plot5', 'requestOut', es, 'getConc')
    moose.connect('/model/plot6', 'requestOut',
                  '/model/compartment/s_xfer_endo', 'getConc')
示例#10
0
def test_gsolve_paralllel(nT=4):
    """
    This example implements a reaction-diffusion like system which is
    bistable and propagates losslessly. It is based on the NEURON example 
    rxdrun.py, but incorporates more compartments and runs for a longer time.
    The system is implemented in a function rather than as a proper system
    of chemical reactions. Please see rxdReacDiffusion.py for a variant that 
    uses a reaction plus a function object to control its rates.
    """
    print( 'Using %d threads' % nT )
    dt = 0.1
    # define the geometry
    compt = moose.CylMesh( '/cylinder' )
    compt.r0 = compt.r1 = 100e-9
    compt.x1 = 200e-09
    compt.diffLength = 0.2e-9
    assert( compt.numDiffCompts == compt.x1/compt.diffLength)

    #define the molecule. Its geometry is defined by its parent volume, cylinder
    c = moose.Pool( '/cylinder/pool' )
    c.diffConst = 1e-13 # define diffusion constant

    # Here we set up a function calculation
    func = moose.Function( '/cylinder/pool/func' )
    func.expr = "(-x0*(30e-9-x0)*(100e-9-x0))*0.0001"
    #  func.x.num = 1 #specify number of input variables.

    #Connect the molecules to the func
    moose.connect( c, 'nOut', func.x[0], 'input' )
    #Connect the function to the pool
    moose.connect( func, 'valueOut', c, 'increment' )

    #Set up solvers
    ksolve = moose.Gsolve( '/cylinder/Gsolve' )
    ksolve.numThreads = nT

    dsolve = moose.Dsolve( '/cylinder/dsolve' )
    stoich = moose.Stoich( '/cylinder/stoich' )
    stoich.compartment = compt
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = '/cylinder/##'

    #initialize
    x = np.arange( 0, compt.x1, compt.diffLength )
    c.vec.nInit = [ 1000.0 for q in x ]

    # Run and plot it.
    moose.reinit()
    updateDt = 50
    runtime = updateDt * 10
    t1 = time.time()
    res = []
    clk = moose.element( '/clock' )
    for t in range( 0, runtime-1, updateDt ):
        y = c.vec.n
        s = np.sum(y)
        v = (np.mean(y), np.max(y), np.min(y), s)
        print(v)
        res.append(v)
        moose.start( updateDt )
        currTime = clk.currentTime

    # One molecule here and there because thread launching has undeterministic
    # characteristics. Even after setting moose.seed; we may not see same
    # numbers on all platfroms.
    expected = [
            (1000.0, 1000.0, 1000.0, 1000000.0)
            , (9.908, 10.0, 8.0, 9908.0)
            , (6.869, 7.0, 6.0, 6869.0)
            , (5.354, 6.0, 5.0, 5354.0)
            , (4.562, 5.0, 4.0, 4562.0)
            , (3.483, 4.0, 3.0, 3483.0)
            , (3.043, 4.0, 3.0, 3043.0)
            , (2.261, 3.0, 2.0, 2261.0)
            , (1.967, 2.0, 1.0, 1967.0)
            , (1.997, 2.0, 1.0, 1997.0) ]
    print("Time = ", time.time() - t1)
    assert np.isclose(res, expected, atol=1, rtol=1).all(), "Got %s, expected %s" % (res, expected)
示例#11
0
def main(compt_name, **kwargs):
    global args
    global model_path_
    global curr_subsec_
    global compt_
    moose.Neutral(model_path_)
    args = kwargs
    voxels = []
    l = args['voxel_length']
    radius = 30e-9
    args['volume'] = math.pi * radius * radius * l
    args['camkii_conc'] = n_to_conc(args['camkii'])
    args['pp1_conc'] = n_to_conc(args['pp1'])
    args['psd_volume'] = 0.0

    if isinstance(args['diff_dict'], str):
        args['diff_dict'] = eval(args['diff_dict'])
        _logger.info('Diffusion dict %s' % args['diff_dict'])

    compt_ = moose.CylMesh('%s/%s' % (model_path_, compt_name))
    compt_.x1 = l
    compt_.r0 = compt_.r1 = radius

    _logger.info('Volume of compt %g' % compt_.volume)
    for i in range(args['num_voxels']):
        curr_subsec_ = 'sw%d' % i
        voxel = moose.Neutral('%s/%s' % (compt_.path, curr_subsec_))
        _logger.info("Creating voxles %d" % i)
        _logger.debug('==== Created subsystem inside %s' % voxel.name)
        make_model(voxel, **kwargs)
        voxels.append(voxel)

    for x in ['x']:
        _logger.info("Setting up diffusion for %s" % x)
        setup_diffusion(voxels, x)

    setup_solvers(compt_, stochastic=True)
    print_compt(compt_)

    # Now add solvers and other goodies in compartment.
    moose.setClock(18, args['record_dt'])  # Table2
    tables = setupTables()

    st = moose.Streamer('/model/streamer')
    st.outfile = args['outfile']
    _logger.info('Added streamer with outfile  %s' % st.outfile)
    st.addTables(tables)
    t1 = time.time()
    stamp = datetime.datetime.now().isoformat()
    # moose.setClock( 10, 0.003 )
    # moose.setClock( 15, 0.03 )
    # moose.setClock( 16, 0.03 )
    moose.reinit()
    print('== Gainers')
    print(sorted(gainers_))
    print('== Loosers')
    print(sorted(loosers_))
    print('== Dephosphorylated')
    print(sorted(dephospho_))

    # sanity tests
    verify()
    runtime = 24 * 3600 * float(args['simtime'])
    _logger.info('Running for %d seconds' % runtime)
    moose.start(runtime, 1)

    # append parameters to streamer file.
    with open(st.outfile, 'a') as f:
        f.write("# %s" % str(args))
    print('[INFO] Appended simulation parameters to file')

    _logger.info('Total time taken %s' % (time.time() - t1))
示例#12
0
def main( nT ):
    """
    This example implements a reaction-diffusion like system which is
    bistable and propagates losslessly. It is based on the NEURON example 
    rxdrun.py, but incorporates more compartments and runs for a longer time.
    The system is implemented in a function rather than as a proper system
    of chemical reactions. Please see rxdReacDiffusion.py for a variant that 
    uses a reaction plus a function object to control its rates.
    """
    print( 'Using %d threads' % nT )

    dt = 0.1

    # define the geometry
    compt = moose.CylMesh( '/cylinder' )
    compt.r0 = compt.r1 = 100e-9
    compt.x1 = 200e-9
    compt.diffLength = 0.2e-9
    assert( compt.numDiffCompts == compt.x1/compt.diffLength )

    #define the molecule. Its geometry is defined by its parent volume, cylinder
    c = moose.Pool( '/cylinder/pool' )
    c.diffConst = 1e-13 # define diffusion constant


    # Here we set up a function calculation
    func = moose.Function( '/cylinder/pool/func' )
    func.expr = "(-x0 * (30e-9 - x0) * (100e-9 - x0))*0.0001"
    func.x.num = 1 #specify number of input variables.

    #Connect the molecules to the func
    moose.connect( c, 'nOut', func.x[0], 'input' )
    #Connect the function to the pool
    moose.connect( func, 'valueOut', c, 'increment' )

    #Set up solvers
    ksolve = moose.Gsolve( '/cylinder/Gsolve' )
    try:
        ksolve.numThreads = nT
    except Exception as e:
        print( 'OLD MOOSE. Does not support multithreading' )
    dsolve = moose.Dsolve( '/cylinder/dsolve' )
    stoich = moose.Stoich( '/cylinder/stoich' )
    stoich.compartment = compt
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = '/cylinder/##'

    #initialize
    x = np.arange( 0, compt.x1, compt.diffLength )
    c.vec.nInit = [ 1000.0 for q in x ]

    # Run and plot it.
    moose.reinit()
    updateDt = 50
    runtime = updateDt * 10
    t1 = time.time()
    res = []
    for t in range( 0, runtime-1, updateDt ):
        moose.start( updateDt )
        y = c.vec.n
        res.append( (np.mean(y), np.std(y)) )

    expected = [(9.0, 0.0), (6.0, 0.0), (5.0, 0.0), (3.0, 0.0), (2.0, 0.0),
        (2.0, 0.0), (2.0, 0.0), (1.0, 0.0), (1.0, 0.0), (1.0, 0.0)]
    print(("Time = ", time.time() - t1))
    print( res )
    assert res == expected
import sys

print(('[DEBUG] Using moose from %s' % moose.__file__))
'''
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 = 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
示例#14
0
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)
示例#15
0
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-16  # 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')
    c = moose.Pool('/model/compartment/c')
    d = moose.Pool('/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 = 2

    #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
    c.diffConst = diffConst / 10
    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 == 3)
    #    a.vec.concInit = [2]*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
    avec = moose.vec('/model/compartment/a').concInit
    ael = moose.element('/model/compartment/a')
    savec = avec.size
    randper = numpy.random.uniform(5, 10, savec)
    #a.vec.concInit = randper
    #    r2.Kf=ael.vec[50].conc
    #    r2.Kb=0.5*ael.vec[50].conc
    a.vec[50].concInit = 2
    #b.vec[99].concInit *= 0.5
    c.vec[50].concInit = 1
    d.vec.concInit = 0
示例#16
0
def makeModel():
    # create container for model
    num = 1  # number of compartments
    model = moose.Neutral('/model')
    compartment = moose.CylMesh('/model/compartment')
    compartment.x1 = 1.0e-6  # Set it to a 1 micron single-voxel cylinder

    # create molecules and reactions
    prd = moose.Pool('/model/compartment/prd')
    rXfer = moose.Reac('/model/compartment/rXfer')
    #####################################################################
    # Put in endo compartment. Add molecule s
    endo = moose.EndoMesh('/model/endo')
    endo.isMembraneBound = True
    endo.surround = compartment
    sub = moose.Pool('/model/endo/sub')
    enzPool = moose.Pool('/model/endo/enzPool')
    enzPool.concInit = eInit
    enz = moose.MMenz('/model/endo/enzPool/enz')
    #####################################################################
    moose.connect(enz, 'sub', sub, 'reac')
    moose.connect(enz, 'prd', prd, 'reac')
    moose.connect(enzPool, 'nOut', enz, 'enzDest')
    moose.connect(rXfer, 'sub', prd, 'reac')
    moose.connect(rXfer, 'prd', sub, 'reac')
    rXfer.Kf = Kf  # 0.04/sec
    rXfer.Kb = 0.0  # 0.02/sec
    enz.Km = Km
    enz.kcat = kcat
    # v = es.kcat/(s+Km)
    # v = Kf * conc.
    #####################################################################
    fixXreacs.fixXreacs('/model')
    fixXreacs.restoreXreacs('/model')
    fixXreacs.fixXreacs('/model')
    #####################################################################

    # Make solvers
    ksolve = moose.Ksolve('/model/compartment/ksolve')
    dsolve = moose.Dsolve('/model/dsolve')
    eksolve = moose.Ksolve('/model/endo/ksolve')
    edsolve = moose.Dsolve('/model/endo/dsolve')

    stoich = moose.Stoich('/model/compartment/stoich')
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = "/model/compartment/##"
    assert (dsolve.numPools == 2)
    sub.vec.concInit = subInit
    enzPool.vec.concInit = eInit

    estoich = moose.Stoich('/model/endo/stoich')
    estoich.compartment = endo
    estoich.ksolve = eksolve
    estoich.dsolve = edsolve
    estoich.path = "/model/endo/##"
    assert (edsolve.numPools == 3)

    edsolve.buildMeshJunctions(dsolve)

    plot1 = moose.Table2('/model/plot1')
    plot2 = moose.Table2('/model/plot2')
    moose.connect('/model/plot1', 'requestOut', sub, 'getN')
    moose.connect('/model/plot2', 'requestOut', prd, 'getN')
    plot3 = moose.Table2('/model/plot3')
    plot4 = moose.Table2('/model/plot4')
    moose.connect('/model/plot3', 'requestOut', sub, 'getConc')
    moose.connect('/model/plot4', 'requestOut', prd, 'getConc')
示例#17
0
def makeModel():
    # create container for model
    num = 1 # number of compartments
    model = moose.Neutral( '/model' )
    compartment = moose.CylMesh( '/model/compartment' )
    compartment.x1 = 1.0e-6 # Set it to a 1 micron single-voxel cylinder

    # create molecules and reactions
    u = moose.Pool( '/model/compartment/u' )
    #####################################################################
    # Put in endo compartment. Add molecule s
    endo = moose.EndoMesh( '/model/endo' )
    endo.isMembraneBound = True
    endo.surround = compartment
    rXfer = moose.Reac( '/model/endo/rXfer' )
    et = moose.Pool( '/model/endo/t' )
    es = moose.Pool( '/model/endo/s' )
    #####################################################################
    moose.connect( rXfer, 'sub', u, 'reac' )
    moose.connect( rXfer, 'sub', et, 'reac' )
    moose.connect( rXfer, 'prd', es, 'reac' )
    u.concInit = 1.0
    et.concInit = 1.0

    #####################################################################
    # [u0] = 1 in compt, [t0] = 1 in endo, [s0] = 0
    # [u] + [s]/8 = [u0]  ; [t] + [s] = [t0]; nu + ns = nu0, nt + ns = nt0
    # At equil, numKf*nu*nt = numKb*ns
    # Express all # in terms of ns.
    # nu = nu0-ns; nt = nt0-ns      Also, nu0 = 8*nt0
    # So  numKf*(nu0-ns)*(nt0-ns) = numKb*ns
    # Target level is nt = ns = nt0/2
    # So numKf*( 8nt0 - nt0/2)*nt0/2 = numKb*nt0/2
    # So 7.5*nt0 = numKb/numKf
    rXfer.numKb = 0.1
    rXfer.numKf = 0.1/(7.5 * et.nInit)
    #print( "Rates = {}, {}".format( rXfer.Kf, rXfer.Kb ))
    #####################################################################
    fixXreacs.fixXreacs( '/model' )
    #fixXreacs.restoreXreacs( '/model' )
    #fixXreacs.fixXreacs( '/model' )
    #####################################################################

    # Make solvers
    ksolve = moose.Ksolve( '/model/compartment/ksolve' )
    dsolve = moose.Dsolve( '/model/compartment/dsolve' )
    eksolve = moose.Ksolve( '/model/endo/ksolve' )
    edsolve = moose.Dsolve( '/model/endo/dsolve' )

    stoich = moose.Stoich( '/model/compartment/stoich' )
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = "/model/compartment/##"
    assert( dsolve.numPools == 1 )

    estoich = moose.Stoich( '/model/endo/stoich' )
    estoich.compartment = endo
    estoich.ksolve = eksolve
    estoich.dsolve = edsolve
    estoich.path = "/model/endo/##"
    assert( edsolve.numPools == 3 )

    edsolve.buildMeshJunctions( dsolve )

    plot1 = moose.Table2( '/model/plot1' )
    plot2 = moose.Table2( '/model/plot2' )
    plot3 = moose.Table2( '/model/plot3' )
    moose.connect( '/model/plot1', 'requestOut', u, 'getN' )
    moose.connect( '/model/plot2', 'requestOut', et, 'getN' )
    moose.connect( '/model/plot3', 'requestOut', es, 'getN' )
    plot4 = moose.Table2( '/model/plot4' )
    plot5 = moose.Table2( '/model/plot5' )
    plot6 = moose.Table2( '/model/plot6' )
    moose.connect( '/model/plot4', 'requestOut', u, 'getConc' )
    moose.connect( '/model/plot5', 'requestOut', et, 'getConc' )
    moose.connect( '/model/plot6', 'requestOut', es, 'getConc' )
示例#18
0
def makeModel():
    """
    This example illustrates how to set up a diffusion/transport model with 
    a simple reaction-diffusion system in a tapering cylinder: 

    | Molecule **a** diffuses with diffConst of 10e-12 m^2/s. 
    | Molecule **b** diffuses with diffConst of 5e-12 m^2/s. 
    | Molecule **b** also undergoes motor transport with a rate of 10e-6 m/s
    |   Thus it 'piles up' at the end of the cylinder.
    | Molecule **c** does not move: diffConst = 0.0
    | Molecule **d** does not move: diffConst = 10.0e-12 but it is buffered. 
    |   Because it is buffered, it is treated as non-diffusing.

    All molecules other than **d** start out only in the leftmost (first)
    voxel, with a concentration of 1 mM. **d** is present throughout
    at 0.2 mM, except in the last voxel, where it is at 1.0 mM.

    The cylinder has a starting radius of 2 microns, and end radius of 
    1 micron. So when the molecule undergoing motor transport gets to the
    narrower end, its concentration goes up.

    There is a little reaction in all compartments: ``b + d <===> c``

    As there is a high concentration of **d** in the last compartment,
    when the molecule **b** reaches the end of the cylinder, the reaction
    produces lots of **c**.

    Note that molecule **a** does not participate in this reaction.

    The concentrations of all molecules are displayed in an animation.
    """
    # create container for model
    r0 = 2e-6	# m
    r1 = 1e-6	# m
    num = 100
    diffLength = 1e-6 # m
    len = num * diffLength	# m
    diffConst = 10e-12
    #motorRate = 1e-6
    #diffConst = 0
    motorRate = 0

    model = moose.Neutral( 'model' )
    compartment = moose.CylMesh( '/model/compartment' )
    compartment.r0 = r0
    compartment.r1 = r1
    compartment.x0 = 0
    compartment.x1 = len
    compartment.diffLength = diffLength
    
    assert( compartment.numDiffCompts == num )

    # create molecules and reactions
    a = moose.Pool( '/model/compartment/a' )
    b = moose.Pool( '/model/compartment/b' )
    c = moose.Pool( '/model/compartment/c' )
    d = moose.Pool( '/model/compartment/d' )
    r1 = moose.Reac( '/model/compartment/r1' )
    moose.connect( r1, 'sub', b, 'reac' )
    moose.connect( r1, 'sub', d, 'reac' )
    moose.connect( r1, 'prd', c, 'reac' )
    r1.Kf = 1000.0 # 1/(mM.sec)
    r1.Kb = 1 # 1/sec

    # Assign parameters
    a.diffConst = diffConst
    b.diffConst = diffConst / 2.0
    b.motorConst = motorRate
    c.diffConst = diffConst
    d.diffConst = diffConst


    # Make solvers
    ksolve = moose.Gsolve( '/model/compartment/ksolve' )
    dsolve = moose.Dsolve( '/model/compartment/dsolve' )
    stoich = moose.Stoich( '/model/compartment/stoich' )
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    os.kill( PID, signal.SIGUSR1 )
    stoich.path = "/model/compartment/##"

    print dsolve.numPools
    assert( dsolve.numPools == 4 )
    a.vec.concInit = concA
    b.vec.concInit = concA / 5.0
    c.vec.concInit = concA
    d.vec.concInit = concA / 5.0
    for i in range( num ):
        d.vec[i].concInit = concA * 2 * i / num
示例#19
0
def makeModel():
    # create container for model
    r0 = 1e-6        # m
    r1 = 1e-6        # m
    num = 25
    diffLength = 1e-6 # m
    len = num * diffLength        # m
    diffConst = 1e-12 # m^2/sec
    motorConst = 1e-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.Pool( '/model/compartment/d' )
    """
    r1 = moose.Reac( '/model/compartment/r1' )
    moose.connect( r1, 'sub', b, 'reac' )
    moose.connect( r1, 'sub', d, 'reac' )
    moose.connect( r1, 'prd', c, 'reac' )
    r1.Kf = 100 # 1/(mM.sec)
    r1.Kb = 0.01 # 1/sec
    """

    # Assign parameters
    a.diffConst = 0.0;
    b.diffConst = 0.0;
    #b.motorRate = motorRate
    c.diffConst = 0.0;
    d.diffConst = 0.0;
    #d.diffConst = diffConst;
    os.kill( PID, signal.SIGUSR1 )
    a.motorConst = motorConst
    b.motorConst = motorConst
    c.motorConst = -motorConst
    d.motorConst = -motorConst


    # 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
    stoich.path = "/model/compartment/##"
    assert( dsolve.numPools == 4 )
    a.vec[0].concInit = concA * 1
    b.vec[num-1].concInit = concA * 2
    c.vec[0].concInit = concA * 3
    d.vec[num-1].concInit = concA * 4
示例#20
0
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.
        s ----Receptor---> a  // Receptor is activated by the ligand to cause an increase the conc of a. Here ligand-receptor interaction is not accounted for.
    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.5  # 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')
    e4 = moose.MMenz('/model/compartment/e4')
    r1 = moose.Reac('/model/compartment/r1')
    rec = moose.Pool('/model/compartment/rec')

    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

    moose.connect(e4, 'sub', s, 'reac')
    moose.connect(e4, 'prd', a, 'reac')
    moose.connect(rec, 'nOut', e4, 'enzDest')
    e4.Km = 0.001
    e4.kcat = 4

    # Assign parameters
    a.diffConst = diffConst / 10
    b.diffConst = diffConst
    s.diffConst = diffConst
    rec.diffConst = diffConst / 20

    # 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[10].concInit *= 1.2
    a.vec[35].concInit *= 1.2
    a.vec[60].concInit *= 1.2
    a.vec[85].concInit *= 1.2
    print moose.showfields(a)
    b.vec.concInit = [0.1] * num
    s.vec.concInit = [1] * num
    rec.vec.concInit = [0] * num
示例#21
0
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
    diffLength = 1e-7  # m
    len = num * diffLength  # m
    diffConst = 1e-12  # 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
    rec1 = moose.Pool('/model/compartment/rec1')
    rec2 = moose.Pool('/model/compartment/rec2')
    rec2m = moose.Pool('/model/compartment/rec2m')
    rec21 = moose.Pool('/model/compartment/rec21')
    m = moose.Pool('/model/compartment/m')
    r1 = moose.Reac('/model/compartment/r1')
    r2 = moose.Reac('/model/compartment/r2')
    r3 = moose.Reac('/model/compartment/r3')
    r4 = moose.Reac('/model/compartment/r4')

    moose.connect(r1, 'sub', rec2, 'reac')
    moose.connect(r1, 'sub', m, 'reac')
    moose.connect(r1, 'prd', rec2m, 'reac')
    r1.Kf = 0.1
    r1.Kb = 1e-6

    moose.connect(r2, 'sub', rec2m, 'reac')
    moose.connect(r2, 'sub', rec1, 'reac')
    moose.connect(r2, 'prd', m, 'reac')
    r2.Kf = 0.01
    r2.Kb = 0.

    moose.connect(r3, 'sub', rec2m, 'reac')
    moose.connect(r3, 'sub', rec1, 'reac')
    moose.connect(r3, 'prd', rec21, 'reac')
    r3.Kf = 0.01
    r3.Kb = 0.

    moose.connect(r4, 'sub', rec2, 'reac')
    moose.connect(r4, 'sub', rec1, 'reac')
    moose.connect(r4, 'prd', rec21, 'reac')
    r4.Kf = 0.
    r4.Kb = 0.002

    #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
    m.diffConst = diffConst
    rec1.diffConst = 0
    rec2.diffConst = 0
    rec21.diffConst = 0
    rec2m.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 == 5)
    #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
    m.vec[0].concInit = 100
    #a.vec[30].concInit *= 1.2
    #a.vec[50].concInit *= 1.2
    #b.vec[99].concInit *= 0.5
    #for i in range(0, num-1,50):
    #c.vec[i].concInit = 0.1
    #c.vec[i].concInit = 0.5
    #d.vec[i].concInit = 0.5
    # print i
    rec1.vec.concInit = 1
    rec2.vec.concInit = 1
    rec21.vec.concInit = [0] * num
    rec2m.vec.concInit = [0] * num
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
示例#23
0
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)