From 012ca2c4eed9e47622cae853a09edfee5b01a66c Mon Sep 17 00:00:00 2001 From: paulflang Date: Mon, 2 Dec 2024 12:57:11 +0100 Subject: [PATCH 1/5] add test for is_event_assignment --- test/simresults.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/simresults.jl b/test/simresults.jl index 16a0f2c..aad1a7d 100644 --- a/test/simresults.jl +++ b/test/simresults.jl @@ -8,7 +8,8 @@ const case_ids = [7, # boundary_condition 140, # compartment size overridden with assignmentRule 170, # Model using parameters and rules only 325, # One reactions and two rate rules with four species in a 2D compartment - 679 # Initial value calculated by assignmentRule in compartment of non-unit size # 1208, # Non-hOSU species with rateRule in variable compartment -> require MTK fix. + 679, # Initial value calculated by assignmentRule in compartment of non-unit size # 1208, # Non-hOSU species with rateRule in variable compartment -> require MTK fix. + 944 # Non-constant parameter as target of event_assignment ] const logdir = joinpath(@__DIR__, "logs") From f7e0f82ae8593fe249257be9fc3b7eefdcdfa056 Mon Sep 17 00:00:00 2001 From: paulflang Date: Mon, 2 Dec 2024 14:18:39 +0100 Subject: [PATCH 2/5] fix is_event_assignment --- src/drafts.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drafts.jl b/src/drafts.jl index 2d313b2..4a0c3c2 100644 --- a/src/drafts.jl +++ b/src/drafts.jl @@ -1,5 +1,5 @@ function is_event_assignment(k, model) - for ev in values(model.events) + for ev in last.(model.events) for as in ev.event_assignments if as.variable == k return true From 27c1def456d533114ddd6319566be0b3cc2e521e Mon Sep 17 00:00:00 2001 From: paulflang Date: Mon, 2 Dec 2024 14:22:06 +0100 Subject: [PATCH 3/5] bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3fb013c..3a0203c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SBMLToolkit" uuid = "86080e66-c8ac-44c2-a1a0-9adaadfe4a4e" authors = ["paulflang", "anandijain"] -version = "0.1.29" +version = "0.1.30" [deps] Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83" From 087083ff266fe2f161d4cfed931c01f0fa7201a4 Mon Sep 17 00:00:00 2001 From: paulflang Date: Mon, 2 Dec 2024 16:51:25 +0100 Subject: [PATCH 4/5] define zero ODE for parameters/compartments with event assignments --- src/systems.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/systems.jl b/src/systems.jl index ffc6e2f..5dc53d9 100644 --- a/src/systems.jl +++ b/src/systems.jl @@ -87,11 +87,20 @@ function Catalyst.ReactionSystem(model::SBML.Model; kwargs...) # Todo: requires # Dict(Catalyst.DEFAULT_IV.val => 0))) push!(raterules_subs, rhs ~ o.lhs) end + zero_rates = [] + for (k, v) in merge(model.parameters, model.compartments) + if is_event_assignment(k, model) + if v.constant + ErrorException("$k appears in event assignment but should be constant.") + end + push!(zero_rates, D(create_var(k, IV; isbcspecies = true)) ~ 0) + end + end if haskey(kwargs, :defaults) defs = ModelingToolkit._merge(defs, kwargs[:defaults]) kwargs = filter(x -> !isequal(first(x), :defaults), kwargs) end - rs = ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged...], + rs = ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged..., zero_rates...], IV, first.(u0map), first.(parammap); defaults = defs, name = gensym(:SBML), continuous_events = get_events(model), From 20a54303e9e3848acdfbde5f8051093cf26f7cb5 Mon Sep 17 00:00:00 2001 From: paulflang Date: Mon, 2 Dec 2024 17:52:17 +0100 Subject: [PATCH 5/5] format --- src/systems.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/systems.jl b/src/systems.jl index 5dc53d9..e20a7ef 100644 --- a/src/systems.jl +++ b/src/systems.jl @@ -100,7 +100,8 @@ function Catalyst.ReactionSystem(model::SBML.Model; kwargs...) # Todo: requires defs = ModelingToolkit._merge(defs, kwargs[:defaults]) kwargs = filter(x -> !isequal(first(x), :defaults), kwargs) end - rs = ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged..., zero_rates...], + rs = ReactionSystem( + [rxs..., algrules..., raterules_subs..., obsrules_rearranged..., zero_rates...], IV, first.(u0map), first.(parammap); defaults = defs, name = gensym(:SBML), continuous_events = get_events(model),