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 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 Assign NameStore Str If AttributeLoad NameLoad attr body AugAssignAdd NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Str Assign NameStore Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr Str Str Assign NameStore BinOpAdd Str BinOpMult Str Num Assign NameStore ListLoad For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore BinOpMod Str TupleLoad Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr If CompareEq NameLoad BinOpSub Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Num body AugAssignAdd NameStore Str orelse AugAssignAdd NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad AugAssignAdd NameStore Call AttributeLoad BinOpAdd Str BinOpMult Str Num attr NameLoad Assign NameStore BinOpMod BinOpAdd Str BinOpMult Str Num Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr AugAssignAdd NameStore Call AttributeLoad BinOpAdd Str BinOpMult Str Num attr ListComp BinOpMod Str TupleLoad BinOpAdd NameLoad Num Call NameLoad AttributeLoad SubscriptLoad NameLoad Index Num attr SubscriptLoad NameLoad Index Num comprehension TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore BinOpAdd Str BinOpMult Str Num Assign NameStore ListLoad For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore BinOpMod Str TupleLoad Call NameLoad AttributeLoad NameLoad attr Call AttributeLoad Str attr ListComp Call NameLoad BinOpAdd NameLoad Num comprehension NameStore AttributeLoad NameLoad attr Call AttributeLoad Str attr ListComp Call NameLoad NameLoad comprehension NameStore AttributeLoad NameLoad attr If CompareEq NameLoad BinOpSub Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Num body AugAssignAdd NameStore Str orelse AugAssignAdd NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad AugAssignAdd NameStore Call AttributeLoad BinOpAdd Str BinOpMult Str Num attr NameLoad Assign NameStore ListComp BinOpMod Str NameLoad comprehension TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore ListComp BinOpMod Str TupleLoad BinOpAdd NameLoad Num 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 ListComp NameLoad comprehension NameStore Call NameLoad NameLoad NameLoad comprehension NameStore NameLoad Assign NameStore Call AttributeLoad BinOpAdd Str BinOpMult Str Num attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Lambda arguments args NameParam defaults BinOpMod Str BinOpAdd Call NameLoad Call AttributeLoad NameLoad attr Num Num NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Str NameLoad For TupleStore NameStore NameStore Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Assign NameStore Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr BinOpMod Str Call NameLoad AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Call NameLoad Str Num Dict Str Str Str Str Str Str Str NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad Return Call AttributeLoad NameLoad attr decorator_list decorator_list FunctionDef arguments args NameParam defaults body If Call AttributeLoad NameLoad attr Str body Return BinOpAdd Str NameLoad orelse Return NameLoad decorator_list
N/A N/A 
A class for converting a PySB model to a set of ordinary differential
equations for integration in MATLAB.

Note that for use in MATLAB, the name of the ``.m`` file must match the name of
the exported MATLAB class (e.g., ``robertson.m`` for the example below).

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

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

Information on the form and usage of the generated MATLAB class is contained in
the documentation for the MATLAB model, as shown in the following example for
``pysb.examples.robertson``::

    classdef 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.
        % 
        % A class implementing the ordinary differential equations
        % for the robertson model.
        %
        % Save as robertson.m.
        %
        % Generated by pysb.export.matlab.MatlabExporter.
        %
        % Properties
        % ----------
        % observables : struct
        %     A struct containing the names of the observables from the
        %     PySB model as field names. Each field in the struct
        %     maps the observable name to a matrix with two rows:
        %     the first row specifies the indices of the species
        %     associated with the observable, and the second row
        %     specifies the coefficients associated with the species.
        %     For any given timecourse of model species resulting from
        %     integration, the timecourse for an observable can be
        %     retrieved using the get_observable method, described
        %     below.
        %
        % parameters : struct
        %     A struct containing the names of the parameters from the
        %     PySB model as field names. The nominal values are set by
        %     the constructor and their values can be overriden
        %     explicitly once an instance has been created.
        %
        % Methods
        % -------
        % robertson.odes(tspan, y0)
        %     The right-hand side function for the ODEs of the model,
        %     for use with MATLAB ODE solvers (see Examples).
        %
        % robertson.get_initial_values()
        %     Returns a vector of initial values for all species,
        %     specified in the order that they occur in the original
        %     PySB model (i.e., in the order found in model.species).
        %     Non-zero initial conditions are specified using the
        %     named parameters included as properties of the instance.
        %     Hence initial conditions other than the defaults can be
        %     used by assigning a value to the named parameter and then
        %     calling this method. The vector returned by the method
        %     is used for integration by passing it to the MATLAB
        %     solver as the y0 argument.
        %
        % robertson.get_observables(y)
        %     Given a matrix of timecourses for all model species
        %     (i.e., resulting from an integration of the model),
        %     get the trajectories corresponding to the observables.
        %     Timecourses are returned as a struct which can be
        %     indexed by observable name.
        %
        % Examples
        % --------
        % Example integration using default initial and parameter
        % values:
        %
        % >> m = robertson();
        % >> tspan = [0 100];
        % >> [t y] = ode15s(@m.odes, tspan, m.get_initial_values());
        %
        % Retrieving the observables:
        %
        % >> y_obs = m.get_observables(y)
        %
        properties
            observables
            parameters
        end

        methods
            function self = robertson()
                % Assign default parameter values
                self.parameters = struct( ...
                    'k1', 0.040000000000000001, ...
                    'k2', 30000000, ...
                    'k3', 10000, ...
                    'A_0', 1, ...
                    'B_0', 0, ...
                    'C_0', 0);

                % Define species indices (first row) and coefficients
                % (second row) of named observables
                self.observables = struct( ...
                    'A_total', [1; 1], ...
                    'B_total', [2; 1], ...
                    'C_total', [3; 1]);
            end

            function initial_values = get_initial_values(self)
                % Return the vector of initial conditions for all
                % species based on the values of the parameters
                % as currently defined in the instance.

                initial_values = zeros(1,3);
                initial_values(1) = self.parameters.A_0; % A()
                initial_values(2) = self.parameters.B_0; % B()
                initial_values(3) = self.parameters.C_0; % C()
            end

            function y = odes(self, tspan, y0)
                % Right hand side function for the ODEs

                % Shorthand for the struct of model parameters
                p = self.parameters;

                % A();
                y(1,1) = -p.k1*y0(1) + p.k3*y0(2)*y0(3);
                % B();
                y(2,1) = p.k1*y0(1) - p.k2*power(y0(2), 2) - p.k3*y0(2)*y0(3);
                % C();
                y(3,1) = p.k2*power(y0(2), 2);
            end

            function y_obs = get_observables(self, y)
                % Retrieve the trajectories for the model observables
                % from a matrix of the trajectories of all model
                % species.

                % Initialize the struct of observable timecourses
                % that we will return
                y_obs = struct();

                % Iterate over the observables;
                observable_names = fieldnames(self.observables);
                for i = 1:numel(observable_names)
                    obs_matrix = self.observables.(observable_names{i});
                    species = obs_matrix(1, :);
                    coefficients = obs_matrix(2, :);
                    y_obs.(observable_names{i}) = ...
                                    y(:, species) * coefficients';
                end
            end
        end
    end
 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 pysb.export Exporter pad MatlabExporter N/A Exporter N/A N/A A class for returning the ODEs for a given PySB model for use in
    MATLAB.

    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 a MATLAB class definition containing the ODEs for the PySB
        model associated with the exporter.

        Returns
        -------
        string
            String containing the MATLAB code for an implementation of 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 docstring N/A N/A self docstring N/A N/A docstring N/A N/A N/A self docstring replace 
    %  N/A model_name N/A N/A N/A N/A self model name replace . _ N/A params_str N/A self.parameters = struct( ...
 N/A 16 N/A params_str_list N/A N/A N/A i p N/A enumerate N/A N/A self model parameters N/A N/A cur_p_str N/A '%s', %.17g N/A N/A _fix_underscores N/A p name N/A p value N/A N/A i N/A N/A len N/A N/A self model parameters 1 N/A N/A cur_p_str ); N/A N/A cur_p_str , ... N/A N/A N/A params_str_list append cur_p_str N/A params_str N/A N/A N/A N/A 16 join params_str_list N/A initial_values_str N/A N/A initial_values = zeros(1,%d);
 N/A 12 N/A len N/A N/A self model species N/A initial_values_str N/A N/A N/A N/A 12 join N/A N/A initial_values(%d) = self.parameters.%s; %% %s N/A N/A i 1 N/A _fix_underscores N/A N/A ic N/A 1 name N/A ic N/A 0 N/A N/A i ic N/A enumerate N/A N/A self model initial_conditions N/A observables_str N/A self.observables = struct( ...
 N/A 16 N/A observables_str_list N/A N/A N/A i obs N/A enumerate N/A N/A self model observables N/A N/A cur_obs_str N/A '%s', [%s; %s] N/A N/A _fix_underscores N/A obs name N/A N/A join N/A N/A str N/A sp 1 N/A sp N/A obs species N/A N/A join N/A N/A str c N/A c N/A obs coefficients N/A N/A i N/A N/A len N/A N/A self model observables 1 N/A N/A cur_obs_str ); N/A N/A cur_obs_str , ... N/A N/A N/A observables_str_list append cur_obs_str N/A observables_str N/A N/A N/A N/A 16 join observables_str_list N/A species_list N/A N/A %% %s; s N/A N/A i s N/A enumerate N/A N/A self model species N/A odes_list N/A N/A y(%d,1) = %s; N/A N/A i 1 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_species_list N/A item N/A sublist N/A zip species_list odes_list N/A item sublist N/A odes_str N/A N/A N/A N/A 12 join odes_species_list N/A odes_str N/A N/A re sub __s(\d+) N/A N/A N/A m N/A N/A y0(%s) N/A N/A int N/A N/A m group 1 1 odes_str N/A odes_str N/A N/A re sub pow\( power( 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 p.%s N/A _fix_underscores N/A p name odes_str N/A N/A N/A output write N/A N/A pad 
            classdef %(model_name)s
                %% %(docstring)s
                %% A class implementing the ordinary differential equations
                %% for the %(model_name)s model.
                %%
                %% Save as %(model_name)s.m.
                %%
                %% Generated by pysb.export.matlab.MatlabExporter.
                %%
                %% Properties
                %% ----------
                %% observables : struct
                %%     A struct containing the names of the observables from the
                %%     PySB model as field names. Each field in the struct
                %%     maps the observable name to a matrix with two rows:
                %%     the first row specifies the indices of the species
                %%     associated with the observable, and the second row
                %%     specifies the coefficients associated with the species.
                %%     For any given timecourse of model species resulting from
                %%     integration, the timecourse for an observable can be
                %%     retrieved using the get_observable method, described
                %%     below.
                %%
                %% parameters : struct
                %%     A struct containing the names of the parameters from the
                %%     PySB model as field names. The nominal values are set by
                %%     the constructor and their values can be overriden
                %%     explicitly once an instance has been created.
                %%
                %% Methods
                %% -------
                %% %(model_name)s.odes(tspan, y0)
                %%     The right-hand side function for the ODEs of the model,
                %%     for use with MATLAB ODE solvers (see Examples).
                %%
                %% %(model_name)s.get_initial_values()
                %%     Returns a vector of initial values for all species,
                %%     specified in the order that they occur in the original
                %%     PySB model (i.e., in the order found in model.species).
                %%     Non-zero initial conditions are specified using the
                %%     named parameters included as properties of the instance.
                %%     Hence initial conditions other than the defaults can be
                %%     used by assigning a value to the named parameter and then
                %%     calling this method. The vector returned by the method
                %%     is used for integration by passing it to the MATLAB
                %%     solver as the y0 argument.
                %%
                %% %(model_name)s.get_observables(y)
                %%     Given a matrix of timecourses for all model species
                %%     (i.e., resulting from an integration of the model),
                %%     get the trajectories corresponding to the observables.
                %%     Timecourses are returned as a struct which can be
                %%     indexed by observable name.
                %%
                %% Examples
                %% --------
                %% Example integration using default initial and parameter
                %% values:
                %%
                %% >> m = %(model_name)s();
                %% >> tspan = [0 100];
                %% >> [t y] = ode15s(@m.odes, tspan, m.get_initial_values());
                %%
                %% Retrieving the observables:
                %%
                %% >> y_obs = m.get_observables(y)
                %%
                properties
                    observables
                    parameters
                end

                methods
                    function self = %(model_name)s()
                        %% Assign default parameter values
                        %(params_str)s

                        %% Define species indices (first row) and coefficients
                        %% (second row) of named observables
                        %(observables_str)s
                    end

                    function initial_values = get_initial_values(self)
                        %% Return the vector of initial conditions for all
                        %% species based on the values of the parameters
                        %% as currently defined in the instance.

                        %(initial_values_str)s
                    end

                    function y = odes(self, tspan, y0)
                        %% Right hand side function for the ODEs

                        %% Shorthand for the struct of model parameters
                        p = self.parameters;

                        %(odes_str)s
                    end

                    function y_obs = get_observables(self, y)
                        %% Retrieve the trajectories for the model observables
                        %% from a matrix of the trajectories of all model
                        %% species.

                        %% Initialize the struct of observable timecourses
                        %% that we will return
                        y_obs = struct();

                        %% Iterate over the observables;
                        observable_names = fieldnames(self.observables);
                        for i = 1:numel(observable_names)
                            obs_matrix = self.observables.(observable_names{i});
                            species = obs_matrix(1, :);
                            coefficients = obs_matrix(2, :);
                            y_obs.(observable_names{i}) = ...
                                            y(:, species) * coefficients';
                        end
                    end
                end
            end
             0 N/A docstring model_name params_str initial_values_str observables_str params_str odes_str docstring model_name params_str initial_values_str observables_str params_str odes_str N/A N/A N/A output getvalue N/A N/A _fix_underscores N/A N/A name N/A N/A N/A N/A N/A name startswith _ N/A N/A N/A X name N/A N/A name N/A