LAMMPS from scratch · 25 min
Units
The units command decides what every number in a script means. You see the conversion constants inside LAMMPS, derive one by hand, then run melt twice: in Lennard-Jones units and as real argon in Å, femtoseconds and kcal/mol. Converted by hand, the two runs agree at every printed step.
- What each unit style means for mass, length, time, energy, temperature and pressure
- The constants LAMMPS uses inside (Boltzmann, force-to-acceleration, pressure) and where one comes from
- Convert melt to argon in real units, predict its output by hand and match it step by step
1 · Understand: the same number means different things
Set units before creating the simulation box or defining force-field settings, so LAMMPS interprets later values correctly. This example places it near the top. timestep 1.0 is one femtosecond in real units and one picosecond in metal units.
| lj | real | metal | si | |
|---|---|---|---|---|
| mass | m (set to 1) | g/mol | g/mol | kg |
| distance | σ | Å | Å | m |
| time | τ = σ√(m/ε) | fs | ps | s |
| energy | ε | kcal/mol | eV | J |
| temperature | ε/kB | K | K | K |
| pressure | ε/σ³ | atm | bar | Pa |
| default time step | 0.005 τ | 1 fs | 0.001 ps | 10⁻⁸ s |
| default neighbour skin | 0.3 σ | 2 Å | 2 Å | 0.001 m |
| thermo energies are | per atom | totals | totals | totals |
The last row matters when comparing numbers: in LJ units thermo divides energies by the number of atoms; in all other styles it prints the total.
2 · The constants inside LAMMPS
Equations of motion need a few conversion factors. LAMMPS sets them in Update::set_units(). For real units (lines 171–176 and nearby):
In LJ units all five are 1. Where does 48.88821291 come from? A force of 1 kcal/mol/Å on a mass of 1 g/mol gives an acceleration of:
3 · Modify: melt as real argon
Argon is often modelled with σ = 3.405 Å, ε = 0.2381 kcal/mol (0.996 kJ/mol) and m = 39.948 g/mol. Every LJ number in melt becomes a real number by multiplying with the right combination:
Both scripts use loop all instead of loop geom for the velocities. With loop geom the random velocity of each atom is seeded from its coordinates, and the coordinates are different numbers in Å and in σ, so the two runs would start with different (equally valid) velocities.
Predict by hand
4 · Observe and match: run both
Each button runs the real LAMMPS (250 steps, about 2 seconds). After both runs, every real-unit number is converted back to LJ units by hand and compared with the LJ run.
What the two runs show
- Converted, the two runs agree at every printed step to 6–8 digits: units change the numbers, never the physics. The last digits differ because the computer rounds different numbers (Å instead of σ).
- Every quantity needs its own conversion factor: kB for temperature, ε × N for energies (and the per-atom normalisation), ε/σ³ × nktv2p for pressure.
- LJ results are therefore general: the same run describes argon, krypton or any LJ fluid, once you choose σ, ε and m.
Your turn
1. A real-units run prints Temp = 200.79919 K at step 50. What is that in LJ units?
2. You copy timestep 2.0 from a real-units water script into a metal-units script. What time step do you get?
3. Why do the real-units energies look 952 times larger than the LJ ones?