In the first step the distance between each pair of particle i.e i and j are calculated and stored in xr. A cut-off distance of rc is chosen in such a manner so that the force computation is neglected for pairs which has distance more than this distance. This cut-off distance is usually half the distance of the periodic box (here denoted by box).Thus for the force calculation the distance between the particle i and the nearest image j should be less than box/2.The nint(x) rounds the integer to the nearest whole number[Frenkel and Smit,2002]. Thus the distance between I and the nearest image j is calculated via
![]()
Finally a check is made for all the square of the distances rij2 with the square of distances rc2.The force is then computed by the following expression

Integration of equation of motions
Once all the forces are available and computed we are in a position to integrate the newton’s equation of motion. A sample code is given below:
Figure 11 Force calculation in MD (Adapted from D. Frenkel and B. Smit, Understanding Molecular Simulation, From Algorithms to Applications, 2nd ed., Academic Press, London, 2001.)