LAMMPS¶
Back to the Anvil Software section
Large-scale Atomic/Molecular Massively Parallel Simulator (LAMMPS) is a molecular dynamics program from Sandia National Laboratories. LAMMPS makes use of Message Passing Interface for parallel communication and is a free and open-source software, distributed under the terms of the GNU General Public License.
Provided LAMMPS module¶
LAMMPS modules¶
The Anvil team provides LAMMPS module with our default module environment gcc/11.2.0 and openmpi/4.0.6 to all users. It can be accessed by:
The LAMMPS executable is lmp and the LAMMPS potential files are installed at $LAMMPS_HOME/share/lammps/potentials, where the value of $LAMMPS_HOMEis the path to LAMMPS build folder. Use this variable in any scripts. Your actual LAMMPS folder path may change without warning, but this variable will remain current. The current path is:
LAMMPS Job Submit Script¶
This is an example of a job submission file for running parallel LAMMPS jobs using the LAMMPS module installed on Anvil.
Build your own LAMMPS¶
Build your own LAMMPS¶
LAMMPS provides a very detailed instruction of Build LAMMPS with a lot of customization options. In the following sections, we provide basic installation instructions of how to install LAMMPS on Anvil, as well as a LAMMPS Installation Script in current user guide section for users who would like to build their own LAMMPS on Anvil:
Step 1: Download¶
LAMMPS is an open-source code, you can download LAMMPS as a tarball from LAMMPS download page. There are several versions available on the LAMMPS webpage, we strongly recommend downloading the latest released stable version and unzip and untar it. It will create a LAMMPS directory:
Step 2: Build source code¶
LAMMPS provides two ways to build the source code: traditional configure && make method and the cmake method. These are two independent approaches and users should not mix them together. You can choose the one you are more familiar with.
Build LAMMPS with Make¶
Traditional make method requires a Makefile file appropriate for your system in either the src/MAKE, src/MAKE/MACHINES, src/MAKE/OPTIONS, or src/MAKE/MINE directory. It provides various options to customize your LAMMPS. If you would like to build your own LAMMPS on Anvil with make, please follow the instructions for Build LAMMPS with make. In the following sections, we will provide some instructions on how to install LAMMPS on Anvil with make.
Include LAMMPS Packages
In LAMMPS, a package is a group of files that enable a specific set of features. For example, force fields for molecular systems or rigid-body constraints are in packages. Usually, you can include only the packages you plan to use, but it doesn't hurt to run LAMMPS with additional packages.
To use make command to see the make options and package status, you need to first jump to src subdirectory. Here we will continue use lammps-23Jun2022 as an example:
For most LAMMPS packages, you can include them by:
A few packages require additional steps to include libraries or set variables, as explained on Packages with extra build options. If a package requires external libraries, you must configure and build those libraries before building LAMMPS and especially before enabling such a package.
If you have issues with installing external libraries, please contact us at Help Desk.
Instead of specifying all the package options via the command line, LAMMPS provides some Make shortcuts for installing many packages, such as make yes-most, which will install most LAMMPS packages w/o libs. You can pick up one of the shortcuts based on your needs.
Compilation
Once the desired packages are included, you can compile lammps with our default environment: compiler gcc/11.2.0 and MPI library openmpi/4.0.6 , you can load them all at once by module load modtree/cpu. Then corresponding make option will be make g++_openmpi for OpenMPI with compiler set to GNU g++.
Then the LAMMPS executable lmp_g++_openmpi will be generated in the build folder.
LAMMPS support parallel compiling, so you may submit an Interactive job to do parallel compiling.
If you get some error messages and would like to start over the installation process, you can delete compiled objects, libraries and executables with make clean-all.
Examples
Here is an example of how to install the lammps-23Jun2022 version on Anvil with most packages enabled:
Tips
When you run LAMMPS and get an error like "command or style is unknown", it is likely due to the fact you did not include the required packages for that command or style. If the command or style is available in a package included in the LAMMPS distribution, the error message will indicate which package would be needed.
For more information about LAMMPS build options, please refer to these sections of LAMMPS documentation:
- Serial vs parallel build
- Choice of compiler and compile/link options
- Build the LAMMPS executable and library
- Including and removing debug support
- Build LAMMPS tools
- Install LAMMPS after a build
- Optional build settings
Build LAMMPS with Cmake¶
CMake is an alternative to compiling LAMMPS in addition to the traditional Make method. CMake has several advantages, and might be helpful for people with limited experience in compiling software or for those who want to modify or extend LAMMPS. If you prefer using cmake, please follow the instructions for Build LAMMPS with CMake. In the following sections, we will provide some instructions on how to install LAMMPS on Anvil with cmake and the LAMMPS Installation Script in current user guide section:
Use CMake to generate a build environment
- First go to your LAMMPS directory and generate a new folder
buildfor build environment. Here we will continue uselammps-23Jun2022as an example:
cmakefeatures, you need to module load cmake first.
3. For basic LAMMPS installation with no add-on packages enabled and no customization, you can generate a build environment by:
In LAMMPS, a package is a group of files that enable a specific set of features. For example, force fields for molecular systems or rigid-body constraints are in packages. Usually, you can include only the packages you plan to use, but it doesn't hurt to run LAMMPS with additional packages.
For most LAMMPS packages, you can include it by adding the following flag to cmake command:
For example:
A few packages require additional steps to include libraries or set variables, as explained on Packages with extra build options. If you have issue with installing external libraries, please contact us at Help Desk.
5. Instead of specifying all the package options via the command line, LAMMPS provides some CMake setting scripts in /cmake/presets folder. You can pick up one of them or customize it based on your needs.
6. If you get some error messages after the cmake ../cmake step and would like to start over, you can delete the whole build folder and create new one:
Compilation
- Once the build files are generated by
cmakecommand, you can compile lammps with our default environments: compilergcc/11.2.0and MPI libraryopenmpi/4.0.6, you can load them all at once bymodule load modtree/cpu. - Then, the next step is to compile LAMMPS with
makeorcmake --build, upon completion, the LAMMPS executablelmpwill be generated in thebuildfolder. - LAMMPS supports parallel compiling, so you may submit an Interactive job to do parallel compilation.
- If you get some error with compiling, you can delete compiled objects, libraries and executables with
make cleanorcmake --build . --target clean.
Examples
Here is an example of how to install the lammps-23Jun2022 version on Anvil with most packages enabled:
The CMake setting script /cmake/presets/most.cmake we used in the example here will includes 57 most common packages:
Tips
When you run LAMMPS and get an error like "command or style is unknown", it is likely due to you did not include the required packages for that command or style. If the command or style is available in a package included in the LAMMPS distribution, the error message will indicate which package would be needed.
After the initial build, whenever you edit LAMMPS source files, enable or disable packages, change compiler flags or build options, you must recompile LAMMPS with make.
For more information about LAMMPS build options, please following these links from LAMMPS website:
- Serial vs parallel build
- Choice of compiler and compile/link options
- Build the LAMMPS executable and library
- Including and removing debug support
- Build LAMMPS tools
- Install LAMMPS after a build
- Optional build settings
LAMMPS Installation Script
Here we provide a lammps-23Jun2022 installation script with cmake. It contains the procedures from downloading the source code to what we mentioned in Build LAMMPS with Cmake Example section. You will start with making an empty folder. Then, download the installation scriptinstall-lammps.sh to this folder. Since parallel compiling with 12 cores is used in the script, you may submit an Interactive job to ask for 12 cores: