LAMMPS from scratch · 20 min

The terminal in 10 commands

LAMMPS is used by typing commands, on your own computer and on every supercomputer. Ten commands are enough for everything in this course. You practise them here in a terminal that runs the real LAMMPS, edit the melt script, and check the result by hand.

1 · Understand: talking to the computer in sentences

A terminal is a window where you type instructions instead of clicking. LAMMPS has no buttons of its own (LAMMPS-GUI adds some), and supercomputers offer nothing but a terminal, so this is how almost everyone runs it.

Every instruction is a short sentence: the name of a program, then options (starting with -), then what it should work on. Press Enter and the program runs.

grep -n pair in.melt │ │ │ └ the file to search │ │ └ what to look for │ └ option: show line numbers └ the program

2 · The ten commands

CommandWhat it doesExample
lslist what is in the current folderls
cdchange folder; cd .. goes up one, cd ~ goes homecd lammps-course/melt
catprint a whole filecat in.melt
lessread a long file page by page (q quits)less log.lammps
grepshow only the lines that contain a wordgrep -n pair in.melt
mkdirmake a new foldermkdir cold
cpcopy a filecp in.melt cold/
nanoedit a text filenano in.melt
./lmprun a program; ./ means "the one in this folder"./lmp -in in.melt
mpirunrun a program on several processorsmpirun -np 4 lmp -in in.melt

One more is handy: pwd prints where you are. Folder paths work like addresses: ~ is your home folder, .. the folder above, and cold/in.melt means "the file in.melt inside the folder cold".

3 · Modify and observe: practise here

This terminal keeps its files in your browser only. The lmp command runs the real LAMMPS. Tap a command to type it, or type it yourself.

  1. Where am I? pwd prints the folder you are in.

    Predict: /home/you (your home folder)

  2. What is here? ls lists files and folders. Folders end with /.

    Predict: one folder: lammps-course/

  3. Go into a folder with cd. It prints nothing; the prompt changes. Then type ls again.

    Predict: the prompt ends in ~/lammps-course/melt; ls shows in.melt

  4. Print a whole file with cat.

    Predict: the 33 lines of the melt script

  5. Find lines containing a word with grep; -n adds line numbers.

    Predict: two lines, numbers 14 and 15

  6. less shows a long file one screen at a time (q quits).

    Predict: the same text as cat

  7. Make a new folder with mkdir, copy the script into it with cp, and move in.

    Predict: no output; ls inside cold shows in.melt

  8. Edit with nano: change create 3.0 to create 1.0 on line 12, then Save and exit.

    Predict: the copy in cold/ now starts at T = 1.0; the original is untouched

  9. Run LAMMPS on the edited copy. On your computer it may be ./lmp (the program in this folder), lmp, lmp_serial or lmp.exe.

    Predict: step 0: E_pair −6.7733681 (positions unchanged), TotEng −5.2737431, Press −5.3913283

  10. Run in parallel with mpirun: -np 4 starts 4 copies that share the atoms.

    Predict: the same numbers: splitting the work does not change the physics

4 · Match: the edited run by hand

Task 8 changed only the starting temperature. At step 0 the atoms still sit on the crystal, so the pair energy cannot change; only the kinetic parts do (the Start page, change D):

E_pair = −6.7733681 (positions unchanged) KE/N = 1.5 × T × (N−1)/N = 1.5 × 1.0 × 0.99975 = 1.4996250 TotEng = −6.7733681 + 1.4996250 = −5.2737431 Press = 0.8442 × 1.0 × 0.99975 − 6.2353173 = −5.3913283

Run LAMMPS in the terminal (task 9) and its step-0 numbers appear here next to the hand values.

5 · On your own computer

SystemWhere the terminal isNote
Linuxthe Terminal application (Ctrl+Alt+T on Ubuntu)all ten commands work as here
macOSApplications → Utilities → Terminalall ten commands work as here
WindowsPowerShell or Windows Terminal; or Ubuntu inside Windows (WSL)in PowerShell use type instead of cat and Select-String instead of grep; WSL behaves like Linux

Two habits save hours: press Tab to complete a file name, and press ↑ to bring back the last command. ↑ also works in the practice terminal above.

Your turn

1. You are in ~/lammps-course/melt/cold. Where does cd ../.. take you?

2. How many lines of in.melt contain "create", and what does grep -c create in.melt print?

3. You type lmp -in in.melt in your home folder and get "Cannot open input script in.melt". Why, and what are two fixes?