You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/model_creation/model_file_loading_and_export.md
+40-47Lines changed: 40 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Pkg.add("SBMLImporter")
16
16
</details>
17
17
```
18
18
\
19
-
19
+
20
20
Catalyst stores chemical reaction network (CRN) models in `ReactionSystem` structures. This tutorial describes how to load such `ReactionSystem`s from, and save them to, files. This can be used to save models between Julia sessions, or transfer them from one session to another. Furthermore, to facilitate the computation modelling of CRNs, several standardised file formats have been created to represent CRN models (e.g. [SBML](https://sbml.org/)). This enables CRN models to be shared between different software and programming languages. While Catalyst itself does not have the functionality for loading such files, we will here (briefly) introduce a few packages that can load different file types to Catalyst `ReactionSystem`s.
21
21
22
22
## [Saving Catalyst models to, and loading them from, Julia files](@id model_file_import_export_crn_serialization)
@@ -46,33 +46,34 @@ cc_loaded # hide
46
46
Here, `include` is used to execute the Julia code from any file. This means that `save_reactionsystem` actually saves the model as executable code which re-generates the exact model which was saved (this is the reason why we use the ".jl" extension for the saved file). Indeed, we can confirm this if we check what is printed in the file:
47
47
```
48
48
let
49
+
# Serialised using Catalyst version v1.12.5.
49
50
50
51
# Independent variable:
51
-
@parameters t
52
+
@independent_variables t
52
53
53
54
# Parameters:
54
-
ps = @parameters kB kD kP
55
+
ps = @parameters k₁ k₂ k₃
55
56
56
57
# Species:
57
-
sps = @species S(t) E(t) SE(t) P(t)
58
+
sps = @species S₁(t) C(t) S₁C(t) S₂(t) CP(t) P(t)
58
59
59
60
# Reactions:
60
61
rxs = [
61
-
Reaction(kB, [S, E], [SE], [1, 1], [1]),
62
-
Reaction(kD, [SE], [S, E], [1], [1, 1]),
63
-
Reaction(kP, [SE], [P, E], [1], [1, 1])
62
+
Reaction(k₁, [S₁, C], [S₁C], [1, 1], [1]),
63
+
Reaction(k₂, [S₁C, S₂], [CP], [1, 1], [1]),
64
+
Reaction(k₃, [CP], [C, P], [1], [1, 1])
64
65
]
65
66
66
67
# Declares ReactionSystem model:
67
-
rs = ReactionSystem(rxs, t, sps, ps; name = Symbol("##ReactionSystem#12592"))
68
+
rs = ReactionSystem(rxs, t, sps, ps; name = Symbol("##ReactionSystem#288"))
68
69
complete(rs)
69
70
70
71
end
71
72
```
72
73
!!! note
73
74
The code that `save_reactionsystem` prints uses [programmatic modelling](@ref programmatic_CRN_construction) to generate the written model.
74
75
75
-
In addition to transferring models between Julia sessions, the `save_reactionsystem` function can also be used or print a model to a text file where you can easily inspect its components.
76
+
In addition to transferring models between Julia sessions, the `save_reactionsystem` function can also be used to print a model to a text file where you can easily inspect its components.
76
77
77
78
## [Loading and saving arbitrary Julia variables using Serialization.jl](@id model_file_import_export_julia_serialisation)
78
79
Julia provides a general and lightweight interface for loading and saving Julia structures to and from files that it can be good to be aware of. It is called [Serialization.jl](https://docs.julialang.org/en/v1/stdlib/Serialization/) and provides two functions, `serialize` and `deserialize`. The first allows us to write a Julia structure to a file. E.g. if we wish to save a parameter set associated with our model, we can use
@@ -92,55 +93,56 @@ loaded_sol # hide
92
93
A general-purpose format for storing CRN models is so-called .net files. These can be generated by e.g. [BioNetGen](https://bionetgen.org/). The [ReactionNetworkImporters.jl](https://github.com/SciML/ReactionNetworkImporters.jl) package enables the loading of such files to Catalyst `ReactionSystem`. Here we load a [Repressilator](@ref basic_CRN_library_repressilator) model stored in the "repressilator.net" file:
Here, .net files not only contain information regarding the reaction network itself, but also the numeric values (initial conditions and parameter values) required for simulating it. Hence, `loadrxnetwork` generates a `ParsedReactionNetwork` structure, containing all this information. You can access the model as `prn.rn`, the initial conditions as `prn.u0`, and the parameter values as `prn.p`. Furthermore, these initial conditions and parameter values are also made [*default* values](@ref dsl_advanced_options_default_vals) of the model.
98
-
99
-
A parsed reaction network's content can then be provided to various problem types for simulation. E.g. here we perform an ODE simulation of our repressilator model:
98
+
Here, .net files not only contain information regarding the reaction network itself, but also the numeric values (initial conditions and parameter values) required for simulating it. The `loadrxnetwork` function loads the model as a normal `ReactionSystem` structure, but saves the initial conditions and parameter values as [*default* values](@ref dsl_advanced_options_default_vals) that are automatically accounted for in simulations. The loaded model can be provided to various problem types for simulation. E.g. here we perform an ODE simulation of our repressilator model:
Note that, as all initial conditions and parameters have default values, we can provide empty vectors for these into our `ODEProblem`.
110
-
108
+
Note that, as all initial conditions and parameters have default values, we can provide empty vectors for these into our `ODEProblem`. To load these values from the model, the `get_u0_map(rn)` and `get_parameter_map(rn)` functions can be used.
111
109
112
110
!!! note
113
111
It should be noted that .net files support a wide range of potential model features, not all of which are currently supported by ReactionNetworkImporters. Hence, there might be some .net files which `loadrxnetwork` will not be able to load.
114
112
115
113
A more detailed description of ReactionNetworkImporter's features can be found in its [documentation](https://docs.sciml.ai/ReactionNetworkImporters/stable/).
116
114
117
-
## [Loading SBML files using SBMLImporter.jl and SBMLToolkit.jl](@id model_file_import_export_sbml)
118
-
The Systems Biology Markup Language (SBML) is the most widespread format for representing CRN models. Currently, there exist two different Julia packages, [SBMLImporter.jl](https://github.com/sebapersson/SBMLImporter.jl)and [SBMLToolkit.jl](https://github.com/SciML/SBMLToolkit.jl), that are able to load SBML files to Catalyst `ReactionSystem` structures. SBML is able to represent a *very* wide range of model features, with both packages supporting most features. However, there exist SBML files (typically containing obscure model features such as events with time delays) that currently cannot be loaded into Catalyst models.
115
+
## [Loading SBML files using SBMLImporter.jl](@id model_file_import_export_sbml)
116
+
The Systems Biology Markup Language (SBML) is the most widespread format for representing CRN models. Here, the [SBMLImporter.jl](https://github.com/sebapersson/SBMLImporter.jl)package is able to load SBML files to Catalyst `ReactionSystem` structures. SBML is able to represent a *very* wide range of model features, with SBMLImporter supporting most features. However, there exist SBML files (typically containing obscure model features such as events with time delays) that currently cannot be loaded into Catalyst models.
119
117
120
-
SBMLImporter's `load_SBML` function can be used to load SBML files. Here, we load a [Brusselator](@ref basic_CRN_library_brusselator) model stored in the "brusselator.xml" file:
118
+
SBMLImporter's `load_SBML` function can be used to load SBML files. Here, we load a
119
+
[Brusselator](@ref basic_CRN_library_brusselator) model stored in the "brusselator.xml"
120
+
file:
121
121
```julia
122
122
using SBMLImporter
123
-
prn, cbs =load_SBML("brusselator.xml", massaction =true)
123
+
rn, cbs =load_SBML("brusselator.xml", massaction =true)
124
124
```
125
-
Here, while [ReactionNetworkImporters generates a `ParsedReactionSystem` only](@ref model_file_import_export_sbml_rni_net), SBMLImporter generates a `ParsedReactionSystem` (here stored in `prn`) and a [so-called `CallbackSet`](https://docs.sciml.ai/DiffEqDocs/stable/features/callback_functions/#CallbackSet) (here stored in `cbs`). While `prn` can be used to create various problems, when we simulate them, we must also supply `cbs`. E.g. to simulate our brusselator we use:
125
+
126
+
`load_SBML` returns two outputs: a `ReactionSystem` (`rn`) and a `CallbackSet` (`cbs`). The `CallbackSet` contains SBML events and callbacks generated from any SBML `piecewise` expressions. While `rn` can be used to create problems, when we simulate them, we must also supply `cbs`. The SBML file also contains simulation initial condition and parameter values. These are saved within the `rn` and can be extracted using the `get_u0_map` and `get_parameter_map` functions. Here we simulate the loaded brusselator model, providing `u0`, `ps`, and `cb` as described.
Note that, while ReactionNetworkImporters adds initial condition and species values as default to the imported model, SBMLImporter does not do this. These must hence be provided to the `ODEProblem` directly.
139
+
!!! note
140
+
While ReactionNetworkImporters saves parameters (`ps`) and species values (`u0`) as default to the imported model, SBMLImporter does not do this. These must hence be explicitly loaded through `get_u0_map` and `get_parameter_map` and then provided to the `ODEProblem`.
136
141
137
142
A more detailed description of SBMLImporter's features can be found in its [documentation](https://sebapersson.github.io/SBMLImporter.jl/stable/).
138
143
139
144
!!! note
140
-
The `massaction = true` option informs the importer that the target model follows mass-action principles. When given, this enables SBMLImporter to make appropriate modifications to the model (which are important for e.g. jump simulation performance).
141
-
142
-
### [SBMLImporter and SBMLToolkit](@id model_file_import_export_package_alts)
143
-
Above, we described how to use SBMLImporter to import SBML files. Alternatively, SBMLToolkit can be used instead. It has a slightly different syntax, which is described in its [documentation](https://github.com/SciML/SBMLToolkit.jl), and does not support as wide a range of SBML features as SBMLImporter. A short comparison of the two packages can be found [here](https://github.com/sebapersson/SBMLImporter.jl?tab=readme-ov-file#differences-compared-to-sbmltoolkit). Generally, while they both perform well, we note that for *jump simulations* SBMLImporter is preferable (its way for internally representing reaction event enables more performant jump simulations).
145
+
The `massaction = true` option informs the importer that the target model follows mass-action principles. When given, this enables SBMLImporter to make appropriate modifications to the model (which are important for jump simulation performance).
144
146
145
147
## [Loading models from matrix representation using ReactionNetworkImporters.jl](@id model_file_import_export_matrix_representations)
146
148
While CRN models can be represented through various file formats, they can also be represented in various matrix forms. E.g. a CRN with $m$ species and $n$ reactions (and with constant rates) can be represented with either
@@ -155,32 +157,23 @@ The advantage of these forms is that they offer a compact and very general way t
155
157
---
156
158
## [Citations](@id petab_citations)
157
159
If you use any of this functionality in your research, [in addition to Catalyst](@ref doc_index_citation), please cite the paper(s) corresponding to whichever package(s) you used:
title = {SBMLToolkit.jl: a Julia package for importing SBML into the SciML ecosystem},
178
-
title = {},
179
-
author = {Paul F. Lang and Anand Jain and Christopher Rackauckas},
180
-
pages = {20240003},
181
-
journal = {Journal of Integrative Bioinformatics},
182
-
doi = {doi:10.1515/jib-2024-0003},
183
-
year = {2024},
184
-
lastchecked = {2024-06-02}
168
+
```bibtex
169
+
@article{PEtabBioinformatics2025,
170
+
title={PEtab.jl: advancing the efficiency and utility of dynamic modelling},
171
+
author={Persson, Sebastian and Fr{\"o}hlich, Fabian and Grein, Stephan and Loman, Torkel and Ognissanti, Damiano and Hasselgren, Viktor and Hasenauer, Jan and Cvijovic, Marija},
0 commit comments