LAMMPS from scratch · 25 min
Forces and neighbours in the script
Five commands control how forces are computed: pair_style, pair_coeff, pair_modify, neighbor and neigh_modify. You predict by hand what shifting the energy, adding a tail correction and mixing two atom types do, run each live, and then examine how the melt example's neighbour-list settings behave in this particular run.
- What pair_style, pair_coeff and pair_modify (shift, tail, mix) change, predicted and checked
- How many neighbours each atom has in the list, counted by hand
- How neigh_modify trades speed against missed interactions ("dangerous builds")
1 · Understand: five commands
| Command | Sets | In melt |
|---|---|---|
pair_style lj/cut 2.5 | the kind of force, and the default cutoff | Lennard-Jones, cut at 2.5 |
pair_coeff 1 1 1.0 1.0 2.5 | ε, σ (and optionally the cutoff) for one pair of atom types | types 1–1: ε = 1, σ = 1 |
pair_modify … | shift yes: energy 0 at the cutoff; tail yes: add the part beyond the cutoff; mix: rule for unlike types | not used |
neighbor 0.3 bin | the skin: neighbour lists reach cutoff + 0.3 = 2.8; bin: how they are built (Lesson 2.6) | 2.8 |
neigh_modify every 20 delay 0 check no | when to rebuild the lists | every 20 steps, no checking |
2 · Modify, predict, observe, match
Shift the energy to zero at the cutoff
Predict by hand:
Add the missing tail beyond the cutoff
Predict by hand:
Two atom types: mixing rules
Give type 2 its own ε = 0.5 and σ = 1.2 and say nothing about the pair 1–2. LAMMPS invents it with a mixing rule; lj/cut uses the geometric rule unless told otherwise. Two atoms, type 1 at x = 0 and type 2 at x = 1.2:
Force fields are built for one rule: OPLS uses geometric, AMBER and CHARMM use arithmetic (Lorentz–Berthelot). Using the wrong one changes every unlike interaction.
3 · The neighbour list, counted by hand
The list holds every pair closer than cutoff + skin = 2.8. In the perfect crystal at step 0 the shells inside 2.8 are 12 + 6 + 24 + 12 + 24 = 78 atoms (the fifth, at 2.6557, is inside the skin but outside the cutoff). Each pair is stored once (Newton's third law), so:
4 · Observe: are melt's neighbour settings safe?
The list can miss an interaction if, between rebuilds, an atom moves far enough that a pair previously outside the list cutoff (2.8) enters the force cutoff (2.5). LAMMPS flags a dangerous build when its displacement check detects this condition at a rebuild. With check no, that check is disabled, so LAMMPS cannot report whether scheduled rebuilds were dangerous. Whether this schedule misses interactions depends on the timestep, skin, and actual particle motion; the estimate below indicates why this setup deserves caution.
| neigh_modify | idea | list builds | dangerous | TotEng at 250 | |
|---|---|---|---|---|---|
every 20 delay 0 check no | melt as shipped | ||||
every 20 delay 0 check yes | same schedule, but count the dangerous builds | ||||
every 10 delay 0 check yes | look twice as often | ||||
every 1 delay 0 check yes | look every step, rebuild only when needed |
In the recorded run, the melt settings rebuilt the list 12 times, but with check no LAMMPS did not check or report dangerous builds. With every 1 delay 0 check yes, it rebuilt 42 times (about every 6 steps) and reported no dangerous builds. The total energy at step 250 was −2.2812174 for the original settings and −2.2797308 for the checked settings, versus −2.2744931 at step 0. These results are specific to this input and LAMMPS build; use a checked neighbor schedule when validating a simulation.
Your turn
1. With pair_modify shift yes, why does the pressure not change at all?
2. With a skin of 0.5 instead of 0.3, how many neighbours per atom does the step-0 list hold?
3. The tail correction lowers the pressure by 0.76. Is that small?