def main():
    """
This example illustrates loading, running of an SBML model defined in XML format.
Default this  file load's 00001-sbml-l3v1.xml which is taken from l3v1 SBML testcase.
Plots are setup.
Model is run for 20sec.
As a general rule we created model under '/path/model' and plots under '/path/graphs'.
If someone wants to load anyother file then 
    `python loadSbmlmodel filepath runtime`
    """

    dfilepath = "../genesis/00001-sbml-l3v1.xml"
    druntime = 20.0
    msg = ""
    try:
        sys.argv[1]
    except IndexError:
        filepath = dfilepath

    else:
        filepath = sys.argv[1]
    if not os.path.exists(filepath):
        msg = "Filename or path does not exist", filepath, "loading default file", dfilepath
        filepath = dfilepath

    try:
        sys.argv[2]
    except:
        runtime = druntime
    else:
        runtime = float(sys.argv[2])
    sbmlId = moose.element('/')
    # Loading the sbml file into MOOSE, models are loaded in path/model
    sbmlId = moose.mooseReadSBML(filepath, '/sbml')
    if isinstance(sbmlId, (list, tuple)):
        print(sbmlId)

    elif sbmlId.path != '/':

        s1 = moose.element('/sbml/model/compartment/S1')
        s2 = moose.element('/sbml/model/compartment/S2')

        # Creating MOOSE Table, Table2 is for the chemical model
        graphs = moose.Neutral('/sbml/graphs')
        outputs1 = moose.Table2('/sbml/graphs/concS1')
        outputs2 = moose.Table2('/sbml/graphs/concS2')

        # connect up the tables
        moose.connect(outputs1, 'requestOut', s1, 'getConc')
        moose.connect(outputs2, 'requestOut', s2, 'getConc')

        # gsl solver is added, default is ee
        moose.mooseAddChemSolver(sbmlId.path, "ee")

        # Reset and Run
        moose.reinit()
        moose.start(runtime)
        return sbmlId, True, msg
    return sbmlId, False, msg
def main():
    """
This example illustrates loading, running of an SBML model defined in XML format.
Default this  file load's 00001-sbml-l3v1.xml which is taken from l3v1 SBML testcase.
Plots are setup.
Model is run for 20sec.
As a general rule we created model under '/path/model' and plots under '/path/graphs'.
If someone wants to load anyother file then 
    `python loadSbmlmodel filepath runtime`
    """

    dfilepath = "../genesis/00001-sbml-l3v1.xml"
    druntime = 20.0
    msg = ""
    try:
        sys.argv[1]
    except IndexError:
        filepath = dfilepath
        
    else:
        filepath = sys.argv[1]
    if not os.path.exists(filepath):
        msg = "Filename or path does not exist",filepath,"loading default file",dfilepath
        filepath = dfilepath
        
    try:
        sys.argv[2]
    except :
        runtime = druntime
    else:
        runtime = float(sys.argv[2])
    sbmlId = moose.element('/')
    # Loading the sbml file into MOOSE, models are loaded in path/model
    sbmlId = moose.mooseReadSBML(filepath,'/sbml')
    if isinstance(sbmlId, (list, tuple)):
        print(sbmlId)

    elif sbmlId.path != '/':

        s1 = moose.element('/sbml/model/compartment/S1')
        s2= moose.element('/sbml/model/compartment/S2')

        # Creating MOOSE Table, Table2 is for the chemical model
        graphs = moose.Neutral( '/sbml/graphs' )
        outputs1 = moose.Table2 ( '/sbml/graphs/concS1')
        outputs2 = moose.Table2 ( '/sbml/graphs/concS2')

        # connect up the tables
        moose.connect( outputs1,'requestOut', s1, 'getConc' );
        moose.connect( outputs2,'requestOut', s2, 'getConc' );

        # gsl solver is added, default is ee
        moose.mooseAddChemSolver(sbmlId.path,"ee")

        # Reset and Run
        moose.reinit()
        moose.start(runtime)
        return sbmlId,True,msg
    return sbmlId,False,msg 
Beispiel #3
0
def main():
    """
    This example illustrates loading, running, and saving a kinetic
    model defined in kkit format. It uses a default kkit model but
    you can specify another using the command line
        ``python filename runtime solver``.
    We use the gsl solver here.
    The model already defines a couple of plots and sets the runtime 20 secs.
    """

    solver = "gsl"  # Pick any of gsl, gssa, ee..
    mfile = os.path.join( scriptDir, './genesis/acc11.g' )
    runtime = 1000.0
    if ( len( sys.argv ) >= 3 ):
        if sys.argv[1][0] == '/':
            mfile = sys.argv[1]
        else:
            mfile = sys.argv[1]
            runtime = float( sys.argv[2] )
    if ( len( sys.argv ) == 4 ):
            solver = sys.argv[3]

    modelId = moose.loadModel( mfile, 'model')
    moose.mooseAddChemSolver('model',solver)
    moose.element( '/model/kinetics/neuroNOS/nNOS.arg' ).concInit = 0.1
    moose.reinit()
    moose.start( runtime )

    # Display all plots.
    for x in moose.wildcardFind( '/model/#graphs/conc#/#' ):
        t = np.arange( 0, x.vector.size, 1 ) * x.dt
        print( x.vector )
        if x.vector.size > 0:
            assert min( x.vector ) >= 0.0, min(x.vector)
        assert x.vector.size in [0, 10001], x.vector.size

    ########################################################
    # Run it again with negative values allowed
    moose.element( '/model/kinetics/stoich' ).allowNegative = True
    moose.reinit()
    moose.start( runtime )
    oneValIsBelowZero = False
    allVals = [ ]
    for x in moose.wildcardFind( '/model/#graphs/conc#/#' ):
        t = np.arange( 0, x.vector.size, 1 ) * x.dt
        if x.vector.size > 0:
            allVals.append( min( x.vector ) )
            if min( x.vector ) <= 0.0:
                oneValIsBelowZero = True

        if allVals:
            assert oneValIsBelowZero, "No value is negative: %s" % allVals 
        assert x.vector.size in [0, 10001], x.vector.size
Beispiel #4
0
def main():
    """ This example illustrates loading, running, and saving a kinetic model
        defined in kkit format. It uses a default kkit model but you can specify another using the command line ``python filename runtime solver``. We use the gsl solver here. The model already defines a couple of plots and sets the runtime to 20 seconds.
        """
    solver = "gsl"  # Pick any of gsl, gssa, ee..
    mfile = os.path.join(scriptdir, 'genesis/kkit_objects_example.g')
    runtime = 20.0
    if (len(sys.argv) >= 3):
        if sys.argv[1][0] == '/':
            mfile = sys.argv[1]
        else:
            mfile = './genesis/' + sys.argv[1]
            runtime = float(sys.argv[2])
    if (len(sys.argv) == 4):
        solver = sys.argv[3]
    modelId = moose.loadModel(mfile, 'model')
    moose.mooseAddChemSolver('model', solver)

    # Increase volume so that the stochastic solver gssa
    # gives an interesting output
    #compt = moose.element( '/model/kinetics' )
    #compt.volume = 1e-19

    moose.reinit()
    moose.start(runtime)

    # Report parameters
    '''
        for x in moose.wildcardFind( '/model/kinetics/##[ISA=PoolBase]' ):
                print x.name, x.nInit, x.concInit
        for x in moose.wildcardFind( '/model/kinetics/##[ISA=ReacBase]' ):
                print x.name, 'num: (', x.numKf, ', ',  x.numKb, '), conc: (', x.Kf, ', ', x.Kb, ')'
        for x in moose.wildcardFind('/model/kinetics/##[ISA=EnzBase]'):
                print x.name, '(', x.Km, ', ',  x.numKm, ', ', x.kcat, ')'
                '''

    # Display all plots.
    for x in moose.wildcardFind('/model/#graphs/conc#/#'):
        t = numpy.arange(0, x.vector.size, 1) * x.dt

    vals = x.vector
    stats = [vals.min(), vals.max(), vals.mean(), vals.std()]
    expected = [0.0, 0.00040464, 0.0001444, 0.00013177]
    assert numpy.allclose(stats, expected,
                          rtol=1e-4), 'Got %s expected %s' % (stats, expected)
Beispiel #5
0
def test_kkit():
    """This example illustrates loading, running, and saving a kinetic model
        defined in kkit format. It uses a default kkit model but you can
        specify another using the command line ``python filename runtime
        solver``. We use the gsl solver here. The model already defines a
        couple of plots and sets the runtime to 20 seconds.
        """
    solver = "gsl"  # Pick any of gsl, gssa, ee..
    mfile = os.path.join(scriptdir, '..', 'data', 'kkit_objects_example.g')
    runtime = 20.0
    modelId = moose.loadModel(mfile, 'model')
    moose.mooseAddChemSolver('model', solver)
    moose.reinit()
    moose.start(runtime)

    for x in moose.wildcardFind('/model/#graphs/conc#/#'):
        t = numpy.arange(0, x.vector.size, 1) * x.dt

    vals = x.vector
    stats = [vals.min(), vals.max(), vals.mean(), vals.std()]
    expected = [0.0, 0.00040464, 0.0001444, 0.00013177]
    assert numpy.allclose(stats, expected,
                          rtol=1e-4), 'Got %s expected %s' % (stats, expected)
Beispiel #6
0
def loadModel(filename, target, method=None):
    solverClass = 'Neutral'
    if method != None:
        solverClass = method
    try:
        f = open(filename, 'r')
        f.close()
    except IOError as e:
        print(e)
        return
    else:
        file_name, extension = splitext(filename)
        if extension in [".swc", ".p"]:
            ret = moose._moose.loadModel(filename, target, "Neutral")
        elif extension in [".g", ".cspace"]:
            #only if genesis or cspace file, then mooseAddChemSolver is called
            ret = moose._moose.loadModel(filename, target, "ee")

            method = "ee"
            if solverClass.lower() in [
                    "gssa", "gillespie", "stochastic", "gsolve"
            ]:
                method = "gssa"
            elif solverClass.lower() in [
                    "gsl", "runge kutta", "deterministic", "ksolve",
                    "rungekutta", "rk5", "rkf", "rk"
            ]:
                method = "gsl"
            elif solverClass.lower() in [
                    "exponential euler", "exponentialeuler", "neutral"
            ]:
                method = "ee"

            if method != 'ee':
                moose.mooseAddChemSolver(target, method)
        return ret
Beispiel #7
0
def loadModel(filename, target, method="ee"):
    moose.loadModel(filename, target)
    moose.mooseAddChemSolver(target, method)
    if moose.exists(target + "/kinetics/info"):
        moose.element(target + "/kinetics/info").solver = method
Beispiel #8
0
initiexpr = function.expr
#S1 connected to function
numVariables = function.numVars
expr = ""
expr = (function.expr + '+' + 'x' + str(numVariables))
expr = expr.lstrip("0 +")
expr = expr.replace(" ", "")
function.expr = expr
s1msg = moose.connect(S1, 'nOut', function.x[numVariables], 'input')
#S2 connected to function
numVariables = function.numVars
expr = ""
expr = (function.expr + '+' + 'x' + str(numVariables))
expr = expr.lstrip("0 +")
expr = expr.replace(" ", "")
function.expr = expr
s2msg = moose.connect(S2, 'nOut', function.x[numVariables], 'input')

compts = moose.wildcardFind(modelRoot.path + '/##[ISA=ChemCompt]')
solver = 'gsl'
moose.mooseAddChemSolver('/model', solver)
moose.mooseDeleteChemSolver('/model')

#moose.delete(s1msg)
#moose.delete(s2msg)
#deleting the function
#moose.delete(function) #deleting this will not cause seg fault
print(function.expr
      )  #function's expr still has the expression which is causing the problem