@@ -21,12 +21,56 @@ function get_rules(model)
21
21
algeqs, obseqs, raterules
22
22
end
23
23
24
+ function extensive_kinetic_math (m:: SBML.Model , formula:: SBML.Math )
25
+ SBML. interpret_math ( # TODO : move this to SBML.jl
26
+ formula,
27
+ map_apply = (x, rec) -> SBML. MathApply (x. fn, rec .(x. args)),
28
+ map_const = identity,
29
+ map_ident = (x:: SBML.MathIdent ) -> begin
30
+ haskey (m. reactions, x. id) && return m. reactions[x. id]. kinetic_math
31
+ haskey (m. species, x. id) || return x
32
+ sp = m. species[x. id]
33
+ sp. only_substance_units && return x
34
+ if isnothing (m. compartments[sp. compartment]. size) &&
35
+ ! seemsdefined (sp. compartment, m)
36
+ if m. compartments[sp. compartment]. spatial_dimensions == 0
37
+ # If the compartment ID doesn't seem directly defined anywhere
38
+ # and it is a zero-dimensional unsized compartment, just avoid
39
+ # any sizing questions.
40
+ return x
41
+ else
42
+ # In case the compartment is expected to be defined, complain.
43
+ throw (
44
+ DomainError (
45
+ sp. compartment,
46
+ " compartment size is insufficiently defined"
47
+ ),
48
+ )
49
+ end
50
+ else
51
+ # Now we are sure that the model either has the compartment with
52
+ # constant size, or the definition is easily reachable. So just use
53
+ # the compartment ID as a variable to compute the concentration (or
54
+ # area-centration etc, with different dimensionalities) by dividing
55
+ # it.
56
+ return SBML. MathApply (" /" , [x, SBML. MathIdent (sp. compartment)])
57
+ end
58
+ end ,
59
+ map_lambda = (x, _) -> error (
60
+ ErrorException (" converting lambdas to extensive kinetic math is not supported" ),
61
+ ),
62
+ map_time = identity,
63
+ map_avogadro = identity,
64
+ map_value = identity
65
+ )
66
+ end
67
+
24
68
function get_var_and_assignment (model, rule)
25
69
if ! haskey (merge (model. species, model. compartments, model. parameters), rule. variable)
26
70
error (" Cannot find target for rule with ID `$(rule. variable) `" )
27
71
end
28
72
var = create_var (rule. variable, IV)
29
- math = SBML . extensive_kinetic_math (model, rule. math)
73
+ math = extensive_kinetic_math (model, rule. math)
30
74
vc = get_volume_correction (model, rule. variable)
31
75
if ! isnothing (vc)
32
76
math = SBML. MathApply (" *" , [SBML. MathIdent (vc), math])
0 commit comments