Skip to content

Commit 7cb91dc

Browse files
committed
- Throws warning when both substrate and product vector is nothing.
- Throws warning when someone gives stochiometry for a 'nothing" substrate or product input. - Empty substrate/product stoichimoetry vectors take the type of the other.
1 parent 4ddfdd4 commit 7cb91dc

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/systems/reaction/reactionsystem.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ end
1111
function Reaction(rate, subs, prods, substoich, prodstoich;
1212
netstoich=nothing, only_use_rate=false, kwargs...)
1313

14-
subsv,substoichv = isnothing(subs) ? (Vector{Operation}(),Int[]) : (subs,substoich)
15-
prodsv,prodstoichv = isnothing(prods) ? (Vector{Operation}(),Int[]) : (prods,prodstoich)
16-
ns = isnothing(netstoich) ? get_netstoich(subsv, prodsv, substoichv, prodstoichv) : netstoich
17-
Reaction(rate, subsv, prodsv, substoichv, prodstoichv, ns, only_use_rate)
14+
(isnothing(prods)&&isnothing(subs)) && error("A reaction requires a non-nothing substrate or product vector.")
15+
if isnothing(subs)
16+
subs = Vector{Operation}()
17+
(substoich!=nothing) && error("If substrates are nothing, substrate stiocihometries have to be so too.")
18+
substoich = (prodstoich == nothing) ? nothing : typeof(prodstoich)()
19+
end
20+
if isnothing(prods)
21+
prods = Vector{Operation}()
22+
(prodstoich!=nothing) && error("If products are nothing, product stiocihometries have to be so too.")
23+
prodstoich = (substoich == nothing) ? nothing : typeof(substoich)()
24+
end
25+
ns = isnothing(netstoich) ? get_netstoich(subs, prods, substoich, prodstoich) : netstoich
26+
Reaction(rate, subs, prods, substoich, prodstoich, ns, only_use_rate)
1827
end
1928

29+
a =[1.,2.3,4.]
30+
typeof(a)()
31+
2032
# three argument constructor assumes stoichiometric coefs are one and integers
2133
function Reaction(rate, subs, prods; kwargs...)
2234

23-
sstoich = isnothing(subs) ? Int[] : ones(Int,length(subs))
24-
pstoich = isnothing(prods) ? Int[] : ones(Int,length(prods))
35+
sstoich = isnothing(subs) ? nothing : ones(Int,length(subs))
36+
pstoich = isnothing(prods) ? nothing : ones(Int,length(prods))
2537
Reaction(rate, subs, prods, sstoich, pstoich; kwargs...)
2638
end
2739

0 commit comments

Comments
 (0)