Skip to content

Commit 3023a88

Browse files
authored
Merge pull request #127 from SciML/pl/speciesreference_duplication
fix handling g of duplicate speciesReference
2 parents f700d96 + 7ae9633 commit 3023a88

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SBMLToolkit"
22
uuid = "86080e66-c8ac-44c2-a1a0-9adaadfe4a4e"
33
authors = ["paulflang", "anandijain"]
4-
version = "0.1.22"
4+
version = "0.1.23"
55

66
[deps]
77
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"

src/reactions.jl

+25-8
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Get reagents
8080
function get_reagents(reactant_references::Vector{SBML.SpeciesReference},
8181
product_references::Vector{SBML.SpeciesReference},
8282
model::SBML.Model)
83-
reactants = Num[]
84-
products = Num[]
83+
reactants = String[]
84+
products = String[]
8585
rstoich = Float64[]
8686
pstoich = Float64[]
8787

@@ -93,11 +93,21 @@ function get_reagents(reactant_references::Vector{SBML.SpeciesReference},
9393
stoich = 1.0
9494
end
9595
iszero(stoich) && @error("Stoichiometry of $sn must be non-zero")
96-
push!(reactants, create_var(sn, IV))
97-
push!(rstoich, stoich)
96+
if sn in reactants
97+
idx = findfirst(isequal(sn), reactants)
98+
rstoich[idx] += stoich
99+
else
100+
push!(reactants, sn)
101+
push!(rstoich, stoich)
102+
end
98103
if model.species[sn].boundary_condition == true
99-
push!(products, create_var(sn, IV))
100-
push!(pstoich, stoich)
104+
if sn in products
105+
idx = findfirst(isequal(sn), products)
106+
pstoich[idx] += stoich
107+
else
108+
push!(products, sn)
109+
push!(pstoich, stoich)
110+
end
101111
end
102112
end
103113
for pr in product_references
@@ -109,10 +119,17 @@ function get_reagents(reactant_references::Vector{SBML.SpeciesReference},
109119
end
110120
iszero(stoich) && @error("Stoichiometry of $sn must be non-zero")
111121
if model.species[sn].boundary_condition != true
112-
push!(products, create_var(sn, IV))
113-
push!(pstoich, stoich)
122+
if sn in products
123+
idx = findfirst(isequal(sn), products)
124+
pstoich[idx] += stoich
125+
else
126+
push!(products, sn)
127+
push!(pstoich, stoich)
128+
end
114129
end
115130
end
131+
reactants = map(x -> Num(create_var(x, IV)), reactants)
132+
products = map(x -> Num(create_var(x, IV)), products)
116133

117134
if (length(reactants) == 0)
118135
reactants = nothing

test/reactions.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ m = SBML.Model(species = Dict("s" => s), reactions = Dict("r1" => r))
105105
SBMLToolkit.get_reagents(r.reactants, r.products, m))
106106
@test isequal((nothing, nothing, nothing, nothing),
107107
SBMLToolkit.get_reagents(r.products, r.reactants, m))
108+
109+
r = SBML.Reaction(reactants = [SBML.SpeciesReference(species = "s", stoichiometry = 1.0),
110+
SBML.SpeciesReference(species = "s", stoichiometry = 1.0)],
111+
reversible = false)
112+
m = SBML.Model(species = Dict("s" => s), reactions = Dict("r1" => r))
113+
@test isequal(([var], [var], [2.0], [2.0]),
114+
SBMLToolkit.get_reagents(r.reactants, r.products, m))
108115

109116
# Test use_rate
110117
@test isequal(SBMLToolkit.use_rate(k1 * s1, [s1], [1]), (k1, false)) # Case hOSU=true
@@ -113,7 +120,7 @@ m = SBML.Model(species = Dict("s" => s), reactions = Dict("r1" => r))
113120

114121
# Test get_massaction
115122
@test isequal(SBMLToolkit.get_massaction(k1 * s1, [s1], [1]), k1) # Case hOSU=true
116-
@test_broken isequal(SBMLToolkit.get_massaction(k1 * s1 / c1, [s1], [1]), k1 / c1) # Case hOSU=false
123+
@test isequal(SBMLToolkit.get_massaction(k1 * s1 / c1, [s1], [1]), k1 / c1) # Case hOSU=false
117124
@test isequal(SBMLToolkit.get_massaction(k1 + c1, nothing, nothing), k1 + c1) # Case zero order kineticLaw
118125
@test isnan(SBMLToolkit.get_massaction(k1 * s1 * s2 / (c1 + s2), [s1], [1])) # Case Michaelis-Menten kinetics
119126
@test isnan(SBMLToolkit.get_massaction(k1 * s1 * IV, [s1], [1])) # Case kineticLaw with time

0 commit comments

Comments
 (0)