Exporting to other formats (pysb.export
)¶
Tools for exporting PySB models to a variety of other formats.
Exporting can be performed at the command-line or programmatically/interactively from within Python.
Command-line usage¶
At the command-line, run as follows:
python -m pysb.export model.py <format>
where model.py
is a file containing a PySB model definition (i.e.,
contains an instance of pysb.core.Model
instantiated as a global variable).
[format]
should be the name of one of the supported formats:
bngl
bng_net
json
kappa
potterswheel
sbml
pysb_flat
mathematica
matlab
stochkit
In all cases, the exported model code will be printed to standard out, allowing it to be inspected or redirected to another file.
Interactive usage¶
Export functionality is implemented by this module’s top-level function
export
. For example, to export the “Robertson” example model as SBML, first
import the model:
from pysb.examples.robertson import model
Then import the export
function from this module:
from pysb.export import export
Call the export
function, passing the model instance and a string
indicating the desired format, which should be one of the ones indicated
in the list in the “Command-line usage” section above:
sbml_output = export(model, 'sbml')
The output (a string) can be inspected or written to a file, e.g. as follows:
with open('robertson.sbml', 'w') as f:
f.write(sbml_output)
Implementation of specific exporters¶
Information on the implementation of specific exporters can be found in the
documentation for the exporter classes in the package pysb.export
:
- Export SBML (
pysb.export.sbml
) - Export ODEs to MATLAB (
pysb.export.matlab
) - Export ODEs to Mathematica (
pysb.export.mathematica
) - Export ODEs to PottersWheel (
pysb.export.potterswheel
) - Export BNGL (
pysb.export.bngl
) - Export BNGL NET file (
pysb.export.bng_net
) - Export Kappa (
pysb.export.kappa
) - Export a “flat” PySB model (
pysb.export.pysb_flat
) - Export to StochKit (
pysb.export.stochkit
) - Export JSON (
pysb.export.json
)
- exception pysb.export.CompartmentsNotSupported[source]¶
Compartments are not supported by this exporter
- exception pysb.export.CustomSympyFunctionsNotSupported[source]¶
Custom sympy functions are not supported by this exporter
- exception pysb.export.EnergyNotSupported[source]¶
Energy features are not supported by this exporter
- class pysb.export.Exporter(model, docstring=None)[source]¶
Base class for all PySB model exporters.
Export functionality is implemented by subclasses of this class. The pattern for model export is the same for all exporter subclasses: a model is passed to the exporter constructor and the
export
method on the instance is called.- Parameters:
- modelpysb.core.Model
The model to export.
- docstringstring (optional)
The header comment to include at the top of the exported file.
Examples
Exporting the “Robertson” example model to SBML using the
SbmlExporter
subclass:>>> from pysb.examples.robertson import model >>> from pysb.export.sbml import SbmlExporter >>> e = SbmlExporter(model) >>> sbml_output = e.export()
- docstring¶
Header comment to include at the top of the exported file.
- export()[source]¶
The export method, which must be implemented by any subclass.
All implementations of this method are expected to return a single string containing the representation of the model in the desired format.
- model¶
The model to export.
- exception pysb.export.ExpressionsNotSupported[source]¶
Expressions are not supported by this exporter
- exception pysb.export.LocalFunctionsNotSupported[source]¶
Local functions are not supported by this exporter
- pysb.export.export(model, format, docstring=None)[source]¶
Top-level function for exporting a model to a given format.
- Parameters:
- modelpysb.core.Model
The model to export.
- formatstring
A string indicating the desired export format.
- docstringstring (optional)
The header comment to include at the top of the exported file.