Since the size of our system is typically 10-100 molecular diameters, this is certainly not a good representation for a macroscopic sample because most of the particles will be situated near a ``wall'' or ``boundary''. To minimize the effects of the boundaries and to simulate more closely the properties of the macroscopic system, it is convenient to choose ``periodic boundary conditions''. These means that our basic box containing particles is surrounded by images (or replicas) of itself. This is equivalent to wrap the coordinates around the boundaries: when one particles hits a wall, instead of bouncing pack, it reappears on the other side of the box. This means that the system has the topology of a torus. If the linear size of the box is , the maximum separation between particles is .
The rule can be summarized as follows: instead of the coordinate of
some particle, we have to adopt
To compute the potential energy or the force between two particles and one augments the periodic boundary conditions we have to adopt the so-called ``nearest image convention''. Imagine that the two particles on opposite sides of the box. The convention dictates that we have to adopt the minimum distance across the walls, or between images in the neighboring replicas. If is larger than , then the particle will be disregarded as an interaction partner of , with its left image, having coordinate in its place. In practice this means simply that when calculating we have to use the quantity instead of . An analogous rule holds for and for the other coordinates.
The rule can be expressed by
Expressions (44) and (43) can be replaced by ifs expressions. In a parallel code this is counter productive, but in a serial code may be preferable. The optimal choice should be base on benchmarks.