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.
- What a terminal is, and how a command is built from a name and its arguments
- The ten commands you need: ls, cd, cat, less, grep, mkdir, cp, nano, lmp and mpirun
- Edit an input script, run LAMMPS on it, and match the new numbers 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.
2 · The ten commands
| Command | What it does | Example |
|---|---|---|
ls | list what is in the current folder | ls |
cd | change folder; cd .. goes up one, cd ~ goes home | cd lammps-course/melt |
cat | print a whole file | cat in.melt |
less | read a long file page by page (q quits) | less log.lammps |
grep | show only the lines that contain a word | grep -n pair in.melt |
mkdir | make a new folder | mkdir cold |
cp | copy a file | cp in.melt cold/ |
nano | edit a text file | nano in.melt |
./lmp | run a program; ./ means "the one in this folder" | ./lmp -in in.melt |
mpirun | run a program on several processors | mpirun -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.
Where am I? pwd prints the folder you are in.
Predict: /home/you (your home folder)
What is here? ls lists files and folders. Folders end with /.
Predict: one folder: lammps-course/
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
Print a whole file with cat.
Predict: the 33 lines of the melt script
Find lines containing a word with grep; -n adds line numbers.
Predict: two lines, numbers 14 and 15
less shows a long file one screen at a time (q quits).
Predict: the same text as cat
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
Edit with nano: change
create 3.0tocreate 1.0on line 12, then Save and exit.Predict: the copy in cold/ now starts at T = 1.0; the original is untouched
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
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):
Run LAMMPS in the terminal (task 9) and its step-0 numbers appear here next to the hand values.
5 · On your own computer
| System | Where the terminal is | Note |
|---|---|---|
| Linux | the Terminal application (Ctrl+Alt+T on Ubuntu) | all ten commands work as here |
| macOS | Applications → Utilities → Terminal | all ten commands work as here |
| Windows | PowerShell 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?
~/lammps-course. Check with pwd.2. How many lines of in.melt contain "create", and what does grep -c create in.melt print?
-c prints only the count: 3.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?
cd lammps-course/melt first, or give the path: lmp -in lammps-course/melt/in.melt.