Initial configurations
ParticleDynamics provides host-side lattice generators for overlap-free starting configurations in 2D and 3D periodic boxes. Every generator returns a NamedTuple containing the periodic box dimensions, positions centered on the origin, and region index arrays so you can assign particle types, masses, charges, or temperatures per region.
Quick examples
2D random fluid on a hexagonal lattice
using ParticleDynamics
N = 256
cfg = hex_random_2d(N, 1.0, 0.35; T=Float32)
system = ParticleSystem(
cfg;
types=[:A],
typeids=fill(Int32(1), N),
masses=Dict(:A => 1.0f0),
)3D FCC fluid and slab coexistence
# 3D disordered fluid initialized on an FCC lattice at packing fraction phi = 0.35
cfg3d = fcc_random_3d(1_024, 1.0, 0.35; T=Float32)
# 3D dense crystal slab coexisting with a dilute vapor region
slab = fcc_slab_coexistence_3d(1_024, 1.0, 0.45, 0.05; T=Float32)
typeids = fill(Int32(1), length(slab.x))
typeids[slab.vapor_idx] .= Int32(2)
system = ParticleSystem(
slab;
types=[:slab, :vapor],
typeids=typeids,
masses=Dict(:slab => 1.0f0, :vapor => 1.0f0),
)Available generators
| Function | Dimension | Geometry |
|---|---|---|
box_from_phi_2d | 2D | Compute periodic box side lengths from particle count, diameter, and packing fraction φ |
box_from_phi_3d | 3D | Compute periodic box side lengths from particle count, diameter, and packing fraction φ |
hex_sites_in_box_2d | 2D | Enumerate hexagonal lattice sites inside a given rectangular box |
hex_random_2d | 2D | Randomly select N non-overlapping sites on a 2D hexagonal lattice |
hex_circle_2d | 2D | Compact circular hexagonal crystal droplet in a periodic 2D box |
hex_circle_in_box_2d | 2D | Circular hexagonal droplet centered inside an explicit 2D box |
hex_circle_plus_random_2d | 2D | Dense circular droplet surrounded by a random dilute gas (returns region indices) |
hex_slab_coexistence_2d | 2D | Periodic 2D slab–vapor coexistence geometry |
fcc_sites_in_box_3d | 3D | Enumerate FCC lattice sites inside a given orthorhombic box |
fcc_random_3d | 3D | Randomly select N non-overlapping sites on a 3D FCC lattice |
fcc_slab_coexistence_3d | 3D | Periodic 3D slab–vapor coexistence geometry |
Custom coordinates, velocities, charges and topology
ParticleSystem also accepts explicit coordinate arrays or vectors of tuples alongside PeriodicBox, initial velocities, per-type or per-particle masses and charges, and a Topology describing bonds, angles, dihedrals, impropers, and nonbonded exclusions:
system = ParticleSystem(
positions;
box=PeriodicBox(Lx, Ly, Lz),
types=[:O, :H],
typeids=typeids,
masses=Dict(:O => 15.9994, :H => 1.008),
charges=Dict(:O => -0.8476, :H => 0.4238),
velocities=velocities,
topology=Topology(bonds=bonds, angles=angles),
)To resume from an existing trajectory instead of generating a fresh lattice, load a saved frame with ParticleSystem.from_gsd("traj.gsd") (see Continue a simulation).
Full signatures and returned fields for every generator are listed in the I/O & Initial Configurations API reference.