Simulating Brownian Dynamics (Overdamped Langevin Dynamics) using LAMMPS
Update 2021.11.22. LAMMPS starts to support brownian dynamics officially in recent versions. See this page for the official fix
command
This article was originally posted on my old Wordpress blog.
LAMMPS is a very powerful Molecular Dynamics simulation software I use in my daily research. In our research group, we mainly run Langevin Dynamics (LD) or Brownian Dynamics (BD) simulation. However, for some reason, LAMMPS doesn’t provide a way to do Brownian Dynamics (BD) simulation. Both the LD and BD can be used to sample correct canonical ensemble, which sometimes also be called NVT ensemble.
The BD is the large friction limit of LD, where the inertia is neglected. Thus BD is also called overdamped Langevin Dynamics. It is very important to know the difference between LD and BD since these two terms seems be used indifferently by many people which is simply not correct.
The equation of motion of LD is,
where is the mass of the particle, is its position and is the damping constant. is random force. The random force is subjected to fluctuation-dissipation theorem. . where is the drag coefficient. is nowhere differentiable, its integral is called Wiener process. Denote the wiener process associated with as . It has the property , is the Gaussian random variable of zero mean, variance of .
The fix fix langevin
provided in LAMMPS
is the numerical simulation of the above equation. LAMMPS
uses a very simple integration scheme. It is the Velocity-Verlet algorithm where the force on a particle includes the friction drag term and the noise term. Since it is just a first order algorithm in terms of the random noise, it can not be used for large friction case. Thus the langevin fix
in LAMMPS
is mainly just used as a way to conserve the temperature (thermostat) in the simulation to sample the conformation space. However in many cases, we want to study the dynamics of our interested system realistically where friction is much larger than the inertia. We need to do BD simulation.
For a overdamped system, is very large, let’s take the limit , the bath becomes infinitely dissipative (overdamped). Then we can neglect the left side of the equation of LD. Thus for BD, the equation of motion becomes
The first order integration scheme of the above equation is called Euler-Maruyama algorithm, given as
where is the gaussian random variable with zero mean and unit variance (not the same varaible appeared above). Since for BD, the velocities are not well defined anymore, only the positions are updated. The implementation of this scheme in LAMMPS
is straightforward. Based on source codes fix_langevin.cpp
and fix_langevin.h
in the LAMMPS
, I wrote a custom fix
of BD myself. The core part of the code is the following. The whole code is on github.
void FixBD::initial_integrate(int vflag)
{
double dtfm;
double randf;
// update x of atoms in group
double **x = atom->x;
double **f = atom->f;
double *rmass = atom->rmass;
double *mass = atom->mass;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
if (rmass) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
dtfm = dtf / rmass[i];
randf = sqrt(rmass[i]) * gfactor;
x[i][0] += dtv * dtfm * (f[i][0]+randf*random->gaussian());
x[i][1] += dtv * dtfm * (f[i][1]+randf*random->gaussian());
x[i][2] += dtv * dtfm * (f[i][2]+randf*random->gaussian());
}
} else {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]];
randf = sqrt(mass[type[i]]) * gfactor;
x[i][0] += dtv * dtfm * (f[i][0]+randf*random->gaussian());
x[i][1] += dtv * dtfm * (f[i][1]+randf*random->gaussian());
x[i][2] += dtv * dtfm * (f[i][2]+randf*random->gaussian());
}
}
}
As one can see, the implementation of the integration scheme is easy, shown above. dtv
is the time step used. dtfm
is and randf
is .
The Euler-Maruyama scheme is a simple first order algorithm. Many studies has been done on higher order integration scheme allowing large time step being used. I also implemented a method shown in this paper. The integration scheme called BAOAB
is very simple, given as
The source code of this method can be downloaded. In addition, feel free to fork my Github repository for fix bd
and fix bd/baoab
. I have done some tests and have been using this code in my research for a while and haven’t found problems. But please test the code yourself if you intend to use it and welcome any feedback if you find any problems.
To decide whether to use LD or BD in the simulation, one need to compare relevant timescales. Consider a free particle governed by the Langevin equation. Solving for the velocity autocorrelation function leads to, . This shows that the relaxation time for momentum is . There is another timescale called Brownian timescale calculated by where is the size of the particle. is the timescale at which the particle diffuses about its own size. If and if you are not interested at the dynamics on the timescale , then one can use BD since the momentum can be safely integrated out. However, if these two timescales are comparable or , then only LD can be used because the momentum cannot be neglected in this case. To make the problem more complicated, there are more than just these two timescales in most of simulation cases, such as the relaxation time of bond vibration, etc… Fortunately, practically, comparing these two timescales is good enough for many cases.