### Navigate to Notebooks and Run Jupyter Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/README.md Change directory to the notebook examples and start the Jupyter notebook server. ```bash (te) cd tellurium/examples/notebooks (te) jupyter notebook index.ipynb ``` -------------------------------- ### Start Jupyter Notebook Server Source: https://github.com/sys-bio/tellurium/blob/develop/docs/README.md Command to launch the notebook server for managing code examples. ```bash cd tellurium/examples/notebooks/ jupyter notebook ``` -------------------------------- ### Full Layout Example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/antimony.md A complete example demonstrating basic layout activation and autolayout configuration. ```default J0: S1->S2; # If you just want layout on: model.layout = on # Only need to turn on if don't define anything else; doesn't work to turn it off. //Autolayout options: model.autolayout.maxNumConnectedEdges = 5 # If a single species is involved in more than this number of reactions, it gets aliased. Default 3. ``` -------------------------------- ### Test Roadrunner Installation Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels After installing a wheel, import the package and run its tests to verify the installation. This example shows how to test the roadrunner package. ```python import roadrunner as rr rr.__version__ rr.runTests() rr.[TAB] ``` -------------------------------- ### Start Livy Server Source: https://github.com/sys-bio/tellurium/wiki/Livy-Instructions Use this command to start the Livy server. Ensure LIVY_HOME is set correctly. ```bash $LIVY_HOME/bin/livy-server start ``` -------------------------------- ### Install Tellurium development version Source: https://github.com/sys-bio/tellurium/blob/develop/VirtualEnv.md Follow these steps to clone the repository, install requirements, and perform an editable installation of Tellurium. ```bash # clone repository git clone https://github.com/sys-bio/tellurium cd tellurium # make virtual environment mkvirtualenv tellurium (tellurium) pip install -r requirements.txt # checkout branch (tellurium) git checkout master # install tellurium (tellurium) pip install -e . ``` -------------------------------- ### Install Tellurium from source Source: https://github.com/sys-bio/tellurium/blob/develop/README.md Installs the latest stable version directly from the GitHub repository. ```bash pip install git+https://github.com/sys-bio/tellurium.git ``` -------------------------------- ### Create Virtual Environment and Install Packages Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/README.md Commands to create a virtual environment named 'te', install tellurium and jupyter notebook, and register the IPython kernel. ```bash # create virtualenv mkvirtualenv te (te) pip install tellurium (te) pip install jupyter notebook # register the kernel (te) ipython kernel install --user --name=te ``` -------------------------------- ### Install pygraphviz for Network Diagrams Source: https://github.com/sys-bio/tellurium/blob/develop/docs/notebooks.md This command installs the pygraphviz library, which is required for drawing network diagrams in Tellurium examples. It may require specific include and library paths depending on your system configuration. ```bash /path/to/python3 -m pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib64/graphviz/" ``` ```bash /path/to/python3 -m pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/" ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/sys-bio/tellurium/blob/develop/docs/README.md Required Python packages for building the documentation. ```bash pip install sphinx sphinx-autobuild sphinx_rtd_theme mock ``` -------------------------------- ### Install Twine and Wheel for Python Versions Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Use this command to install the necessary packaging tools for each specific Python version you are supporting. Ensure you are using the correct Python executable (e.g., python3x) for the installation. ```bash python3x -m pip install twine wheel ``` -------------------------------- ### Install Wheel File Locally Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Install a locally built wheel file using pip. This is useful for testing the package before uploading. ```bash python -m pip install FILENAME.whl ``` -------------------------------- ### Define and Simulate an Activator System Model Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tellurium_examples.md This example defines a biological model with multiple reactions and parameters, simulates its behavior, and plots the results. Ensure matplotlib is installed for plotting. ```python import warnings warnings.filterwarnings("ignore") import tellurium as te te.setDefaultPlottingEngine('matplotlib') # model Definition r = te.loada (''' #J1: S1 -> S2; Activator*kcat1*S1/(Km1+S1); J1: S1 -> S2; SE2*kcat1*S1/(Km1+S1); J2: S2 -> S1; Vm2*S2/(Km2+S2); J3: T1 -> T2; S2*kcat3*T1/(Km3+T1); J4: T2 -> T1; Vm4*T2/(Km4+T2); J5: -> E2; Vf5/(Ks5+T2^h5); J6: -> E3; Vf6*T2^h6/(Ks6+T2^h6); #J7: -> E1; J8: -> S; kcat8*E1 J9: E2 -> ; k9*E2; J10:E3 -> ; k10*E3; J11: S -> SE2; E2*kcat11*S/(Km11+S); J12: S -> SE3; E3*kcat12*S/(Km12+S); J13: SE2 -> ; SE2*kcat13; J14: SE3 -> ; SE3*kcat14; Km1 = 0.01; Km2 = 0.01; Km3 = 0.01; Km4 = 0.01; Km11 = 1; Km12 = 0.1; S1 = 6; S2 =0.1; T1=6; T2 = 0.1; SE2 = 0; SE3=0; S=0; E2 = 0; E3 = 0; kcat1 = 0.1; kcat3 = 3; kcat8 =1; kcat11 = 1; kcat12 = 1; kcat13 = 0.1; kcat14=0.1; E1 = 1; k9 = 0.1; k10=0.1; Vf6 = 1; Vf5 = 3; Vm2 = 0.1; Vm4 = 2; h6 = 2; h5=2; Ks6 = 1; Ks5 = 1; Activator = 0; at (time > 100): Activator = 5; ''') r.draw(width=300) result = r.simulate (0, 300, 2000, ['time', 'J11', 'J12']); r.plot(result); ``` -------------------------------- ### Rate Laws and Initialization Example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/antimony.md Demonstrates various rate laws and the initialization of species and parameters within a model. ```antimony model pathway() # Examples of different rate laws and initialization S1 -> S2; k1*S1 S2 -> S3; k2*S2 - k3*S3 S3 -> S4; Vm*S3/(Km + S3) S4 -> S5; Vm*S4^n/(Km + S4)^n S1 = 10 S2 = 0 S3 = 0 S4 = 0 S5 = 0 k1 = 0.1 k2 = 0.2 k3 = 0.2 Vm = 6.7 Km = 1E-3 n = 4 end ``` -------------------------------- ### Install Test Requirements Source: https://github.com/sys-bio/tellurium/blob/develop/tellurium/tests/README.md Install the necessary testing dependencies using pip. ```bash pip install nose coverage ``` -------------------------------- ### Running an Example Script in Tellurium Spyder Source: https://github.com/sys-bio/tellurium/blob/develop/docs/walkthrough.md Execute the example script in the editor pane directly on the IPython console by pressing the green arrow, F5, or Run -> Run. A plot will appear in the IPython console as the output. ```Python # Example script content (not provided in source, but implied) ``` -------------------------------- ### Print Simulation Time Values (Example) Source: https://github.com/sys-bio/tellurium/blob/develop/docs/notebooks.md Shows an example of time values obtained from a simulation. These are typically the first column of the simulation results. ```default Time values: [0.00000000e+00 3.43225906e-07 3.43260229e-03 3.77551929e-02 7.20777836e-02 1.60810095e-01 4.37546265e-01 7.14282434e-01 1.23145372e+00 1.74862501e+00 2.26579629e+00 2.78296758e+00 3.30013887e+00 3.81731015e+00 4.33448144e+00 4.85165273e+00 5.36882401e+00 5.88599530e+00 6.40316659e+00 6.92033787e+00 7.43750916e+00 7.95468045e+00 8.47185173e+00 9.25832855e+00 1.00000000e+01] ``` -------------------------------- ### Build Source and Wheel Distributions Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Run this command from the install directory to create source and wheel distributions. Execute this for each required Python version. ```bash python3x setup.py sdist bdist_wheel ``` -------------------------------- ### Install Tellurium using absolute path Source: https://github.com/sys-bio/tellurium/blob/develop/README.md Alternative installation command for Mac OS X if the standard pip command fails. ```bash /Users//opt/anaconda3/bin/pip install tellurium ``` -------------------------------- ### Simulation Output Example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/roadrunnerBasics.md Example output from a simulation, showing time and the concentrations of species S1 and S2. The output format is a list of lists, with the first column being time. ```default time, [S1], [S2] [[ 0, 10, 0], [ 2, 1.23775, 8.76225], [ 4, 0.253289, 9.74671], [ 6, 0.0444091, 9.95559], [ 8, 0.00950381, 9.9905], [ 10, 0.00207671, 9.99792]] ``` -------------------------------- ### Steady State Output Example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/computeSteadyState.md The output format for steady-state values. ```default [S1] = 0.17857142857142858 [S2] = 4.5150957559317066e-35 ``` -------------------------------- ### Install IRkernel for R Source: https://github.com/sys-bio/tellurium/blob/develop/docs/walkthrough.md Commands to install the necessary R packages and the IRkernel for use within Tellurium. ```r install.packages('devtools') install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest')) devtools::install_github('IRkernel/IRkernel') ``` -------------------------------- ### Configure Python package distribution with setuptools Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Defines a custom BinaryDistribution class and uses setup() to package the LibSEDML Python API. ```python from setuptools import setup, Distribution class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" def has_ext_modules(foo): return True setup(name = "tesedml", version = "0.4.5.0", description = "LibSEDML Python API", long_description = ("libSEDML is a library for reading, writing and "+ "manipulating SEDML. It is written in ISO C and C++, supports SEDML "+ "Levels 1, Version 1-3, and runs on Linux, Microsoft Windows, and Apple "+ "MacOS X. For more information about SEDML, please see http://sed-ml.org/."), classifiers=[ 'Intended Audience :: Science/Research', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: C++', ], license = "LGPL", author = "Frank T. Bergmann, J Kyle Medley (packaging)", url = "http://sed-ml.org/", packages = ["tesedml"], package_dir = {'tesedml': 'libsedml'}, package_data = {'tesedml': ['*.so*', '*.pyd', '*.dll', '*.dylib*']}, distclass=BinaryDistribution, ) ``` -------------------------------- ### Install Tellurium in Development Mode Source: https://github.com/sys-bio/tellurium/blob/develop/CONTRIBUTING.rst Install your local copy of Tellurium in editable mode. This allows changes to be reflected immediately without reinstallation. ```bash (tellurium)$ pip install -e . ``` -------------------------------- ### Install Package from TestPyPI Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Install a package from TestPyPI using pip. This allows you to test your uploaded package in a staging environment. ```bash /path/to/python -m pip install --upgrade --index-url https://test.pypi.org/simple PACKAGENAME ``` -------------------------------- ### Full Antimony Layout Example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/antimony.md An example of a complete Antimony layout definition, including model definition, autolayout settings, and detailed positioning for elements and reaction arcs. ```antimony J0: 2 S1 -> S2; ; S3 -| J0; ; model.layout = on model.layout.size = {464.48, 460.35} // Individual element layout information S1.position = {374.48, 394.35} S2.position = {286.19, 30} S3.position = {30, 318.49} J0.position = {245.06, 262.71} J0.S1.species_end = {373.71, 391.49} J0.S1.b1 = {262.59, 280.54} J0.S1.b2 = {311.8, 369.76} J0.S1.arc2.species_end = {367.84, 418.65} J0.S1.arc2.b1 = {262.59, 280.54} J0.S1.arc2.b2 = {302.49, 412.92} J0.S2.species_end = {311.57, 74.96} J0.S2.b1 = {227.53, 244.88} J0.S2.b2 = {304.63, 115.41} J0.S3.species_end = {99.01, 331.65} J0.S3.rxn_end = {231.12, 268.26} J0.S3.b1 = {157.51, 324.39} J0.S3.b2 = {226.48, 270.12} ``` -------------------------------- ### Integrator Output Examples Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/roadrunnerBasics.md Displays the output of printing the integrator state and simulation time values. ```default The current integrator is: < roadrunner.Integrator() > name: cvode settings: relative_tolerance: 0.000001 absolute_tolerance: 0.000000000001 stiff: true maximum_bdf_order: 5 maximum_adams_order: 12 maximum_num_steps: 20000 maximum_time_step: 0 minimum_time_step: 0 initial_time_step: 0 multiple_steps: false variable_step_size: false ``` ```default Time values: [0.00000000e+00 3.43225906e-07 3.43260229e-03 3.77551929e-02 7.20777836e-02 1.60810095e-01 4.37546265e-01 7.14282434e-01 1.23145372e+00 1.74862501e+00 2.26579629e+00 2.78296758e+00 3.30013887e+00 3.81731015e+00 4.33448144e+00 4.85165273e+00 5.36882401e+00 5.88599530e+00 6.40316659e+00 6.92033787e+00 7.43750916e+00 7.95468045e+00 8.47185173e+00 9.25832855e+00 1.00000000e+01] ``` -------------------------------- ### Ship File to Cluster with Fabric Source: https://github.com/sys-bio/tellurium/wiki/Livy-Instructions Example of how to specify a file to be shipped to the cluster when using a Fabric-based wrapper. Prefix the filename with 'file:'. ```python SBML = "file:huang-ferrell-96.xml" ``` -------------------------------- ### Plotting Output Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tellurium_plotting.md This is the output from the 'Plotting multiple simulations' example, showing the reference simulation and parameter variation. ```default Reference Simulation: k1 = 1.5 Parameter variation: k1 = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 1.1 1.2 1.3 1.4 1.5] ``` -------------------------------- ### Get Initial Model as SBML String Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/core/tellurium_export.ipynb Retrieves the SBML representation of the initial model state (when loaded) as a string. ```python str_sbml = r.getSBML() print(str_sbml) ``` -------------------------------- ### Python setup.py for libcombine Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Template for creating a setup.py file to package libcombine as a Python module. ```python #! /usr/bin/env python from setuptools import setup, Distribution class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" def has_ext_modules(foo): return True setup(name='tecombine', version='0.2.7', description='A library for working with COMBINE archives', classifiers=[ 'Intended Audience :: Science/Research', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: C++', ], author='Frank Bergmann, Kyle Medley (packaging)', url='https://github.com/sbmlteam/libCombine', packages=['tecombine'], package_dir={'tecombine': 'libcombine'}, package_data={'tecombine': ['*.so*','*.dylib*','*.pyd','lib*','*.dll']}, distclass=BinaryDistribution, ) ``` -------------------------------- ### Python setup.py for sbml2matlab Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Template for creating a setup.py file to package sbml2matlab as a Python module. ```python #!/usr/bin/env python from setuptools import setup, Distribution class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" def has_ext_modules(foo): return True setup(name='sbml2matlab', version='0.9.1', description='An SBML to MATLAB translator', author='Stanley Gu, Lucian Smith', url='https://github.com/sys-bio/sbml2matlab', packages=['sbml2matlab'], package_data={ "sbml2matlab": ["_sbml2matlab.pyd", "*.dll", "*.txt", "*.lib", "*.so*", "*.dylib*"] }, distclass=BinaryDistribution, ) ``` -------------------------------- ### Get Tellurium Version Info Source: https://github.com/sys-bio/tellurium/blob/develop/README.md Call this function to retrieve version information for Tellurium and its dependencies. Useful for debugging or verifying installation. ```python te.getVersionInfo() ``` -------------------------------- ### Launching JupyterLab from Tellurium Spyder Source: https://github.com/sys-bio/tellurium/blob/develop/docs/walkthrough.md Launch JupyterLab via the Start Menu ('Tellurium Winpython' -> 'Launch JupyterLab') or by running 'Jupyter Lab.exe' in the installation directory. ```Shell Jupyter Lab.exe ``` -------------------------------- ### Launching Jupyter Notebook from Tellurium Spyder Source: https://github.com/sys-bio/tellurium/blob/develop/docs/walkthrough.md Launch Jupyter Notebook via the Start Menu ('Tellurium Winpython' -> 'Launch Jupyter Notebook') or by running 'Jupyter Notebook.exe' in the installation directory. ```Shell Jupyter Notebook.exe ``` -------------------------------- ### Initialize Tellurium Plotting Engine Source: https://github.com/sys-bio/tellurium/blob/develop/docs/notebooks.md This Python code snippet initializes Tellurium's default plotting engine to matplotlib and suppresses warnings. This setup is often used before running examples that involve plotting or visualization. ```python import warnings warnings.filterwarnings("ignore") import tellurium as te te.setDefaultPlottingEngine('matplotlib') ``` -------------------------------- ### libnuml setup.py Template Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels A Python setup.py script for packaging the libnuml library. It defines a custom Distribution class to ensure a binary package is created and specifies package details. ```python #! /usr/bin/env python from setuptools import setup, Distribution class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" def has_ext_modules(foo): return True setup(name='tenuml', version='1.1.1.2', description='Library for reading/writing data in COMBINE archives', classifiers=[ 'Intended Audience :: Science/Research', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: C++', ], author='Frank Bergmann, Kyle Medley (packaging)', url='https://github.com/NuML/NuML', packages=['tenuml'], package_dir= {'tenuml': 'libnuml'}, package_data={'tenuml': ['*.so*','*.dylib*','*.pyd','lib*','*.dll']}, distclass=BinaryDistribution, ) ``` -------------------------------- ### Install Tellurium in Google Colab Source: https://github.com/sys-bio/tellurium/blob/develop/README.md Use this command to install the tellurium package in a Google Colab environment. A runtime restart is required after installation. ```bash !pip install -q tellurium ``` -------------------------------- ### Install pygraphviz with custom paths Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tellurium_examples.md Use this command to install pygraphviz when Graphviz is installed in a non-standard location. Adjust include and library paths as necessary for your system. ```bash /path/to/python3 -m pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib64/graphviz/" ``` ```bash /path/to/python3 -m pip install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/" ``` -------------------------------- ### Install Tellurium using pip Source: https://github.com/sys-bio/tellurium/wiki/FAQ After installing Anaconda and Python, use this command to install Tellurium as a package. It is recommended to manage Tellurium and its dependencies within a separate conda environment. ```bash pip install tellurium ``` -------------------------------- ### Create setup.py for tesbml Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels This script defines the Python distribution package for libSBML, forcing a binary package structure. ```python ## @file setup.py ## @brief Python distutils code for libSBML Python module ## @author Michael Hucka ## @author Ben Bornstein ## @author Ben Kovitz ## @author Frank Bergmann (fbergman@caltech.edu) ## @author J Kyle Medley ## @author Lucian Smith ## ##*/ from setuptools import setup, Distribution class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" def has_ext_modules(foo): return True setup(name = "tesbml", version = "5.18.1", description = "LibSBML Python API", long_description = ("LibSBML is a library for reading, writing and "+ "manipulating the Systems Biology Markup Language "+ "(SBML). It is written in ISO C and C++, supports "+ "SBML Levels 1, 2 and 3, and runs on Linux, Microsoft "+ "Windows, and Apple MacOS X. For more information "+ "about SBML, please see http://sbml.org."), classifiers=[ 'Intended Audience :: Science/Research', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: C++', ], license = "LGPL", author = "SBML Team", author_email = "libsbml-team@googlegroups.com", url = "http://sbml.org", packages = ["tesbml"], package_dir = {'tesbml': 'libsbml'}, package_data = {'tesbml': ['*.so*', '*.dll', '*.dylib*', '*.pyd']}, distclass=BinaryDistribution, ) ``` -------------------------------- ### Load and Simulate a Model in Tellurium Source: https://github.com/sys-bio/tellurium/blob/develop/README.md This example demonstrates loading a simple reaction model, setting a parameter, simulating the model, and plotting the results. Ensure Tellurium is imported and the model string is correctly formatted. ```python r = te.loada ('S1 -> S2; k1*S1; k1 = 0.1; S1 = 10'); r.simulate(); r.plot() ``` -------------------------------- ### Simulate and Export Model State in Python Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/antimonyExample.md Demonstrates loading an Antimony model, running simulations with different stepping configurations, and comparing the model state before and after simulation. ```python import tellurium as te print('-' * 80) te.printVersionInfo() print('-' * 80) r = te.loada(''' model example p1 = 0; at time>=10: p1=10; at time>=20: p1=0; end ''') # convert current state of model back to Antimony / SBML ant_str_before = r.getCurrentAntimony() sbml_str_before = r.getCurrentSBML() # r.exportToSBML('/path/to/test.xml') # set selections r.selections=['time', 'p1'] r.integrator.setValue("variable_step_size", False) r.resetAll() s1 = r.simulate(0, 40, 40) r.plot() # hitting the trigger point directly works r.resetAll() s2 = r.simulate(0, 40, 21) r.plot() # variable step size also does not work r.integrator.setValue("variable_step_size", True) r.resetAll() s3 = r.simulate(0, 40) r.plot() # convert current state of model back to Antimony / SBML ant_str_after = r.getCurrentAntimony() sbml_str_after = r.getCurrentSBML() import difflib print("Comparing Antimony at time 0 & 40 (expect no differences)") print('\n'.join(list(difflib.unified_diff(ant_str_before.splitlines(), ant_str_after.splitlines(), fromfile="before.sb", tofile="after.sb")))) # now simulate up to time 15 r.resetAll() s4 = r.simulate(0, 15) r.plot() # convert current state of model back to Antimony / SBML ant_str_after2 = r.getCurrentAntimony() sbml_str_after2 = r.getCurrentSBML() print("Comparing Antimony at time 0 & 15") print('\n'.join(list(difflib.unified_diff(ant_str_before.splitlines(), ant_str_after2.splitlines(), fromfile="before.sb", tofile="after.sb")))) ``` -------------------------------- ### File Helpers for Reading and Writing Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/core/tellurium_utility.ipynb This example shows how to use `te.saveToFile()` and `r.exportToMatlab()` to save model states to a file, and `te.readFromFile()` to load them back. Temporary files are used for demonstration. ```python import tellurium as te # create tmp file import tempfile ftmp = tempfile.NamedTemporaryFile(suffix=".xml") # load model r = te.loada('S1 -> S2; k1*S1; k1 = 0.1; S1 = 10') # save to file te.saveToFile(ftmp.name, r.getMatlab()) # or easier via r.exportToMatlab(ftmp.name) # load file matlabstr = te.readFromFile(ftmp.name) print('%' + '*'*80) print('Converted MATLAB code') print('%' + '*'*80) print(matlabstr[1531:2000]) print('...') ``` -------------------------------- ### Install msgpack-python via Conda Source: https://github.com/sys-bio/tellurium/blob/develop/README.md Required dependency installation for Mac OS X users using Anaconda. ```bash conda install msgpack-python ``` -------------------------------- ### Initialize Reaction Components Source: https://github.com/sys-bio/tellurium/blob/develop/docs/antimony.md Set initial conditions and parameter values for a reaction to make the model simulatable. ```antimony S1 -> S2; k1*S1 S1 = 10 S2 = 0 k1 = 0.1 ``` -------------------------------- ### Install stable Tellurium via pip Source: https://github.com/sys-bio/tellurium/blob/develop/VirtualEnv.md Use this command to install the stable version of Tellurium within a virtual environment. ```bash mkvirtualenv tellurium (tellurium) pip install tellurium ``` -------------------------------- ### Switch Integrators and Set Parameters Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/roadrunnerBasics.md Demonstrates how to switch between different simulation integrators and set their specific parameters. ```python # set integrator to Gillespie solver r.setIntegrator('gillespie') # identical ways to set integrator r.setIntegrator('rk4') r.integrator = 'rk4' # set back to cvode (the default) r.setIntegrator('cvode') # set integrator settings r.integrator.setValue('variable_step_size', False) r.integrator.setValue('stiff', True) ``` -------------------------------- ### Initialize and Configure ParameterScan Source: https://github.com/sys-bio/tellurium/blob/develop/docs/paramscan.md Import the package, load an Antimony model, and configure simulation parameters before generating a plot. ```python import tellurium as te from tellurium import ParameterScan cell = ''' $Xo -> S1; vo; S1 -> S2; k1*S1 - k2*S2; S2 -> $X1; k3*S2; vo = 1 k1 = 2; k2 = 0; k3 = 3; ''' rr = te.loadAntimonyModel(cell) p = ParameterScan(rr) p.startTime = 0 p.endTime = 20 p.numberOfPoints = 50 p.width = 2 p.xlabel = 'Time' p.ylabel = 'Concentration' p.title = 'Cell' p.plotArray() ``` -------------------------------- ### Install Tellurium using pip Source: https://github.com/sys-bio/tellurium/blob/develop/docs/installation.md Use this command to install Tellurium as a collection of pip packages. This is a standard method for Mac, Linux, and Windows. ```bash $ pip install tellurium ``` -------------------------------- ### Implement Forcing Functions with Tellurium Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/core/phrasedmlExample.ipynb This example demonstrates creating a COMBINE archive with complex forcing functions using Antimony and PhraSEDML, including piecewise and custom functions. It shows how to export and then execute the archive. ```python import tellurium as te antimony_str = ''' // Created by libAntimony v2.9 model *oneStep() // Compartments and Species: compartment compartment_; species S1 in compartment_, S2 in compartment_, $X0 in compartment_, $X1 in compartment_; species $X2 in compartment_; // Reactions: J0: $X0 => S1; J0_v0; J1: S1 => $X1; J1_k3*S1; J2: S1 => S2; (J2_k1*S1 - J2_k_1*S2)*(1 + J2_c*S2^J2_q); J3: S2 => $X2; J3_k2*S2; // Species initializations: S1 = 0; S2 = 1; X0 = 1; X1 = 0; X2 = 0; // Compartment initializations: compartment_ = 1; // Variable initializations: J0_v0 = 8; J1_k3 = 0; J2_k1 = 1; J2_k_1 = 0; J2_c = 1; J2_q = 3; J3_k2 = 5; // Other declarations: const compartment_, J0_v0, J1_k3, J2_k1, J2_k_1, J2_c, J2_q, J3_k2; end ''' phrasedml_str = ''' model1 = model "oneStep" stepper = simulate onestep(0.1) task0 = run stepper on model1 task1 = repeat task0 for local.x in uniform(0, 10, 100), J0_v0 = piecewise(8, x<4, 0.1, 4<=x<6, 8) task2 = repeat task0 for local.index in uniform(0, 10, 1000), local.current = index -> abs(sin(1 / (0.1 * index + 0.1))), model1.J0_v0 = current : current plot "Forcing Function (Pulse)" task1.time vs task1.S1, task1.S2, task1.J0_v0 plot "Forcing Function (Custom)" task2.time vs task2.S1, task2.S2, task2.J0_v0 ''' # create the inline OMEX string inline_omex = '\n'.join([antimony_str, phrasedml_str]) # export to a COMBINE archive workingDir = tempfile.mkdtemp(suffix="_omex") archive_name = os.path.join(workingDir, 'archive.omex') te.exportInlineOmex(inline_omex, archive_name) # convert the COMBINE archive back into an # inline OMEX (transparently) and execute it te.convertAndExecuteCombineArchive(archive_name) ``` -------------------------------- ### Perform Minimal Documentation Build Source: https://github.com/sys-bio/tellurium/blob/develop/docs/README.md Command to rebuild HTML documentation locally after modifying .rst files. ```bash make html && firefox _build/html/index.html ``` -------------------------------- ### Load SBML Model and Run Steady-State Analysis Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/models/phrasedml.ipynb Loads an SBML file, configures the integrator and steady-state selections, and executes the steady-state calculation. ```python from __future__ import print_function, division import tellurium as te import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d import libsedml import pandas import os.path workingDir = '/home/mkoenig/git/tellurium/tellurium/tests/testdata/sedml/sed-ml' # -------------------------------------------------------- # Models # -------------------------------------------------------- # - model1 # Model model1 = te.loadSBMLModel(os.path.join(workingDir, '../models/BorisEJB.xml')) # -------------------------------------------------------- # Tasks # -------------------------------------------------------- # - task1 # Task task1 = [None] model1.setIntegrator('cvode') Config = model1 model1.conservedMoietyAnalysis = True model1.steadyStateSelections = ['[MKKK]', '[MKKK_P]', '[MAPK]', '[MAPK_PP]', '[MKK_P]', '[MAPK_P]', 'time', '[MKK]'] print(model1.selections) print(model1.steadyStateSelections) task1[0] = model1.steadyState() print(task1) model1.conservedMoietyAnalysis = False ``` -------------------------------- ### Get Tellurium Version Information Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tellurium_utility.md Use `te.__version__` or `te.getTelluriumVersion()` to get the Tellurium version. `te.printVersionInfo()` displays detailed version information for Tellurium and its constituent packages. ```python import tellurium as te # to get the tellurium version use print('te.__version__') print(te.__version__) # or print('te.getTelluriumVersion()') print(te.getTelluriumVersion()) # to print the full version info use print('-' * 80) te.printVersionInfo() print('-' * 80) ``` ```default te.__version__ 2.1.0 te.getTelluriumVersion() 2.1.0 -------------------------------------------------------------------------------- tellurium : 2.1.0 roadrunner : 1.5.1 antimony : 2.9.4 libsbml : 5.15.0 libsedml : 0.4.3 phrasedml : 1.0.9 -------------------------------------------------------------------------------- ``` -------------------------------- ### Load Models with Tellurium and libRoadrunner Source: https://github.com/sys-bio/tellurium/blob/develop/docs/tellurium_methods.md Demonstrates loading Antimony models using libRoadrunner directly or via Tellurium shortcuts. ```python 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 using 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 using tellurium ---') r = te.loada(ant_model) result = r.simulate (0, 10, 100) r.plot(result) # same like r = te.loadAntimonyModel(ant_model) ``` -------------------------------- ### Load SBML Model and Run Simulations Source: https://github.com/sys-bio/tellurium/blob/develop/tellurium/dev/oven/archive_plots.ipynb Loads an SBML model and sets up tasks for steady-state simulations with varying parameters. This is useful for parameter scans and sensitivity analysis. ```python import tellurium as te from roadrunner import Config from tellurium.sedml.mathml import * # from tellurium.sedml.tesedml import process_trace, terminate_trace, fix_endpoints import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d try: import libsedml except ImportError: import tesedml as libsedml import pandas import os.path Config.LOADSBMLOPTIONS_RECOMPILE = True workingDir = r'/tmp/tmp28bgsq9i' # -------------------------------------------------------- # Models # -------------------------------------------------------- # Model model1 = te.loadSBMLModel(os.path.join(workingDir, 'BorisEJB.xml')) # -------------------------------------------------------- # Tasks # -------------------------------------------------------- # Task # not part of any DataGenerator: task0 # Task task1 = [] __range__current = [1.0, 5.0, 10.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0] for __k__current, __value__current in enumerate(__range__current): if __k__current == 0: model1.reset() task2 = [] __range__current1 = np.linspace(start=1.0, stop=40.0, num=101) for __k__current1, __value__current1 in enumerate(__range__current1): if __k__current1 == 0: model1.reset() # Task: task0 = [None] model1.setSteadyStateSolver('nleq') if model1.conservedMoietyAnalysis == False: model1.conservedMoietyAnalysis = True model1['J1_KK2'] = __value__current model1['J4_KK5'] = __value__current1 model1.steadyStateSelections = ['J1_KK2', 'J4_KK5', '[MKK]', '[MKK_PP]', '[MKK_P]'] model1.simulate() task0[0] = model1.steadyStateNamedArray() task2.extend(task0) task1.extend(task2) # Task # not part of any DataGenerator: task2 #################################################################################################### ``` -------------------------------- ### Install pyopengl on Anaconda Source: https://github.com/sys-bio/tellurium/wiki/FAQ If Spyder IDE crashes with a segmentation fault when using Tellurium on Anaconda, try installing the 'pyopengl' package using this command. This may resolve compatibility issues. ```bash conda install pyopengl ``` -------------------------------- ### Install cobrapy package in Tellurium Source: https://github.com/sys-bio/tellurium/wiki/FAQ Use this Python code to install the cobrapy package within Tellurium. This is necessary for constraint-based modeling as Tellurium does not natively support it. The Windows version of Tellurium comes with cobrapy pre-installed. ```python import tellurium as te te.installPackage('cobra') ``` ```python import cobra ``` -------------------------------- ### Python __init__.py Boilerplate Source: https://github.com/sys-bio/tellurium/wiki/Building-Binary-Wheels Use this __init__.py file in your library's Python bindings directory. Replace LIBRARY with the actual library name and VERSION with its version string. ```python from .LIBRARY import * __version__ = 'VERSION' ``` -------------------------------- ### Load and Initialize a Model Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/docstrings/docstring_examples.ipynb Loads a simple reaction model from an Antimony string and initializes its parameters. ```python r = te.loada('S1 -> S2; k1*S1; k1 = 0.1; S2 = 10') ``` -------------------------------- ### Simulation Data Output Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/antimonyExample.md Example output of the simulation data table. ```default time, p1 [[ 0, 0], [ 0.000514839, 0], [ 5.1489, 0], [ 10, 0], [ 10, 10], [ 10.0002, 10], [ 12.2588, 10], [ 15, 10]] ``` -------------------------------- ### Register IRkernel Source: https://github.com/sys-bio/tellurium/blob/develop/docs/walkthrough.md Registers the installed IRkernel so it can be discovered by the Tellurium notebook application. ```r IRkernel::installspec() ``` -------------------------------- ### Mixed declaration example Source: https://github.com/sys-bio/tellurium/blob/develop/docs/antimony.md Combine species and formula declarations with mutability keywords. ```default species S1, S2, S3, S4; formula k1, k2, k3, k4; const S1, S4, k1, k3; var S2, S3, k2, k4; ``` -------------------------------- ### Get MATLAB String Representation Source: https://github.com/sys-bio/tellurium/blob/develop/examples/notebooks/core/tellurium_export.ipynb Retrieves the MATLAB string representation of the model. ```python str_matlab = r.getMatlab() print(str_matlab) ``` -------------------------------- ### Load and inspect test models Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tellurium_test.md Demonstrates how to load a test model, retrieve its SBML content, and convert it to Antimony format for inspection. ```ipython2 # To load one of the test models use loadTestModel: # r = te.loadTestModel('feedback.xml') # result = r.simulate (0, 10, 100) # r.plot (result) # If you need to obtain the SBML for the test model, use getTestModel sbml = te.getTestModel('feedback.xml') # To look at one of the test model in Antimony form: ant = te.sbmlToAntimony(te.getTestModel('feedback.xml')) print(ant) ``` -------------------------------- ### Execute SED-ML and Read with libSEDML Source: https://github.com/sys-bio/tellurium/blob/develop/docs/_notebooks/core/tesedmlExample.md Demonstrates writing SBML/SED-ML to temporary files, reading them with libSEDML, and executing the simulation via Tellurium. ```python import tempfile, os, shutil workingDir = tempfile.mkdtemp(suffix="_sedml") sbml_file = os.path.join(workingDir, 'myModel') sedml_file = os.path.join(workingDir, 'sed_main.xml') with open(sbml_file, 'wb') as f: f.write(sbml_str.encode('utf-8')) f.flush() print('SBML written to temporary file') with open(sedml_file, 'wb') as f: f.write(sedml_str.encode('utf-8')) f.flush() print('SED-ML written to temporary file') # For technical reasons, any software which uses libSEDML # must provide a custom build - Tellurium uses tesedml try: import libsedml except ImportError: import tesedml as libsedml sedml_doc = libsedml.readSedML(sedml_file) n_errors = sedml_doc.getErrorLog().getNumFailsWithSeverity(libsedml.LIBSEDML_SEV_ERROR) print('Read SED-ML file, number of errors: {}'.format(n_errors)) if n_errors > 0: print(sedml_doc.getErrorLog().toString()) # execute SED-ML using Tellurium te.executeSEDML(sedml_str, workingDir=workingDir) # clean up #shutil.rmtree(workingDir) ```