8.1.5. Library interface to LAMMPS
As described on the Build basics doc page, LAMMPS can be built as a static or shared library, so that it can be called by another code, used in a coupled manner with other codes, or driven through a Python interface.
At the core of LAMMPS is the
LAMMPS class which encapsulates the
state of the simulation program through the state of the various class
instances that it is composed of. So a calculation using LAMMPS
requires to create an instance of the
LAMMPS class and then send it
(text) commands, either individually or from a file, or perform other
operations that modify the state stored inside that instance or drive
simulations. This is essentially what the
src/main.cpp file does
as well for the standalone LAMMPS executable with reading commands
either from an input file or stdin.
Creating a LAMMPS instance can be done by using C++ code directly or
through a C-style interface library to LAMMPS that is provided in the
C language API, can be used from C and C++,
and is also the basis for the Python and
Fortran interfaces or wrappers included in the
LAMMPS source code.
python/examples directories contain some
example programs written in C++, C, Fortran, and Python, which show how
a driver code can link to LAMMPS as a library, run LAMMPS on a subset of
processors (so the others are available to run some other code
concurrently), grab data from LAMMPS, change it, and send it back into
A detailed documentation of the available APIs and examples of how to use them can be found in the Programmer Documentation section of this manual.