示例#1
0
def main():
    modelname = os.path.join(modeldir, './chem_models/00001-sbml-l3v1.xml')
    model = moose.mooseReadSBML(modelname, '/sbml')
    c = moose.element('/clock')
    moose.reinit()
    moose.start(200)
    check()
示例#2
0
def main():
    modelname = os.path.join(modeldir, './chem_models/00001-sbml-l3v1.xml' )
    model = moose.mooseReadSBML( modelname, '/sbml' )
    c = moose.element('/clock')
    moose.reinit()
    moose.start(200)
    check(  )
示例#3
0
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
示例#4
0
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 
示例#5
0
def loadModels(filepath):
    """ load models into moose if file, if moosepath itself it passes back the path and
    delete solver if exist """

    modelpath = '/'
    loaded = False

    if os.path.isfile(filepath) :
        fpath, filename = os.path.split(filepath)
        # print " head and tail ",head,  " ",tail
        # modelpath = filename[filename.rfind('/'): filename.rfind('.')]
        # print "modelpath ",modelpath
        # ext = os.path.splitext(filename)[1]
        # filename = filename.strip()
        modelpath = '/'+filename[:filename.rfind('.')]
        modeltype = mtypes.getType(filepath)
        subtype = mtypes.getSubtype(filepath, modeltype)

        if subtype == 'kkit' or modeltype == "cspace":
            if moose.exists(modelpath):
                moose.delete(modelpath)
            moose.loadModel(filepath,modelpath)
            loaded = True

        elif subtype == 'sbml':
            if moose.exists(modelpath):
                moose.delete(modelpath)
            moose.mooseReadSBML(filepath,modelpath)
            loaded = True
        else:
            print("This file is not supported for mergering")
            modelpath = moose.Shell('/')

    elif moose.exists(filepath):
        modelpath = filepath
        loaded = True

    return modelpath,loaded
示例#6
0
def loadModels(filepath):
    """ load models into moose if file, if moosepath itself it passes back the path and
    delete solver if exist """

    modelpath = '/'
    loaded = False

    if os.path.isfile(filepath):
        fpath, filename = os.path.split(filepath)
        # print " head and tail ",head,  " ",tail
        # modelpath = filename[filename.rfind('/'): filename.rfind('.')]
        # print "modelpath ",modelpath
        # ext = os.path.splitext(filename)[1]
        # filename = filename.strip()
        modelpath = '/' + filename[:filename.rfind('.')]
        modeltype = mtypes.getType(filepath)
        subtype = mtypes.getSubtype(filepath, modeltype)

        if subtype == 'kkit' or modeltype == "cspace":
            if moose.exists(modelpath):
                moose.delete(modelpath)
            moose.loadModel(filepath, modelpath)
            loaded = True

        elif subtype == 'sbml':
            if moose.exists(modelpath):
                moose.delete(modelpath)
            moose.mooseReadSBML(filepath, modelpath)
            loaded = True
        else:
            print("This file is not supported for mergering")
            modelpath = moose.Shell('/')

    elif moose.exists(filepath):
        modelpath = filepath
        loaded = True

    return modelpath, loaded
示例#7
0
def test_sbml():
    modelname = os.path.join(sdir_, '..', 'data', '00001-sbml-l3v1.xml')
    model = moose.mooseReadSBML( modelname, '/sbml' )
    if not model:
        print("Most likely python-libsbml is not installed.")
        return 0
    moose.reinit()
    moose.start(200)
    # TODO: Add more tests here.
    p = moose.wildcardFind( '/sbml/##' )
    assert len(p) == 8
    names = ['compartment', 'mesh', 'S1', 'info', 'S2', 'info', 'reaction1']
    for x in p:
        assert x.name in names
示例#8
0
def dumpTweakedModelFile(args, params, results):
    filename, file_extension = os.path.splitext(args.model)
    resfname, res_ext = os.path.splitext(args.file)
    if file_extension == ".xml":
        modelId, errormsg = moose.mooseReadSBML(args.model, 'model', 'ee')
        tweakParams(params, results.x)
        moose.mooseWriteSBML(modelId.path, resfname + "_tweaked.xml")
        moose.delete(modelId)
    elif file_extension == ".g":
        modelId = moose.loadModel(args.model, 'model', 'ee')
        tweakParams(params, results.x)
        moose.mooseWriteKkit(modelId.path, resfname + "_tweaked.g")
        moose.delete(modelId)
    else:
        print("Warning: dumpTweakedModelFile: Don't know file type for {}".
              format(args.model))