Version: dev

reaction

Stable type · Document types

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

JuliaTypeScriptPythonRustGo
Reactionnot exportedReactionReactionReaction

Julia

struct Reaction
Reaction(id::String, substrates::Union{Nothing, Vector{EarthSciAST.StoichiometryEntry}}, products::Union{Nothing, Vector{EarthSciAST.StoichiometryEntry}}, rate::ASTExpr; name, reference)
Reaction(reactants::AbstractDict{String, <:Real}, products::AbstractDict{String, <:Real}, rate::ASTExpr; reversible)
Reaction

Chemical reaction with substrates, products, and rate expression.


Reaction(reactants::AbstractDict{String,<:Real}, products::AbstractDict{String,<:Real}, rate::ASTExpr; reversible=false) -> Reaction

Convenience constructor that creates a reaction with an auto-generated, content-derived id: the same reactants, products, and rate always produce the same id (deterministic across sessions and Julia versions, unlike Base.hash).

Source

TypeScript

TypeScript does not export this type.

Python

class Reaction
Reaction(name: str, id: str | None = None, reactants: dict[str, int | float] = dict(), products: dict[str, int | float] = dict(), rate_constant: float | Expr | None = None, conditions: dict[str, Any] = dict(), reference: Reference | None = None, name_authored: bool = True, substrate_entries: list[tuple[str, int | float]] | None = None, product_entries: list[tuple[str, int | float]] | None = None)
Reaction.substrate_list() -> list[tuple[str, int | float]]
Reaction.product_list() -> list[tuple[str, int | float]]

A chemical reaction.

Members

  • substrate_list — The substrate entries in listed order, repeats kept.
  • product_list — The product entries in listed order, repeats kept.

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)
for eq in odes.equations:
    print(earthsci_ast.to_ascii(eq))

# 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"
assert earthsci_ast.to_ascii(odes.equations[2]) == "D(NO2)/Dt = k1 * NO * O3 + -1 * jNO2 * NO2"

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

Rust

pub struct Reaction {
    pub id: Option<String>,
    pub name: Option<String>,
    pub substrates: Option<Vec<StoichiometricEntry>>,
    pub products: Option<Vec<StoichiometricEntry>>,
    pub rate: Expr,
    pub reference: Option<Reference>,
}

Chemical reaction

Source · Rust docs

Go

type Reaction struct {
	ID         string             `json:"id"`
	Name       *string            `json:"name,omitempty"`
	Substrates []SubstrateProduct `json:"substrates"`
	Products   []SubstrateProduct `json:"products"`
	Rate       Expression         `json:"rate"`
	Reference  *Reference         `json:"reference,omitempty"`
}

func (r *Reaction) UnmarshalJSON(data []byte) error

Reaction represents a chemical reaction

Methods

func (r *Reaction) UnmarshalJSON(data []byte) error

Custom JSON unmarshaling for Reaction

Source · Go docs