Commit 67f64299 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

allow rescue in extensive_kinetic_math

closes #117
parent ea39152c
......@@ -111,18 +111,21 @@ from amounts to concentrations.
Handling of units in the conversion process is ignored in this version.
"""
function extensive_kinetic_math(m::SBML.Model, formula::SBML.Math)
function extensive_kinetic_math(
m::SBML.Model,
formula::SBML.Math;
handle_empty_compartment_size = (id::String) -> throw(
DomainError(
"Non-substance-only-unit reference to species `$id' in an unsized compartment `$(m.species[id].compartment)'",
),
),
)
conv(x::SBML.MathIdent) = begin
haskey(m.species, x.id) || return x
sp = m.species[x.id]
sp.only_substance_units && return x
sz = m.compartments[sp.compartment].size
isnothing(sz) && throw(
DomainError(
formula,
"Non-substance-only-unit reference to species `$(x.id)' in an unsized compartment `$(sp.compartment)'.",
),
)
isnothing(sz) && (sz = handle_empty_compartment_size(x.id))
SBML.MathApply("/", [x, SBML.MathVal(sz)])
end
conv(x::SBML.MathApply) = SBML.MathApply(x.fn, conv.(x.args))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment