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
+21-16Lines changed: 21 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
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/)). These enables CRN models to be shared between different softwares 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 files to Catalyst `ReactionSystem`s.
3
3
4
4
## Saving Catalyst models to, and loading them from, Julia files
5
-
Catalyst provides a `save_reaction_system` function, enabling the user to save a `ReactionSystem` to a file. Here we demonstrate it by first creating a simple catalysis network
5
+
Catalyst provides a `save_reactionsystem` function, enabling the user to save a `ReactionSystem` to a file. Here we demonstrate this by first creating a [simple cross-coupling model](@ref basic_CRN_library_cc):
6
6
```@example file_handling_1
7
7
using Catalyst
8
8
rn = @reaction_network begin
@@ -13,21 +13,24 @@ end
13
13
```
14
14
and next saving it to a file
15
15
```@example file_handling_1
16
-
save_reaction_system("reaction_network.jl", rn)
16
+
save_reactionsystem("cross_coupling.jl", rn)
17
17
```
18
-
Here, `save_reaction_system`'s first argument is the path to the file where we wish to save it. The second argument is the `ReactionSystem` we wish to save. To load the file, we use Julia's `include` function:
18
+
Here, `save_reactionsystem`'s first argument is the path to the file where we wish to save it. The second argument is the `ReactionSystem` we wish to save. To load the file, we use Julia's `include` function:
19
19
```@example file_handling_1
20
-
loaded_rn = include("reaction_network.jl")
20
+
loaded_rn = include("cross_coupling.jl")
21
21
```
22
22
23
23
!!! note
24
-
The destination file can be in a folder. E.g. `save_reaction_system("my_folder/reaction_network.jl", rn)` saves the model to the file "reaction_network.jl" in the folder "my_folder".
24
+
The destination file can be in a folder. E.g. `save_reactionsystem("my_folder/reaction_network.jl", rn)` saves the model to the file "reaction_network.jl" in the folder "my_folder".
25
25
26
-
`include` is used to execute the Julia code from any file. This means that `save_reaction_system` 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, if we print the file we can confirm this:
26
+
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, if we print the file we can confirm this:
27
27
```@example file_handling_1
28
-
println(read("reaction_network.jl", String))
29
-
rm("reaction_network.jl") # hide
28
+
read("cross_coupling.jl", String)
30
29
```
30
+
```@example file_handling_1
31
+
rm("cross_coupling.jl")
32
+
```
33
+
This functionality can also be used or print a model to simplify checking its various components.
31
34
32
35
## Loading and Saving arbitrary Julia variables using Serialization.jl
33
36
Julia provide 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 allow 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
A general-purpose format for storing CRN models are 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](https://en.wikipedia.org/wiki/Repressilator) model stored in the "repressilator.net" file:
48
+
A general-purpose format for storing CRN models are 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](@refref) of the model.
56
+
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](@refdsl_advanced_options_default_vals) of the model.
54
57
55
-
A parsed reaction networkcan be provided directly to various problem types for simulation. E.g. here we perform an ODE simulation of our repressilator model:
58
+
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:
Note that, as all initial conditions and parameters have default values, we can provide empty vectors for these into our `ODEProblem`.
67
+
63
68
64
69
!!! note
65
70
It should be noted that .net files supports 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.
@@ -69,7 +74,7 @@ A more detailed description of ReactionNetworkImporter's features can be found i
69
74
## Loading SBML files using SBMLImporter.jl and SBMLToolkit.jl
70
75
The Systems Biology Markup Language (SBML) is the most widespread format for representing CRN models. Currently, there exists two different Julia packages, [SBMLImporter.jl](https://github.com/sebapersson/SBMLImporter.jl) and [SBMLToolkit.jl](https://github.com/SciML/SBMLToolkit.jl), both of which are able to load SBML files to Catalyst `ReactionSystem` structures. SBML is able to represent a *very* wide range of model featuresSome of these are not supported by these packages (or Catalyst). Hence, there exist SBML files (typically containing obscure model features such as events with time delays) that currently cannot be loaded into Catalyst models.
71
76
72
-
SBMLImporter's `load_SBML` function can be used to load SBML files. Here, we load a [Brusselator](https://en.wikipedia.org/wiki/Brusselator) model stored in the "brusselator.xml" file:
77
+
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:
0 commit comments