Export ODEs to Mathematica (pysb.export.mathematica) — PySB 1.16.0+24.g12213c1 documentation (original) (raw)

Module containing a class for converting a PySB model to a set of ordinary differential equations for integration or analysis in Mathematica.

For information on how to use the model exporters, see the documentation for pysb.export.

Output for the Robertson example model

The Mathematica code produced will follow the form as given below forpysb.examples.robertson:

(* A simple three-species chemical kinetics system known as "Robertson's example", as presented in:

H. H. Robertson, The solution of a set of reaction rate equations, in Numerical Analysis: An Introduction, J. Walsh, ed., Academic Press, 1966, pp. 178-182.

Mathematica model definition file for model robertson. Generated by pysb.export.mathematica.MathematicaExporter.

Run with (for example): tmax = 10 soln = NDSolve[Join[odes, initconds], slist, {t, 0, tmax}] Plot[s0[t] /. soln, {t, 0, tmax}, PlotRange -> All] *)

(* Parameters *) k1 = 0.040000000000000001; k2 = 30000000; k3 = 10000; A0 = 1; B0 = 0; C0 = 0;

(* List of Species ) ( s0[t] = A() ) ( s1[t] = B() ) ( s2[t] = C() *)

(* ODEs ) odes = { s0'[t] == -k1s0[t] + k3s1[t]s2[t], s1'[t] == k1s0[t] - k2s1[t]^2 - k3*s1[t]s2[t], s2'[t] == k2s1[t]^2 }

(* Initial Conditions *) initconds = { s0[0] == A0, s1[0] == B0, s2[0] == C0 }

(* List of Variables (e.g., as an argument to NDSolve) *) solvelist = { s0[t], s1[t], s2[t] }

(* Run the simulation -- example *) tmax = 100 soln = NDSolve[Join[odes, initconds], solvelist, {t, 0, tmax}]

(* Observables *) Atotal = (s0[t] * 1) /. soln Btotal = (s1[t] * 1) /. soln Ctotal = (s2[t] * 1) /. soln

The output consists of a block of commands that define the ODEs, parameters, species and other variables for the model, along with a set of descriptive comments. The sections are as follows:

Note that Mathematica does not permit underscores in variable names, so any underscores used in PySB variables will be removed (e.g., A_total will be converted to Atotal).

class pysb.export.mathematica.MathematicaExporter(model, docstring=None)[source]

A class for returning the ODEs for a given PySB model for use in Mathematica.

Inherits from pysb.export.Exporter, which implements basic functionality for all exporters.

export()[source]

Generate the corresponding Mathematica ODEs for the PySB model associated with the exporter.

Returns:

string

String containing the Mathematica code for the model’s ODEs.