Unverified Commit d3413c43 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #118 from LCSB-BioCore/mk-lenient-extensive-kinetic-math

Allow rescue in very deep failure with hOSU and extensive math
parents ea39152c b101210c
...@@ -103,26 +103,42 @@ initial_concentrations(m::SBML.Model; convert_amounts = false) = ( ...@@ -103,26 +103,42 @@ initial_concentrations(m::SBML.Model; convert_amounts = false) = (
""" """
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)'",
),
),
)
Convert a SBML math `formula` to "extensive" kinetic laws, where the references Convert a SBML math `formula` to "extensive" kinetic laws, where the references
to species that are marked as not having only substance units are converted to species that are marked as not having only substance units are converted
from amounts to concentrations. from amounts to concentrations.
If the data is missing, you can supply a function that adds them. A common way
to handle errors is to assume that unsized compartments have volume 1.0 (of
whatever units), you can specify that behavior by supplying
`handle_empty_compartment_size = _ -> 1.0`.
Handling of units in the conversion process is ignored in this version. 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 conv(x::SBML.MathIdent) = begin
haskey(m.species, x.id) || return x haskey(m.species, x.id) || return x
sp = m.species[x.id] sp = m.species[x.id]
sp.only_substance_units && return x sp.only_substance_units && return x
sz = m.compartments[sp.compartment].size sz = m.compartments[sp.compartment].size
isnothing(sz) && throw( isnothing(sz) && (sz = handle_empty_compartment_size(x.id))
DomainError(
formula,
"Non-substance-only-unit reference to species `$(x.id)' in an unsized compartment `$(sp.compartment)'.",
),
)
SBML.MathApply("/", [x, SBML.MathVal(sz)]) SBML.MathApply("/", [x, SBML.MathVal(sz)])
end end
conv(x::SBML.MathApply) = SBML.MathApply(x.fn, conv.(x.args)) 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