chemistrylab.reactions package
chemistrylab.reactions.reaction module
- class chemistrylab.reactions.reaction.Reaction(react_info: ReactInfo, solver: str = 'RK45', newton_steps: int = 100)[source]
Bases:
object
- chemistrylab.reactions.reaction.get_rates(stoich_coeff_arr, pre_exp_arr, activ_energy_arr, conc_coeff_arr, num_reagents, temp, conc)[source]
Finds the rate of reaction \(\frac{dy}{dt}\)
- Parameters:
- Returns:
Rates of change in concentration \(\frac{dy}{dt}\).
- Return type:
np.array
- chemistrylab.reactions.reaction.newton_solve(stoich_coeff_arr, pre_exp_arr, activ_energy_arr, conc_coeff_arr, num_reagents, temp, conc, dt, N)[source]
- Parameters:
num_reagents (int) – The number of reactants involved in the reaction
temp (float) – The temperature of the reactions
conc (float) – The initial concentrations of the materials
dt (float) – The amount of time to pass
N (int) – The minimum number of time-steps to break dt into
*_arr (np.array) – See
ReactInfo
- Returns:
The final concentrations y(dt)
- Return type:
np.array
Solves the initial value problem \(\frac{dy}{dt} = f(y)\) specifically in the case where f(y) is chemical a rate calculation
(The problem is that we have \(y(t_0)\) and need \(y(t_0+dt))\)
- This solver uses newton’s method:
set \(T = \frac{dt}{N}\)
set \(y_0 = y(t_0)\)
- for n = 1,2,3,…N:
\(y_n = y_{n-1} + f(y_{n-1})*T\)
\(y(dt) \leftarrow y_N\)
Intuitively, it is like taking a Riemann sum of dy/dt (but you get dy/dt by bootstrapping your current sum for y(t)) This implementation uses a variable step size in order to account for super fast-changing concentrations (wurtz distill)
chemistrylab.reactions.reaction_info module
- class chemistrylab.reactions.reaction_info.ReactInfo(name, REACTANTS, PRODUCTS, SOLVENTS, MATERIALS, pre_exp_arr, activ_energy_arr, stoich_coeff_arr, conc_coeff_arr)[source]
Bases:
NamedTuple
- MATERIALS: Tuple[str]
All materials or substances involved in the reaction(s) (a union of reactants products and solvents)
- activ_energy_arr: array
The activation energies for the reaction(s)
- conc_coeff_arr: array
The concentration coefficients of all involved materials in each reaction
- dump_to_json(fn)[source]
Saves the reaction information to a json file
- Parameters:
fn (str) – The filename to save as.
- static from_json(fn)[source]
Creates a new ReactInfo object from a json file :param fn: The filename to load from :type fn: str
- Returns:
The ReactInfo object parameterized by the json file
- Return type:
- pre_exp_arr: array
The pre-exponential factors for the reaction(s)
- stoich_coeff_arr: array
Stoichiometric coefficients of the reactants in each reaction