Beispiel #1
0
def main(standalone=False):
    mfile = os.path.join(os.path.dirname(__file__), 'OSC_diff_vols.g')
    runtime = 4000.0
    modelId = moose.loadModel(mfile, 'model', 'ee')
    kin = moose.element('/model/kinetics')
    compt1 = moose.element('/model/compartment_1')
    compt1.x1 += kin.x1
    compt1.x0 += kin.x1
    fixXreacs.fixXreacs('/model')
    #fixXreacs.restoreXreacs( '/model' )
    #fixXreacs.fixXreacs( '/model' )

    ks1 = moose.Ksolve('/model/kinetics/ksolve')
    ds1 = moose.Dsolve('/model/kinetics/dsolve')
    s1 = moose.Stoich('/model/kinetics/stoich')
    s1.compartment = moose.element('/model/kinetics')
    s1.ksolve = ks1
    s1.dsolve = ds1
    s1.path = '/model/kinetics/##'

    ks2 = moose.Ksolve('/model/compartment_1/ksolve')
    ds2 = moose.Dsolve('/model/compartment_1/dsolve')
    s2 = moose.Stoich('/model/compartment_1/stoich')
    s2.compartment = moose.element('/model/compartment_1')
    s2.ksolve = ks2
    s2.dsolve = ds2
    s2.path = '/model/compartment_1/##'

    ds2.buildMeshJunctions(ds1)

    moose.reinit()
    moose.start(runtime)
    # I don't have an analytic way to assess oscillations
    assert (countCrossings('/model/graphs/conc2/M.Co', 0.001) == 4)
    moose.delete('/model')
Beispiel #2
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' )
Beispiel #3
0
    def _configureSolvers(self):
        if not hasattr(self, 'chemid'):
            return
        if not hasattr(self, 'dendCompt'):
            raise BuildError("configureSolvers: no chem meshes defined.")
        dmksolve = moose.Ksolve(self.dendCompt.path + '/ksolve')
        dmdsolve = moose.Dsolve(self.dendCompt.path + '/dsolve')
        dmstoich = moose.Stoich(self.dendCompt.path + '/stoich')
        dmstoich.compartment = self.dendCompt
        dmstoich.ksolve = dmksolve
        dmstoich.dsolve = dmdsolve
        dmstoich.path = self.dendCompt.path + "/##"
        # Below we have code that only applies if there are spines
        # Put in spine solvers. Note that these get info from the dendCompt
        if hasattr(self, 'spineCompt'):
            if self.useGssa:
                smksolve = moose.Gsolve(self.spineCompt.path + '/ksolve')
            else:
                smksolve = moose.Ksolve(self.spineCompt.path + '/ksolve')
            smdsolve = moose.Dsolve(self.spineCompt.path + '/dsolve')
            smstoich = moose.Stoich(self.spineCompt.path + '/stoich')
            smstoich.compartment = self.spineCompt
            smstoich.ksolve = smksolve
            smstoich.dsolve = smdsolve
            smstoich.path = self.spineCompt.path + "/##"
            # Put in PSD solvers. Note that these get info from the dendCompt
            if self.useGssa:
                pmksolve = moose.Gsolve(self.psdCompt.path + '/ksolve')
            else:
                pmksolve = moose.Ksolve(self.psdCompt.path + '/ksolve')
            pmdsolve = moose.Dsolve(self.psdCompt.path + '/dsolve')
            pmstoich = moose.Stoich(self.psdCompt.path + '/stoich')
            pmstoich.compartment = self.psdCompt
            pmstoich.ksolve = pmksolve
            pmstoich.dsolve = pmdsolve
            pmstoich.path = self.psdCompt.path + "/##"

            # Put in cross-compartment diffusion between ksolvers
            dmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve)
            # Put in cross-compartment reactions between ksolvers
            smstoich.buildXreacs(pmstoich)
            #pmstoich.buildXreacs( smstoich )
            smstoich.buildXreacs(dmstoich)
            dmstoich.filterXreacs()
            smstoich.filterXreacs()
            pmstoich.filterXreacs()

            # set up the connections so that the spine volume scaling can happen
            self.elecid.setSpineAndPsdMesh(self.spineCompt, self.psdCompt)
            self.elecid.setSpineAndPsdDsolve(smdsolve, pmdsolve)
Beispiel #4
0
def test_xreac2():
    mfile = os.path.join(os.path.dirname(__file__), 'OSC_diff_vols.g')
    runtime = 4000.0
    modelId = moose.loadModel(mfile, 'model', 'ee')
    kin = moose.element('/model/kinetics')
    compt1 = moose.element('/model/compartment_1')
    compt1.x1 += kin.x1
    compt1.x0 += kin.x1

    # for r in moose.wildcardFind('/##[TYPE=Reac]'):
    #     print("---", r)
    #     print(r.neighbors['sub'])
    #     print(r.neighbors['prd'])

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

    print('After fixing...')
    for r in moose.wildcardFind('/##[TYPE=Reac]'):
        print("---", r)
        print(r.neighbors['sub'])
        print(r.neighbors['prd'])

    ks1 = moose.Ksolve('/model/kinetics/ksolve')
    ds1 = moose.Dsolve('/model/kinetics/dsolve')
    s1 = moose.Stoich('/model/kinetics/stoich')
    s1.compartment = moose.element('/model/kinetics')
    s1.ksolve = ks1
    s1.dsolve = ds1
    s1.path = '/model/kinetics/##'

    ks2 = moose.Ksolve('/model/compartment_1/ksolve')
    ds2 = moose.Dsolve('/model/compartment_1/dsolve')
    s2 = moose.Stoich('/model/compartment_1/stoich')
    s2.compartment = moose.element('/model/compartment_1')
    s2.ksolve = ks2
    s2.dsolve = ds2
    s2.path = '/model/compartment_1/##'

    print(ds1)
    ds2.buildMeshJunctions(ds1)

    moose.reinit()
    moose.start(runtime)
    # I don't have an analytic way to assess oscillations
    nCrossings = countCrossings('/model/graphs/conc2/M.Co', 0.001)
    assert (nCrossings == 4), "Expected 4, got %d" % nCrossings
    moose.delete('/model')
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()
Beispiel #6
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
Beispiel #7
0
    def _configureSolvers(self):
        dmksolve = moose.Ksolve(self.dendCompt.path + '/ksolve')
        dmdsolve = moose.Dsolve(self.dendCompt.path + '/dsolve')
        dmstoich = moose.Stoich(self.dendCompt.path + '/stoich')
        dmstoich.compartment = self.dendCompt
        dmstoich.ksolve = dmksolve
        dmstoich.dsolve = dmdsolve
        dmstoich.path = self.dendCompt.path + "/##"
        print 'Dend solver: numPools = ', dmdsolve.numPools, \
            ', nvox= ', self.dendCompt.mesh.num, dmksolve.numAllVoxels
        # Put in spine solvers. Note that these get info from the dendCompt
        if self.useGssa:
            smksolve = moose.Gsolve(self.spineCompt.path + '/ksolve')
        else:
            smksolve = moose.Ksolve(self.spineCompt.path + '/ksolve')
        smdsolve = moose.Dsolve(self.spineCompt.path + '/dsolve')
        smstoich = moose.Stoich(self.spineCompt.path + '/stoich')
        smstoich.compartment = self.spineCompt
        smstoich.ksolve = smksolve
        smstoich.dsolve = smdsolve
        smstoich.path = self.spineCompt.path + "/##"
        print 'spine num Pools = ', smstoich.numAllPools, \
                ', nvox= ',  self.spineCompt.mesh.num, smksolve.numAllVoxels
        # Put in PSD solvers. Note that these get info from the dendCompt
        if self.useGssa:
            pmksolve = moose.Gsolve(self.psdCompt.path + '/ksolve')
        else:
            pmksolve = moose.Ksolve(self.psdCompt.path + '/ksolve')
        pmdsolve = moose.Dsolve(self.psdCompt.path + '/dsolve')
        pmstoich = moose.Stoich(self.psdCompt.path + '/stoich')
        pmstoich.compartment = self.psdCompt
        pmstoich.ksolve = pmksolve
        pmstoich.dsolve = pmdsolve
        pmstoich.path = self.psdCompt.path + "/##"
        print 'psd num Pools = ', pmstoich.numAllPools, \
                ', voxels=', self.psdCompt.mesh.num, pmksolve.numAllVoxels

        # Put in cross-compartment diffusion between ksolvers
        dmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve)
        # Put in cross-compartment reactions between ksolvers
        smstoich.buildXreacs(pmstoich)
        smstoich.buildXreacs(dmstoich)
        #smstoich.buildXreacs( pmstoich )
        dmstoich.filterXreacs()
        smstoich.filterXreacs()
        pmstoich.filterXreacs()
Beispiel #8
0
def main(standalone=False):
    mfile = os.path.join(os.path.dirname(__file__), 'OSC_diff_vols.g')
    runtime = 4000.0
    modelId = moose.loadModel(mfile, 'model', 'ee')
    kin = moose.element('/model/kinetics')
    compt1 = moose.element('/model/compartment_1')
    compt1.x1 += kin.x1
    compt1.x0 += kin.x1
    fixXreacs.fixXreacs('/model')
    #fixXreacs.restoreXreacs( '/model' )
    #fixXreacs.fixXreacs( '/model' )

    ks1 = moose.Ksolve('/model/kinetics/ksolve')
    ds1 = moose.Dsolve('/model/kinetics/dsolve')
    s1 = moose.Stoich('/model/kinetics/stoich')
    s1.compartment = moose.element('/model/kinetics')
    s1.ksolve = ks1
    s1.dsolve = ds1
    s1.path = '/model/kinetics/##'

    ks2 = moose.Ksolve('/model/compartment_1/ksolve')
    ds2 = moose.Dsolve('/model/compartment_1/dsolve')
    s2 = moose.Stoich('/model/compartment_1/stoich')
    s2.compartment = moose.element('/model/compartment_1')
    s2.ksolve = ks2
    s2.dsolve = ds2
    s2.path = '/model/compartment_1/##'

    ds2.buildMeshJunctions(ds1)

    moose.reinit()
    moose.start(runtime)
    # I don't have an analytic way to assess oscillations
    assert (countCrossings('/model/graphs/conc2/M.Co', 0.001) == 4)

    if standalone:
        # Display all plots.
        for x in moose.wildcardFind('/model/#graphs/conc#/#'):
            t = np.arange(0, x.vector.size, 1) * x.dt
            plt.plot(t, x.vector, label=x.name)
        plt.legend()
        plt.show()
    moose.delete('/model')
Beispiel #9
0
def setCompartmentSolver(modelRoot, solver):
    comptlist = dict(
        (c, c.volume)
        for c in moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]'))
    comptVol = {}
    compts = []
    vol = [v for k, v in comptlist.items()]
    volumeSort = sorted(vol)
    for k, v in comptlist.items():
        comptVol[k] = v
    for volSor in volumeSort:
        for a, b in comptVol.items():
            if b == volSor:
                compts.append(a)

    #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))]
    if (len(compts) == '0'):
        print("Atleast one compartment is required ")
        return
    else:
        if (len(compts) > 3):
            print("Warning: setSolverOnCompt Cannot handle ", len(compts),
                  " chemical compartments\n")
            return

        elif (len(compts) > 1):
            positionCompt(compts)
            if solver != 'ee' or solver != "Exponential Euler":
                fixXreacs(modelRoot)

        for compt in compts:
            if solver != 'ee':
                if (solver == 'gsl') or (solver == 'Runge Kutta'):
                    ksolve = moose.Ksolve(compt.path + '/ksolve')
                if (solver == 'gssa') or (solver == 'Gillespie'):
                    ksolve = moose.Gsolve(compt.path + '/gsolve')

                dsolve = moose.Dsolve(compt.path + '/dsolve')
                stoich = moose.Stoich(compt.path + '/stoich')
                stoich.compartment = compt
                stoich.ksolve = ksolve
                stoich.dsolve = dsolve
                stoich.path = compt.path + "/##"
        ksolveList = moose.wildcardFind(modelRoot + '/##[ISA=Ksolve]')
        dsolveList = moose.wildcardFind(modelRoot + '/##[ISA=Dsolve]')
        stoichList = moose.wildcardFind(modelRoot + '/##[ISA=Stoich]')

        i = 0
        while (i < len(dsolveList) - 1):
            dsolveList[i + 1].buildMeshJunctions(dsolveList[i])
            i += 1

        print("Solver is added to model path %s" % modelRoot)
    '''
Beispiel #10
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.
Beispiel #11
0
def makeModel():
    model = moose.Neutral('/model')
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel('./branching.p', '/model/cell', 'Neutral')
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind('/model/cell/##'):
        i.tick = -1

    # create container for model
    model = moose.element('/model')
    chem = moose.Neutral('/model/chem')
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh('/model/chem/compt0')
    compt0.separateSpines = 0
    compt0.geometryPolicy = 'cylinder'

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel(compt0)  # Populate all compt with the chem system.

    compt0.diffLength = 1e-6  # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.subTreePath = "/model/cell/#"
    #compt0.cell = cell

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve')
    dsolve0 = moose.Dsolve('/model/chem/compt0/dsolve')
    stoich0 = moose.Stoich('/model/chem/compt0/stoich')

    # Configure solvers
    stoich0.compartment = compt0
    stoich0.ksolve = ksolve0
    stoich0.dsolve = dsolve0
    stoich0.path = '/model/chem/compt0/#'
    assert (stoich0.numVarPools == 2)
    assert (stoich0.numProxyPools == 0)
    assert (stoich0.numRates == 0)

    moose.element('/model/chem/compt0/a[0]').concInit = aConcInit
    twigs = findTwigs(compt0)
    print(('twigs = ', twigs))
    for i in twigs:
        e = moose.element('/model/chem/compt0/b[' + str(i) + ']')
        e.concInit = bConcInit

    # Create the output tables
    graphs = moose.Neutral('/model/graphs')
    makeTab('a_soma', '/model/chem/compt0/a[0]')
    makeTab('b_soma', '/model/chem/compt0/b[0]')
    num = twigs[0]
    makeTab('a_apical', '/model/chem/compt0/a[' + str(num) + ']')
    makeTab('b_apical', '/model/chem/compt0/b[' + str(num) + ']')
Beispiel #12
0
def setCompartmentSolver(modelRoot, solver):
    """
     If Solver type is 'gsl' or 'gssa' do add Solver
     if 'ee' nothing

    """
    if solver != 'ee':
        comptlist = dict(
            (c.volume, c)
            for c in moose.wildcardFind(modelRoot + '/##[ISA=ChemCompt]'))
        vollist = sorted(comptlist.keys())
        compts = [comptlist[key] for key in vollist]

        #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))]

        if (len(compts) > 1):
            positionCompt(compts)
            fixXreacs(modelRoot)

        vollist = sorted(comptlist.keys())
        compts = [comptlist[key] for key in vollist]
        #compts = [key for key, value in sorted(comptlist.items(), key=lambda (k,v): (v,k))]

        for compt in compts:
            if solver != 'ee':
                if solver.lower() in ['gsl', 'runge kutta', 'lsoda']:
                    ksolve = moose.Ksolve(compt.path + '/ksolve')
                elif solver.lower() in ['gssa', 'gillespie']:
                    ksolve = moose.Gsolve(compt.path + '/gsolve')

                if (len(compts) > 1):
                    dsolve = moose.Dsolve(compt.path + '/dsolve')

                stoich = moose.Stoich(compt.path + '/stoich')
                stoich.ksolve = ksolve
                if (len(compts) > 1):
                    stoich.dsolve = dsolve

                stoich.compartment = compt
                stoich.path = compt.path + "/##"

        dsolveList = moose.wildcardFind(modelRoot + '/##[ISA=Dsolve]')
        i = 0
        while (i < len(dsolveList) - 1):
            dsolveList[i + 1].buildMeshJunctions(dsolveList[i])
            i += 1
    if not modelRoot[:1].startswith('/'):
        modelRoot = '/' + modelRoot
    print(" Solver is added to model path `%s` with `%s` solver" %
          (modelRoot, solver))
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.path = '/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 ')
Beispiel #14
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
Beispiel #15
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
Beispiel #16
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
def makeModel():
    radius = 1e-6
    len0 = 4e-6
    len1 = 2e-6
    len2 = 1e-6
    # create container for model
    model = moose.Neutral('model')
    a0, b0, compt0 = makeCyl('0', 1, radius, -len0, 0)
    a1, b1, compt1 = makeCyl('1', 2, radius, 0, len1)
    a2, b2, compt2 = makeCyl('2', 6, radius, len1, len1 + len2)

    print('Volumes = ', compt0.volume, compt1.volume, compt2.volume)

    # create molecules and reactions
    reac0 = moose.Reac('/model/compt1/reac0')
    reac1 = moose.Reac('/model/compt1/reac1')

    # connect them up for reactions
    moose.connect(reac0, 'sub', b0, 'reac')
    moose.connect(reac0, 'prd', b1, 'reac')
    moose.connect(reac1, 'sub', b1, 'reac')
    moose.connect(reac1, 'prd', b2, 'reac')

    # Assign parameters
    reac0.Kf = 0.5
    reac0.Kb = 0.05
    reac1.Kf = 0.5
    reac1.Kb = 0.05

    # Create the output tables
    graphs = moose.Neutral('/model/graphs')
    outputA0 = moose.Table2('/model/graphs/concA0')
    outputA1 = moose.Table2('/model/graphs/concA1')
    outputA2 = moose.Table2('/model/graphs/concA2')

    # connect up the tables
    moose.connect(outputA0, 'requestOut', a0, 'getConc')
    moose.connect(outputA1, 'requestOut', a1, 'getConc')
    moose.connect(outputA2, 'requestOut', a2, 'getConc')

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve('/model/compt0/ksolve0')
    ksolve1 = moose.Ksolve('/model/compt1/ksolve1')
    ksolve2 = moose.Ksolve('/model/compt2/ksolve2')
    dsolve0 = moose.Dsolve('/model/compt0/dsolve0')
    dsolve1 = moose.Dsolve('/model/compt1/dsolve1')
    dsolve2 = moose.Dsolve('/model/compt2/dsolve2')
    stoich0 = moose.Stoich('/model/compt0/stoich0')
    stoich1 = moose.Stoich('/model/compt1/stoich1')
    stoich2 = moose.Stoich('/model/compt2/stoich2')

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    stoich0.dsolve = dsolve0
    stoich1.dsolve = dsolve1
    stoich2.dsolve = dsolve2
    stoich0.path = '/model/compt0/#'
    stoich1.path = '/model/compt1/#'
    stoich2.path = '/model/compt2/#'
    dsolve1.buildMeshJunctions(dsolve0)
    dsolve1.buildMeshJunctions(dsolve2)
    stoich1.buildXreacs(stoich0)
    stoich1.buildXreacs(stoich2)
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()
Beispiel #18
0
def makeChemModel( cellId ):
        # create container for model
        r0 = 1e-6    # m
        r1 = 1e-6    # m
        num = 2800
        diffLength = 1e-6 # m
        diffConst = 5e-12 # m^2/sec
        motorRate = 1e-6 # m/sec
        concA = 1 # millimolar

        model = moose.element( '/model' )
        compartment = moose.NeuroMesh( '/model/compartment' )
        # FIXME: No attribute cell
        compartment.cell =  cellId
        compartment.diffLength = diffLength
        print(("cell NeuroMesh parameters: numSeg and numDiffCompt: ", compartment.numSegments, compartment.numDiffCompts))
        
        print(("compartment.numDiffCompts == num: ", compartment.numDiffCompts, num))
        assert( compartment.numDiffCompts == num )

        # create molecules and reactions
        a = moose.Pool( '/model/compartment/a' )
        b = moose.Pool( '/model/compartment/b' )
        s = moose.Pool( '/model/compartment/s' )
        e1 = moose.MMenz( '/model/compartment/e1' )
        e2 = moose.MMenz( '/model/compartment/e2' )
        e3 = moose.MMenz( '/model/compartment/e3' )
        r1 = moose.Reac( '/model/compartment/r1' )
        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
                #b.motorConst = motorRate

        # Make solvers
        ksolve = moose.Ksolve( '/model/compartment/ksolve' )
        dsolve = moose.Dsolve( '/model/compartment/dsolve' )
        stoich = moose.Stoich( '/model/compartment/stoich' )
        stoich.compartment = compartment
        #ksolve.numAllVoxels = compartment.numDiffCompts
        stoich.ksolve = ksolve
        stoich.dsolve = dsolve
        stoich.path = "/model/compartment/##"
        assert( dsolve.numPools == 3 )
        a.vec.concInit = [0.1]*num
        a.vec[0].concInit += 0.5
        a.vec[400].concInit += 0.5
        a.vec[800].concInit += 0.5
        a.vec[1200].concInit += 0.5
        a.vec[1600].concInit += 0.5
        a.vec[2000].concInit += 0.5
        a.vec[2400].concInit += 0.5
        #a.vec[num/2].concInit -= 0.1
        b.vec.concInit = [0.1]*num
        s.vec.concInit = [1]*num
Beispiel #19
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' )
Beispiel #20
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')
Beispiel #21
0
def makeNeuroMeshModel():
    diffLength = 20e-6  # Aim for just 3 compts.
    elec = loadElec()
    loadChem(diffLength)
    neuroCompt = moose.element('/model/chem/dend')
    neuroCompt.diffLength = diffLength
    neuroCompt.cellPortion(elec, '/model/elec/#')
    for x in moose.wildcardFind('/model/chem/##[ISA=PoolBase]'):
        if (x.diffConst > 0):
            x.diffConst = 1e-11
    for x in moose.wildcardFind('/model/chem/##/Ca'):
        x.diffConst = 1e-10

    # Put in dend solvers
    ns = neuroCompt.numSegments
    ndc = neuroCompt.numDiffCompts
    print 'ns = ', ns, ', ndc = ', ndc
    assert (neuroCompt.numDiffCompts == neuroCompt.mesh.num)
    assert (ns == 1)  # dend, 5x (shaft+head)
    assert (ndc == 1)
    nmksolve = moose.Ksolve('/model/chem/dend/ksolve')
    nmdsolve = moose.Dsolve('/model/chem/dend/dsolve')
    nmstoich = moose.Stoich('/model/chem/dend/stoich')
    nmstoich.compartment = neuroCompt
    nmstoich.ksolve = nmksolve
    nmstoich.dsolve = nmdsolve
    nmstoich.path = "/model/chem/dend/##"
    print 'done setting path, numPools = ', nmdsolve.numPools
    assert (nmdsolve.numPools == 1)
    assert (nmdsolve.numAllVoxels == 1)
    assert (nmstoich.numAllPools == 1)
    # oddly, numLocalFields does not work.
    ca = moose.element('/model/chem/dend/DEND/Ca')
    assert (ca.numData == ndc)

    # Put in spine solvers. Note that these get info from the neuroCompt
    spineCompt = moose.element('/model/chem/spine')
    sdc = spineCompt.mesh.num
    print 'sdc = ', sdc
    assert (sdc == 1)
    smksolve = moose.Ksolve('/model/chem/spine/ksolve')
    smdsolve = moose.Dsolve('/model/chem/spine/dsolve')
    smstoich = moose.Stoich('/model/chem/spine/stoich')
    smstoich.compartment = spineCompt
    smstoich.ksolve = smksolve
    smstoich.dsolve = smdsolve
    smstoich.path = "/model/chem/spine/##"
    assert (smstoich.numAllPools == 3)
    assert (smdsolve.numPools == 3)
    assert (smdsolve.numAllVoxels == 1)

    # Put in PSD solvers. Note that these get info from the neuroCompt
    psdCompt = moose.element('/model/chem/psd')
    pdc = psdCompt.mesh.num
    assert (pdc == 1)
    pmksolve = moose.Ksolve('/model/chem/psd/ksolve')
    pmdsolve = moose.Dsolve('/model/chem/psd/dsolve')
    pmstoich = moose.Stoich('/model/chem/psd/stoich')
    pmstoich.compartment = psdCompt
    pmstoich.ksolve = pmksolve
    pmstoich.dsolve = pmdsolve
    pmstoich.path = "/model/chem/psd/##"
    assert (pmstoich.numAllPools == 3)
    assert (pmdsolve.numPools == 3)
    assert (pmdsolve.numAllVoxels == 1)
    foo = moose.element('/model/chem/psd/Ca')
    print 'PSD: numfoo = ', foo.numData
    print 'PSD: numAllVoxels = ', pmksolve.numAllVoxels
    """
	CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' )
	print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume
	CaNspine = moose.vec( '/model/chem/spine/SPINE/CaN_BULK/CaN' )
	print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume
	"""

    # set up adaptors
    aCa = moose.Adaptor('/model/chem/psd/adaptCa', pdc)

    adaptCa = moose.vec('/model/chem/psd/adaptCa')
    chemCa = moose.vec('/model/chem/psd/Ca')
    print 'aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len(
        chemCa), ", numData = ", chemCa.numData
    assert (len(adaptCa) == pdc)
    assert (len(chemCa) == pdc)
    path = '/model/elec/spine_head'
    elecCa = moose.element(path)
    moose.connect(elecCa, 'VmOut', adaptCa[0], 'input', 'Single')
    #moose.connect( adaptCa, 'outputSrc', chemCa, 'setConc', 'OneToOne' )
    adaptCa.inputOffset = 0.0  #
    adaptCa.outputOffset = 0.00008  # 80 nM offset in chem.
    adaptCa.scale = 1e-5  # 520 to 0.0052 mM
Beispiel #22
0
def makeNeuroMeshModel():
    diffLength = 10e-6  # But we only want diffusion over part of the model.
    numSyn = 13
    elec = loadElec()
    synInput = moose.SpikeGen('/model/elec/synInput')
    synInput.threshold = -1.0
    synInput.edgeTriggered = 0
    synInput.Vm(0)
    synInput.refractT = 47e-3

    for i in range(numSyn):
        name = '/model/elec/spine_head_14_' + str(i + 1)
        r = moose.element(name + '/glu')
        r.synapse.num = 1
        syn = moose.element(r.path + '/synapse')
        moose.connect(synInput, 'spikeOut', syn, 'addSpike', 'Single')
        syn.weight = 0.2 * i * (numSyn - 1 - i)
        syn.delay = i * 1.0e-3

    loadChem(diffLength)
    neuroCompt = moose.element('/model/chem/dend')
    neuroCompt.diffLength = diffLength
    neuroCompt.cellPortion(elec, '/model/elec/#')
    for x in moose.wildcardFind('/model/chem/##[ISA=PoolBase]'):
        if (x.diffConst > 0):
            x.diffConst = 1e-11
    for x in moose.wildcardFind('/model/chem/##/Ca'):
        x.diffConst = 1e-10

    # Put in dend solvers
    ns = neuroCompt.numSegments
    ndc = neuroCompt.numDiffCompts
    print('ns = ', ns, ', ndc = ', ndc)
    assert (neuroCompt.numDiffCompts == neuroCompt.mesh.num)
    assert (ns == 36)  # dend, 5x (shaft+head)
    assert (ndc == 278)
    nmksolve = moose.Ksolve('/model/chem/dend/ksolve')
    nmdsolve = moose.Dsolve('/model/chem/dend/dsolve')
    nmstoich = moose.Stoich('/model/chem/dend/stoich')
    nmstoich.compartment = neuroCompt
    nmstoich.ksolve = nmksolve
    nmstoich.dsolve = nmdsolve
    nmstoich.path = "/model/chem/dend/##"
    print('done setting path, numPools = ', nmdsolve.numPools)
    assert (nmdsolve.numPools == 1)
    # oddly, numLocalFields does not work.
    ca = moose.element('/model/chem/dend/DEND/Ca')
    assert (ca.numData == ndc)

    # Put in spine solvers. Note that these get info from the neuroCompt
    spineCompt = moose.element('/model/chem/spine')
    sdc = spineCompt.mesh.num
    print('sdc = ', sdc)
    assert (sdc == 13)
    smksolve = moose.Ksolve('/model/chem/spine/ksolve')
    smdsolve = moose.Dsolve('/model/chem/spine/dsolve')
    smstoich = moose.Stoich('/model/chem/spine/stoich')
    smstoich.compartment = spineCompt
    smstoich.ksolve = smksolve
    smstoich.dsolve = smdsolve
    smstoich.path = "/model/chem/spine/##"
    assert (smstoich.numAllPools == 36)

    # Put in PSD solvers. Note that these get info from the neuroCompt
    psdCompt = moose.element('/model/chem/psd')
    pdc = psdCompt.mesh.num
    assert (pdc == 13)
    pmksolve = moose.Ksolve('/model/chem/psd/ksolve')
    pmdsolve = moose.Dsolve('/model/chem/psd/dsolve')
    pmstoich = moose.Stoich('/model/chem/psd/stoich')
    pmstoich.compartment = psdCompt
    pmstoich.ksolve = pmksolve
    pmstoich.dsolve = pmdsolve
    pmstoich.path = "/model/chem/psd/##"
    print('numAllPools = ', pmstoich.numAllPools)
    assert (pmstoich.numAllPools == 56)
    foo = moose.element('/model/chem/psd/Ca')
    bar = moose.element('/model/chem/psd/I1_p')
    print('PSD: numfoo = ', foo.numData, 'numbar = ', bar.numData)
    print('PSD: numAllVoxels = ', pmksolve.numAllVoxels)

    # Put in junctions between diffusion solvers
    nmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve)
    """
	CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' )
	print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume
	CaNspine = moose.vec( '/model/chem/spine/SPINE/CaN_BULK/CaN' )
	print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume
	"""

    # set up adaptors
    aCa = moose.Adaptor('/model/chem/psd/adaptCa', pdc)
    adaptCa = moose.vec('/model/chem/psd/adaptCa')
    chemCa = moose.vec('/model/chem/psd/Ca')
    print('aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len(chemCa),
          ", numData = ", chemCa.numData)
    assert (len(adaptCa) == pdc)
    assert (len(chemCa) == pdc)
    for i in range(pdc):
        path = '/model/elec/spine_head_14_' + str(i + 1) + '/NMDA_Ca_conc'
        elecCa = moose.element(path)
        moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single')
        moose.connect(adaptCa, 'output', chemCa, 'setConc', 'OneToOne')
        adaptCa[i].inputOffset = 0.0  #
        adaptCa[i].outputOffset = 0.00008  # 80 nM offset in chem.
        adaptCa[i].scale = 1e-5  # 520 to 0.0052 mM
    #print adaptCa.outputOffset
    #print adaptCa.scale
    """
        """
    """
Beispiel #23
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')
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
Beispiel #25
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
Beispiel #26
0
def makeNeuroMeshModel():
    diffLength = 10e-6  # Aim for 2 soma compartments.
    elec = loadElec()
    loadChem(diffLength)
    neuroCompt = moose.element('/model/chem/dend')
    neuroCompt.diffLength = diffLength
    neuroCompt.cellPortion(elec, '/model/elec/#')
    for x in moose.wildcardFind('/model/chem/##[ISA=PoolBase]'):
        if (x.diffConst > 0):
            x.diffConst = 1e-11
    for x in moose.wildcardFind('/model/chem/##/Ca'):
        x.diffConst = 1e-10

    # Put in dend solvers
    ns = neuroCompt.numSegments
    ndc = neuroCompt.numDiffCompts
    print 'ns = ', ns, ', ndc = ', ndc
    assert (neuroCompt.numDiffCompts == neuroCompt.mesh.num)
    assert (ns == 36)  #
    assert (ndc == 278)  #
    nmksolve = moose.Ksolve('/model/chem/dend/ksolve')
    nmdsolve = moose.Dsolve('/model/chem/dend/dsolve')
    nmstoich = moose.Stoich('/model/chem/dend/stoich')
    nmstoich.compartment = neuroCompt
    nmstoich.ksolve = nmksolve
    nmstoich.dsolve = nmdsolve
    nmstoich.path = "/model/chem/dend/##"
    print 'done setting path, numPools = ', nmdsolve.numPools
    assert (nmdsolve.numPools == 1)
    assert (nmdsolve.numAllVoxels == ndc)
    assert (nmstoich.numAllPools == 1)
    # oddly, numLocalFields does not work.
    ca = moose.element('/model/chem/dend/DEND/Ca')
    assert (ca.numData == ndc)

    # Put in spine solvers. Note that these get info from the neuroCompt
    spineCompt = moose.element('/model/chem/spine')
    sdc = spineCompt.mesh.num
    print 'sdc = ', sdc
    assert (sdc == 13)
    smksolve = moose.Ksolve('/model/chem/spine/ksolve')
    smdsolve = moose.Dsolve('/model/chem/spine/dsolve')
    smstoich = moose.Stoich('/model/chem/spine/stoich')
    smstoich.compartment = spineCompt
    smstoich.ksolve = smksolve
    smstoich.dsolve = smdsolve
    smstoich.path = "/model/chem/spine/##"
    print 'spine num Pools = ', smstoich.numAllPools, smdsolve.numPools
    assert (smstoich.numAllPools == 35)
    assert (smdsolve.numPools == 30)
    assert (smdsolve.numAllVoxels == sdc)

    # Put in PSD solvers. Note that these get info from the neuroCompt
    psdCompt = moose.element('/model/chem/psd')
    pdc = psdCompt.mesh.num
    assert (pdc == 13)
    pmksolve = moose.Ksolve('/model/chem/psd/ksolve')
    pmdsolve = moose.Dsolve('/model/chem/psd/dsolve')
    pmstoich = moose.Stoich('/model/chem/psd/stoich')
    pmstoich.compartment = psdCompt
    pmstoich.ksolve = pmksolve
    pmstoich.dsolve = pmdsolve
    pmstoich.path = "/model/chem/psd/##"
    print 'psd num Pools = ', pmstoich.numAllPools, pmdsolve.numPools
    assert (pmstoich.numAllPools == 55)
    assert (pmdsolve.numPools == 48)
    assert (pmdsolve.numAllVoxels == pdc)
    foo = moose.element('/model/chem/psd/Ca')
    print 'PSD: numfoo = ', foo.numData
    print 'PSD: numAllVoxels = ', pmksolve.numAllVoxels

    # Put in junctions between the diffusion solvers
    nmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve)
    """
	CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' )
	print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume
	CaNspine = moose.vec( '/model/chem/spine/SPINE/CaN_BULK/CaN' )
	print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume
	"""

    ##################################################################
    # set up adaptors
    aCa = moose.Adaptor('/model/chem/spine/adaptCa', sdc)
    adaptCa = moose.vec('/model/chem/spine/adaptCa')
    chemCa = moose.vec('/model/chem/spine/Ca')
    #print 'aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len( chemCa ), ", numData = ", chemCa.numData, "len( adaptCa ) = ", len( adaptCa )
    assert (len(adaptCa) == sdc)
    assert (len(chemCa) == sdc)
    for i in range(sdc):
        elecCa = moose.element('/model/elec/spine_head_14_' + str(i + 1) +
                               '/NMDA_Ca_conc')
        #print elecCa
        moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single')
    moose.connect(adaptCa, 'output', chemCa, 'setConc', 'OneToOne')
    adaptCa.inputOffset = 0.0  #
    adaptCa.outputOffset = 0.00008  # 80 nM offset in chem.
    adaptCa.scale = 5e-3  # 520 to 0.0052 mM
    #print adaptCa.outputOffset

    moose.le('/model/chem/dend/DEND')

    compts = neuroCompt.elecComptList
    begin = neuroCompt.startVoxelInCompt
    end = neuroCompt.endVoxelInCompt
    aCa = moose.Adaptor('/model/chem/dend/DEND/adaptCa', len(compts))
    adaptCa = moose.vec('/model/chem/dend/DEND/adaptCa')
    chemCa = moose.vec('/model/chem/dend/DEND/Ca')
    #print 'aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len( chemCa ), ", numData = ", chemCa.numData, "len( adaptCa ) = ", len( adaptCa )
    assert (len(chemCa) == ndc)
    for i in zip(compts, adaptCa, begin, end):
        name = i[0].path + '/Ca_conc'
        if (moose.exists(name)):
            elecCa = moose.element(name)
            #print i[2], i[3], '   ', elecCa
            #print i[1]
            moose.connect(elecCa, 'concOut', i[1], 'input', 'Single')
            for j in range(i[2], i[3]):
                moose.connect(i[1], 'output', chemCa[j], 'setConc', 'Single')
    adaptCa.inputOffset = 0.0  #
    adaptCa.outputOffset = 0.00008  # 80 nM offset in chem.
    adaptCa.scale = 20e-6  # 10 arb units to 2 uM.
Beispiel #27
0
def makeModel():
    model = moose.Neutral('/model')
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel('./spinyNeuron.p', '/model/cell', 'Neutral')
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind('/model/cell/##'):
        i.tick = -1

    # create container for model
    model = moose.element('/model')
    chem = moose.Neutral('/model/chem')
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh('/model/chem/compt0')
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh('/model/chem/compt1')
    moose.connect(compt0, 'spineListOut', compt1, 'spineList', 'OneToOne')
    compt2 = moose.PsdMesh('/model/chem/compt2')
    moose.connect(compt0, 'psdListOut', compt2, 'psdList', 'OneToOne')

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel(compt0, True)  # Populate all 3 compts with the chem system.
    makeChemModel(compt1, False)
    makeChemModel(compt2, True)

    compt0.diffLength = 2e-6  # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.cell = cell
    moose.showfields(compt0)

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve')
    if useGssa:
        ksolve1 = moose.Gsolve('/model/chem/compt1/ksolve')
        ksolve2 = moose.Gsolve('/model/chem/compt2/ksolve')
    else:
        ksolve1 = moose.Ksolve('/model/chem/compt1/ksolve')
        ksolve2 = moose.Ksolve('/model/chem/compt2/ksolve')
    dsolve0 = moose.Dsolve('/model/chem/compt0/dsolve')
    dsolve1 = moose.Dsolve('/model/chem/compt1/dsolve')
    dsolve2 = moose.Dsolve('/model/chem/compt2/dsolve')
    stoich0 = moose.Stoich('/model/chem/compt0/stoich')
    stoich1 = moose.Stoich('/model/chem/compt1/stoich')
    stoich2 = moose.Stoich('/model/chem/compt2/stoich')

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    stoich0.dsolve = dsolve0
    stoich1.dsolve = dsolve1
    stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert (stoich0.numVarPools == 1)
    assert (stoich0.numProxyPools == 0)
    assert (stoich0.numRates == 1)
    assert (stoich1.numVarPools == 1)
    assert (stoich1.numProxyPools == 0)
    if useGssa:
        assert (stoich1.numRates == 2)
        assert (stoich2.numRates == 2)
    else:
        assert (stoich1.numRates == 1)
        assert (stoich2.numRates == 1)
    assert (stoich2.numVarPools == 1)
    assert (stoich2.numProxyPools == 0)
    dsolve0.buildNeuroMeshJunctions(dsolve1, dsolve2)
    stoich0.buildXreacs(stoich1)
    stoich1.buildXreacs(stoich2)
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()

    Ca_input_dend = moose.vec('/model/chem/compt0/Ca_input')
    print len(Ca_input_dend)
    for i in range(60):
        Ca_input_dend[3 + i * 3].conc = 2.0

    Ca_input_PSD = moose.vec('/model/chem/compt2/Ca_input')
    print len(Ca_input_PSD)
    for i in range(5):
        Ca_input_PSD[2 + i * 2].conc = 1.0

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral('/model/graphs')
    makeTab('Ca_soma', '/model/chem/compt0/Ca[0]')
    makeTab('Ca_d1', '/model/chem/compt0/Ca[1]')
    makeTab('Ca_d2', '/model/chem/compt0/Ca[2]')
    makeTab('Ca_d3', '/model/chem/compt0/Ca[3]')
    makeTab('Ca_s3', '/model/chem/compt1/Ca[3]')
    makeTab('Ca_s4', '/model/chem/compt1/Ca[4]')
    makeTab('Ca_s5', '/model/chem/compt1/Ca[5]')
    makeTab('Ca_p3', '/model/chem/compt2/Ca[3]')
    makeTab('Ca_p4', '/model/chem/compt2/Ca[4]')
    makeTab('Ca_p5', '/model/chem/compt2/Ca[5]')
Beispiel #28
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()
Beispiel #29
0
def makeModel():
    model = moose.Neutral( '/model' )
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel( './spinyNeuron.p', '/model/cell', 'Neutral' )
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind( '/model/cell/##' ):
        i.tick = -1

    diffConst = 0.0
    # create container for model
    model = moose.element( '/model' )
    chem = moose.Neutral( '/model/chem' )
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh( '/model/chem/compt0' )
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh( '/model/chem/compt1' )
    moose.connect( compt0, 'spineListOut', compt1, 'spineList', 'OneToOne' )
    compt2 = moose.PsdMesh( '/model/chem/compt2' )
    moose.connect( compt0, 'psdListOut', compt2, 'psdList', 'OneToOne' )

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel( compt0 ) # Populate all 3 compts with the chem system.
    makeChemModel( compt1 )
    makeChemModel( compt2 )

    compt0.diffLength = 2e-6 # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.cell = cell 
    moose.showfields( compt0 )

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve( '/model/chem/compt0/ksolve' )
    ksolve1 = moose.Ksolve( '/model/chem/compt1/ksolve' )
    ksolve2 = moose.Ksolve( '/model/chem/compt2/ksolve' )
    dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' )
    dsolve1 = moose.Dsolve( '/model/chem/compt1/dsolve' )
    dsolve2 = moose.Dsolve( '/model/chem/compt2/dsolve' )
    stoich0 = moose.Stoich( '/model/chem/compt0/stoich' )
    stoich1 = moose.Stoich( '/model/chem/compt1/stoich' )
    stoich2 = moose.Stoich( '/model/chem/compt2/stoich' )

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    stoich0.dsolve = dsolve0
    stoich1.dsolve = dsolve1
    stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert( stoich0.numVarPools == 3 )
    assert( stoich0.numProxyPools == 0 )
    assert( stoich0.numRates == 4 )
    assert( stoich1.numVarPools == 3 )
    assert( stoich1.numProxyPools == 0 )
    assert( stoich1.numRates == 4 )
    assert( stoich2.numVarPools == 3 )
    assert( stoich2.numProxyPools == 0 )
    assert( stoich2.numRates == 4 )
    dsolve0.buildNeuroMeshJunctions( dsolve1, dsolve2 )
    stoich0.buildXreacs( stoich1 )
    stoich1.buildXreacs( stoich2 )
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()
    
    moose.element( '/model/chem/compt2/a[0]' ).concInit *= 1.5

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral( '/model/graphs' )
    makeTab( 'a_soma', '/model/chem/compt0/a[0]' )
    makeTab( 'b_soma', '/model/chem/compt0/b[0]' )
    makeTab( 'a_apical', '/model/chem/compt0/a[' + str( num ) + ']' )
    makeTab( 'b_apical', '/model/chem/compt0/b[' + str( num ) + ']' )
    makeTab( 'a_spine', '/model/chem/compt1/a[5]' )
    makeTab( 'b_spine', '/model/chem/compt1/b[5]' )
    makeTab( 'a_psd', '/model/chem/compt2/a[5]' )
    makeTab( 'b_psd', '/model/chem/compt2/b[5]' )
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