Skip to content

Commit 93c94c9

Browse files
committed
init
1 parent 1a4a816 commit 93c94c9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/registered_functions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ expand_registered_functions(expr)
116116
117117
Takes an expression, and expands registered function expressions. E.g. `mm(X,v,K)` is replaced with v*X/(X+K). Currently supported functions: `mm`, `mmr`, `hill`, `hillr`, and `hill`.
118118
"""
119-
function expand_registered_functions(expr)
119+
function expand_registered_functions!(expr)
120120
iscall(expr) || return expr
121121
args = arguments(expr)
122122
if operation(expr) == Catalyst.mm
@@ -132,13 +132,13 @@ function expand_registered_functions(expr)
132132
((args[1])^args[5] + (args[2])^args[5] + (args[4])^args[5])
133133
end
134134
for i in 1:length(args)
135-
args[i] = expand_registered_functions(args[i])
135+
args[i] = expand_registered_functions!(args[i])
136136
end
137137
return expr
138138
end
139139
# If applied to a Reaction, return a reaction with its rate modified.
140140
function expand_registered_functions(rx::Reaction)
141-
Reaction(expand_registered_functions(rx.rate), rx.substrates, rx.products,
141+
Reaction(expand_registered_functions!(deepcopy(rx.rate)), rx.substrates, rx.products,
142142
rx.substoich, rx.prodstoich, rx.netstoich, rx.only_use_rate, rx.metadata)
143143
end
144144
# If applied to a Equation, returns it with it applied to lhs and rhs

test/reactionsystem_core/custom_crn_functions.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,18 @@ let
154154
@test isequal(Catalyst.expand_registered_functions(eq3), 0 ~ V * (X^N) / (X^N + K^N))
155155
@test isequal(Catalyst.expand_registered_functions(eq4), 0 ~ V * (K^N) / (X^N + K^N))
156156
@test isequal(Catalyst.expand_registered_functions(eq5), 0 ~ V * (X^N) / (X^N + Y^N + K^N))
157+
end
158+
159+
# Ensures that original system is not modified.
160+
let
161+
# Create model with a registered function.
162+
@species X(t)
163+
@parameters v K
164+
rxs = [Reaction(mm(X,v,K), [], [X])]
165+
@named rs = ReactionSystem(rxs, t)
166+
167+
# Check that `expand_registered_functions` does not mutate original model.
168+
rs_expanded_funcs = Catalyst.expand_registered_functions(rs)
169+
@test isequal(only(Catalyst.get_rxs(rs)).rate, Catalyst.mm(X,v,K))
170+
@test isequal(only(Catalyst.get_rxs(rs_expanded_funcs)).rate, v*X/(X + K))
157171
end

0 commit comments

Comments
 (0)