LAMMPS Potential¶
Changed in version 2.12: LAMMPS is now loaded at runtime via dlopen/LoadLibrary. No compile-time
flag is needed. A single eOn binary can use LAMMPS potentials if liblammps
is installed, without requiring LAMMPS at build time.
conda-forge availability
The conda-forge eOn package works with LAMMPS out of the box. Simply install
LAMMPS in the same environment: conda install lammps. eOn will find and load
liblammps automatically at runtime.
How It Works¶
eOn uses a singleton LammpsLoader that searches for the LAMMPS shared library
at the first potential evaluation. The search order is:
Linux:
liblammps.so,liblammps.so.0macOS:
liblammps.dylib,liblammps.0.dylibWindows:
lammps.dll,liblammps.dll
If the library is found, seven LAMMPS C API functions are loaded via dlsym.
If not found, eOn prints a clear error message with installation instructions.
The cross-platform dynamic loading is handled by DynLib.h, a lightweight
header-only abstraction over dlopen/LoadLibrary.
Setup¶
Install LAMMPS in the same conda/pixi environment as eOn:
conda install -c conda-forge lammps
Or build LAMMPS from source and install the shared library:
cmake -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
-D BUILD_MPI=no \
-D BUILD_SHARED_LIBS=yes \
../cmake
make -j4
make install
No eOn rebuild is needed. The potential = lammps configuration option works
immediately once liblammps is on the library search path.
Usage¶
Set the potential to lammps in the configuration file and place a LAMMPS
input file named in.lammps in the potfiles directory. This file specifies
which LAMMPS potential to use. Example for the Morse potential:
pair_style morse 9.5 #morse potential with 9.5 Angstrom cutoff
pair_coeff * * 0.7102 1.6047 2.797 #specify parameters
pair_modify shift yes #shift the potential to be zero at the cutoff
Troubleshooting¶
If eOn reports “LAMMPS library not found”, ensure that:
liblammps.so(or.dylib/.dll) is on the library search path (LD_LIBRARY_PATHon Linux,DYLD_LIBRARY_PATHon macOS)The LAMMPS library was built as a shared library (
BUILD_SHARED_LIBS=yes)The LAMMPS version is compatible (tested with LAMMPS 2Aug2023 and later)