Module Expr Str Import alias Import alias Import alias Import alias TryExcept body ImportFrom alias handlers ExceptHandler type NameLoad body ImportFrom alias ImportFrom alias alias ImportFrom alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpAdd BinOpAdd Str AttributeLoad NameLoad attr Str orelse Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd BinOpAdd Str AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Assign NameStore Str For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Str If CompareEq AttributeLoad NameLoad attr Num body AugAssignAdd NameStore BinOpMod Str TupleLoad NameLoad AttributeLoad NameLoad attr orelse Assign NameStore BinOpMod Str AttributeLoad NameLoad attr If CompareIn Str NameLoad body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Str AugAssignAdd NameStore BinOpMod Str TupleLoad NameLoad NameLoad NameLoad orelse AugAssignAdd NameStore BinOpMod Str TupleLoad NameLoad NameLoad Assign NameStore Str AugAssignAdd NameStore Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad AttributeLoad NameLoad attr attr Index NameLoad comprehension NameStore Call NameLoad Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad NameLoad attr Str Lambda arguments args NameParam defaults BinOpMod Str Call NameLoad Call AttributeLoad NameLoad attr Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Str NameLoad AugAssignAdd NameStore Str For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Str Str NameLoad Assign NameStore BinOpMult ListLoad Str Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign SubscriptStore NameLoad Index Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index Num Call AttributeLoad AttributeLoad SubscriptLoad NameLoad Index Num attr attr Str Str Assign NameStore Str AugAssignAdd NameStore Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad AugAssignAdd NameStore Str Assign NameStore Str AugAssignAdd NameStore Call AttributeLoad Str attr ListComp BinOpMod Str NameLoad comprehension NameStore Call NameLoad Num Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr AugAssignAdd NameStore Str Assign NameStore Str For NameStore AttributeLoad AttributeLoad NameLoad attr attr body AugAssignAdd NameStore BinOpAdd Call AttributeLoad AttributeLoad NameLoad attr attr Str Str Str AugAssignAdd NameStore Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AugAssignAdd NameStore Str Assign NameStore Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Return Call AttributeLoad NameLoad attr decorator_list decorator_list
N/A N/A 
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 :py:mod:`pysb.export`.

Output for the Robertson example model
======================================

The Mathematica code produced will follow the form as given below for
``pysb.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] == -k1*s0[t] + k3*s1[t]*s2[t],
    s1'[t] == k1*s0[t] - k2*s1[t]^2 - k3*s1[t]*s2[t],
    s2'[t] == k2*s1[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:

* The header comments identify the model and show an example of how to
  integrate the ODEs in Mathematica.
* The parameters block defines the numerical values of the named parameters.
* The list of species gives the mapping between the indexed species (``s0``,
  ``s1``, ``s2``) and their representation in PySB (``A()``, ``B()``, ``C()``).
* The ODEs block defines the set of ordinary differential equations and assigns
  the set of equations to the variable ``odes``.
* The initial conditions block defines the initial values for each species and
  assigns the set of conditions to the variable ``initconds``.
* The "list of variables" block enumerates all of the species in the model
  (``s0[t]``, ``s1[t]``, ``s2[t]``) and assigns them to the variable
  ``solvelist``; this list can be passed to the Mathematica command ``NDSolve``
  to indicate the variables to be solved for.
* This is followed by an example of how to call ``NDSolve`` to integrate the
  equations.
* Finally, the observables block enumerates the observables in the model,
  expressing each one as a linear combination of the appropriate species in
  the model. The interpolating functions returned by ``NDSolve`` are substituted
  in from the solution variable ``soln``, allowing the observables to be
  plotted.

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``).
 N/A pysb N/A pysb.bng N/A sympy N/A re N/A N/A cStringIO StringIO N/A N/A N/A ImportError N/A io StringIO math floor log pysb.export Exporter MathematicaExporter N/A Exporter N/A N/A A class for returning the ODEs for a given PySB model for use in
    Mathematica.

    Inherits from :py:class:`pysb.export.Exporter`, which implements
    basic functionality for all exporters.
     export N/A N/A self N/A N/A N/A 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.
         N/A output N/A StringIO N/A N/A N/A N/A pysb bng generate_equations N/A self model N/A N/A self docstring N/A N/A N/A N/A output write N/A N/A (*
 N/A self docstring N/A N/A N/A N/A output write (*
 N/A N/A N/A output write Mathematica model definition file for  N/A N/A N/A output write N/A N/A model  N/A N/A self model name .
 N/A N/A N/A output write Generated by pysb.export.mathematica.MathematicaExporter.
 N/A N/A N/A output write N/A N/A N/A output write Run with (for example):
 N/A N/A N/A output write tmax = 10
 N/A N/A N/A output write soln = NDSolve[Join[odes, initconds], slist, {t, 0, tmax}]
 N/A N/A N/A output write Plot[s0[t] /. soln, {t, 0, tmax}, PlotRange -> All]
 N/A N/A N/A output write *)

 N/A params_str N/A N/A i p N/A enumerate N/A N/A self model parameters N/A N/A pname N/A N/A N/A p name replace _ N/A N/A N/A p value 0 N/A N/A params_str N/A %s = %g;
 N/A pname N/A p value N/A N/A val_str N/A %.17g N/A p value N/A N/A e val_str N/A N/A N/A mantissa exponent N/A N/A val_str split e N/A params_str N/A %s = %s * 10^%s;
 N/A pname mantissa exponent N/A N/A params_str N/A %s = %s;
 N/A pname val_str N/A odes_str odes = {
 N/A odes_str N/A N/A ,
 join N/A N/A s%d == %s N/A i N/A N/A sympy ccode N/A N/A N/A self model odes N/A i N/A i N/A range N/A len N/A N/A self model odes N/A odes_str N/A N/A re sub s(\d+) N/A N/A N/A m N/A N/A s%s[t] N/A int N/A N/A m group 1 odes_str N/A odes_str N/A N/A re sub s(\d+)\[t\] == s\1'[t] == odes_str N/A odes_str N/A N/A re sub pow\(([^,]+), ([^)]+)\) \1^\2 odes_str N/A odes_str 
} N/A N/A i p N/A enumerate N/A N/A self model parameters N/A N/A odes_str N/A N/A re sub N/A \b(%s)\b N/A p name N/A N/A N/A p name replace _ odes_str N/A ic_values N/A N/A 0 N/A len N/A N/A self model odes N/A N/A i ic N/A enumerate N/A N/A self model initial_conditions N/A N/A N/A ic_values N/A N/A N/A N/A self model get_species_index N/A ic N/A 0 N/A N/A N/A N/A ic N/A 1 name replace _ N/A init_conds_str initconds = {
 N/A init_conds_str N/A N/A ,
 join N/A N/A s%s[0] == %s N/A i val N/A N/A i val N/A enumerate ic_values N/A init_conds_str 
} N/A solvelist_str solvelist = {
 N/A solvelist_str N/A N/A ,
 join N/A N/A s%s[t] i N/A i N/A range 0 N/A len N/A N/A self model odes N/A solvelist_str 
} N/A observables_str N/A obs N/A N/A self model observables N/A N/A observables_str N/A N/A N/A N/A obs name replace _  =  N/A observables_str N/A N/A  +  join N/A N/A (s%s[t] * %d) N/A s c N/A N/A s c N/A zip N/A obs species N/A obs coefficients N/A observables_str  /. soln
 N/A species_str N/A N/A join N/A N/A (* s%d[t] = %s *) N/A i s N/A N/A i s N/A enumerate N/A N/A self model species N/A N/A N/A output write (* Parameters *)
 N/A N/A N/A output write N/A params_str N/A N/A N/A output write (* List of Species *)
 N/A N/A N/A output write N/A species_str N/A N/A N/A output write (* ODEs *)
 N/A N/A N/A output write N/A odes_str N/A N/A N/A output write (* Initial Conditions *)
 N/A N/A N/A output write N/A init_conds_str N/A N/A N/A output write (* List of Variables (e.g., as an argument to NDSolve) *)
 N/A N/A N/A output write N/A solvelist_str N/A N/A N/A output write (* Run the simulation -- example *)
 N/A N/A N/A output write tmax = 100
 N/A N/A N/A output write soln = NDSolve[Join[odes, initconds], solvelist, {t, 0, tmax}]

 N/A N/A N/A output write (* Observables *)
 N/A N/A N/A output write N/A observables_str N/A N/A N/A output getvalue N/A N/A