structs.jl 1.92 KB
Newer Older
1

2
3
const Maybe{X} = Union{Nothing,X}

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
4
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
5
Part of a measurement unit definition that corresponds to the SBML definition
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
6
of `Unit`. For example, the unit "per square megahour", Mh^(-2), is written as:
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
7

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
8
9
10
11
12
13
14
15
    UnitPart("second",  # base SI unit, this says we are measuring time
             -2,        # exponent, says "per square"
             6,         # log-10 scale of the unit, says "mega"
             1/3600)    # second-to-hour multiplier

Compound units (such as "volt-amperes" and "dozens of yards per ounce") are
built from multiple `UnitPart`s; see the definition of field `units` in
[`Model`](@ref).
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
16
"""
17
18
19
20
21
22
23
24
struct UnitPart
    kind::String
    exponent::Int
    scale::Int
    multiplier::Float64
    UnitPart(k, e, s, m) = new(k, e, s, m)
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
25
26
"""
Reaction with stoichiometry that assigns reactants and products their relative
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
27
28
29
consumption/production rates (accessible in field `stoichiometry`), lower/upper
bounds (in tuples `lb` and `ub`, with unit names), and objective coefficient
(`oc`).
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
30
"""
31
32
33
34
35
struct Reaction
    stoichiometry::Dict{String,Float64}
    lb::Tuple{Float64,String}
    ub::Tuple{Float64,String}
    oc::Float64
36
37
    notes::Maybe{String}
    Reaction(s, l, u, o, n) = new(s, l, u, o, n)
38
39
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
40
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
41
42
Species metadata -- contains a human-readable `name`, and a `compartment`
identifier
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
43
"""
44
45
46
struct Species
    name::String
    compartment::String
47
    formula::String
48
49
50
    charge::Maybe{Int}
    notes::Maybe{String}
    Species(na, co, f, ch, no) = new(na, co, f, ch, no)
51
52
end

Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
53
"""
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
54
55
56
Structure that collects the model-related data. Contains `units`,
`compartments`, `species` and `reactions`. The contained dictionaries are
indexed by identifiers of the corresponding objects.
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
57
"""
58
struct Model
St. Elmo's avatar
St. Elmo committed
59
    params::Dict{String,Float64}
60
61
62
63
    units::Dict{String,Vector{UnitPart}}
    compartments::Vector{String}
    species::Dict{String,Species}
    reactions::Dict{String,Reaction}
64
65
    notes::Maybe{String}
    Model(p, u, c, s, r, n) = new(p, u, c, s, r, n)
66
end