Guide · LAMMPS · SLURM · 14 min read

How do I keep a long LAMMPS run safe?

Checked against the docs · LAMMPS stable release 30 Sep 2026 and SLURM 26.05 · Last checked 11 November 2026 · Spot a mistake? Tell us

Short answer

Write restart files as the run goes (restart N file.a file.b alternates between two), stop cleanly before the walltime with timer timeout, write a last write_restart, and continue in the next job with read_restart and run N upto. Keep dumps sparse enough that the trajectory fits your storage, and set thermo so the log shows how the run is going.

What can go wrong in a long run?

A long molecular dynamics run, days of simulated nanoseconds, is exposed to four things:

  • The walltime. A cluster job has a time limit, its walltime. When it is reached, SLURM sends every task the signal to stop and then kills it (sbatch, --time). Whatever LAMMPS had not written is gone.
  • A failure. A node crashes, the job is canceled, the file system hiccups.
  • The disk. A trajectory written too often can fill your quota before the run ends.
  • Not knowing. A run that has gone wrong (exploding temperature, lost atoms) can burn days of allocation unnoticed if the log says nothing.

Three kinds of output protect against them:

  • A restart file is a binary snapshot of the whole simulation: positions, velocities, the box, the timestep, the force field styles and more. A new job can read it and carry on from that step (read_restart).
  • A dump file is the trajectory: snapshots of the atoms every N steps, for analysis and viewing (dump).
  • Thermo output is the lines of temperature, energy and pressure LAMMPS writes to the screen and to log.lammps (thermo).

When does this matter?

In every run longer than you would be willing to repeat, and in every run longer than one job's walltime. Two LAMMPS defaults make it easy to get wrong:

  • restart 0 is the default: LAMMPS writes no restart files unless you ask (restart).
  • thermo 0 is the default: thermo output only at the start and the end of a run (thermo). A week-long run would show two lines until it finished.

How do restart files work?

The restart command writes them as the run goes, in one of two modes (restart):

Example
restart         10000 poly.restart
restart         10000 tmp.restart.a tmp.restart.b
  • With one name, LAMMPS writes a new file every N steps and adds the timestep to the name (poly.restart.10000, poly.restart.20000), or puts it where a * is (restart.*.equil becomes restart.10000.equil). You keep every one, which costs disk.
  • With two names, LAMMPS toggles between them, so there are only ever two files, each overwritten in turn.

You can use both at once; the manual's own example is archival files every 100 000 steps with one name and frequent temporary ones every 1000 steps with two. restart 0 turns both off.

Restart files are written on steps that are a multiple of N, but not on the first step of a run, and not on the last step unless it is a multiple of N. To write one at a particular moment, such as the end of a run, use write_restart (write_restart):

Example
write_restart   end.*.restart

The * becomes the current timestep.

What a restart file holds, and what it does not. It stores the units, the atom style, the box, the timestep size and number, the atoms with their velocities, groups and masses, the force field styles and, for some styles, their coefficients. It does not store fixes, computes, variables, regions, neighbor list settings, or the thermo, dump and restart output settings: the script that reads it must give those again (read_restart). Many-body and tabulated pair styles (EAM, Tersoff, and the machine-learned snap, pace and mliap, among others) do not store their coefficients, so their pair_style and pair_coeff lines must be repeated too. Some fixes, the Nosé-Hoover thermostat of fix nvt and fix npt among them, write their internal state into the file, and pick it up only when the new script defines a fix of the same style with the same fix ID (fix nvt).

Restart files belong to one LAMMPS. The format is binary, so that a restarted run follows exactly the trajectory the original would have. The manual says it is only expected to be read correctly by the same executable on the same platform; another version or build may fail to read it, or read it wrongly. For a portable copy, convert it with the executable that wrote it:

Terminal
lmp -restart2data end.500000.restart end.500000.data

which writes a text data file that read_data can read (Command-line options).

How often should I write restart files?

The manual gives no number: it depends on how much of the run you can afford to lose, against what each file costs. Think it through like this:

QuestionWhy it matters
How long does the run take to reach one restart interval?A failure costs you up to that much computing time. Read the time per step from a short test (the Performance: line at the end of the log).
How big is one restart file?It holds the whole system; with two toggled names you keep only two. Check after a short test with ls -lh.
How often do you need to keep a state, not only a backup?Keep those with a single name (every one is kept), less often than the toggled backups.
Does writing slow the run?Each restart write forces a neighbor list rebuild on that step, so very frequent writes add work.

The manual gives no interval; the answers to the questions above set it for your run.

What it depends on:

  • The time per step, which grows with the system size and the cost of the potential.
  • Your walltime, and how often the cluster's nodes fail.
  • Your disk quota, since every kept restart file is a full copy of the system.

How do I stop cleanly before the walltime?

Tell LAMMPS the time it has, so it stops the run on its own a little before SLURM would kill it, then writes a restart file (timer):

Example
timer           timeout 23:30:00 every 100
restart         10000 tmp.restart.a tmp.restart.b
run             5000000 upto
write_restart   end.*.restart
  • timer timeout 23:30:00 sets a wall-time limit of 23 hours 30 minutes (an example for a 24-hour job), counted from when the command is read, so put it near the top of the script. The manual asks for a value somewhat smaller than the walltime you requested, because starting a job takes some time, and advises writing a restart file after a run stopped by the timeout. It gives no margin: leave enough for that final restart file to be written, and check after your first job that it was.
  • every 100 checks the clock every 100 steps (the default is 10). Checking too often can slow the run; too rarely, and it stops later than you wanted.
  • When the time is up, the run ends at the next check and every later run or minimize in the script is skipped; other commands still run, so write_restart saves the last step.
  • The thermo keyword timeremain shows the seconds left on the timer, and cpuremain estimates the time the current run still needs (thermo_style).

How do I split a long run across several jobs?

Use run N upto. It runs from the current step up to step N, not N more steps: from step 10 000, run 100000 upto runs 90 000 steps (run). The manual describes exactly this use: on a machine that gives you time in chunks, you can restart the same script again and again, reading the last restart file, until the run reaches its end.

The first job starts from your data file; every later one starts from the restart file and repeats what a restart file does not hold:

Example
# in.continue: every job after the first
read_restart    end.*.restart              # the newest of the end files
pair_style      eam/alloy                  # many-body styles: repeat both lines
pair_coeff      * * your.eam.alloy Ni      # your own file and elements
neighbor        2.0 bin                    # not stored: repeat your own
fix             1 all nvt temp 300.0 300.0 0.1   # same ID and style as the first job
thermo_style    custom step temp pe etotal press
thermo          1000
thermo_modify   flush yes
dump            1 all custom 1000 dump.lammpstrj id type x y z
dump_modify     1 append yes
timer           timeout 23:30:00 every 100
restart         10000 tmp.restart.a tmp.restart.b
run             5000000 upto
write_restart   end.*.restart
  • read_restart end.*.restart reads the file in the series with the largest timestep, the newest (read_restart).
  • No velocity command: the velocities are in the restart file, and a new velocity create would replace them.
  • dump_modify 1 append yes adds the new frames to the existing text dump instead of overwriting it; it does not work for binary or compressed dumps (dump_modify).
  • The numbers (time step, temperature, intervals) are examples, not suggestions.

Give each job its own log, or the next job overwrites log.lammps: lmp -in in.continue -log log.job2 (Command-line options), or log log.lammps append in the script (log).

If a job died instead of timing out, there is no new end file. Continue from the newer of the two toggled files (ls -lt tmp.restart.*, or lmp -restart2info tmp.restart.a to see what a file holds).

Chain the jobs in SLURM so each starts when the one before ends (sbatch):

Terminal
sbatch --dependency=afterany:123456 job-continue.sh

123456 is an example job id: the one sbatch printed for the previous job. afterany starts the new job once the earlier one has ended in any state; afterok only after it ended with exit code 0. How to write and submit the job script is in How do I submit a job on a SLURM cluster?

How often should I write the trajectory?

A dump is written on every step that is a multiple of N, including step 0 (dump). Its size is roughly the frames times the atoms times the columns you ask for, so it grows fast: 10 000 atoms with five columns, dumped every step of a million-step run, is ten billion lines of text. Decide what the analysis needs:

  • Every N steps, where N matches what you will measure. Slow processes (diffusion, a phase change) need fewer frames than fast ones (vibrations).
  • Only the columns you need. dump custom takes a list (id type x y z); velocities and forces double or triple the size.
  • Only the atoms you need, by dumping a group.

Before the long run, dump for a short test, look at the file with ls -lh, and scale it up to the full run. You can change N between runs with dump_modify every.

Compressed and binary dumps (dump):

DumpHowSize and speedNeeds
Textdump 1 all custom 1000 dump.lammpstrj ...The referenceNothing
BinaryA file name ending in .bin or .lammpsbinAbout the same size as text, much faster to write; convert with the binary2txt toolatom and custom styles only
Compressed, gzipcustom/gz with a .gz name, level set by dump_modify compression_levelAbout 3 × smaller than text, slower to writeThe COMPRESS package
Compressed, Zstandardcustom/zstd with a .zst nameAs above, with the Zstd libraryThe COMPRESS package
Compressed through a pipeA plain style with a .gz file nameAs aboveA build with gzip support; the manual warns it can hang or crash on clusters whose fast network forbids fork()

The manual recommends the /gz and /zstd styles on such clusters (Optional build settings). Remember that dump_modify append does not work for compressed dumps: in a chain of jobs, give each job's compressed dump its own name.

How often should thermo output be written?

Often enough that the log shows the run's health. Set thermo N yourself, since the default prints only the first and last steps (thermo). When you suspect a run is going wrong, the manual's advice is to print thermo output very often, even every step, and to look at the atoms' motion (Common issues). For a production run, you need enough points to see trends and, later, to judge when the run is equilibrated (How do I know when dynamics is equilibrated?).

Make the lines appear as they are written. LAMMPS buffers its output, so the log can lag behind the run and lose its last lines if LAMMPS stops early. thermo_modify flush yes (the default is no) flushes each thermo line out at once; the manual notes it does not protect against what the operating system or the hardware lose in a hardware failure (thermo_modify). Dumps are flushed after each snapshot by default (dump_modify flush yes).

How do I know my run is protected?

Test the restart before you need it. Run a short job that writes a restart file, then read it in a second short job and compare the thermo output at the same step. The manual's own example shows them matching where the restart was written; a thermostat that uses random numbers (such as fix langevin) or a run on a different number of processors makes them drift apart slowly afterwards, which is expected (Restart a simulation, read_restart). If the restarted run differs at once, the manual says it could be a bug.

Check that LAMMPS re-enabled your fixes. When a restarted script defines a fix whose saved state is in the file, LAMMPS prints a message that it is re-enabling it; when nothing claims the saved state, it prints a list of the fixes whose state it is discarding (read_restart). A discarded thermostat means the fix ID or style did not match.

Estimate the job length from a short run. The end of each log gives a Performance: line, in ns/day and hours/ns among others (Screen and logfile output). From it, work out how many steps fit in your walltime, and set the timer and the restart interval to suit.

Watch the files grow. ls -lh on the dump and the restart files after the first hour, and the free space in your quota, before the run has days to fill it.

What goes wrong in long runs?

MistakeWhat you would seeWhat to do
No restart commandThe job hits its walltime or a node fails, and there is nothing to continue from.Add restart N file.a file.b; the default writes none.
Only a write_restart after the runSLURM kills the job before it gets there.timer timeout a little under the walltime, then write_restart; plus periodic restart files for failures.
run 5000000 in the continuation scriptEach job runs another five million steps from where it starts.run 5000000 upto.
Fixes not given again after read_restartNothing stops the run, but it is not the run you set up: without fix nvt, nothing integrates the atoms' motion or holds the temperature; with a new fix ID, the thermostat starts from scratch and LAMMPS discards its saved state.Repeat every fix with the same ID and style; read the log for the re-enabled or discarded message.
Many-body pair_coeff not repeatedThe potential's coefficients are not in the restart file, so the run cannot go on without them.Repeat pair_style and pair_coeff after read_restart.
A restart file read by another LAMMPSIt may not read, or read wrongly; the format is meant for the same executable on the same platform.Continue with the same build; for anything else, convert with -restart2data first.
The continuation job overwrites the dump or the logOnly the last job's frames or lines are left.dump_modify append yes for a text dump, a new name per job otherwise; -log log.jobN.
A dump every stepA file of hundreds of gigabytes and a full quota.Dump every N steps, with only the columns and atoms you need, compressed if your build has COMPRESS.
thermo left at its defaultTwo lines in the log: the start and the end.thermo N, and thermo_modify flush yes.
Compressed dumps through a pipe on a fast networkThe run hangs or crashes.Use the custom/gz or custom/zstd styles.

Set up shows "Restart file every", "Dump positions every", "Thermo output every" and "Flush each thermo line" for a LAMMPS run, each with its explanation, and pre-flight checks them before you submit. Continue from here starts a new run from a finished run's end, with its restart files.