All simulations executed in HOOMD-blue occur in a triclinic simulation box with periodic boundary conditions in all three directions. A triclinic box is defined by six values: the extents Lx, Ly and Lz of the box in the three directions, and three tilt factors xy, xz and yz.
The parameter matrix h is defined in terms of the lattice vectors a⃗1, a⃗2 and a⃗3:
h ≡ (a⃗1,a⃗2,a⃗3)
By convention, the first lattice vector a⃗1 is parallel to the unit vector e⃗x = (1, 0, 0). The tilt factor xy indicates how the second lattice vector a⃗2 is tilted with respect to the first one. It specifies many units along the x-direction correspond to one unit of the second lattice vector. Similarly, xz and yz indicate the tilt of the third lattice vector a⃗3 with respect to the first and second lattice vector.
The full cell parameter matrix is:
The tilt factors xy, xz and yz are dimensionless. The relationships between the tilt factors and the box angles α, β and γ are as follows:
Given an arbitrarily oriented lattice with box vectors v⃗1, v⃗2, v⃗3, the HOOMD-blue box parameters for the rotated box can be found as follows.
Example:
# boxMatrix contains an arbitrarily oriented right-handed box matrix.
v[0] = boxMatrix[:,0]
v[1] = boxMatrix[:,1]
v[2] = boxMatrix[:,2]
Lx = numpy.sqrt(numpy.dot(v[0], v[0]))
a2x = numpy.dot(v[0], v[1]) / Lx
Ly = numpy.sqrt(numpy.dot(v[1],v[1]) - a2x*a2x)
xy = a2x / Ly
v0xv1 = numpy.cross(v[0], v[1])
v0xv1mag = numpy.sqrt(numpy.dot(v0xv1, v0xv1))
Lz = numpy.dot(v[2], v0xv1) / v0xv1mag
a3x = numpy.dot(v[0], v[2]) / Lx
xz = a3x / Lz
yz = (numpy.dot(v[1],v[2]) - a2x*a3x) / (Ly*Lz)
You can specify all parameters of a triclinic box in a GSD file.
You can also pass a :pyhoomd.data.boxdim
argument to the constructor of any initialization method. Here is an example for :pyhoomd.deprecated.init.create_random
:
init.create_random(box=data.boxdim(L=18, xy=0.1, xz=0.2, yz=0.3), N=1000))
This creates a triclinic box with edges of length 18, and tilt factors xy = 0.1, xz = 0.2 and yz = 0.3.
You can also specify a 2D box to any of the initialization methods:
init.create_random(N=1000, box=data.boxdim(xy=1.0, volume=2000, dimensions=2), min_dist=1.0)
The triclinic unit cell can be updated in various ways.
The simulation box can be gradually resized during a simulation run using :pyhoomd.update.box_resize
.
To update the tilt factors continuously during the simulation (shearing the simulation box with Lees-Edwards boundary conditions), use:
update.box_resize(xy = variant.linear_interp([(0,0), (1e6, 1)]))
This command applies shear in the xy -plane so that the angle between the x and y-directions changes continuously from 0 to 45∘ during 106 time steps.
:pyhoomd.update.box_resize
can change any or all of the six box parameters.
In a constant pressure ensemble, the box is updated every time step, according to the anisotropic stresses in the system. This is supported by:
- :py
hoomd.md.integrate.npt
- :py
hoomd.md.integrate.nph