tellurium.sedml package

Subpackages

Submodules

tellurium.sedml.data module

Reading NUML, CSV and TSV data from DataDescriptions

class tellurium.sedml.data.DataDescriptionParser[source]

Bases: object

Class for parsing DataDescriptions.

FORMAT_CSV = 'urn:sedml:format:csv'
FORMAT_NUML = 'urn:sedml:format:numl'
FORMAT_TSV = 'urn:sedml:format:tsv'
FORMAT_URN = 'urn:sedml:format:'
SUPPORTED_FORMATS = ['urn:sedml:format:numl', 'urn:sedml:format:csv', 'urn:sedml:format:tsv']
classmethod parse(dd, workingDir=None)[source]

Parses single DataDescription.

Returns dictionary of data sources {DataSource.id, slice_data}

Parameters:
  • dd – SED-ML DataDescription

  • workingDir – workingDir relative to which the sources are resolved

Returns:

classmethod parse_dimension_description(description)[source]

Parses the given dimension description.

Returns dictionary of { key: dtype }

Parameters:

description

Returns:

classmethod read_numl_document(path)[source]

Helper to read numl document and checking errors

Parameters:

path – path of file

Returns:

tellurium.sedml.mathml module

Helper functions for evaluation of mathml expressions. In this namespace all the possible names occuring in formula strings have to be defined.

In build in python are

*, /, +, - and, or, not

tellurium.sedml.mathml.evaluableMathML(astnode, variables={}, array=False)[source]

Create evaluable python string.

tellurium.sedml.mathml.evaluateMathML(astnode, variables={}, array=False)[source]

Evaluate MathML string with given set of variable and parameter values.

Parameters:
  • astnode (libsbml.ASTNode) – astnode of MathML string

  • variables (dict) – dictionary of var : value

  • parameters (dict) – dictionary of par : value

Returns:

value of evaluated MathML

Return type:

float

tellurium.sedml.mathml.piecewise(*args)[source]
tellurium.sedml.mathml.product(*args)[source]
tellurium.sedml.mathml.renameNPFuncs(astnode)[source]
tellurium.sedml.mathml.root(a, b)[source]
tellurium.sedml.mathml.sqr(x)[source]
tellurium.sedml.mathml.xor(*args)[source]

tellurium.sedml.tesedml module

Tellurium SED-ML support.

This module implements SED-ML support for tellurium.

Overview SED-ML

SED-ML is build of main classes

the Model Class, the Simulation Class, the Task Class, the DataGenerator Class, and the Output Class.

The Model Class

The Model class is used to reference the models used in the simulation experiment. SED-ML itself is independent of the model encoding underlying the models. The only requirement is that the model needs to be referenced by using an unambiguous identifier which allows for finding it, for example using a MIRIAM URI. To specify the language in which the model is encoded, a set of predefined language URNs is provided. The SED-ML Change class allows the application of changes to the referenced models, including changes on the XML attributes, e.g. changing the value of an observable, computing the change of a value using mathematics, or general changes on any XML element of the model representation that is addressable by XPath expressions, e.g. substituting a piece of XML by an updated one.

TODO: DATA CLASS

The Simulation Class

The Simulation class defines the simulation settings and the steps taken during simulation. These include the particular type of simulation and the algorithm used for the execution of the simulation; preferably an unambiguous reference to such an algorithm should be given, using a controlled vocabulary, or ontologies. One example for an ontology of simulation algorithms is the Kinetic Simulation Algorithm Ontology KiSAO. Further information encodable in the Simulation class includes the step size, simulation duration, and other simulation-type dependent information.

The Task Class

SED-ML makes use of the notion of a Task class to combine a defined model (from the Model class) and a defined simulation setting (from the Simulation class). A task always holds one reference each. To refer to a specific model and to a specific simulation, the corresponding IDs are used.

The DataGenerator Class

The raw simulation result sometimes does not correspond to the desired output of the simulation, e.g. one might want to normalise a plot before output, or apply post-processing like mean-value calculation. The DataGenerator class allows for the encoding of such post-processings which need to be applied to the simulation result before output. To define data generators, any addressable variable or parameter of any defined model (from instances of the Model class) may be referenced, and new entities might be specified using MathML definitions.

The Output Class

The Output class defines the output of the simulation, in the sense that it specifies what shall be plotted in the output. To do so, an output type is defined, e.g. 2D-plot, 3D-plot or data table, and the according axes or columns are all assigned to one of the formerly specified instances of the DataGenerator class.

For information about SED-ML please refer to http://www.sed-ml.org/ and the SED-ML specification.

SED-ML in tellurium: Implementation

SED-ML support in tellurium is based on Combine Archives. The SED-ML files in the Archive can be executed and stored with results.

SED-ML in tellurium: Supported Features

Tellurium supports SED-ML L1V3 with SBML as model format.

SBML models are fully supported, whereas for CellML models only basic support is implemented (when additional support is requested it be implemented). CellML models are transformed to SBML models which results in different XPath expressions, so that targets, selections cannot be easily resolved in the CellMl-SBML.

Supported input for SED-ML are either SED-ML files (‘.sedml’ extension), SED-ML XML strings or combine archives (‘.sedx’|’.omex’ extension). Executable python code is generated from the SED-ML which allows the execution of the defined simulation experiment.

In the current implementation all SED-ML constructs with exception of XML transformation changes of the model

  • Change.RemoveXML

  • Change.AddXML

  • Change.ChangeXML

are supported.

Notice

The main maintainer for SED-ML support is Matthias König. Please let changes to this file be reviewed and make sure that all SED-ML related tests are working.

class tellurium.sedml.tesedml.SEDMLCodeFactory(inputStr, sedmlFile=None, workingDir=None, createOutputs=True, saveOutputs=False, outputDir=None, plottingEngine=None)[source]

Bases: object

Code Factory generating executable code.

class Stack[source]

Bases: object

Stack implementation for nodes.

isEmpty()[source]
peek()[source]
pop()[source]
push(item)[source]
size()[source]
TEMPLATE_DIR = '/home/docs/checkouts/readthedocs.org/user_builds/tellurium/envs/latest/lib/python3.11/site-packages/tellurium/sedml/templates'
class TaskNode(task, depth)[source]

Bases: object

Tree implementation of task tree.

add_child(obj)[source]
info()[source]
is_leaf()[source]
static algorithmParameterToParameterKey(par)[source]

Resolve the mapping between parameter keys and roadrunner integrator keys.

static createTaskTree(doc, rootTask)[source]

Creates the task tree. Required for resolution of order of all simulations.

dataDescriptionToPython(dataDescription)[source]

Python code for DataDescription.

Parameters:

dataDescription (DataDescription) – SedModel instance

Returns:

python str

Return type:

str

static dataGeneratorToPython(doc, generator)[source]

Create variable from the data generators and the simulation results and data sources.

The data of repeatedTasks is handled differently depending on if reset=True or reset=False. reset=True:

every repeat is a single curve, i.e. the data is a list of data

reset=False:

all curves belong to a single simulation and are concatenated to one dataset

executePython()[source]

Executes python code.

The python code is created during the function call. See createpython()

Returns:

returns dictionary of information with keys

static getDataGeneratorsForTask(doc, task)[source]

Get the DataGenerators which reference the given task.

Parameters:
  • doc

  • task

Returns:

Return type:

static getIntegratorNameForKisaoID(kid)[source]

RoadRunner integrator name for algorithm KisaoID.

Parameters:

kid (str) – KisaoID

Returns:

RoadRunner integrator name.

Return type:

str

static getModelsFrom(task)[source]

Parameters

tasklibsedml.SedRepeatedTask

The repeated task that you need the models from.

Returns

A vector of unique model IDs from the repeated task’s subtasks.

static getOrderedSubtasks(task)[source]

Ordered list of subtasks for task.

static isSupportedAlgorithmForSimulationType(kisao, simType)[source]

Check Algorithm Kisao Id is supported for simulation.

Returns:

is supported

Return type:

bool

localParamsInModelChanges()[source]

Returns True if any of the model changes target local parameters.

static modelChangeToPython(model, change)[source]

Creates the apply change python string for given model and change.

Currently only a very limited subset of model changes is supported. Namely changes of parameters and concentrations within a SedChangeAttribute.

Parameters:
  • model (SedModel) – given model

  • change (SedChange) – model change

Returns:

Return type:

str

modelToPython(model)[source]

Python code for SedModel.

Parameters:

model (SedModel) – SedModel instance

Returns:

python str

Return type:

str

outputPlot2DToPython(doc, output)[source]

OutputReport

If workingDir is provided the plot is saved in the workingDir. :param doc: :type doc: SedDocument :param output: :type output: SedOutputReport :return: list of python lines :rtype: list(str)

outputPlot3DToPython(doc, output)[source]

OutputPlot3D

Parameters:
  • doc (SedDocument) –

  • output (SedOutputPlot3D) –

Returns:

list of python lines

Return type:

list(str)

static outputPlotSettings()[source]

Settings for all plot types.

Returns:

Return type:

outputReportToPython(doc, output)[source]

OutputReport

Parameters:
  • doc (SedDocument) –

  • output (SedOutputReport) –

Returns:

list of python lines

Return type:

list(str)

outputToPython(doc, output)[source]

Create output

static repeatedTaskToPython(doc, node)[source]

Create python for RepeatedTask.

Must create - the ranges (Ranges) - apply all changes (SetValues)

sedmlString()[source]

Get the SEDML XML string of the current document.

Returns:

SED-ML XML

Return type:

str

static selectionFromVariable(var, modelId)[source]

Resolves the selection for the given variable.

First checks if the variable is a symbol and returns the symbol. If no symbol is set the xpath of the target is resolved and used in the selection

Parameters:

var (SedVariable) – variable to resolve

Returns:

a single selection

Return type:

Selection (namedtuple: id type)

static selectionsForTask(doc, task)[source]

Populate variable lists from the data generators for the given task.

These are the timeCourseSelections and steadyStateSelections in RoadRunner.

Search all data generators for variables which have to be part of the simulation.

static simpleTaskMainSim(doc, node)[source]

Creates the simulation python code for a given taskNode.

The taskNodes are required to handle the relationships between RepeatedTasks, SubTasks and SimpleTasks (Task).

Parameters:
  • doc (SEDDocument) – sedml document

  • node (TaskNode) – taskNode of the current task

Returns:

Return type:

static simpleTaskParentInit(doc, node)[source]

Creates the simulation python code for a given taskNode.

The taskNodes are required to handle the relationships between RepeatedTasks, SubTasks and SimpleTasks (Task).

Parameters:
  • doc (SEDDocument) – sedml document

  • node (TaskNode) – taskNode of the current task

Returns:

Return type:

static simpleTaskSetup(doc, node)[source]

Creates the first half of simulation python code for a given taskNode.

The taskNodes are required to handle the relationships between RepeatedTasks, SubTasks and SimpleTasks (Task).

Parameters:
  • doc (SEDDocument) – sedml document

  • node (TaskNode) – taskNode of the current task

Returns:

Return type:

static simpleTaskToPython(doc, node)[source]

Creates the simulation python code for a given taskNode.

The taskNodes are required to handle the relationships between RepeatedTasks, SubTasks and SimpleTasks (Task).

Parameters:
  • doc (SEDDocument) – sedml document

  • node (TaskNode) – taskNode of the current task

Returns:

Return type:

static targetToExpr(xpath, modelId)[source]

Creates python line for given xpath target and value. :param xpath: :type xpath: :type value: :return: :rtype:

static targetToPython(xpath, value, modelId)[source]

Creates python line for given xpath target and value. :param xpath: :type xpath: :param value: :type value: :return: :rtype:

static taskToPython(doc, task)[source]

Create python for arbitrary task (repeated or simple).

Parameters:
  • doc

  • task

Returns:

Return type:

static taskTreeToPython(doc, tree)[source]

Python code generation from task tree.

toPython(python_template='tesedml_template.template')[source]

Create python code by rendering the python template. Uses the information in the SED-ML document to create python code

Renders the respective template.

Returns:

returns the rendered template

Return type:

str

static uniformRangeToPython(r)[source]

Create python lines for uniform range. :param r: :type r: :return: :rtype:

static vectorRangeToPython(r)[source]
class tellurium.sedml.tesedml.SEDMLTools[source]

Bases: object

Helper functions to work with sedml.

INPUT_TYPE_FILE_COMBINE = 'COMBINE_FILE'
INPUT_TYPE_FILE_SEDML = 'SEDML_FILE'
INPUT_TYPE_STR = 'SEDML_STRING'
classmethod checkSEDMLDocument(doc)[source]

Checks the SedDocument for errors. Raises IOError if error exists. :param doc: :type doc:

classmethod readSEDMLDocument(inputStr, workingDir)[source]

Parses SedMLDocument from given input.

Returns:

dictionary of SedDocument, inputType and working directory.

Return type:

{doc, inputType, workingDir}

static resolveModelChanges(doc)[source]

Resolves the original source model and full change lists for models.

Going through the tree of model upwards until root is reached and collecting changes on the way (example models m* and changes c*) m1 (source) -> m2 (c1, c2) -> m3 (c3, c4) resolves to m1 (source) [] m2 (source) [c1,c2] m3 (source) [c1,c2,c3,c4] The order of changes is important (at least between nodes on different levels of hierarchies), because later changes of derived models could reverse earlier changes.

Uses recursive search strategy, which should be okay as long as the model tree hierarchy is not getting to big.

tellurium.sedml.tesedml.combineArchiveToPython(omexPath)[source]

All python code generated from given combine archive.

Parameters:

omexPath

Returns:

dictionary of { sedml_location: pycode }

tellurium.sedml.tesedml.executeCombineArchive(omexPath, workingDir=None, printPython=False, createOutputs=True, saveOutputs=False, outputDir=None, plottingEngine=None)[source]

Run all SED-ML simulations in given COMBINE archive.

If no workingDir is provided execution is performed in temporary directory which is cleaned afterwards. The executed code can be printed via the ‘printPython’ flag.

Parameters:
  • omexPath – OMEX Combine archive

  • workingDir – directory to extract archive to

  • printPython – boolean switch to print executed python code

  • createOutputs – boolean flag if outputs should be created, i.e. reports and plots

  • saveOutputs – flag if the outputs should be saved to file

  • outputDir – directory where the outputs should be written

  • plottingEngin – string of which plotting engine to use; uses set plotting engine otherwise

:return dictionary of sedmlFile:data generators

tellurium.sedml.tesedml.executeSEDML(inputStr, workingDir=None, createOutputs=True, saveOutputs=False, outputDir=None, plottingEngine=None)[source]

Run a SED-ML file or combine archive with results.

If a workingDir is provided the files and results are written in the workingDir.

Parameters:

inputStr

Returns:

Return type:

tellurium.sedml.tesedml.fix_endpoints(x, y, color, tag, fig)[source]

Adds endpoint markers wherever there is a discontinuity in the data.

tellurium.sedml.tesedml.getKisaoStringFromVal(val)[source]
tellurium.sedml.tesedml.getKisaoValFromString(id)[source]
tellurium.sedml.tesedml.process_trace(trace)[source]

If each entry in the task consists of a single point (e.g. steady state scan), concatenate the points. Otherwise, plot as separate curves.

tellurium.sedml.tesedml.sedmlToPython(inputStr, workingDir=None)[source]

Convert sedml file to python code.

Parameters:

inputStr (path) – full path name to SedML model or SED-ML string

Returns:

generated python code

tellurium.sedml.tesedml.terminate_trace(trace)[source]

If each entry in the task consists of a single point (e.g. steady state scan), concatenate the points. Otherwise, plot as separate curves.

tellurium.sedml.utils module

Template functions to run the example cases.

tellurium.sedml.utils.run_case(call_file, antimony_str, phrasedml_str, py_code=False, working_dir=None)[source]

Run one of the example phrasedml cases.

Parameters:
  • case_id

  • antimony_str

  • phrasedml_str

Returns:

tellurium.sedml.xpath module

Module contents