You are on page 1of 8

MATHEMATICAL BIOSCIENCES 22, 113-120 (1974) 113

A Monte Carlo Simulation of Chemical Reactions

WILLIAM D. C. MOEBS
Department of Physics, Purdue Fort Wayne,
Fort Wayne, Indiana 46805

Communicated by S. Azen

ABSTRACT

A computer-based algorithm to solve complex chemical rate equations is introduced. A


simple Monte Carlo sampling method is used to generate chemical reactions in numbers
proportional to reaction probabilities, and a second-order Runge-Kutta method is used to
calculate time. The method is compared with a closed form mathematical solution for a
simple chemical system, and it is compared with a numerical integration of the rate
equations for a more complicated system.

INTRODUCTION
Suppose a system of chemicals C,(i= 1, . ..,N) reacts according to the
stoichiometric equations

(1)
a=l,...l-,

where the a, and bi, are the stoichiometric coefficients for the reactants and
products, respectively, the Roman subscripts denote chemical species, and
the Greek subscripts denote chemical reactions, which are r in number. The
chemical concentrations [ Ci] obey the differential equations

F= ~ek,[Cjl”“[C~l”“...[C,]x”i=l,...,N, (2)

where the k, are rate constants, the x, are constants, often equal to the a,,
the summation is over all reactions for which Ci is a reactant or product, 17,
is -a, if Ci is a reactant, and rl, is + bia if Ci is a product. Since the
concentration is proportional to the number of molecules Ni, [C;.] can be
6 American Elsevier Publishing Company, Inc., 1974
114 W. MOEBS

replaced by Ni in the rate equations. A rate equation then represents the


time rate of change of the number of molecules. The rate equations given in
(2) can then be written

(3)

Equations (2) or (3) can be integrated in closed form for some simple
systems [l]. For complicated systems numerical methods must be used to
solve the rate equations [2].
It is the purpose of this article to describe a Monte Carlo technique [3]
which can be used to solve the rate equations for the time development of
the [C,] or Ni. This technique uses the digital computer to generate chemical
reactions, the number of each type being dependent on the appropriate
term in the summation of Eq. (3).
A listing of the program and sample input and output data are available
from the author.

THE MONTE CARLO METHOD

If the product

R cl= k UIN”I+~~~.
/ . . N”na
n (4)

is interpreted as the relative probability for the reaction

a, Ci + aja C, + .a. +a,,Cnk-+br,Cr+ b,,C,+ ... + b,,C, (5)

occurring at a time t, then R&/R, represents the ratio of the number of (Y


reactions that occur between the times t and t +At to the number of p
reactions taking place in the same small time interval. If an initial number
of molecules is assumed for each chemical Ci, and reactions are assumed to
occur at a frequency proportional to the ratios

RJR,,-/% (6)

the time development of the Ni can be calculated by means of the following


algorithm.

1. Assume an initial number of molecules for each chemical. For the


systems tested so far, initial numbers between 1,000 and 2,000 have been
used.
2. For each reaction calculate

R, = k, NpNjx2.. . . N;-
MONTE CARLO SIMULATION OF CHEMICAL REACTIONS 115

3. Find the maximum R,, RMAX.


4. For each reaction check whether

is less than, equal to, or greater than a random number. A is an arbitrary


constant between 0.0 and 1.0.
a. If it is less than a random number, the reaction is assumed not to take
place, and the number of molecules is not changed.
b. If it is equal to or greater than a random number, the reaction is
assumed to take place and

Nj=Ni-a,, N,=N,+b,,
Nj = N, - ajm N,=N,+b,,
(7)

N,,=h,,-a,, N,=i,+b,,

This selection method yields changes in the numbers of molecules in ratios


given by formula (6).

5. Repeat steps 2,3, and 4 M, times. M, has been 20 and A has been 0.5
for those systems tested so far.
6. After M, iterations find that chemical which has the smallest change
in

-- dN,(l) (8)
dt

where dlv,(l)/dt represents dNi/dt before the first iteration and dNi(M,)/dt ,
represents dN,/dt after the M,‘st iteration. That chemical which has the
smallest percentage change in its derivative is assumed to give the most
accurate estimate of the time interval in Eq. (9).
7. Using the chemical found in step 6, calculate the time interval for the
M, iterations from the second-order Runge-Kutta [4] formula

Nj(M,)-Ni(l) represents the difference in Ni between the first and M,‘st


iteration and
116 W. MOEBS

represents the average of dN,/dt between the first and M,‘st iterations.
Because of the statistical nature of this calculation, a reaction with a low
probability of acceptance can possibly be chosen in Step 6. This usually
results in a poor estimate of the time interval. In order to avoid this
difficulty, the choices in Step 6 are restricted to those for which AN, > 3 (if
Mi = 20 and A = 0.5).
8. If ANi < 3 for all chemicals, do M, more iterations and repeat Steps 6
and 7 with M, replaced by 2 M,. If ANi < 3 after two iterations, do M, more
iterations and repeat Steps 6 and 7 with M, replaced by 3 M,. If ANi<
after three iterations, assume the system has reached chemical equilibrium
and terminate the calculation.
9. Repeat Steps 2 through 8 M, times. The size of M, is dependent on
the complexity of the system and the total time interval for which the
calculation is to be made.

THE COMPUTER PROGRAM

This algorithm has been programmed for a maximum of 100 chemicals


participating in up to 100 reactions, each of which can be one of ten
different reaction types. All of the information about each reaction type is
contained in one subroutine. The substitution of one reaction type for
another in the program is therefore accomplished by changing a single
subroutine.
The program has been applied to the system
k, k,
Ci + c2 c3+‘c2

k, t
(10)
c2-+c3 Cz+G

Since the rate equations for this system can be solved in closed form [l], the
program’s computation can be compared with an exact solution. These two
solutions are compared in Fig. 1. It is seen that they agree very well. The
Monte Carlo solution ends at t = 5.6 sec. This is because the system is so
close to equilibrium at this point in time that the calculation is terminated,
as explained in Step 8.
The time development for the system

4 k,
c,+c2 c,+c,-+c,

(11)

has also been calculated using the Monte Carlo method. This solution is
compared with a numerical integration of the rate equations using the
MONTE CARLO SIMULATION OF CHEMICAL REACTIONS 117
1

1.0 2.0 3.0 4.0

TIME (SECONDS)

FIG. 1. The time development of the chemicals concentrations in reaction (IO). The
solid lines represent the theoretical curves, and the d.esignated points represent the Monte
Carlo calculation.
k,=5.0 set-‘; k,=4.0 set-‘; k,=3.0 see-I; k,=3.0 see-‘.

Mimic language [5], which is written specifically to solve differential equa-


tions by the fourth-order Runge-Kutta method [6]. It is seen from Fig. 2
that the Monte Carlo method again gives reasonable solutions to the rate
equations.
COMMENTS

One useful characteristic of this method is its versatility. For example, at


the end of an iteration it is possible to calculate the distribution of any
function which depends on concentration. If one is interested in the
radiation emitted by chemical. C, in reactions (1 l), or the partial pressure
due to chemical C5 in reactions (1 l), they can be easily found by calling a
subroutine after each iteration which calculates these quantities.
The program can also be easily expanded to treat more complicated
systems. The inclusion of diffusion into the system and spatial dependence
of the chemical concentrations is now being developed. These additions
should make the program especially useful for biological systems. It is also
hoped that int.emal diffusion between various parts of the system can be
included in the program at a later time.
Although it has not yet been done, the acceptance or rejection of a
reaction could be based on a comparison of the activation energy with the
Boltzmann distribution of the center-of-mass energy. By choosing the
2
( 0)
t

TIME (SECONDS)

TIME ( SECONDS 1

FIG. 2. The time development of the chemical concentrations in reaction (11). The
solid lines represent the Runge-Kutta integration, and the designated points represent the
Monte Carlo calculations.
k,=2.0~ 10-l set-‘; k,=4.0x10-6molecule-‘sec-‘; k3=4.0X 10-l set-‘;
k,= 1.0~ lo-’ molecule-’ set-‘; k,= 1.0~ 10e6 molecule-‘set-‘;
k6=5.0x 10e6 molecule-‘set-‘.
MONTE CARLO SIMULATION OF CHEMICAL REACTIONS 119

center-of-mass energy on the basis of the Boltzmann distribution, a reaction


can be accepted or rejected, depending on whether the activation energy is
less than or greater than the center-of-mass energy of the colliding mole-
cules.
The statistical nature of this calculation introduces statistical error into
the results. Although an analytical expression for the error has not been
found, it does decrease with an increase in the number of molecules. This is
seen in Fig. 3 where the computed concentration of C, in reaction (10) is
compared with the exact solution. Three different assumptions for the initial
number of molecules of C, are made. Although the error does behave as
expected, it does not increase at all strongly with a decrease in the number
of molecules.

TIME (SECONDSI

FIG. 3. Monte Carlo calculations of the time development of C, from reaction (10)
for three different assumptions for the initial number of molecules of C,.

t,,=2..10 set; tw=3.88 set; I,~= 14.93 sec.

Of course, the computing time increases with the initial number of


molecules assumed for the calculation. The computation times for the three
calculations are given with the graphs. For this case the computation time
increases almost linearly with the initial number of molecules of C,.
120 W. MOEBS

The author would like to thank R. Svoboda, D. Bash, D. Lyng, R. Pacer, E.


Haglund, and R. Lee for their many hours of helpful discussion. Special thanks
go to R. Svoboda who furnished the differential equation solutions of reactions
[III.

REFERENCES

1 Robert Livingston in, Technique of Organic Chemisr~, 2nd Ed., Part 1, (S. L. Friess, E.
S. Lewis, and A. Weissberger, Eds.) Interscience, New York, 1961, pp. 136138.
2 Roger G. E. Franks, Modeling and Simulation in Chemical Engineering, Wiley, New
York, 1972, Chap. VI.
3 D. P. Landau and R. Alben, Am. J. Physics 41, 394 (1973).
4 Roger G. E. Franks, lot. cit., pp. 55-56.
5 Rudy Svoboda, Mathematics Department, Purdue Fort Wayne, Fort Wayne, Indiana
(private communication).
6 Roger G. E. Franks, lot. cit., pp. 5961.

You might also like