How to use the tellurium.antimonyToSBML function in tellurium

To help you get started, we’ve selected a few tellurium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sys-bio / tellurium / tellurium / tecombine.py View on Github external
:param phrasedmlStr: phraSEDML string
        :param antimonyStr: antimony string to be referenced
        :param arcname: (optional) desired name of SEDML file
        """
        warnings.warn('Use inline_omex instead.', DeprecationWarning)
        # FIXME: This does not work for multiple referenced models !.
        reModel = r"""(\w*) = model ('|")(.*)('|")"""
        phrasedmllines = phrasedmlStr.splitlines()
        for k, line in enumerate(phrasedmllines):
            reSearchModel = re.split(reModel, line)
            if len(reSearchModel) > 1:
                modelsource = str(reSearchModel[3])
                modelname = os.path.basename(modelsource)
                modelname = str(modelname).replace(".xml", '')

        phrasedml.setReferencedSBML(modelsource, te.antimonyToSBML(antimonyStr))
        sedmlstr = phrasedml.convertString(phrasedmlStr)
        if sedmlstr is None:
            raise Exception(phrasedml.getLastError())

        phrasedml.clearReferencedSBML()
        self.addSEDML(sedmlstr, arcname)
github sys-bio / tellurium / tellurium / sedml / tephrasedml.py View on Github external
# model info from phrasedml
        modelsource, modelname = self._modelInfoFromPhrasedml(phrasedmlStr)
        print('Model source:', modelsource)
        # print('Model name:', modelname)

        # find index of antimony str
        antIndex = None
        for k, antStr in enumerate(self.antimonyList):
            r = te.loada(antStr)
            modelName = r.getModel().getModelName()
            if modelName == modelsource:
                antIndex = k
        if antIndex is None:
            raise Exception("Cannot find the model name referenced in the PhraSEDML string")

        phrasedml.setReferencedSBML(modelsource, te.antimonyToSBML(self.antimonyList[antIndex]))
        sedmlstr = phrasedml.convertString(phrasedmlStr)
        if sedmlstr is None:
            raise Exception(phrasedml.getLastPhrasedError())

        phrasedml.clearReferencedSBML()
        f = tempfile.NamedTemporaryFile('w', suffix=".sedml")
        f.write(sedmlstr)
        f.flush()
        pysedml = tesedml.sedmlToPython(f.name)

        # perform some replacements in the sedml
        if self.modelispath[antIndex] is False:
            lines = pysedml.splitlines()
            for k, line in enumerate(lines):
                reSearchPath = re.split(rePath, line)
                if len(reSearchPath) > 1:
github sys-bio / tellurium / examples / notebooks-py / tellurium_interconversion.py View on Github external
#!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!!
from __future__ import print_function
import tellurium as te

# antimony model
ant_model = """
    S1 -> S2; k1*S1;
    S2 -> S3; k2*S2;

    k1= 0.1; k2 = 0.2; 
    S1 = 10; S2 = 0; S3 = 0;
"""

# convert to SBML
sbml_model = te.antimonyToSBML(ant_model)

# convert to CellML
cellml_model = te.antimonyToCellML(ant_model)

# or from the sbml
cellml_model = te.sbmlToCellML(sbml_model)
github sys-bio / tellurium / examples / notebooks-py / tellurium_model_loading.py View on Github external
from __future__ import print_function
import tellurium as te

# Load an antimony model
ant_model = '''
    S1 -> S2; k1*S1;
    S2 -> S3; k2*S2;

    k1= 0.1; k2 = 0.2; 
    S1 = 10; S2 = 0; S3 = 0;
'''
# At the most basic level one can load the SBML model directly using libRoadRunner
print('---  load roadrunner ---')
import roadrunner
# convert to SBML model
sbml_model = te.antimonyToSBML(ant_model)
r = roadrunner.RoadRunner(sbml_model)
result = r.simulate(0, 10, 100)
r.plot(result)

# The method loada is simply a shortcut to loadAntimonyModel
print('---  load tellurium ---')
r = te.loada(ant_model)
result = r.simulate (0, 10, 100)
r.plot(result)

# same like
r = te.loadAntimonyModel(ant_model)
github sys-bio / tellurium / examples / notebooks-py / tesedmlExample.py View on Github external
model myModel
  S1 -> S2; k1*S1
  S1 = 10; S2 = 0
  k1 = 1
end
'''

phrasedml_str = '''
  model1 = model "myModel"
  sim1 = simulate uniform(0, 5, 100)
  task1 = run sim1 on model1
  plot "Figure 1" time vs S1, S2
'''

# create the sedml xml string from the phrasedml
sbml_str = te.antimonyToSBML(antimony_str)
phrasedml.setReferencedSBML("myModel", sbml_str)

sedml_str = phrasedml.convertString(phrasedml_str)
if sedml_str == None:
    print(phrasedml.getLastPhrasedError())
print(sedml_str)


# In[2]:

# Create the temporary files and execute the code
import tempfile
f_sbml = tempfile.NamedTemporaryFile(prefix="myModel", suffix=".xml")
f_sbml.write(sbml_str)
f_sbml.flush()
print(f_sbml.name)
github sys-bio / tellurium / tellurium / tecombine.py View on Github external
def addAntimony(self, antimonyStr, filename=None):
        """ Adds SBML file as Antimony into COMBINE archive.
        :param antimonyStr: antimony string
        """
        warnings.warn('Use inline_omex instead.', DeprecationWarning)
        sbmlStr = te.antimonyToSBML(antimonyStr)
        self.addSBML(sbmlStr, filename)
github sys-bio / tellurium / tellurium / dev / deprecated / tephrasedml.py View on Github external
warnings.warn('Use inline_omex instead.', DeprecationWarning)
        modelNames = []
        for aStr in self.antimonyList:
            r = te.loada(aStr)
            name = r.getModel().getModelName()
            modelNames.append(name)

        sources = self._modelsFromPhrasedml(phrasedmlStr)
        for source, name in iteritems(sources):
            # not a antimony model
            if name not in modelNames:
                continue

            # set as referenced model
            aStr = self.antimonyList[modelNames.index(name)]
            phrasedml.setReferencedSBML(source, te.antimonyToSBML(aStr))