示例#1
0
def test( ):
    compt = moose.CubeMesh( '/compt' )
    r = moose.Reac( '/compt/r' )
    a = moose.Pool( '/compt/a' )
    a.concInit = 1
    b = moose.Pool( '/compt/b' )
    b.concInit = 2
    c = moose.Pool( '/compt/c' )
    c.concInit = 0.5
    moose.connect( r, 'sub', a, 'reac' )
    moose.connect( r, 'prd', b, 'reac' )
    moose.connect( r, 'prd', c, 'reac' )
    r.Kf = 0.1
    r.Kb = 0.01

    tabA = moose.Table2( '/compt/a/tab' )
    tabB = moose.Table2( '/compt/tabB' )
    tabC = moose.Table2( '/compt/tabB/tabC' )
    print(tabA, tabB, tabC)

    moose.connect( tabA, 'requestOut', a, 'getConc' )
    moose.connect( tabB, 'requestOut', b, 'getConc' )
    moose.connect( tabC, 'requestOut', c, 'getConc' )

    # Now create a streamer and use it to write to a stream
    st = moose.Streamer( '/compt/streamer' )
    st.outfile = os.path.join( os.getcwd(), 'temp.npy' )
    print(("outfile set to: %s " % st.outfile ))
    assert st.outfile  == os.path.join( os.getcwd(), 'temp.npy' ), st.outfile

    st.addTable( tabA )
    st.addTables( [ tabB, tabC ] )

    assert st.numTables == 3

    moose.reinit( )
    print( '[INFO] Running for 57 seconds' )
    moose.start( 57 )
    outfile = st.outfile
    moose.quit() # Otherwise Streamer won't flush the rest of entries.

    # Now read the table and verify that we have written
    print( '[INFO] Reading file %s' % outfile )
    if 'csv' in outfile:
        data = np.loadtxt(outfile, skiprows=1 )
    else:
        data = np.load( outfile )
    # Total rows should be 58 (counting zero as well).
    # print(data)
    # print( data.dtype )
    time = data['time'] 
    print( time ) 
    assert data.shape >= (58,), data.shape
    print( '[INFO] Test 2 passed' )
    return 0
示例#2
0
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')
示例#3
0
def makeModel():
    # create container for model
    model = moose.Neutral('model')
    compartment = moose.CubeMesh('/model/compartment')
    compartment.volume = 1e-21  # m^3
    # the mesh is created automatically by the compartment
    mesh = moose.element('/model/compartment/mesh')

    # create molecules and reactions
    a = moose.Pool('/model/compartment/a')
    b = moose.Pool('/model/compartment/b')
    c = moose.Pool('/model/compartment/c')
    enz1 = moose.Enz('/model/compartment/b/enz1')
    enz2 = moose.Enz('/model/compartment/c/enz2')
    cplx1 = moose.Pool('/model/compartment/b/enz1/cplx')
    cplx2 = moose.Pool('/model/compartment/c/enz2/cplx')
    reac = moose.Reac('/model/compartment/reac')

    # connect them up for reactions
    moose.connect(enz1, 'sub', a, 'reac')
    moose.connect(enz1, 'prd', b, 'reac')
    moose.connect(enz1, 'enz', b, 'reac')
    moose.connect(enz1, 'cplx', cplx1, 'reac')

    moose.connect(enz2, 'sub', b, 'reac')
    moose.connect(enz2, 'prd', a, 'reac')
    moose.connect(enz2, 'enz', c, 'reac')
    moose.connect(enz2, 'cplx', cplx2, 'reac')

    moose.connect(reac, 'sub', a, 'reac')
    moose.connect(reac, 'prd', b, 'reac')

    # 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.0001
    reac.Kb = 0.001

    # Create the output tables
    graphs = moose.Neutral('/model/graphs')
    outputA = moose.Table2('/model/graphs/concA')
    outputB = moose.Table2('/model/graphs/concB')
    outputC = moose.Table2('/model/graphs/concC')

    # connect up the tables
    moose.connect(outputA, 'requestOut', a, 'getConc')
    moose.connect(outputB, 'requestOut', b, 'getConc')
    moose.connect(outputC, 'requestOut', c, 'getConc')
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) + ') )'

    # 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
示例#5
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')
    endo.isMembraneBound = True
    endo.surround = compartment
    es = moose.Pool('/model/endo/s')
    #####################################################################
    moose.connect(rXfer, 'sub', s, 'reac')
    moose.connect(rXfer, 'sub', s, 'reac')
    moose.connect(rXfer, 'prd', es, 'reac')
    moose.connect(rXfer, 'prd', es, 'reac')
    rXfer.Kf = 0.01  # 0.01/sec
    rXfer.Kb = 0.01  # 0.01/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 == 2)
    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 == 1)
    edsolve.buildMeshJunctions(dsolve)
示例#6
0
def buildLargeSystem(useStreamer=False):
    # create a huge system.
    if moose.exists('/comptB'):
        moose.delete('/comptB')
    moose.CubeMesh('/comptB')

    tables = []
    for i in range(300):
        r = moose.Reac('/comptB/r%d' % i)
        a = moose.Pool('/comptB/a%d' % i)
        a.concInit = 10.0
        b = moose.Pool('/comptB/b%d' % i)
        b.concInit = 2.0
        c = moose.Pool('/comptB/c%d' % i)
        c.concInit = 0.5
        moose.connect(r, 'sub', a, 'reac')
        moose.connect(r, 'prd', b, 'reac')
        moose.connect(r, 'prd', c, 'reac')
        r.Kf = 0.1
        r.Kb = 0.01

        # Make table name large enough such that the header is larger than 2^16
        # . Numpy version 1 can't handle such a large header. If format 1 is
        # then this test will fail.
        t = moose.Table2('/comptB/TableO1%d' % i + 'abc' * 100)
        moose.connect(t, 'requestOut', a, 'getConc')
        tables.append(t)

    if useStreamer:
        s = moose.Streamer('/comptB/streamer')
        s.datafile = 'data2.npy'
        print("[INFO ] Total tables %d" % len(tables))

        # Add tables using wilcardFind.
        s.addTables(moose.wildcardFind('/comptB/##[TYPE=Table2]'))

        print("Streamer has %d table" % s.numTables)
        assert s.numTables == len(tables), (s.numTables, len(tables))

    moose.reinit()
    moose.start(10)

    if useStreamer:
        # load the data
        data = np.load(s.datafile)
        header = str(data.dtype.names)
        assert len(header) > 2**16
    else:
        data = {x.columnName: x.vector for x in tables}
    return data
示例#7
0
def makeChemModel(compt):

    # create molecules and reactions
    a = moose.Pool(compt.path + '/a')
    b = moose.Pool(compt.path + '/b')

    a.concInit = 0
    b.concInit = 0

    # Assign parameters
    a.diffConst = diffConst
    a.motorConst = motorConst
    b.diffConst = diffConst
    b.motorConst = -motorConst
示例#8
0
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 makeChemProto(name='hydra'):
    maxs = 0.05
    chem = moose.Neutral('/library/' + name)
    compt = moose.CubeMesh('/library/' + name + '/' + name)
    A = moose.Pool(compt.path + '/A')
    B = moose.Pool(compt.path + '/B')
    S = moose.Pool(compt.path + '/S')
    space = moose.Pool(compt.path + '/space')
    #C=moose.Pool(compt.path+'/C')
    #A.diffConst=params['diffA']
    #B.diffConst=params['diffB']
    Adot = moose.Function(A.path + '/Adot')
    Bdot = moose.Function(B.path + '/Bdot')
    Sdot = moose.Function(S.path + '/Sdot')
    spacedot = moose.Function(space.path + '/spacedot')
    #Cdot = moose.Function( C.path + '/Cdot' )
    #Adot.expr="0.001*((x0^2/x1)+1)-1*x0+0.5*x0"
    #Bdot.expr="0*x0+0.001*x0^2-1*x1+1*x1"
    #Adot.expr="-x0+x1(0.067+(1*x0^2)/(1+x0^2))"
    #Bdot.expr="x0-x1(0.067+(1*x0^2)/(1+x0^2))"
    Adot.expr = "-x0+x1*(0.067+(1*x0^2)/(1+x0^2))+(t<20)*(0.05/2)*(1+cos(" + str(
        np.pi) + "*x3))*x1*x2+(t>20)*(t<25)*(0.05/4)*(cos(" + str(
            np.pi) + "*(t-20)/5))*(1+cos(" + str(np.pi) + "*x3))*x1*x2"
    Bdot.expr = "x0-x1*(0.067+(1*x0^2)/(1+x0^2))-(t<20)*(0.05/2)*(1+cos(" + str(
        np.pi) + "*x3))*x1*x2-(t>20)*(t<25)*(0.05/4)*(cos(" + str(
            np.pi) + "*(t-20)/5))*(1+cos(" + str(np.pi) + "*x3))*x1*x2"
    Sdot.expr = "0"
    spacedot.expr = "0"
    #Cdot.expr="0*x0+0.11*x1-0.11*x2+0.1*x0^2-0.1*(x1+x2)"

    print "$$$$> ", Adot, Bdot
    print Adot.expr, Bdot.expr
    print moose.showmsg(Adot)
    Adot.x.num = 4  #2
    Bdot.x.num = 4  #2
    moose.connect(A, 'nOut', Adot.x[0], 'input')
    moose.connect(B, 'nOut', Adot.x[1], 'input')
    moose.connect(S, 'nOut', Adot.x[2], 'input')
    moose.connect(space, 'nOut', Adot.x[3], 'input')
    moose.connect(Adot, 'valueOut', A, 'increment')

    moose.connect(A, 'nOut', Bdot.x[0], 'input')
    moose.connect(B, 'nOut', Bdot.x[1], 'input')
    moose.connect(S, 'nOut', Bdot.x[2], 'input')
    moose.connect(space, 'nOut', Bdot.x[3], 'input')
    moose.connect(Bdot, 'valueOut', B, 'increment')

    return compt
示例#10
0
def createPool(compt, name, concInit):
    meshEntries = moose.element(compt.path + '/mesh')
    pool = moose.Pool(compt.path + '/' + name)
    moose.connect(pool, 'mesh', meshEntries, 'mesh', 'Single')
    pool.concInit = concInit
    pool.diffConst = 1e-11
    return pool
示例#11
0
def test_vec3():
    print("test vec3")
    foo = moose.Pool('/foo3', 500)
    foo.vec.concInit = 0.123
    print(foo.vec)
    assert foo.concInit == 0.123, foo.concInit
    assert np.allclose(foo.vec.concInit, [0.123]*500)
def createChemModel(neuroCompt):
    dendCa = createPool(neuroCompt, 'Ca', 1e-4)
    dendKinaseInact = createPool(neuroCompt, 'inact_kinase', 1e-4)
    dendKinase = createPool(neuroCompt, 'Ca.kinase', 0.0)
    dendTurnOnKinase = moose.Reac(neuroCompt.path + '/turnOnKinase')
    moose.connect(dendTurnOnKinase, 'sub', dendCa, 'reac')
    moose.connect(dendTurnOnKinase, 'sub', dendKinaseInact, 'reac')
    moose.connect(dendTurnOnKinase, 'prd', dendKinase, 'reac')
    dendTurnOnKinase.Kf = 50000
    dendTurnOnKinase.Kb = 1
    dendKinaseEnz = moose.Enz(dendKinase.path + '/enz')
    dendKinaseEnzCplx = moose.Pool(dendKinase.path + '/enz/cplx')
    kChan = createPool(neuroCompt, 'kChan', 1e-3)
    kChan_p = createPool(neuroCompt, 'kChan_p', 0.0)
    moose.connect(dendKinaseEnz, 'enz', dendKinase, 'reac', 'OneToOne')
    moose.connect(dendKinaseEnz, 'sub', kChan, 'reac', 'OneToOne')
    moose.connect(dendKinaseEnz, 'prd', kChan_p, 'reac', 'OneToOne')
    moose.connect(dendKinaseEnz, 'cplx', dendKinaseEnzCplx, 'reac', 'OneToOne')
    dendKinaseEnz.Km = 1e-4
    dendKinaseEnz.kcat = 20
    dendPhosphatase = moose.Reac(neuroCompt.path + '/phosphatase')
    moose.connect(dendPhosphatase, 'sub', kChan_p, 'reac')
    moose.connect(dendPhosphatase, 'prd', kChan, 'reac')
    dendPhosphatase.Kf = 1
    dendPhosphatase.Kb = 0.0
示例#13
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()
示例#14
0
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
示例#15
0
def dephosphorylate(frmPool, toPool, michealson_mentis=False):
    global molecules_
    global curr_subsec_
    dephospho_.append(frmPool.name)
    if michealson_mentis:
        e = moose.MMenz('%s/%s.dephospho' % (frmPool.path, frmPool.name))
        moose.connect(e, 'sub', frmPool, 'reac')
        moose.connect(e, 'prd', toPool, 'reac')
        moose.connect(molecules_['PP1'], 'nOut', e, 'enzDest')
        e.Km = _p.K_M
        e.kcat = 10
    else:
        # if not Michealson-Mentis scheme and use this.
        inter = moose.Pool('%s/pp1_%s_cplx' % (frmPool.path, frmPool.name))
        inter.name = curr_subsec_ + '.' + inter.name
        inter.nInit = 0
        r = add_reaction('%s/%s.add_pp1' % (frmPool.path, frmPool.name))
        moose.connect(r, 'sub', frmPool, 'reac')
        moose.connect(r, 'sub', molecules_[curr_subsec_ + '.' + 'PP1'], 'reac')
        moose.connect(r, 'prd', inter, 'reac')
        r.Kf = (_p.k_2) / _p.K_M
        r.Kb = 0.0

        rr = add_reaction('%s/%s.dephospho' % (frmPool.path, frmPool.name))
        moose.connect(rr, 'sub', inter, 'reac')
        moose.connect(rr, 'prd', molecules_[curr_subsec_ + '.' + 'PP1_'],
                      'reac')
        moose.connect(rr, 'prd', toPool, 'reac')
        rr.numKf = 10.0
        rr.numKb = 0.0

    _logger.debug("Reaction (dephospho): %s -> %s, enzymatic=%s" %
                  (frmPool.name, toPool.name, michealson_mentis))
示例#16
0
def test_vec():
    foo = moose.Pool('/foo1', 500)
    #  bar = moose.vec('/foo1')
    bar = moose.vec(foo)
    assert len(bar) == 500, len(bar)
    for i in range(len(bar)):
        print(bar[i])
示例#17
0
def test_ksolve():
    compt = moose.CubeMesh( '/compt' )
    compt.volume = 1e-20

    pools = []
    for r in range( 10 ):
        a1 = moose.Pool( '/compt/a1%s' % r )
        a1.concInit = 10
        a2 = moose.Pool( '/compt/a2%s' % r )
        a2.concInit = 5
        b1 = moose.Pool( '/compt/b1%s' % r )
        b1.concInit = 0.054
        b2 = moose.Pool( '/compt/b2%s' % r )
        b2.concInit = 3.9
        r = moose.Reac( '/compt/reac%s'% r )
        moose.connect( r, 'sub', a1, 'reac' )
        moose.connect( r, 'sub', a2, 'reac' )
        moose.connect( r, 'prd', b1, 'reac' )
        moose.connect( r, 'prd', b2, 'reac' )
        r.Kf = 2.9
        r.Kb = 4.5
        pools += [ a1, a2, b1, b2 ]

    ksolve = moose.Ksolve( '/compt/ksolve' )
    stoich = moose.Stoich( '/compt/stoich' )
    stoich.compartment = compt
    stoich.ksolve = ksolve
    ksolve.numThreads = 2
    stoich.path = '/compt/##'
    moose.reinit()
    print( '[INFO] Using method = %s' % ksolve.method )
    t1 = time.time()
    moose.start( 100 )
    print('[INFO] Time taken %s' % (time.time() - t1 ))
    expected = [ 7.77859 , 2.77858 , 2.27541 , 6.12141 , 7.77858 , 2.77858
            , 2.27541 , 6.12141 , 7.77858 , 2.77858 , 2.27541 , 6.12141 , 7.77858
            , 2.77858 , 2.27541 , 6.12141 , 7.77858 , 2.77858 , 2.27541 , 6.12141
            , 7.77858 , 2.77858 , 2.27541 , 6.12141 , 7.77858 , 2.77858 , 2.27541
            , 6.12141 , 7.77858 , 2.77858 , 2.27541 , 6.12141 , 7.77858 , 2.77858
            , 2.27541 , 6.12141 , 7.77858 , 2.77858 , 2.27541 , 6.12141
            ]
    concs = [ p.conc for p in pools ]
    if(not np.isclose( concs, expected ).all() ):
        print( " Expected %s" % expected )
        print( " Got %s" % concs )
        quit(1)
    print( 'Test passed' )
def test():
    compt = moose.CubeMesh('/compt')
    r = moose.Reac('/compt/r')
    a = moose.Pool('/compt/a')
    a.concInit = 1
    b = moose.Pool('/compt/b')
    b.concInit = 2
    c = moose.Pool('/compt/c')
    c.concInit = 0.5
    moose.connect(r, 'sub', a, 'reac')
    moose.connect(r, 'prd', b, 'reac')
    moose.connect(r, 'prd', c, 'reac')
    r.Kf = 0.1
    r.Kb = 0.01

    tabA = moose.Table2('/compt/a/tabA')
    tabA.format = 'npy'
    tabA.useStreamer = 1  # Setting format alone is not good enough

    tabB = moose.Table2('/compt/b/tabB')
    tabB.outfile = 'table2.npy'

    tabC = moose.Table2('/compt/c/tabC')
    tabC.outfile = 'tablec.csv'

    moose.connect(tabA, 'requestOut', a, 'getConc')
    moose.connect(tabB, 'requestOut', b, 'getConc')
    moose.connect(tabC, 'requestOut', c, 'getConc')

    moose.reinit()
    [print_table(x) for x in [tabA, tabB, tabC]]
    runtime = 1000
    print('Starting moose for %d secs' % runtime)
    moose.start(runtime, 1)
    print(' MOOSE is done')

    # Now read the numpy and csv and check the results.
    a = np.load('_tables/compt/a/tabA.npy')
    b = np.load('table2.npy')
    c = np.loadtxt('tablec.csv', skiprows=1)
    print(a)
    print(b)
    print(c)
    print(a['time'])
    print(b['time'])
    assert len(a['time']) == len(a['/compt/a/tabA'])
示例#19
0
def makeChemProto(name='hydra'):
    chem = moose.Neutral('/library/' + name)
    compt = moose.CubeMesh('/library/' + name + '/' + name)
    A = moose.Pool(compt.path + '/A')
    #B=moose.Pool(compt.path+'/B')
    C = moose.Pool(compt.path + '/C')
    r1 = moose.Reac(compt.path + '/r1')
    #e1=moose.MMenz(compt.path+'/e1')
    moose.connect(r1, 'sub', A, 'reac')
    moose.connect(r1, 'prd', C, 'reac')
    #moose.connect(C,'nOut',e1,'enzDest')
    r1.Kf = 1
    r1.Kb = 0.1
    A.nInit = 0
    #B.nInit=0
    C.nInit = 0
    return compt
def create_model(compt, sec):
    global pools_
    for s in ['A']:
        x = moose.Pool('%s/%s.%s' % (compt.path, sec, s))
        pools_[x.name] = x
        t = moose.Table2('%s/tab%s.%s' % (compt.path, sec, s))
        moose.connect(t, 'requestOut', x, 'getConc')
        tables_[x.name] = t
示例#21
0
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()
示例#22
0
def makeChemProto(name):
    chem = moose.Neutral('/library/' + name)
    for i in (['dend', 1e-18], ['spine', 1e-19], ['psd', 1e-20]):
        print('making ', i)
        compt = moose.CubeMesh(chem.path + '/' + i[0])
        compt.volume = i[1]
        Ca = moose.Pool(compt.path + '/Ca')
        Ca.concInit = 0.08
        Ca.diffConst = 1e-11
示例#23
0
def makeChemProto(name):
    chem = moose.Neutral('/library/' + name)
    for i in ('dend', 'spine', 'psd'):
        print(('making ', i))
        compt = moose.CubeMesh(chem.path + '/' + i)
        compt.volume = 1e-18
        ca = moose.Pool(compt.path + '/Ca')
        ca.concInit = 0.08e-3
        ca.diffConst = 1e-12
示例#24
0
def test_other():
    a1 = moose.Pool('/ada')
    assert a1.className == 'Pool', a1.className
    finfo = moose.getFieldDict(a1.className)
    s = moose.Streamer('/asdada')
    p = moose.PulseGen('pg1')
    assert p.delay[0] == 0.0
    p.delay[1] = 0.99
    assert p.delay[1] == 0.99, p.delay[1]
def makeChemProto(name='hydra'):
        chem=moose.Neutral('/library/'+name)
        compt=moose.CubeMesh('/library/'+name + '/' + name)
        A=moose.Pool(compt.path+'/A')
        B=moose.Pool(compt.path+'/B')
        C=moose.Pool(compt.path+'/C')
        #A.diffConst=params['diffA']
        #B.diffConst=params['diffB']
        Adot = moose.Function( A.path + '/Adot' )
        Bdot = moose.Function( B.path + '/Bdot' )
        Cdot = moose.Function( C.path + '/Cdot' )
        #Adot.expr="0.001*((x0^2/x1)+1)-1*x0+0.5*x0"
        #Bdot.expr="0*x0+0.001*x0^2-1*x1+1*x1"
        Adot.expr="-0.1*x0+((0.1*x0^2)/(x1+x2))"
        Bdot.expr="0*x0-0.11*x1+0.11*x2+0.1*x0^2-0.1*(x1+x2)"
        Cdot.expr="0*x0+0.11*x1-0.11*x2+0.1*x0^2-0.1*(x1+x2)"
 
        
        print "$$$$> ", Adot, Bdot, Cdot
        print Adot.expr, Bdot.expr, Cdot.expr
        print moose.showmsg(Adot)
        Adot.x.num = 3 #2
        Bdot.x.num = 3 #2
        Cdot.x.num = 3
        #A.nInit=10
        #B.nInit=5
        A.nInit=1
        B.nInit=1
        C.nInit=1
        moose.connect( A, 'nOut', Adot.x[0], 'input' )
        moose.connect( B, 'nOut', Adot.x[1], 'input' )
        moose.connect( C, 'nOut', Adot.x[2], 'input' )
        moose.connect( Adot, 'valueOut', A, 'increment' )

        moose.connect( A, 'nOut', Bdot.x[0], 'input' )
        moose.connect( B, 'nOut', Bdot.x[1], 'input' )
        moose.connect( C, 'nOut', Bdot.x[2], 'input' )
        moose.connect( Bdot, 'valueOut', B, 'increment' )
        
        moose.connect( A, 'nOut', Cdot.x[0], 'input' )
        moose.connect( B, 'nOut', Cdot.x[1], 'input' )
        moose.connect( C, 'nOut', Cdot.x[2], 'input' )
        moose.connect( Cdot, 'valueOut', C, 'increment' )
        return compt
示例#26
0
def test_access():
    a1 = moose.Pool('ac1')
    try:
        a2 = moose.Compartment('ac1')
    except Exception:
        pass
    else:
        raise RuntimeError("Should have failed.")
    a2 = moose.element(a1)
    a3 = moose.element(a1.path)
    assert a2 == a3, (a2, a3)
示例#27
0
def add_pool( root, name ):
    global molecules_
    pname = pool_name( root, name )
    ppath = '%s/%s' % (root.path, name)
    if moose.exists( ppath ):
        _logger.warn( 'Already exists %s' % ppath )
        return moose.element( ppath )
    else:
        p = moose.Pool( ppath )
        p.name = pname
        molecules_[pname] = p
        return p
def makeFuncRate():
    model = moose.Neutral('/library')
    model = moose.Neutral('/library/chem')
    compt = moose.CubeMesh('/library/chem/compt')
    compt.volume = 1e-15
    A = moose.Pool('/library/chem/compt/A')
    B = moose.Pool('/library/chem/compt/B')
    C = moose.Pool('/library/chem/compt/C')
    reac = moose.Reac('/library/chem/compt/reac')
    func = moose.Function('/library/chem/compt/reac/func')
    func.x.num = 1
    func.expr = "(x0/1e8)^2"
    moose.connect(C, 'nOut', func.x[0], 'input')
    moose.connect(func, 'valueOut', reac, 'setNumKf')
    moose.connect(reac, 'sub', A, 'reac')
    moose.connect(reac, 'prd', B, 'reac')

    A.concInit = 1
    B.concInit = 0
    C.concInit = 0
    reac.Kb = 1
示例#29
0
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 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