• What is a barrier?

  • How do barriers relate to the simulation box?

  • How do I prevent particles from crossing barriers?


  • Define barrier.

  • Explain that there are no inherent barriers in the periodic box.

Barriers and the simulation box

A barrier obstructs the motion of particles in a simulation. In typical cases, barriers split space into two regions - one where particles are allowed and one where particles are not.

The simulation’s periodic box is always periodic. When a particle’s position leaves the primary image, it is always wrapped back into the box on the other side.

You must ensure that any barriers you place are commensurate with these periodic boundary conditions. Otherwise, particles may cross from an allowed to a disallowed region via wrapping.

Example of an invalid barrier

In the above example: 1) A particle moving up from an allowed region wraps into a disallowed region on the bottom. 2) A particle moving left from from an allowed region wraps into a disallowed region on the right.

Similarly, HOOMD-blue always applies pairwise interactions accounting for the periodic boundary conditions. When desired, set the box length and width of the disallowed region accordingly to prevent such interactions:

Example of a valid barrier

In the above example, the barriers are half the interaction distance away from the edge of the primary box image. Therefore, a particle who’s center is exactly on the edge of the allowed region can never interact with a particle in the allowed region on the opposite side of the box.

Preventing particles from crossing barriers

To prevent particles from crossing a barrier, you must add interactions between particles and the barrier. There are many ways to achieve this goal. See the remaining sections of this tutorial for examples.


This section introduced the concept of barriers in the simulation box and explain that they must be placed carefully to take the always period box into account. The next section will show you how to make a barrier out of particles.