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 after you 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.0

  • macOS: liblammps.dylib, liblammps.0.dylib

  • Windows: 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

The client opens in.lammps in its working directory. A missing file raises LAMMPS: in.lammps not found in working directory.

[Main]
job = point

[Potential]
potential = lammps

job = point reads pos.con. Run it with eonclient from that directory. A server run copies each file from [Paths] pot into the job directory. The default directory is potfiles. The client then opens in.lammps there. A direct eonclient run does not copy potfiles/.

The file selects the LAMMPS potential. 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”, check:

  1. liblammps.so (or .dylib/.dll) is on the library search path (LD_LIBRARY_PATH on Linux, DYLD_LIBRARY_PATH on macOS)

  2. The LAMMPS library was built as a shared library (BUILD_SHARED_LIBS=yes)

  3. The LAMMPS version is compatible (tested with LAMMPS 2Aug2023 and later)

References