# How to partilly instantiate parameters of a reaction network in Catalyst (or ModelingToolkit ?)

**URL:** <https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427>\
**Category:** Modelling & Simulations\
**Tags:** question, modelingtoolkit, catalyst\
**Created:** [September 18, 2022, 8:29am UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427 "2022-09-18T08:29:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cedric\_Lh](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Cedric\_Lh](https://discourse.julialang.org/u/Cedric_Lh)\
**Post date:** [September 18, 2022, 8:29am UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427/1 "2022-09-18T08:29:22Z")

</div>

Hi! Is there a simple way, in [Catalyst.jl](https://github.com/search?q=Catalyst.jl&type=Repositories), to instantiate some of the parameters of a reaction system ? Suppose, I have this simple network:

```julia
rn1 = @reaction_network begin
    a, X --> ∅
    b, Y --> X
end a b

```

so, `parameters(rn1)` are `[a,b]`, and I want to fix `a` to say 1.0 to obtain the reaction network:

```julia
rn2 = @reaction_network begin
    1.0, X --> ∅
    b, Y --> X
end b

```

where `parameters(rn2)` are `[b]`. So, is there a function `foo` already available so that I can write, for instance

```julia
rn2 = foo(rn1, (:a => 1.0))

```

that will do the job automatically ? I tried with Symbolics.substitute but unfortunately this doesn’t work…

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [September 18, 2022, 8:27pm UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427/2 "2022-09-18T20:27:00Z")

</div>

Not currently, but we could look into adding a `substitute` type function that can be applied to a network. Would you mind opening an issue on the Catalyst GitHub repo?

---

<div class="post-metadata">

**Author:** ![Cedric\_Lh](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Cedric\_Lh](https://discourse.julialang.org/u/Cedric_Lh)\
**Post date:** [September 19, 2022, 8:21am UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427/3 "2022-09-19T08:21:22Z")

</div>

I opened an issue. Thanks!

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [September 19, 2022, 11:44am UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427/4 "2022-09-19T11:44:27Z")

</div>

Will try to get to it in the next week or so, but this month is super busy so it may lag till the start of October.

---

<div class="post-metadata">

**Author:** ![Cedric\_Lh](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Cedric\_Lh](https://discourse.julialang.org/u/Cedric_Lh)\
**Post date:** [September 20, 2022, 10:11am UTC](https://discourse.julialang.org/t/how-to-partilly-instantiate-parameters-of-a-reaction-network-in-catalyst-or-modelingtoolkit/87427/5 "2022-09-20T10:11:39Z")

</div>

In case this can help, here is my own implementation of the substitution (for both parameters and variables). It’s probably not the best way to proceed, as I had to apply many type conversions and I don’t know if it covers all cases of reaction networks.

```julia
import SymbolicUtils.substitute

substitute(p::Pair,subs) = Pair(substitute(p[1],subs),substitute(p[2],subs)) 

substitute(r::Reaction, subs) = Reaction( 
                                       substitute(r.rate, subs),
                                       convert(Vector{Any},[substitute(s, subs) for s in r.substrates]), 
                                       convert(Vector{Any},[substitute(s, subs) for s in r.products]),
                                       convert(Vector{Any},[substitute(s, subs) for s in r.substoich]),
                                       convert(Vector{Any},[substitute(s, subs) for s in r.prodstoich]),
                                       convert(Vector{Pair{Any,Any}},[substitute(d, subs) for d in r.netstoich]),
                                       r.only_use_rate
                                      )

substitute(rn::ReactionSystem, subs; name = rn.name) = ReactionSystem(convert(Vector{Reaction},[substitute(r,subs) for r in rn.eqs]),rn.iv, name = name)

```
