mass.core.mass_solution

MassSolution is a class for storing the simulation results.

After a Simulation is used to simulate a mass model, MassSolutions are created to store the results computed over the time interval specified when simulating. These results are divided into two categories:

  • Concentration solutions (abbreviated as ConcSols)

  • Reaction Flux solutions (abbreviated as FluxSols)

MassSolutions are therefore given an identifier of the following format: {id_or_model}_{solution_type}Sols where id_or_model and solution_type correspond to the simulated model and resulting solution category, respectively.

All solutions in a MassSolution can be accessed via attribute accessors. A MassSolution also contains standard dict methods.

All functions from the mass.visualization submodule are designed to work seamlessly with MassSolutions, provided they are properly created.

Module Contents

Classes

MassSolution

Container to store the solutions for the simulation of a model.

class mass.core.mass_solution.MassSolution(id_or_model, solution_type='', data_dict=None, time=None, interpolate=False, initial_values=None)[source]

Bases: mass.util.dict_with_id.DictWithID

Container to store the solutions for the simulation of a model.

Parameters
  • id_or_model (str, MassModel) – A MassModel or a string identifier to associate with the stored solutions. If a MassModel is provided, then the model identifier will be used.

  • solution_type (str) – The type of solution being stored. Must be 'Conc' or 'flux'.

  • data_dict (dict) – A dict containing the solutions to store. If None provided then the MassSolution will be initialized with no solutions. Solutions can be added or changed later using various dict methods (e.g. update()).

  • time (array-like) – An array-like object containing the time points used in obtaining the solutions.

  • interpolate (bool) –

    If True then all solutions are converted and stored as scipy.interpolate.interp1d objects. If False, solutions are converted and stored as numpy.ndarrays.

    Default value is False.

property simulation[source]

Return the associated Simulation.

property time[source]

Get or set the time points stored in the MassSolution.

Notes

If the solutions stored in the MassSolution are numpy.ndarrays and the numerical arrays of the solutions will be recomputed to correspond to the new time points using scipy.interpolate.interp1d interpolating functions

Parameters

value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.

property t[source]

Shorthand method to get or set the stored time points.

Notes

If the solutions stored in the MassSolution are numpy.ndarrays and the numerical arrays of the solutions will be recomputed to correspond to the new time points using interp1d interpolating functions

Parameters

value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.

property interpolate[source]

Get or set whether solutions are stored as interpolating functions.

Parameters

value (bool) – If True, solutions are stored in the MassSolution as interp1d objects. Otherwise solutions are stored as arrays.

property initial_values[source]

Get or set a dict of the initial values for solution variables.

Notes

Primarily for storing the intial values used in a simulation and for calculating deviations from the initial state.

Parameters

initial_values (dict) – A dict containining the variables stored in the MassSolution and their initial values.

view_time_profile(deviation=False, plot_function='loglog')[source]

Generate a quick view of the time profile for the solution.

See visualization documentation for more information.

Parameters
  • deviation (bool) – Whether to plot time profiles as a deviation from their initial value.

  • plot_function (str) –

    The plotting function to use. Accepted values are the following:

    • "plot" for a linear x-axis and a linear y-axis via Axes.plot()

    • "loglog" for a logarithmic x-axis and a logarithmic y-axis via Axes.loglog()

    • "semilogx” for a logarithmic x-axis and a linear y-axis via Axes.semilogx()

    • "semilogy" for a linear x-axis and a logarithmic y-axis via Axes.semilogy()

Notes

Will clear and use the current axis (accessible via matplotlib.pyplot.gca()).

view_tiled_phase_portraits()[source]

Generate a preview of the phase portraits for the solution.

See visualization documentation for more information.

Notes

Will clear and use the current axis (accessible via matplotlib.pyplot.gca()).

to_frame()[source]

Return the stored solutions as a pandas.DataFrame.

make_aggregate_solution(aggregate_id, equation, variables=None, parameters=None, update=True)[source]

Make a new aggregate variable and its solution from an equation.

Parameters
  • aggregate_id (str) – An identifier for the solution to be made.

  • equation (str) – A string representing the equation of the new solution.

  • variables (iterable or None) – Either an iterable of object identifiers or the objects themselves representing keys in the MassSolution that are used as variables in equation. If None, then all keys of the solution object are checked as variables, potentially resulting in lower performance time.

  • parameters (dict or None) – A dict of additional parameters to use, where key:value pairs are the parameter identifiers and their numerical values. If None then it is assumed that there are no additional parameters in the equation.

  • update (bool) – Whether to add the new solution into the MassSolution. via the update() method. Default is True.

Returns

solution – A dict containing where the key is the aggregate_id and the value is the newly created solution as the same type as the variable solutions

Return type

dict

Raises

SympifyError – Raised if the equation_str could not be interpreted.

__getattribute__(name)[source]

Override of default getattr() to enable attribute accessors.

Warning

This method is intended for internal use only.

__dir__()[source]

Override of default dir() to include solution accessors.

Warning

This method is intended for internal use only.