Skip to content
Projects

opencr.data.native

OpenCR’s native, versioned file format for reaction networks.

A network is written as one JSON document::

{"format": "opencr-network", "version": 1, "name": ..., "assumptions": [...],
"species": [...], "states": [...], "reactions": [...]}

Each reaction lists its reactants and products by state name ("e" for the electron), its kind, its rate model (opencr.core.rates.RateModel.to_dict; a Function is written as its table) and its provenance. Reading checks the format name and version, then builds and checks the network. Files of a newer major version are refused.

Attributes

NameDescription
FORMAT_NAMENo description.
FORMAT_VERSIONNo description.

Functions

NameDescription
load_networkRead a network written by save_network.
network_from_dictReturn the network of network_to_dict's output, checked.
network_to_dictReturn the network in the native format as plain data.
rate_from_dictReturn the rate model of to_dict's output.
save_networkWrite the network to path as native JSON and return the path.

FORMAT_NAMEattributemodule attribute#

FORMAT_NAME = 'opencr-network'

FORMAT_VERSIONattributemodule attribute#

FORMAT_VERSION = 1

load_networkfunction#

def load_network(path: str | Path) -> ReactionNetwork

Read a network written by save_network.

network_from_dictfunction#

def network_from_dict(data: Mapping[str, Any]) -> ReactionNetwork

Return the network of network_to_dict’s output, checked.

network_to_dictfunction#

def network_to_dict(network: ReactionNetwork) -> dict[str, Any]

Return the network in the native format as plain data.

rate_from_dictfunction#

def rate_from_dict(data: Mapping[str, Any]) -> RateModel

Return the rate model of to_dict’s output.

save_networkfunction#

def save_network(network: ReactionNetwork, path: str | Path) -> Path

Write the network to path as native JSON and return the path.