LAMMPS from scratch · 20 min
What an input script is
An input script is a list of commands that LAMMPS carries out one at a time, top to bottom, the moment it reads each one. You take the melt example apart six ways, predict for each whether LAMMPS stops, runs normally or runs differently, then run it live and check the numbers by hand.
- The three rules of an input script: one command at a time, top to bottom, immediately
- Settings (remembered for later) versus actions (done now), and why order matters
- Which mistakes LAMMPS catches with an error, and which it cannot catch at all
1 · Understand: three rules
- One command per line. The first word names the command; the rest are its settings (page A.2 shows how a line is read).
- Top to bottom. LAMMPS never looks ahead. A command can only use what earlier lines created.
- Immediately. Each command is carried out as soon as it is read, before the next line is even looked at.
Commands come in two kinds. A setting is remembered and used later; an action does something now, with whatever exists at that moment.
| melt line | kind | what it needs before it |
|---|---|---|
units lj, atom_style atomic | setting | must come first: everything else depends on them |
lattice fcc 0.8442 | setting | |
region box block … | setting (a named shape) | the lattice (its numbers are in lattice cells) |
create_box 1 box | action: makes the box and 1 atom type | the region |
create_atoms 1 box | action: puts 4000 atoms in | the box and the lattice |
mass 1 1.0 | setting | the atom type |
velocity all create 3.0 … | action: gives velocities now | atoms and their mass |
pair_style, pair_coeff | setting | pair_coeff needs the atom types |
neighbor, neigh_modify, fix, thermo | setting | |
run 250 | action: uses every setting made so far | all of the above |
2 · Modify, predict, observe: six rearranged scripts
For each change, choose what you think LAMMPS will do, then run the real LAMMPS to see.
A. The force field before the box
Change: the two pair lines moved above lattice.
B. No mass
Change: the line mass 1 1.0 deleted.
C. Velocities before atoms
Change: velocity moved above create_atoms.
D. Printing set after the run
Change: thermo 50 moved below run 250.
E. Moving atoms switched on too late
Change: fix 1 all nve moved below run 250.
F. No forces at all
Change: both pair lines deleted.
3 · What the six results teach
| Change | LAMMPS | Lesson |
|---|---|---|
| A, B, C | stops with an error | an action or a setting used something that did not exist yet |
| D | runs; fewer lines printed | a setting placed after an action does not affect it |
| E | runs; a warning; nothing moves | a missing step is not always an error |
| F | runs; two warnings; an ideal gas | LAMMPS checks the order, never your intention: only a hand calculation catches this |
The last row is the reason for the hand calculations on every page of this section. An input that runs is not the same as an input that is right.
Your turn
1. You add timestep 0.001 after run 250. What happens to the run?
2. In change F, why is the pressure exactly ρT(N−1)/N?
3. Can you put pair_style lj/cut 2.5 as the very first line?