Wall potential (HPMC)#

Overview#

Questions#

  • How do I apply interactions between wall geometries and particles in HPMC simulations?

Objectives#

  • 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:

[3]:
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:
    f.append(frame)

Prepare a hard particle Monte Carlo simulation:

[4]:
simulation = hoomd.Simulation(device=hoomd.device.CPU(), seed=1)
simulation.create_state_from_gsd(filename='initial_state.gsd')
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:

[5]:
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:

[6]:
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 part of a particle’s shape is on the inactive side.

Note: HPMC implements shape-wall overlap checks only for certain shape and wall combinations. Check the documentation for the shape to see which wall types it supports (if any).

Run the simulation#

[7]:
simulation.run(10_000)
[8]:
render(simulation.state.get_snapshot())
[8]:
../../_images/tutorial_08-Placing-Barriers-in-the-Simulation-Box_05-Wall-potential-HPMC_15_0.png

Conclusion#

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