Introduction

Boris Belousov discovered in the early 1950s that a solution of citric acid, potassium bromate, and cerium (IV) sulphate in dilute sulfuric acid did not react directly to equilibrium, instead turned colorless for a long time before returning to yellow. It is interesting to note that the journals to which this reaction was reported had declined to publish as it was apparently seen to contradict the second law of thermodynamics (Belousov 1959). Later, Anatol Zhabotinsky, a graduate student working under Professor Schnoll's supervision, investigated the reaction in-depth and reported the findings (Zhabotinsky 1964). Zhabotinsky et al. demonstrated that the oscillations in the solution colour were caused by oscillations in the concentration of Ce4+ by replacing citric acid with malonic acid. This complex chemical system, popularly referred to as the BZ reaction, as well as related systems, has sparked a lot of interest since then (Field et al. 1972; Field and Noyes 1974; Györgyi et al. 1990; Turanui et al. 1993; Zhabotinsky et al. 1993; Zhabotinsky 2007). This reaction not only has great importance from the physical and chemical point of view, as well as mathematical, but it is also extremely suggestive from a biological point of view (Sánchez-Pérez et al. 2020).

Analogous to the simple pendulum, the oscillations in these reactions are caused by a decrease in potential energy. The energy landscape of a complex reaction is not as smooth as a textbook diagram would suggest. A slow energy-releasing reaction is always present behind all chemical oscillations. The cycle is typically made up of the production and consumption of specific intermediates, which are triggered in order by a species' threshold concentration. Alfred Lotka proposed a mathematical model of this type of predator–prey behaviour in 1910 to describe autocatalytic reactions called the Lotka–Volterra equations (Lotka 1910). These coupled differential equations have been extensively used to describe positive-feedback systems involving two and three variables. Even though they are potential candidates for describing the BZ reactions, there has not been much work in this area, possibly due to the complexity of the system. The overall BZ reaction equation is:

$$3{\mathrm{CH}}_{2}{(\mathrm{COOH})}_{2}+4{\mathrm{BrO}}_{3}^{-}+3C\to 4{\mathrm{Br}}^{-}+9{\mathrm{CO}}_{2}+6{\mathrm{H}}_{2}\mathrm{O}$$

Cerium (or manganese) acts as a catalyst in this case. Zhabotinsky discovered that the oxidation of Ce3+ by HBrO3 is autocatalytic, and those self-sustained oscillations in Ce4+ concentration occur after bromomalonic acid accumulates during the induction period (Zhabotinsky 1964, 2007; Zhabotinsky et al. 1993). A detailed thermodynamic and kinetic analysis was performed by Field, Körös, and Noyes (FKN) to suggest a mechanism for these oscillations (Field et al. 1972; Field and Noyes 1974). Györgi, Turanyi, and Field introduced a mechanistic model for the BZ system with 80 reactions and 26 species (Györgyi et al. 1990). According to the FKN reactions, the 10 processes that define the kinetics of the BZ reactions are (Field et al. 1972):

$${\mathrm{BrO}}_{3}^{-}+2{\mathrm{H}}^{+}+\mathrm{ B}{\mathrm{r}}^{-}\rightleftharpoons \mathrm{ HBr}{\mathrm{O}}_{2}+\mathrm{HOBr}$$
(1)
$${\mathrm{HBrO}}_{2}+{\mathrm{H}}^{+}+\mathrm{ B}{\mathrm{r}}^{-}\rightleftharpoons 2\mathrm{HOBr}$$
(2)
$$\mathrm{HOBr}+{\mathrm{H}}^{+}+{\mathrm{Br}}^{-}\rightleftharpoons {\mathrm{Br}}_{2}+{\mathrm{H}}_{2}\mathrm{O}$$
(3)
$${\mathrm{BrO}}_{3}^{-}+{\mathrm{HBrO}}_{2}+{\mathrm{H}}^{+}\rightleftharpoons 2{\mathrm{BrO}}_{2}^{\circ }+{\mathrm{H}}_{2}\mathrm{O}$$
(4)
$${\mathrm{BrO}}_{2}^{\circ }+{\mathrm{Ce}}^{3+}+{\mathrm{H}}^{+}\rightleftharpoons \mathrm{ HBr}{\mathrm{O}}_{2}+{\mathrm{Ce}}^{4+}$$
(5)
$$2{\mathrm{HBrO}}_{2} \rightleftharpoons \mathrm{ Br}{\mathrm{O}}_{3}^{-}+\mathrm{HOBr}+{\mathrm{ H}}^{+}$$
(6)
$${\mathrm{Br}}_{2} +{\mathrm{CH}}_{2}{\left(\mathrm{COOH}\right)}_{2} \to \mathrm{ BrCH}{\left(\mathrm{COOH}\right)}_{2}+{\mathrm{H}}^{+}+\mathrm{ B}{\mathrm{r}}^{-}$$
(7)
$$6{\mathrm{Ce}}^{4+} +{\mathrm{CH}}_{2}{(\mathrm{COOH})}_{2} +{2\mathrm{H}}_{2}\mathrm{O } \to 6{\mathrm{Ce}}^{3+}+\mathrm{HCOOH}+2{\mathrm{CO}}_{2}+6{\mathrm{H}}^{+}$$
(8)
$$4{\mathrm{Ce}}^{4+} +\mathrm{BrCH}{(\mathrm{COOH})}_{2} +{2\mathrm{H}}_{2}\mathrm{O } \to 4{\mathrm{Ce}}^{3+}+\mathrm{HCOOH}+{\mathrm{Br}}^{-}+2{\mathrm{CO}}_{2}+5{\mathrm{H}}^{+}$$
(9)
$${\mathrm{Br}}_{2}+\mathrm{HCOOH} \to 2{\mathrm{Br}}^{-}+{\mathrm{CO}}_{2}+ 2{\mathrm{H}}^{+}$$
(10)

Notwithstanding the cautions of applying Occam’s Razor while deducing mechanisms of chemical reactions as articulated by Hoffman et al. (International Journal for Philosophy of Chemistry ) we proceed further with the simplistic FKN model also known as Oregonator (origin from the University of Oregon) is the simplest qualitative model to describe BZ reactions(Field and Noyes 1974; Field 2007). It uses steady-state approximation on certain reaction components, particularly \({\mathrm{BrO}}_{3}^{-}\), \(\mathrm{HOBr}\), \(\mathrm{BrCH}{(\mathrm{COOH})}_{2},{\mathrm{ Ce}}^{3+},{\mathrm{ H}}^{+}\mathrm{ and }{\mathrm{H}}_{2}\mathrm{O}\) which do not change during the period of a few cycles. In contrast to this, the concentrations of \({\mathrm{HBrO}}_{2},\mathrm{ B}{\mathrm{r}}^{-}\mathrm{ and }{\mathrm{ Ce}}^{4+}\) change drastically over the course of reactions, and thus, their reactions are of significant importance for the overall kinetics of the reaction. The five coupled stoichiometries make up the Oregonator model are:

$$\begin{array}{*{20}c} {{\mathbf{Step}}} & {{\mathbf{Reaction}}} & {{\mathbf{Rate}}\;{\mathbf{Constant}}} \\ {(I)} & {A + Y \to X + P} & {k_{1} = k_{R1} [H^{ + } ]^{2} } \\ {(II)} & {X + Y \to 2P} & {k_{2} = k_{R2} [H^{ + } ]} \\ {(III)} & {A + X \to 2X + 2Z} & {k_{3} = k_{R4} [H^{ + } ]} \\ {(IV)} & {2X \to A + P} & {k_{4} = k_{R6} [H^{ + } ]} \\ {(V)} & {B + Z \to \frac{1}{2}fZ} & {k_{5} } \\ \end{array}$$

The species involved in the above reaction scheme are \(\mathrm{X}={\mathrm{HBrO}}_{2},\mathrm{ Y}={\mathrm{Br}}^{-},\mathrm{ Z}={\mathrm{Ce}}^{4+},\mathrm{ A}={\mathrm{BrO}}_{3}^{-},\mathrm{ B}={\mathrm{CH}}_{2}{(\mathrm{COOH})}_{2}\mathrm{ and P}=\mathrm{HOBr}(\mathrm{or BrCH}{(\mathrm{COOH})}_{2})\) with adjustable stoichiometric factor \(f\) and an adjustable-rate parameter k5.

In a homogeneous (well-stirred) system, the Law of Mass Action yields a system of three nonlinear ordinary differential rate equations for X, Y, and Z (Field 2007). To present them in a more dimensionless form:

$$\in \frac{dx}{d\tau }=qy-xy+x(1-x)$$
(i)
$$\delta \frac{dy}{d\tau }=-qy-xy+fz$$
(ii)
$$\frac{dz}{d\tau }=x-z$$
(iii)

by change of variables x = X/Xo, y = Y/Yo, z = Z/Zo, \(\tau =t/T\) where

$$\begin{aligned} X_{o} & = \frac{{k_{3} A}}{{2k_{4} }},Y_{o} = \frac{{k_{3} A}}{{k_{2} }},Z_{o} = \frac{{(k_{3} A)^{2} }}{{k_{4} k_{5} B}},T = \frac{1}{{k_{5} B}}, \\ \in & = \frac{{k_{5} B}}{{k_{3} A}},\delta = \frac{{2k_{4} k_{5} B}}{{k_{2} k_{3} A}},q = \frac{{2k_{1} k_{4} }}{{k_{2} k_{3} }} \\ \end{aligned}$$
(14)

By using the normalized nondimensionalization, comprising of simple mathematical manipulations (Buckingham 1914; Langhaar 1951; Alhama and Madrid 2012), the dimensionless groups are derived the kinetic differential equations can be reduced from which.

The MATLAB platform offers inbuilt codes to understand this BZ reaction where it digitally analyses a mobile video recording and extracts 24-bit RGB components, and displays the concentration profiles of various chemicals in the BZ reaction, thereby performing a quantitative analysis of experimental data. The Oregonator model's theoretical prediction can be compared to experimental data using MATLAB functions and a standard Runge Kutta routine to solve the system of rate equations (Lozano-Parada et al. 2018).

In this work we provide an alternate way for quantitatively analysing the BZ reaction using the Python platform. There have been efforts made to promote the use of open data and open source computational methods, particularly in the field of chemistry (Guha et al. 2006; O'Boyle et al. 2011). This paper focuses on producing open source (readable and editable) codes in python for simulating and observing the concentrations of the components involved in BZ reaction with time.

Method

For the equations defined above, two methods/techniques are discussed, namely: Runge–Kutta algorithm (4th order) and the Livermore solver for ordinary differential equation (called the LSODE algorithm). A variation of the LSODE algorithm, namely the LSODA algorithm, is used where the suffix A stands for automatic. Although there are other methods for solving non-linear differential equations, such as Heun's method and Euler's method, it has been experimentally proven that the error produced by Runge–Kutta method is 0.625 times that of Heun's method and 0.0007 times that of Euler's method for 32-function evaluations using Euler method, 16-function evaluations using Heun's method, and 8-function evaluations using Runge–Kutta method (https://ece.uwaterloo.ca). Similarly, based on the relative and absolute error bounds supplied in the function, the LSODA algorithm shifts between Adam-Bashford technique (AB) and Backward differentiation method (BDF). Both the AB technique and the BDF are high-precision solvers that are controlled within error limitations in this scenario to provide additional precision and accuracy (Hindmarsh and ODEPACK 1983).

Results and discussion

The codes (shown in the annexure 1) developed by us produce the graphs shown in Fig. 1 using online Jupyter Notebook (https://jupyter.org; https://jupyter.org/try) as the code editor, scipy.integrate (Library for implementation of scientific equations)) as the base function with the initial values of

Fig. 1
figure 1

Identical results are obtained from both the algorithms namely RK45 and LSODA

$${\mathrm{X}}_{\mathrm{o}}={\mathrm{HBrO}}_{2}=1, {\mathrm{Y}}_{\mathrm{o}}={\mathrm{Br}}^{-}=1, {\mathrm{Z}}_{\mathrm{o}}={\mathrm{Ce}}^{4+}=1$$
(a)

and the dimensionless parameters for the Eqs. (i), (ii) and (iii) being \(\epsilon\) = 3.6 × 10−2, δ = 1.2 × 10−4 and q = 2.4 × 10−4 (Barzykina 2020). These dimensionless parameters are derived from the values kR1 = 2 mol−3·dm9 s−1, kR2 = 1.8 × 106 mol−2·dm6 s−1, kR4 = 48 mol−2·dm6 s−1, kR6 = 3 × 103 mol−1·dm3 s−1, [H+] = 1.68 mol·dm−3, A = [BrO3] = 0.058 mol· dm−3, and B = [CH2(COOH)2] = 0.105 mol·dm−3, along with k5 = 1.6 mol−1·dm3 s−1, f = 1 as proposed by Fields (2007), and the Eqs. (I) to (iv) shown above.

Here scaling the values signifies,

$$\mathrm{Scaled HBr}{\mathrm{O}}_{2}={\mathrm{log}}_{10}\left(\frac{X}{{X}_{o}}\right), \mathrm{Scaled B}{\mathrm{r}}^{-}={\mathrm{log}}_{10}\left(\frac{Y}{{Y}_{o}}\right), \mathrm{Scaled }{\mathrm{Ce}}^{4+}={\mathrm{log}}_{10}\left(\frac{Z}{{Z}_{o}}\right)$$

When numerically integrating a differential equation, it is expected for the required step size to be small in areas where the solution curve exhibits a lot of variation and large in areas where the solution curve straightens out to approach a line with a slope near zero. In some cases, a numerical method must have an unacceptably small step size in a region where the solution curve is very smooth in order to provide a reliable solution to the differential system. This phenomenon is called stiffness. The equations which follow this phenomenon or property are called stiff differential equations and vice versa. There are a few numerical methods that are more commonly used to solve these types of differential equations (Hindmarsh and "ODEPACK 1983). Runge–Kutta integration method used here (called RK45) is an explicit method or order 5(4) (Dormand and Prince 1980). The error is controlled based on the fourth-order method's accuracy, but steps are taken based on the fifth-order precise formula (with local extrapolation). For the dense output, a quartic interpolation polynomial is used (Shampine 1986). In general, it can be applied in the complex domain to non-stiff differential equation problems. Ordinary Differential Equation Solver for Stiff or Non-Stiff Systems, on the other hand, is LSODA. This is a wrapper of the Fortran solver from ODEPACK (Barzykina 2020). When the problem is stiff, LSODA uses a dense or banded Jacobian to solve the system dy/dt = f, but it automatically chooses between non-stiff (Adams) and stiff (BDF) methods (Petzold 1980). It starts with the non-stiff method and then monitors data in real time to decide which method to use. To make modification easier, the LSODA source is heavily commented. There are two versions available: a single-precision version and a double-precision version.

It was possible to achieve a remarkable agreement of the theoretically predicted oscillation curve in MATLAB with a theory for cerium(IV) as a catalyst by taking the rate constants of the processes involved from the literature and substituting the conditions of the current study to the results obtained above (Barzykina 2020).

The RK45 and LSODA codes can be compared based on run-time and the preciseness (number of iterations) of both programs. The run time of a program can be understood as the total time required to perform the given set of operations in the same computer system. In this case, we take the start of the run-time before initializing the dimensionless parameters and end the same after plotting the curve for both algorithms. The number of iterations defines preciseness. An increase in the number of iterations or the number of data points within the given time interval (in this case [0,40]) produced will, in turn, reduce the scope of the error in the graphs produced.

Using the timeit module (https://docs.python.org) in python, the performance of both the algorithms executed on the computer machine with a 1.8 GHz processor is compared in Table 1.

Table 1 Comparison of RK45 and LSODA algorithms

From the above table, it is evident that the run time of RK45 algorithm is almost 22 times that of the LSODA algorithm which will remain same for all processing systems. From the result obtained, it can be observed that the RK45 algorithm creates many data points in the same time interval at the cost of the run time of the overall program.

Although both the codes work successfully, the code using the LSODA algorithm can certainly be extended to problems with bigger datasets for faster calculation. The RK45 algorithm, on the other hand, can certainly be used for problems involving high precision and accuracy since it produces large datasets in the same time frame.

There is a shift in HBrO2 concentration in a poorly stirred BZ reaction system. It functions as a limiter at each stage, limiting the amount of HBrO2 that can be used in that iteration. This indicates that if the HBrO2 concentration obtained in the previous iteration is higher than the one necessary in the next, the maximum HBrO2 concentration will be used in the computation. Because the code is iterative, running it with a simple conditional statement to see if the limit concentration of HBrO2 is equal to the current concentration will provide the desired graph (https://ro.uow.edu.au).

Conclusion

The Field, Körös, and Noyes (FKN) model for the mechanism of the BZ reaction, which involves three cyclic stages: bromate reduction by bromide, autocatalytic production of bromous acid accompanied by oxidation and reduction of the metal ion catalyst, and regeneration of bromide ion, was taken up in this work and the corresponding dimensionless differential equations were successfully solved using a novel open-source approach.

It is hereby conclusively demonstrated that the simulation models of the BZ reaction from a computing language like MATLAB can be extended to a more futuristic general-purpose language like python. Two methods using RK45 and the LSODA algorithm respectively were used to produce the same result as obtained with a MATLAB ODE45 code.

Extension of the current study would be rewarding because BZ reactions are fascinating and rich in their displayed behavior. These pieces of code are general in nature. With a little tweak in the structures of differential equations and the parameters involved graph for the desired oscillatory system can be produced. Another interesting project that can be derived from this paper is to generalize this piece of code for non-oscillatory systems to observe various reactions.