# Catalyst.jl - what's the best way to extract interpolation from the reaction\_network

**URL:** <https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [June 24, 2025, 2:17pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171 "2025-06-24T14:17:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mindy](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Mindy](https://discourse.julialang.org/u/Mindy)\
**Post date:** [June 24, 2025, 2:17pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/1 "2025-06-24T14:17:54Z")

</div>

Hi!

If I want to extract and plot the interpolating variable - $d\_rate (temporal dynamic profile) from this example code, does catalyst.jl have any built-in function so that I can extract the results directly, instead of re-write and re-calculate? Thanks!

```julia
@species X1(t) X2(t) X12(t)
@parameters a b c
d_rate = c * X1 * X2
rn = @reaction_network begin
    a, X1 --> 0
    b, X2 --> 0
    $d_rate, X1 + X2 => X12
end

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 24, 2025, 6:30pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/2 "2025-06-24T18:30:49Z")

</div>

Are you looking for `sol[d_rate]` or the interpolating function `sol(t; idxs = d_rate)` from the solution?

---

<div class="post-metadata">

**Author:** ![Mindy](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Mindy](https://discourse.julialang.org/u/Mindy)\
**Post date:** [June 24, 2025, 7:30pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/3 "2025-06-24T19:30:24Z")

</div>

Thanks!! Yes, I was looking for `sol[d_rate]`

---

<div class="post-metadata">

**Author:** ![Mindy](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Mindy](https://discourse.julialang.org/u/Mindy)\
**Post date:** [August 8, 2025, 3:49am UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/4 "2025-08-08T03:49:19Z")

</div>

A follow up question - when I put it inside the function, the sol[d\_rate] no longer work, I tried sol[:d\_rate] which doesn’t work neiter. Any suggestions? Thank you so much for your help!!

```julia-auto
function model()
     t = default_t()     
     @species X1(t) X2(t) X12(t)
     @parameters a b c

     d_rate = c * X1 * X2
     rn = @reaction_network begin
          $d_rate, X1 + X2 => X12 # the full system has many rate, and with all different type of eqautions
      end
      return rn
end

# perform analysis
rn = model()
prob = ODEProblem(rn, u0, tspan, p)
sol = solve(prob)

# try to extract d_rate
sol[d_rate] # error: d_rate not defined 
sol[:d_rate] # error: key :d_rate not found

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 8, 2025, 3:55am UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/5 "2025-08-08T03:55:13Z")

</div>

`sol[rn.d_rate]`

---

<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:** [August 8, 2025, 1:27pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/6 "2025-08-08T13:27:28Z")

</div>

> [@Mindy](#):
>
> ```julia-auto
> function model()
> t = default_t()     
> @species X1(t) X2(t) X12(t)
> @parameters a b c
> 
> d_rate = c * X1 * X2
> rn = @reaction_network begin
> $d_rate, X1 + X2 => X12 # the full system has many rate, and with all different type of eqautions
> end
> return rn
> end
> 
> ```

This is equivalent to directly writing

```julia
function model()
     rn = @reaction_network begin
          c * X1 * X2, X1 + X2 => X12 
      end
      return rn
end

```

i.e. when you interpolate `d_rate` it is eagerly substituted for its symbolic expression. If you want `d_rate` to actually be a variable in the system you can query you need to add an equation for it. I’d suggest making your model like

```julia
function model()
     rn = @reaction_network begin
          @parameters c
          @equations begin
              d_rate ~ c * X1 * X2
          end
          d_rate * X1 * X2, X1 + X2 => X12       
      end
      return rn
end

rn = model()

# note you need to call structural_simplify to remove d_rate as an equation in the converted ODESystem
osys = structural_simplify(convert(ODESystem, rn))  

prob = ODEProblem(osys, u0, tspan, p)
sol = solve(prob)
sol[osys.d_rate] # should now work

```

---

<div class="post-metadata">

**Author:** ![Mindy](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Mindy](https://discourse.julialang.org/u/Mindy)\
**Post date:** [August 21, 2025, 2:44pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/8 "2025-08-21T14:44:58Z")

</div>

Thanks Sam! A follow up clairification question about your code. After @equations, you have

```julia-auto
          d_rate * X1 * X2, X1 + X2 => X12   

```

do you mean ` d_rate, X1 + X2 => X12 `  
or

```julia-auto
          c * X1 * X2, X1 + X2 => X12   

```

---

<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:** [August 21, 2025, 3:22pm UTC](https://discourse.julialang.org/t/catalyst-jl-whats-the-best-way-to-extract-interpolation-from-the-reaction-network/130171/9 "2025-08-21T15:22:11Z")

</div>

That’s a typo. It should just be `d_rate` for the rate to be consistent with your code.
