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:
Link to section 'Use CMake to generate a build environment' of 'Build LAMMPS with Cmake' Use CMake to generate a build environment
-
First go to your LAMMPS directory and generate a new folder
build
for build environment. Here we will continue uselammps-23Jun2022
as an example:$ cd lammps-23Jun2022 $ mkdir build; cd build # create and change to a build directory
-
To use
cmake
features, you need tomodule load cmake
first. -
For basic LAMMPS installation with no add-on packages enabled and no customization, you can generate a build environment by:
$ cmake ../cmake # configuration reading CMake scripts from ../cmake
-
You can also choose to include or exclude packages to or from build.
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:-D PKG_NAME=yes # degualt value is "no", which means exclude the package
For example:
$ cmake -D PKG_MOLECULE=yes -D PKG_RIGID=yes -D PKG_MISC=yes ../cmake
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.
-
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. -
If you get some error messages after the
cmake ../cmake
step and would like to start over, you can delete the wholebuild
folder and create new one:$ cd lammps-23Jun2022 $ rm -rf build $ mkdir build && cd build
Link to section 'Compilation' of 'Build LAMMPS with Cmake' Compilation
-
Once the build files are generated by
cmake
command, you can compile lammps with our default environments: compilergcc/11.2.0
and 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
make
orcmake --build
, upon completion, the LAMMPS executablelmp
will be generated in thebuild
folder. -
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 clean
orcmake --build . --target clean
.
Link to section 'Examples' of 'Build LAMMPS with Cmake' Examples
Here is an example of how to install the lammps-23Jun2022
version on Anvil with most packages enabled:
# Setup module environments
$ module purge
$ module load modtree/cpu
$ module load hdf5 fftw gsl netlib-lapack
$ module load cmake anaconda
$ module list
$ cd lammps-23Jun2022 # change to the LAMMPS distribution directory
$ mkdir build; cd build; # create and change to a build directory
# enable most packages and setup Python package library path
$ cmake -C ../cmake/presets/most.cmake -D PYTHON_EXECUTABLE=$CONDA_PYTHON_EXE ../cmake
# If everything works well, you will see
# -- Build files have been written to: /path-to-lammps/lammps-23Jun2022/build
# compilation
$ make # or "make -j 12" to do parallel compiling if you open an interactive session with 12 cores.
# If everything works well, you will see
# [100%] Built target lmp
The CMake setting script /cmake/presets/most.cmake
we used in the example here will includes 57 most common packages:
$ ASPHERE BOCS BODY BROWNIAN CG-DNA CG-SDK CLASS2 COLLOID COLVARS COMPRESS CORESHELL DIELECTRIC DIFFRACTION DIPOLE DPD-BASIC DPD-MESO DPD-REACT DPD-SMOOTH DRUDE EFF EXTRA-COMPUTE EXTRA-DUMP EXTRA-FIX EXTRA-MOLECULE EXTRA-PAIR FEP GRANULAR INTERLAYER KSPACE MACHDYN MANYBODY MC MEAM MISC ML-IAP ML-SNAP MOFFF MOLECULE OPENMP OPT ORIENT PERI PLUGIN POEMS QEQ REACTION REAXFF REPLICA RIGID SHOCK SPH SPIN SRD TALLY UEF VORONOI YAFF
Link to section 'Tips' of 'Build LAMMPS with Cmake' 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:
$ mkdir lammps; cd lammps; # create and change to a lammps directory
$ wget https://www.rcac.purdue.edu/files/knowledge/compile/src/install-lammps.sh
$ ls
install-lammps.sh
$ sinteractive -N 1 -n 12 -A oneofyourallocations -p shared -t 1:00:00
$ bash install-lammps.sh