LAMMPS

User Documentation

  • 1. Introduction
  • 2. Install LAMMPS
  • 3. Build LAMMPS
    • 3.1. Build LAMMPS with CMake
    • 3.2. Build LAMMPS with make
    • 3.3. Link LAMMPS as a library to another code
    • 3.4. Basic build options
    • 3.5. Optional build settings
    • 3.6. Include packages in build
    • 3.7. Packages with extra build options
    • 3.8. Notes for building LAMMPS on Windows
    • 3.9. Development build options (CMake only)
  • 4. Run LAMMPS
  • 5. Commands
  • 6. Optional packages
  • 7. Accelerate performance
  • 8. Howto discussions
  • 9. Example scripts
  • 10. Auxiliary tools
  • 11. Modify & extend LAMMPS
  • 12. Use Python with LAMMPS
  • 13. Errors
  • 14. Building the LAMMPS manual

Index

  • Commands
  • Fixes
  • Computes
  • Pair Styles
  • Bond Styles
  • Angle Styles
  • Dihedral Styles
  • Improper Styles
 
LAMMPS
LAMMPS 19 Sep 2019
  • Docs »
  • 3. Build LAMMPS »
  • 3.3. Link LAMMPS as a library to another code
  • Website Commands

Next Previous

3.3. Link LAMMPS as a library to another code

LAMMPS can be used as a library by another application, including Python scripts. The files src/library.cpp and library.h define the C-style API for using LAMMPS as a library. See the Howto library doc page for a description of the interface and how to extend it for your needs.

The Build basics doc page explains how to build LAMMPS as either a shared or static library. This results in one of these 2 files:

liblammps.so # shared library liblammps.a # static library


Link with LAMMPS as a static library:

The calling application can link to LAMMPS as a static library with a link command like this:

g++ caller.o -L/home/sjplimp/lammps/src -llammps -o caller

The -L argument is the path to where the liblammps.a file is. The -llammps argument is shorthand for the file liblammps.a.


Link with LAMMPS as a shared library:

If you wish to link to liblammps.so, the operating system finds shared libraries to load at run-time using the environment variable LD_LIBRARY_PATH. To enable this you can do one of two things:

(1) Copy the liblammps.so file to a location the system can find it, such as /usr/local/lib. I.e. a directory already listed in your LD_LIBRARY_PATH variable. You can type

printenv LD_LIBRARY_PATH

to see what directories are in that list.

(2) Add the LAMMPS src directory (or the directory you perform CMake build in) to your LD_LIBRARY_PATH, so that the current version of the shared library is always available to programs that use it.

For the csh or tcsh shells, you would add something like this to your ~/.cshrc file:

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/home/sjplimp/lammps/src

Calling the LAMMPS library:

Either flavor of library (static or shared) allows one or more LAMMPS objects to be instantiated from the calling program.

When used from a C++ program, all of LAMMPS is wrapped in a LAMMPS_NS namespace; you can safely use any of its classes and methods from within the calling code, as needed.

When used from a C or Fortran program, the library has a simple C-style interface, provided in src/library.cpp and src/library.h.

See the Python library doc page for a description of the Python interface to LAMMPS, which wraps the C-style interface.

See the sample codes in examples/COUPLE/simple for examples of C++ and C and Fortran codes that invoke LAMMPS through its library interface. Other examples in the COUPLE directory use coupling ideas discussed on the Howto couple doc page.

Next Previous

© Copyright 2019 Sandia Corporation.

Built with Sphinx using a theme provided by Read the Docs.