# Homodimerization and Annihilation¶

This is for an integrated test of E-Cell4. Here, we test homodimerization and annihilation.

:

%matplotlib inline
from ecell4.prelude import *


Parameters are given as follows. D, radius, N_A, and ka_factor mean a diffusion constant, a radius of molecules, an initial number of molecules of A, and a ratio between an intrinsic association rate and collision rate defined as ka andkD below, respectively. Dimensions of length and time are assumed to be micro-meter and second.

:

D = 1
N_A = 60
ka_factor = 0.1  # 0.1 is for reaction-limited

:

N = 30  # a number of samples


Calculating optimal reaction rates. ka is intrinsic, kon is effective reaction rates. Be careful about the calculation of a effective rate for homo-dimerization. An intrinsic must be halved in the formula. This kind of parameter modification is not automatically done.

:

import numpy
kD = 4 * numpy.pi * (radius * 2) * (D * 2)
ka = kD * ka_factor
kon = ka * kD / (ka + kD)


Start with A molecules, and simulate 3 seconds.

:

y0 = {'A': N_A}
duration = 3
opt_kwargs = {'xlim': (0, duration), 'ylim': (0, N_A)}


Make a model with an effective rate. This model is for macroscopic simulation algorithms.

:

with species_attributes():

with reaction_rules():
A + A > ~A2 | kon * 0.5

m = get_model()


Save a result with ode as obs, and plot it:

:

ret1 = run_simulation(duration, y0=y0, model=m)
ret1.plot(**opt_kwargs) Simulating with gillespie:

:

ret2 = ensemble_simulations(duration, ndiv=20, y0=y0, model=m, solver='gillespie', repeat=N)
ret2.plot('o', ret1, '-', **opt_kwargs) Simulating with meso:

:

ret2 = ensemble_simulations(duration, ndiv=20, y0=y0, model=m, solver=('meso', Integer3(4, 4, 4)), repeat=N)
ret2.plot('o', ret1, '-', **opt_kwargs) Make a model with an intrinsic rate. This model is for microscopic (particle) simulation algorithms.

:

with species_attributes():

with reaction_rules():
A + A > ~A2 | ka

m = get_model()


Simulating with spatiocyte:

:

ret2 = ensemble_simulations(duration, ndiv=20, y0=y0, model=m, solver=('spatiocyte', radius), repeat=N)
ret2.plot('o', ret1, '-', **opt_kwargs) Simulating with egfrd:

:

ret2 = ensemble_simulations(duration, ndiv=20, y0=y0, model=m, solver=('egfrd', Integer3(4, 4, 4)), repeat=N)
ret2.plot('o', ret1, '-', **opt_kwargs) 