chemistry
- class rnets.chemistry.ChemCfg(T: float = 273.15, e_units: str = 'eV', kb: float = 8.62e-05, A: float = 10000000000000.0)[source]
Chemical system general configuration.
- T
Temperature of the chemical system in Kelvin. Defaults to the standard temperature (
DEF_T
.).- Type:
float
- e_units
Energy units. Defaults to "eV"
- Type:
str
- kb
(float): Boltzmann constat. Defaults to eV and K (
DEF_KB
)- Type:
float
- A
(float): Arrhenius pre-exponential factor. Defaults to 1 (
DEF_A
).- Type:
float
- rnets.chemistry.build_chemcfg(T: float = DEF_T, e_units: str = 'eV', kb: float | None = None, h: float | None = None, A: float | None = None) ChemCfg [source]
Wrapper to build a ChemCfg taking into account pre-known constant values.
- Parameters:
T (float) -- Temperature of the chemical system in Kelvin. Defaults to the standard temperature (
DEF_T
.).e_units (str, optional) -- Energy units. Defaults to "eV".
kb (float) -- Boltzmann constat. If None, its value will be search at
CONSTANTS
. If the constant is not found, aNotImplementedError
will be raised.h (float) -- Planck constat. In case
h
andA
are None, its value will be search atCONSTANTS
based on the provided units. If the constant is not found, aNotImplementedError
will be raised. Defaults to NoneA (float) -- Arrhenius pre-exponential factor. If not provided, it will be computed with kb and h.
- Returns:
ChemCfg
with the given configuration.- Raises:
NotADirectoryError -- if a constant is not provided and is not found in
CONSTANTS
for the given units (e_units
)
- rnets.chemistry.calc_A(T: float, kb: float, h: float) float [source]
Given a temperature, a boltzmann constant and the planck constant, compute the Arrhenius pre-exponential factor.
- Parameters:
T (float) -- Temperature.
kb (float) -- Boltzmann constant.
h (float) -- Planck constant.
- Returns:
Arrhenius pre-exponential factor as float.
- rnets.chemistry.calc_activation_energy(r: Reaction, reverse: bool = False) float [source]
Computes the activation energy of a given compounds
- Parameters:
r (
Reaction
) -- Reaction that will be used to calculate the Ea.inv (bool, optional) -- Compute the energy of the reverse reaction. Defaults to False
- Returns:
Activation energy.
- Return type:
float
Note
- Note that the units are not checked. The energy of the
Reaction
and its attached compounds should be in the same units.
- rnets.chemistry.calc_net_rate(r: Reaction, T: float, A: float, kb: float) float | None [source]
Given a reaction, a temperature, and pre-exponential factor, computer the net rate constant.
- Parameters:
T (float) -- Temperature of the reaction.
A (float) -- Pre-exponential factor used in the Arrhenius equation.
kb (float) -- Boltzmann constant.
Note
Note that the units are not checked. The user should provide the arguments with matching units.
- rnets.chemistry.calc_pseudo_k_constant(ea: float, T: float = DEF_T, A: float = DEF_A, kb: float = DEF_KB) float [source]
Uses the arrhenious equation to compute a pseudo equilibrium constant (k) for the given activation energy. This constant serves a proxy to visually compare reaction kinetics.
- Parameters:
ea (float) -- Reaction energy.
T (float) -- Temperature at which the kinetic constant is computed. Defaults to
DEF_T
.A (float) -- Pre-exponential factor for the Arrhenious equation. Defaults to
DEF_A
.kb (float) -- Boltzmann constant. Defaults to
DEF_KB
- Returns:
Computed pseudo-k.
- Return type:
float
Notes
Use
calc_activation_energy
to compute the energy for a giveReaction
object.Units are not taken into account. Make sure that the temperature and energy units match.
- rnets.chemistry.calc_reactions_k_norms(rs: Sequence[Reaction], T: float = DEF_T, A: float = DEF_A, kb: float = DEF_KB, norm_range: tuple[float, float] = (0., 1.)) Iterator[float] [source]
From a set of reactions, compute the norm of each reaction using the pseudo kinetic constant (see
calc_pseudo_kconstant
).- Parameters:
rs (sequence of
Reaction
) -- Reactions to use to compute the norm.T (float) -- Temperature at which the kinetic constant is computed. Defaults to
DEF_T
.A (float) -- Pre-exponential factor for the Arrhenious equation. Defaults to
DEF_A
.kb (float) -- Boltzmann constant. Defaults to
DEF_KB
- Returns:
- Computed k norms preserving the order of the
given reactions.
- Return type:
Iterator
of float
- rnets.chemistry.minmax(xs: Iterable[float]) tuple[float, float] [source]
Simple function that returns the minimum and the maximum of a sequence of floats.
- Parameters:
xs (sequence of float) -- Sequence to examine.
- Returns:
With the form of (min, max).
- Return type:
tuple of two floats
Notes
- I tried to make this function from scratch, but it seems that the
- implementation of min and max are extremely efficient; it is better
to create two maps and then search for the min and max.
- rnets.chemistry.network_conc_normalizer(nw: Network) Callable[[float], float] [source]
Given a reaction network, build a concentration normalizer based on the maximum and minimum concentration of the compounds in the network.
- Parameters:
nw (
Network
) -- Network for which the normalizer will be built.- Returns:
Function that normalizes a float using minimum and maximum values of the network and an offset
- Return type:
Callable[[float], float]
- rnets.chemistry.network_energy_normalizer(n: Network) Callable[[float], float] [source]
Given a reaction network, build an energy normalizer based on the minimum and maximum energies of the compounds and reactions.
- Parameters:
n (
Network
) -- Network for which the normalizer will be built.- Returns:
Function that normalizes a given float using minimum and maximum values of the network and an offset.
- Return type:
Callable[[float], float]
- rnets.chemistry.normalizer(s: float, e: float) Callable[[float], float] [source]
Creates a normalization function that returns a value between 0 and 1 depending on the minimum and maximum values.
- Parameters:
s (float) -- Starting (mininum) value used for the normalization.
e (float) -- Ending (maximum) value used for the normalization.
- Returns:
- Function that normalizes a float within the
normalization range.
- Return type:
Callable[[float], float]
Note
- If the normalization function overflows, it will return 0 in case of
values smaller than the minimum or 1 in case of values higher than the ending value.