Skip to content

Commit 1e3bb24

Browse files
committed
add test
1 parent 4cd280f commit 1e3bb24

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

test/reactionsystem_core/custom_crn_functions.jl

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,105 @@ let
216216
@test isequal(get_continuous_events(rs_expanded), continuous_events)
217217
@test isequal(get_discrete_events(rs_expanded), discrete_events)
218218
end
219+
220+
# test for hill function expansion
221+
let
222+
rn = @reaction_network begin
223+
hill(X, v, K, n), X + Y --> Z
224+
mm(X, v, K), X + Y --> Z
225+
hillr(X, v, K, n), X + Y --> Z
226+
mmr(X, v, K), X + Y --> Z
227+
end
228+
osys = complete(convert(ODESystem, rn; expand_catalyst_funs = false))
229+
t = default_t()
230+
D = default_time_deriv()
231+
@unpack X, v, K, n, Y, Z = rn
232+
osyseqs = equations(osys)
233+
eqs = [D(X) ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
234+
D(Y) ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
235+
D(Z) ~ hill(X, v, K, n)*X*Y + mm(X,v,K)*X*Y + hillr(X,v,K,n)*X*Y + mmr(X,v,K)*X*Y]
236+
reorder = [findfirst(eq -> isequal(eq.lhs, osyseq.lhs), eqs) for osyseq in osyseqs]
237+
for (osysidx,eqidx) in enumerate(reorder)
238+
@test iszero(simplify(eqs[eqidx].rhs - osyseqs[osysidx].rhs))
239+
end
240+
241+
osys2 = complete(convert(ODESystem, rn))
242+
hill2(x, v, k, n) = v * x^n / (k^n + x^n)
243+
mm2(X,v,K) = v*X / (X + K)
244+
mmr2(X,v,K) = v*K / (X + K)
245+
hillr2(X,v,K,n) = v * (K^n) / (X^n + K^n)
246+
eqs2 = [D(X) ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
247+
D(Y) ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
248+
D(Z) ~ hill2(X, v, K, n)*X*Y + mm2(X,v,K)*X*Y + hillr2(X,v,K,n)*X*Y + mmr2(X,v,K)*X*Y]
249+
osyseqs2 = equations(osys2)
250+
reorder = [findfirst(eq -> isequal(eq.lhs, osyseq.lhs), eqs2) for osyseq in osyseqs2]
251+
for (osysidx,eqidx) in enumerate(reorder)
252+
@test iszero(simplify(eqs2[eqidx].rhs - osyseqs2[osysidx].rhs))
253+
end
254+
255+
nlsys = complete(convert(NonlinearSystem, rn; expand_catalyst_funs = false))
256+
nlsyseqs = equations(nlsys)
257+
eqs = [0 ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
258+
0 ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
259+
0 ~ hill(X, v, K, n)*X*Y + mm(X,v,K)*X*Y + hillr(X,v,K,n)*X*Y + mmr(X,v,K)*X*Y]
260+
for (i, eq) in enumerate(eqs)
261+
@test iszero(simplify(eq.rhs - nlsyseqs[i].rhs))
262+
end
263+
264+
nlsys2 = complete(convert(NonlinearSystem, rn))
265+
nlsyseqs2 = equations(nlsys2)
266+
eqs2 = [0 ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
267+
0 ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
268+
0 ~ hill2(X, v, K, n)*X*Y + mm2(X,v,K)*X*Y + hillr2(X,v,K,n)*X*Y + mmr2(X,v,K)*X*Y]
269+
for (i, eq) in enumerate(eqs2)
270+
@test iszero(simplify(eq.rhs - nlsyseqs2[i].rhs))
271+
end
272+
273+
sdesys = complete(convert(SDESystem, rn; expand_catalyst_funs = false))
274+
sdesyseqs = equations(sdesys)
275+
eqs = [D(X) ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
276+
D(Y) ~ -hill(X, v, K, n)*X*Y - mm(X,v,K)*X*Y - hillr(X,v,K,n)*X*Y - mmr(X,v,K)*X*Y,
277+
D(Z) ~ hill(X, v, K, n)*X*Y + mm(X,v,K)*X*Y + hillr(X,v,K,n)*X*Y + mmr(X,v,K)*X*Y]
278+
reorder = [findfirst(eq -> isequal(eq.lhs, sdesyseq.lhs), eqs) for sdesyseq in sdesyseqs]
279+
for (sdesysidx,eqidx) in enumerate(reorder)
280+
@test iszero(simplify(eqs[eqidx].rhs - sdesyseqs[sdesysidx].rhs))
281+
end
282+
sdesysnoiseeqs = ModelingToolkit.get_noiseeqs(sdesys)
283+
neqvec = diagm(sqrt.(abs.([hill(X, v, K, n)*X*Y, mm(X,v,K)*X*Y, hillr(X,v,K,n)*X*Y, mmr(X,v,K)*X*Y])))
284+
neqmat = [-1 -1 -1 -1; -1 -1 -1 -1; 1 1 1 1]
285+
neqmat *= neqvec
286+
@test all(iszero, simplify.(sdesysnoiseeqs .- neqmat))
287+
288+
sdesys = complete(convert(SDESystem, rn))
289+
sdesyseqs = equations(sdesys)
290+
eqs = [D(X) ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
291+
D(Y) ~ -hill2(X, v, K, n)*X*Y - mm2(X,v,K)*X*Y - hillr2(X,v,K,n)*X*Y - mmr2(X,v,K)*X*Y,
292+
D(Z) ~ hill2(X, v, K, n)*X*Y + mm2(X,v,K)*X*Y + hillr2(X,v,K,n)*X*Y + mmr2(X,v,K)*X*Y]
293+
reorder = [findfirst(eq -> isequal(eq.lhs, sdesyseq.lhs), eqs) for sdesyseq in sdesyseqs]
294+
for (sdesysidx,eqidx) in enumerate(reorder)
295+
@test iszero(simplify(eqs[eqidx].rhs - sdesyseqs[sdesysidx].rhs))
296+
end
297+
sdesysnoiseeqs = ModelingToolkit.get_noiseeqs(sdesys)
298+
neqvec = diagm(sqrt.(abs.([hill2(X, v, K, n)*X*Y, mm2(X,v,K)*X*Y, hillr2(X,v,K,n)*X*Y, mmr2(X,v,K)*X*Y])))
299+
neqmat = [-1 -1 -1 -1; -1 -1 -1 -1; 1 1 1 1]
300+
neqmat *= neqvec
301+
@test all(iszero, simplify.(sdesysnoiseeqs .- neqmat))
302+
303+
jsys = convert(JumpSystem, rn; expand_catalyst_funs = false)
304+
jsyseqs = equations(jsys).x[2]
305+
rates = getfield.(jsyseqs, :rate)
306+
affects = getfield.(jsyseqs, :affect!)
307+
reqs = [ Y*X*hill(X, v, K, n), Y*X*mm(X, v, K), hillr(X, v, K, n)*Y*X, Y*X*mmr(X, v, K)]
308+
affeqs = [Z ~ 1 + Z, Y ~ -1 + Y, X ~ -1 + X]
309+
@test all(iszero, simplify(rates .- reqs))
310+
@test all(aff -> isequal(aff, affeqs), affects)
311+
312+
jsys = convert(JumpSystem, rn)
313+
jsyseqs = equations(jsys).x[2]
314+
rates = getfield.(jsyseqs, :rate)
315+
affects = getfield.(jsyseqs, :affect!)
316+
reqs = [ Y*X*hill2(X, v, K, n), Y*X*mm2(X, v, K), hillr2(X, v, K, n)*Y*X, Y*X*mmr2(X, v, K)]
317+
affeqs = [Z ~ 1 + Z, Y ~ -1 + Y, X ~ -1 + X]
318+
@test all(iszero, simplify(rates .- reqs))
319+
@test all(aff -> isequal(aff, affeqs), affects)
320+
end

0 commit comments

Comments
 (0)