Esempio n. 1
0
def makeModel():
    # create container for model
    model = moose.Neutral('model')
    compartment = moose.CubeMesh('/model/compartment')
    compartment.volume = 1e-15
    # the mesh is created automatically by the compartment
    mesh = moose.element('/model/compartment/mesh')

    # create molecules and reactions
    # a <----> b
    # b + 10c ---func---> d
    a = moose.Pool('/model/compartment/a')
    b = moose.Pool('/model/compartment/b')
    c = moose.Pool('/model/compartment/c')
    d = moose.BufPool('/model/compartment/d')
    reac = moose.Reac('/model/compartment/reac')
    func = moose.Function('/model/compartment/d/func')
    func.numVars = 2
    #func.x.num = 2

    # connect them up for reactions

    moose.connect(reac, 'sub', a, 'reac')
    moose.connect(reac, 'prd', b, 'reac')
    if useY:
        moose.connect(func, 'requestOut', b, 'getN')
        moose.connect(func, 'requestOut', c, 'getN')
    else:
        moose.connect(b, 'nOut', func.x[0], 'input')
        moose.connect(c, 'nOut', func.x[1], 'input')

    moose.connect(func, 'valueOut', d, 'setN')
    if useY:
        func.expr = "y0 + 10*y1"
    else:
        func.expr = "x0 + 10*x1"

    # connect them up to the compartment for volumes
    #for x in ( a, b, c, cplx1, cplx2 ):
    #			moose.connect( x, 'mesh', mesh, 'mesh' )

    # Assign parameters
    a.concInit = 1
    b.concInit = 0.5
    c.concInit = 0.1
    reac.Kf = 0.001
    reac.Kb = 0.01

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

    # connect up the tables
    moose.connect(outputA, 'requestOut', a, 'getConc')
    moose.connect(outputB, 'requestOut', b, 'getConc')
    moose.connect(outputC, 'requestOut', c, 'getConc')
    moose.connect(outputD, 'requestOut', d, 'getConc')
Esempio n. 2
0
def add_reaction( reacPath ):
    if moose.exists( reacPath ):
        mu.warn( 'Reaction %s already exists' % reacPath )
        return moose.element( reacPath )
    else:
        r =  moose.Reac( reacPath )
        return r
Esempio n. 3
0
def makeChemModel(compt):
    """
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 = 10e-12  # m^2/sec
    motorRate = 1e-6  # m/sec
    concA = 1  # millimolar

    # create molecules and reactions
    a = moose.Pool(compt.path + '/a')
    b = moose.Pool(compt.path + '/b')
    s = moose.Pool(compt.path + '/s')
    e1 = moose.MMenz(compt.path + '/e1')
    e2 = moose.MMenz(compt.path + '/e2')
    e3 = moose.MMenz(compt.path + '/e3')
    r1 = moose.Reac(compt.path + '/r1')

    a.concInit = 0.1
    b.concInit = 0.1
    s.concInit = 1

    moose.connect(e1, 'sub', s, 'reac')
    moose.connect(e1, 'prd', a, 'reac')
    moose.connect(a, 'nOut', e1, 'enzDest')
    e1.Km = 1
    e1.kcat = 1

    moose.connect(e2, 'sub', s, 'reac')
    moose.connect(e2, 'prd', b, 'reac')
    moose.connect(a, 'nOut', e2, 'enzDest')
    e2.Km = 1
    e2.kcat = 0.5

    moose.connect(e3, 'sub', a, 'reac')
    moose.connect(e3, 'prd', s, 'reac')
    moose.connect(b, 'nOut', e3, 'enzDest')
    e3.Km = 0.1
    e3.kcat = 1

    moose.connect(r1, 'sub', b, 'reac')
    moose.connect(r1, 'prd', s, 'reac')
    r1.Kf = 0.3  # 1/sec
    r1.Kb = 0  # 1/sec

    # Assign parameters
    a.diffConst = diffConst / 10
    b.diffConst = diffConst
    s.diffConst = 0
Esempio n. 4
0
def makeChemProto(name):
    chem = moose.Neutral('/library/' + name)
    comptVol = diffLen * dendDia * dendDia * PI / 4.0
    for i in (['dend', comptVol], ['spine', 1e-19], ['psd', 1e-20]):
        print(('making ', i))
        compt = moose.CubeMesh(chem.path + '/' + i[0])
        compt.volume = i[1]
        z = moose.Pool(compt.path + '/z')
        z.concInit = 0.0
        z.diffConst = diffConst
    nInit = comptVol * 6e23 * concInit
    nstr = str(1 / nInit)

    x = moose.Pool(chem.path + '/dend/x')
    x.diffConst = diffConst
    func = moose.Function(x.path + '/func')
    func.expr = "-x0 * (0.3 - " + nstr + " * x0) * ( 1 - " + nstr + " * x0)"
    print((func.expr))
    func.x.num = 1
    moose.connect(x, 'nOut', func.x[0], 'input')
    moose.connect(func, 'valueOut', x, 'increment')
    z = moose.element('/library/' + name + '/dend/z')
    reac = moose.Reac('/library/' + name + '/dend/reac')
    reac.Kf = 1
    reac.Kb = 10
    moose.connect(reac, 'sub', x, 'reac')
    moose.connect(reac, 'prd', z, 'reac')
Esempio n. 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, '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 == 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)

    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')
Esempio n. 6
0
def nand( a, b ):
    compt = moose.CubeMesh( '/compt' )
    compt.volume = 1
    species = {}
    tables = { }
    concInit  =  { 'a' : a, 'b' : b, 'r' : 1, 'x' : 1 }

    for s in [ 'a', 'b', 'r', 'x', 'x*', 'ab', 'xab' ] :
        p = moose.Pool( '%s/%s' % (compt.path, s) )
        t = moose.Table2( '%s/%s_table' % (compt.path, s ) ) 
        moose.connect( t, 'requestOut', p, 'getConc' )
        tables[ s ] = t
        p.concInit = concInit.get( s, 0.0 )
        species[ s ] = p

    # Now the reactions.
    r1 = moose.Reac( '%s/reac1' % compt.path )
    moose.connect( r1, 'sub', species[ 'a' ], 'reac' )
    moose.connect( r1, 'sub', species[ 'b' ], 'reac' )
    moose.connect( r1, 'prd', species[ 'ab' ], 'reac' )
    r1.Kf = 1
    r1.Kb = 0

    r2 = moose.Reac( '%s/reac2' % compt.path )
    moose.connect( r2, 'sub', species[ 'r' ], 'reac' )
    moose.connect( r2, 'sub', species[ 'x' ], 'reac' )
    moose.connect( r2, 'prd', species[ 'x*' ], 'reac' )
    moose.connect( r2, 'prd', species[ 'r' ], 'reac' )
    r2.Kf = 1
    r2.Kb = 0

    r3 = moose.Reac( '%s/reac3' % compt.path )
    moose.connect( r3, 'sub', species[ 'x*' ], 'reac' )
    moose.connect( r3, 'sub', species[ 'ab' ], 'reac' )
    moose.connect( r3, 'prd', species[ 'xab' ], 'reac' )
    r3.Kf = 100
    r3.Kb = 0.01

    stoich = moose.Stoich( '%s/stoich' % compt.path )
    ksolve = moose.Ksolve( '%s/ksolve' % compt.path )
    stoich.ksolve = ksolve
    stoich.compartment = compt
    stoich.path = '%s/#' % compt.path

    moose.reinit( )
    moose.start( 20 )
    return tables['x*'].vector[-1]
def makeModel():
    """ This function creates a bistable reaction system using explicit
    MOOSE calls rather than load from a file.
    The reaction is::

        a ---b---> 2b    # b catalyzes a to form more of b.
        2b ---c---> a    # c catalyzes b to form a.
        a <======> 2b    # a interconverts to b.

    """
    # create container for model
    model = moose.Neutral('model')
    compartment = moose.CubeMesh('/model/compartment')
    compartment.volume = 1e-15
    # the mesh is created automatically by the compartment
    mesh = moose.element('/model/compartment/mesh')

    # create molecules and reactions
    size = 100
    for i in range(size):
        a = moose.Pool('/model/compartment/a%s' % i)
        b = moose.Pool('/model/compartment/b%s' % i)
        c = moose.Pool('/model/compartment/c%s' % i)
        enz1 = moose.Enz('%s/enz1' % a.path)
        enz2 = moose.Enz('%s/enz2' % c.path)
        cplx1 = moose.Pool('%s/cplx' % enz1.path)
        cplx2 = moose.Pool('%s/cplx' % enz2.path)
        reac = moose.Reac('/model/compartment/reac%s' % i)

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

        moose.connect(enz2, 'sub', b, 'reac')
        moose.connect(enz2, 'sub', b, 'reac')  # Note 2 molecules of b.
        moose.connect(enz2, 'prd', a, 'reac')
        moose.connect(enz2, 'enz', c, 'reac')
        moose.connect(enz2, 'cplx', cplx2, 'reac')

        moose.connect(reac, 'sub', a, 'reac')
        moose.connect(reac, 'prd', b, 'reac')
        moose.connect(reac, 'prd', b, 'reac')  # Note 2 order in b.
        add_table(a)
        add_table(b)
        add_table(c)
        # Assign parameters
        a.concInit = 1
        b.concInit = 0
        c.concInit = 0.01
        enz1.kcat = 0.4
        enz1.Km = 4
        enz2.kcat = 0.6
        enz2.Km = 0.01
        reac.Kf = 0.001
        reac.Kb = 0.01
    return compartment
Esempio n. 8
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
Esempio n. 9
0
def test_streamer():
    compt = moose.CubeMesh('/compt')
    assert compt
    r = moose.Reac('/compt/r')
    a = moose.Pool('/compt/a')
    a.concInit = 1
    b = moose.Pool('/compt/b')
    b.concInit = 2
    c = moose.Pool('/compt/c')
    c.concInit = 0.5
    moose.connect(r, 'sub', a, 'reac')
    moose.connect(r, 'prd', b, 'reac')
    moose.connect(r, 'prd', c, 'reac')
    r.Kf = 0.1
    r.Kb = 0.01

    outfile = 'streamer_test.csv'
    if os.path.exists(outfile):
        os.remove(outfile)

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

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

    # Now create a streamer and use it to write to a stream
    st = moose.Streamer('/compt/streamer')
    st.outfile = outfile

    print("outfile set to: %s " % st.outfile)
    st.addTable(tabA)
    st.addTables([tabB, tabC])
    assert st.numTables == 3

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

    print('Moose is done. Waiting for monitor to shut down...')

    # Now read the table and verify that we have written
    print('[INFO] Reading file %s' % outfile)
    if 'csv' in outfile:
        data = np.loadtxt(outfile, skiprows=1)
    else:
        data = np.load(outfile)
    # Total rows should be 58 (counting zero as well).
    #  print(data)
    # print( data.dtype )
    assert data.shape >= (101, ), data.shape
    print('[INFO] Test 2 passed')
    return 0
Esempio n. 10
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()
def enable_diffusion(s1, s2, pool, kfkb):
    global compt_
    global pools_
    p1 = pools_['%s.%s' % (s1, pool)]
    p2 = pools_['%s.%s' % (s2, pool)]
    r = moose.Reac('%s/%s_%s' % (compt_.path, s1, s2))
    moose.connect(r, 'sub', p1, 'reac')
    moose.connect(r, 'prd', p2, 'reac')
    r.Kf = r.Kb = kfkb
Esempio n. 12
0
def makeModel():
                # create container for model
                model = moose.Neutral( 'model' )
                compartment = moose.CubeMesh( '/model/compartment' )
                compartment.volume = 1e-20
                # the mesh is created automatically by the compartment
                mesh = moose.element( '/model/compartment/mesh' )

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

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

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

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

                # connect them up to the compartment for volumes
                #for x in ( a, b, c, cplx1, cplx2 ):
                #                        moose.connect( x, 'mesh', mesh, 'mesh' )

                # Assign parameters
                a.concInit = 1
                b.concInit = 0
                c.concInit = 0.01
                enz1.kcat = 0.4
                enz1.Km = 4
                enz2.kcat = 0.6
                enz2.Km = 0.01
                reac.Kf = 0.001
                reac.Kb = 0.01

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

                # connect up the tables
                moose.connect( outputA, 'requestOut', a, 'getConc' );
                moose.connect( outputB, 'requestOut', b, 'getConc' );

                '''
Esempio n. 13
0
def makeModel():
    """This function creates a bistable reaction system using explicit
    MOOSE calls rather than load from a file.
    The reaction is::

        a ---b---> 2b    # b catalyzes a to form more of b.
        2b ---c---> a    # c catalyzes b to form a.
        a <======> 2b    # a interconverts to b.

    """
    # create container for model
    model = moose.Neutral("model")
    compartment = moose.CubeMesh("/model/compartment")
    compartment.volume = 1e-15
    # the mesh is created automatically by the compartment
    mesh = moose.element("/model/compartment/mesh")

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

    # connect them up for reactions
    moose.connect(enz1, "sub", a, "reac")
    moose.connect(enz1, "prd", b, "reac")
    moose.connect(enz1, "prd", b, "reac")  # Note 2 molecules of b.
    moose.connect(enz1, "enz", b, "reac")
    moose.connect(enz1, "cplx", cplx1, "reac")

    moose.connect(enz2, "sub", b, "reac")
    moose.connect(enz2, "sub", b, "reac")  # Note 2 molecules of b.
    moose.connect(enz2, "prd", a, "reac")
    moose.connect(enz2, "enz", c, "reac")
    moose.connect(enz2, "cplx", cplx2, "reac")

    moose.connect(reac, "sub", a, "reac")
    moose.connect(reac, "prd", b, "reac")
    moose.connect(reac, "prd", b, "reac")  # Note 2 order in b.

    # Assign parameters
    a.concInit = 1
    b.concInit = 0
    c.concInit = 0.01
    enz1.kcat = 0.4
    enz1.Km = 4
    enz2.kcat = 0.6
    enz2.Km = 0.01
    reac.Kf = 0.001
    reac.Kb = 0.01

    return compartment
Esempio n. 14
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
Esempio n. 15
0
def makeCubeMultiscale():
    makeSpinyCompt()
    model = moose.Neutral('/model')
    elec = moose.element('/n')
    elec.name = 'elec'
    moose.move(elec, model)
    synInput = moose.element('/model/elec/compt/synInput')
    synInput.refractT = 47e-3
    makeChemInCubeMesh()
    # set up a reaction to fake diffusion between compts.
    headCa = moose.element('/model/chem/spineMesh/Ca')
    dendCa = moose.element('/model/chem/neuroMesh/Ca')
    diffReac = moose.Reac('/model/chem/spineMesh/diff')
    moose.connect(diffReac, 'sub', headCa, 'reac')
    moose.connect(diffReac, 'prd', dendCa, 'reac')
    diffReac.Kf = 1
    diffReac.Kb = headCa.volume / dendCa.volume

    # set up adaptors
    headCa = moose.element('/model/chem/spineMesh/Ca')
    dendCa = moose.element('/model/chem/neuroMesh/Ca')
    adaptCa = moose.Adaptor('/model/chem/adaptCa')
    elecCa = moose.element('/model/elec/head2/ca')
    # There are 5 spine heads in the electrical model. Average their input.
    for i in range(5):
        path = '/model/elec/head' + str(i) + '/ca'
        elecCa = moose.element(path)
        moose.connect(elecCa, 'concOut', adaptCa, 'input', 'Single')
    moose.connect(adaptCa, 'output', headCa, 'setConc')
    adaptCa.outputOffset = 0.0001  # 100 nM offset in chem.
    adaptCa.scale = 0.05  # 0.06 to 0.003 mM

    adaptGluR = moose.Adaptor('/model/chem/psdMesh/adaptGluR')
    chemR = moose.element('/model/chem/psdMesh/psdGluR')
    # Here we connect up the chem adaptors to only 3 of the spine
    # heads in the elec model, just to make it interesting.
    elec1R = moose.element('/model/elec/head1/gluR')
    elec2R = moose.element('/model/elec/head2/gluR')
    elec3R = moose.element('/model/elec/head3/gluR')
    moose.connect(adaptGluR, 'requestOut', chemR, 'getN', 'OneToAll')
    moose.connect(adaptGluR, 'output', elec1R, 'setGbar', 'OneToAll')
    moose.connect(adaptGluR, 'output', elec2R, 'setGbar', 'OneToAll')
    moose.connect(adaptGluR, 'output', elec3R, 'setGbar', 'OneToAll')
    adaptGluR.outputOffset = 1e-9  # pS
    adaptGluR.scale = 1e-8 / 100  # from n to pS

    adaptK = moose.Adaptor('/model/chem/neuroMesh/adaptK')
    chemK = moose.element('/model/chem/neuroMesh/kChan')
    elecK = moose.element('/model/elec/compt/K')
    moose.connect(adaptK, 'requestOut', chemK, 'getConc', 'OneToAll')
    moose.connect(adaptK, 'output', elecK, 'setGbar', 'OneToAll')
    adaptK.scale = 0.3  # from mM to Siemens
Esempio n. 16
0
def add_x_diffusion_approximation(root, kf=1e-6, kb=1e-6):
    """Convert x to y. 
    This function approximate the effect of loosing subunit 'x' via diffusion.
    In one implementation we converted x to xs; now we change x to y immediately
    so that we do not loose the mass-conversation.
    """
    global curr_subsec_
    global molecules_
    r = moose.Reac('%s/%s.xtoy' % (root.path, curr_subsec_))
    moose.connect(r, 'sub', molecules_['%s.x' % curr_subsec_], 'reac')
    moose.connect(r, 'prd', molecules_['%s.xs' % curr_subsec_], 'reac')
    r.numKf = kf
    r.numKb = kb
Esempio n. 17
0
def remove_extra( pool, limit ):
    null = moose.BufPool( '%s/null' % pool.path )
    null.nInit = 0.0
    nullReac = moose.Reac( '%s/null_reac' % pool.path )
    nullReac.numKb = 0.0
    moose.connect( nullReac, 'sub', pool, 'reac' )
    moose.connect( nullReac, 'prd', null, 'reac' )
    nullF = moose.Function( '%s/func_null' % pool.path )
    nullF.expr = '(x0 > %f)?1e-2:0' % limit
    _logger.debug( 'Removing extra from pool %s' % pool.path )
    _logger.debug( '\tExpression on nullR %s' % nullF.expr )
    moose.connect( pool, 'nOut', nullF.x[0], 'input' )
    moose.connect( nullF, 'valueOut', nullReac, 'setNumKf' )
Esempio n. 18
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
Esempio n. 19
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'])
Esempio n. 21
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
Esempio n. 22
0
def setup_diffusion_of_pool( voxel1, voxel2, species, diff_const = 1e-12 ):
    """Setup diffusion between voxels """
    global molecules_
    global compt_
    pool1 = molecules_[ '%s.%s' % (voxel1.name, species ) ]
    pool2 = molecules_[ '%s.%s' % (voxel2.name, species ) ]
    r = moose.Reac( '%s/diff_%s' % (voxel1.path, species ) )
    moose.connect( r, 'sub', pool1, 'reac' )
    moose.connect( r, 'prd', pool2, 'reac' )
    _logger.info( 
            'Diffusion reaction between %s <-> %s' % (pool1.name, pool2.name)
            )
    # The rate constant is given by D / l / l. For diffusion coefficients of 1
    # uM^2/sec in a 
    d = diff_const / (( compt_.x1 - compt_.x0 ) ** 2)
    _logger.debug( 'Diffusion coefficient (%s) %f -> rate %f' % (species, diff_const, d) )
    r.numKf = d 
    r.numKb = d
Esempio n. 23
0
def analogStimTable():
    simtime = 150
    simdt = 0.1
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    # This is the stimulus generator
    stimtable = moose.StimulusTable('/model/stim')
    a = moose.BufPool('/model/a')
    b = moose.Pool('/model/b')
    reac = moose.Reac('/model/reac')
    reac.Kf = 0.1
    reac.Kb = 0.1
    moose.connect(stimtable, 'output', a, 'setConcInit')
    moose.connect(reac, 'sub', a, 'reac')
    moose.connect(reac, 'prd', b, 'reac')
    aPlot = moose.Table('/data/aPlot')
    moose.connect(aPlot, 'requestOut', a, 'getConc')
    bPlot = moose.Table('/data/bPlot')
    moose.connect(bPlot, 'requestOut', b, 'getConc')
    moose.setClock(stimtable.tick, simdt)
    moose.setClock(a.tick, simdt)
    moose.setClock(aPlot.tick, simdt)

    ####################################################
    # Here we set up the stimulus table. It is half a sine-wave.
    stim = [np.sin(0.01 * float(i)) for i in range(314)]
    stimtable.vector = stim
    stimtable.stepSize = 0  # This forces use of current time as x value

    # The table will interpolate its contents over the time start to stop:
    # At values less than startTime, it emits the first value in table
    stimtable.startTime = 5
    # At values more than stopTime, it emits the last value in table
    stimtable.stopTime = 60
    stimtable.doLoop = 1  # Enable repeat playbacks.
    stimtable.loopTime = 10 + simtime / 2.0  # Repeat playback over this time

    moose.reinit()
    moose.start(simtime)
    t = [x * simdt for x in range(len(aPlot.vector))]
    pylab.plot(t, aPlot.vector, label='Stimulus waveform')
    pylab.plot(t, bPlot.vector, label='Reaction product b')
    pylab.legend()
    pylab.show()
def 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
Esempio n. 25
0
def setup_diffusion_of_pool( voxel1, voxel2, species, diff_const = 1e-12 ):
    """Setup diffusion between voxels """
    global molecules_
    global compt_, args
    if diff_const <= 0:
        _logger.warn( 'D=0. Ignoring diffusion between %s and %s' % (voxel1,voxel2) )
        return
    pool1 = molecules_[ '%s.%s' % (voxel1.name, species ) ]
    pool2 = molecules_[ '%s.%s' % (voxel2.name, species ) ]
    r = moose.Reac( '%s/diff_%s2%s_%s' % (voxel1.path, voxel1.name, voxel2.name, species ) )
    moose.connect( r, 'sub', pool1, 'reac' )
    moose.connect( r, 'prd', pool2, 'reac' )
    _logger.info( 
            'Diffusion reaction between %s <-> %s' % (pool1.name, pool2.name)
            )
    # The rate constant is given by D / l / l. The mean nearest neighbour
    # distance is rougly 40nM. see http://www.jneurosci.org/content/23/35/11270
    d = diff_const / (40e-9**2)
    _logger.info( 'Diffusion coefficient (%s) %f -> rate %f' % (species, diff_const, d) )
    r.numKf = d 
    r.numKb = d
Esempio n. 26
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
Esempio n. 28
0
def simple_model_a():
    compt = moose.CubeMesh( '/compt' )
    r = moose.Reac( '/compt/r' )
    a = moose.Pool( '/compt/a' )
    a.concInit = 1
    b = moose.Pool( '/compt/b' )
    b.concInit = 2
    c = moose.Pool( '/compt/c' )
    c.concInit = 0.5
    moose.connect( r, 'sub', a, 'reac' )
    moose.connect( r, 'prd', b, 'reac' )
    moose.connect( r, 'prd', c, 'reac' )
    r.Kf = 0.1
    r.Kb = 0.01

    tabA = moose.Table2( '/compt/a/tab' )
    tabB = moose.Table2( '/compt/tabB' )
    tabC = moose.Table2( '/compt/tabB/tabC' )
    print(tabA, tabB, tabC)
    moose.connect( tabA, 'requestOut', a, 'getConc' )
    moose.connect( tabB, 'requestOut', b, 'getConc' )
    moose.connect( tabC, 'requestOut', c, 'getConc' )
    return [tabA, tabB, tabC]
Esempio n. 29
0
def buildSystem(outfile):
    if moose.exists('/compt'):
        moose.delete('/compt')
    compt = moose.CubeMesh('/compt')
    assert compt
    r = moose.Reac('/compt/r')
    a = moose.Pool('/compt/a')
    a.concInit = 1
    b = moose.Pool('/compt/b')
    b.concInit = 2
    c = moose.Pool('/compt/c')
    c.concInit = 0.5
    moose.connect(r, 'sub', a, 'reac')
    moose.connect(r, 'prd', b, 'reac')
    moose.connect(r, 'prd', c, 'reac')
    r.Kf = 0.1
    r.Kb = 0.01

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

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

    # Now create a streamer and use it to write to a stream
    st = moose.Streamer('/compt/streamer')
    st.outfile = outfile

    print("outfile set to: %s " % st.outfile)
    st.addTable(tabA)
    st.addTables([tabB, tabC])
    assert st.numTables == 3
    return st
Esempio n. 30
0
def makeModel():
    # create container for model
    model = moose.Neutral('model')
    compartment = moose.CubeMesh('/model/compartment')
    compartment.volume = 1e-20
    # the mesh is created automatically by the compartment
    mesh = moose.element('/model/compartment/mesh')

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

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

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

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

    # connect them up to the compartment for volumes
    #for x in ( a, b, c, cplx1, cplx2 ):
    #			moose.connect( x, 'mesh', mesh, 'mesh' )

    # Assign parameters
    a.concInit = 1
    b.concInit = 0
    c.concInit = 0.01
    enz1.kcat = 0.4
    enz1.Km = 4
    enz2.kcat = 0.6
    enz2.Km = 0.01
    reac.Kf = 0.001
    reac.Kb = 0.01

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

    # connect up the tables
    moose.connect(outputA, 'requestOut', a, 'getConc')
    moose.connect(outputB, 'requestOut', b, 'getConc')

    # Schedule the whole lot
    moose.setClock(4, 0.01)  # for the computational objects
    moose.setClock(8, 1.0)  # for the plots
    # The wildcard uses # for single level, and ## for recursive.
    moose.useClock(4, '/model/compartment/##', 'process')
    moose.useClock(8, '/model/graphs/#', 'process')