Wall potential (HPMC)



  • How do I apply interactions between wall geometries and particles in hard particle Monte Carlo simulations?


  • Demonstrate the use of the wall potential class.

Boilerplate code

The render function in the next (hidden) cell will render the system state using fresnel. Find the source in the hoomd-examples repository.

Place particles in the center of a large simulation box:

import itertools

import gsd.hoomd
import hoomd
import numpy

L = 20
m = 10
N = m**2
x = numpy.linspace(start=-m / 2, stop=m / 2, endpoint=False, num=m) + 1 / 2
position_2d = numpy.array(list(itertools.product(x, repeat=2)))

frame = gsd.hoomd.Frame()
frame.particles.N = N
frame.particles.position = numpy.stack(
    (position_2d[:, 0], position_2d[:, 1], numpy.zeros(N)), axis=-1
frame.particles.types = ['mobile']
frame.configuration.box = [L, L, 0, 0, 0, 0]

with gsd.hoomd.open(name='initial_state.gsd', mode='x') as f:

Prepare a hard particle Monte Carlo simulation:

simulation = hoomd.Simulation(device=hoomd.device.CPU(), seed=1)
simulation.operations.integrator = hoomd.hpmc.integrate.Sphere()
simulation.operations.integrator.shape['mobile'] = dict(diameter=1.0)

Adding the hard wall potential

Define the same wall surfaces used in the previous section of this tutorial:

top = hoomd.wall.Plane(origin=(0, 7, 0), normal=(0, -1, 0))
bottom = hoomd.wall.Plane(origin=(0, -7, 0), normal=(0, 1, 0))
left = hoomd.wall.Plane(origin=(-7, 0, 0), normal=(1, 0, 0))
right = hoomd.wall.Plane(origin=(7, 0, 0), normal=(-1, 0, 0))

In a Monte Carlo simulation, the integrator accepts or rejects trial moves based on the potential energy of the system. Set the external_potential attribute to evaluate the wall potentials during the trial moves:

wall_potential = hoomd.hpmc.external.wall.WallPotential(
    walls=[top, bottom, left, right]
simulation.operations.integrator.external_potential = wall_potential

Where MD computes forces between the particle center and the wall surface, the HPMC integrator checks the full extent of each particle’s shape and sets the energy to infinity whenever any point in the particle’s shape has a negative distance to the wall’s surface.

Note: HPMC implements shape-wall overlap checks only for certain shape/wall combinations. The documentation for each HPMC shape integrator documents which (if any) wall types it supports.

Run the simulation



This section demonstrates how to apply a hard potential between wall geometries and particles during hard particle Monte Carlo simulations. The previous section showed how to run the same simulation with molecular dynamics.