Version: v0.14.0

reaction_system

Stable type · Document types

Tier: stable · Kind: type · Topic: Document types

JuliaTypeScriptPythonRustGo
ReactionSystemnot exportedReactionSystemReactionSystemReactionSystem

Julia

struct ReactionSystem
ReactionSystem(species::Vector{Species}, reactions::Vector{Reaction}; parameters, subsystems, constraint_equations, discrete_events, continuous_events, tolerance, tests, analyses, reference)
ReactionSystem

Collection of chemical reactions with associated species, supporting hierarchical composition.

Carries every property esm-schema.json’s ReactionSystem defines, including subsystems (a reaction-system hierarchy), constraint_equations (additional algebraic/ODE constraints), continuous_events / discrete_events and analyses, all of which load and serialize. analyses is kept VERBATIM for the reason Model ’s is.

Source

Example (reactions)

doc = load_path(joinpath(FIXTURES, "ozone.esm"))
rs = doc.reaction_systems["Ozone"]
@assert rs isa ReactionSystem
@assert length(rs.reactions) == 2

odes = derive_odes(rs)  # a Model with one D(species)/dt per species
# d[NO2]/dt = k1 [NO][O3] - jNO2 [NO2], compared as canonical JSON.
no2 = odes.equations[3]
println(canonical_json(no2.rhs))
@assert canonical_json(no2.rhs) ==
    """{"args":[{"args":["NO","O3","k1"],"op":"*"},{"args":[-1,"NO2","jNO2"],"op":"*"}],"op":"+"}"""

# Rows are species (O3, NO, NO2), columns are reactions (R1, R2).
@assert stoichiometric_matrix(rs) == [-1.0 1.0; -1.0 1.0; 1.0 -1.0]

From docs/api/examples/julia/reactions.jl

TypeScript

TypeScript does not export this type.

Python

class ReactionSystem
ReactionSystem(name: str, species: list[Species] = list(), parameters: list[Parameter] = list(), reactions: list[Reaction] = list(), constraint_equations: list[Equation] = list(), subsystems: dict[str, ReactionSystem] = dict(), tolerance: Tolerance | None = None, tests: list[Test] = list(), analyses: list[Analysis] = list(), continuous_events: list[ContinuousEvent] = list(), discrete_events: list[DiscreteEvent] = list(), reference: Reference | None = None)

A system of chemical reactions.

Source

Example (reactions)

doc = earthsci_ast.load_path(FIXTURES / "ozone.esm")
system = doc.reaction_systems["Ozone"]
assert [s.name for s in system.species] == ["O3", "NO", "NO2"]
assert [r.id for r in system.reactions] == ["R1", "R2"]

odes = earthsci_ast.derive_odes(system)

# One equation per species, in declaration order; rate constants become parameters.
assert earthsci_ast.ode_states(odes) == ["NO", "NO2", "O3"]
assert [eq.lhs.args[0] for eq in odes.equations] == ["O3", "NO", "NO2"]
assert odes.variables["k1"].type == "parameter"
# d[NO2]/dt = k1 [NO][O3] - jNO2 [NO2]
assert odes.equations[2].rhs == ExprNode(
    op="+",
    args=[
        ExprNode(op="*", args=["k1", "NO", "O3"]),
        ExprNode(op="*", args=[-1, ExprNode(op="*", args=["jNO2", "NO2"])]),
    ],
)

From docs/api/examples/python/reactions.py

Rust

pub struct ReactionSystem {
    pub reference: Option<Reference>,
    pub species: IndexMap<String, Species>,
    pub parameters: IndexMap<String, Parameter>,
    pub reactions: Vec<Reaction>,
    pub constraint_equations: Option<Vec<Equation>>,
    pub discrete_events: Option<Vec<DiscreteEvent>>,
    pub continuous_events: Option<Vec<ContinuousEvent>>,
    pub subsystems: Option<IndexMap<String, Value>>,
    pub tolerance: Option<Tolerance>,
    pub tests: Option<Vec<ModelTest>>,
    pub analyses: Option<Vec<ModelAnalysis>>,
}

Reaction network component

Source · Rust docs

Go

type ReactionSystem struct {
	Reference           *Reference           `json:"reference,omitempty"`
	Species             map[string]Species   `json:"species"`
	Parameters          map[string]Parameter `json:"parameters"`
	Reactions           []Reaction           `json:"reactions"`
	ConstraintEquations []Equation           `json:"constraint_equations,omitempty"`
	DiscreteEvents      []DiscreteEvent      `json:"discrete_events,omitempty"`
	ContinuousEvents    []ContinuousEvent    `json:"continuous_events,omitempty"`
	Subsystems          map[string]any       `json:"subsystems,omitempty"`
	// Tolerance is the component-level default numerical tolerance for inline
	// tests (esm-spec §6.6).
	Tolerance *Tolerance `json:"tolerance,omitempty"`
	// Tests are inline validation tests for this reaction system (esm-spec §6.6).
	Tests []Test `json:"tests,omitempty"`
	// Analyses are inline illustrative runs + plot specs (esm-spec §6.7).
	Analyses []Analysis `json:"analyses,omitempty"`
	// contains filtered or unexported fields
}

ReactionSystem represents a chemical reaction network

Source · Go docs