12. Use Python with LAMMPS
These doc pages describe various ways that LAMMPS and Python can be used together.
- 12.1. Overview of Python and LAMMPS
- 12.2. Run LAMMPS from Python
- 12.3. Build LAMMPS as a shared library
- 12.4. Installing LAMMPS in Python
- 12.5. Extending Python to run in parallel
- 12.6. Test the Python/LAMMPS interface
- 12.7. Python library interface
- 12.8. PyLammps interface
- 12.9. Example Python scripts that use LAMMPS
- 12.10. Call Python from a LAMMPS input script
If you’re not familiar with Python, it’s a powerful scripting and programming language which can do most everything that lower-level languages like C or C++ can do in fewer lines of code. The only drawback is slower execution speed. Python is also easy to use as a “glue” language to drive a program through its library interface, or to hook multiple pieces of software together, such as a simulation code plus a visualization tool, or to run a coupled multiscale or multiphysics model.
See the Howto_couple doc page for more ideas about coupling LAMMPS to other codes. See the Howto library doc page for a description of the LAMMPS library interface provided in src/library.h and src/library.h. That interface is exposed to Python either when calling LAMMPS from Python or when calling Python from a LAMMPS input script and then calling back to LAMMPS from Python code. The library interface is designed to be easy to add functionality to. Thus the Python interface to LAMMPS is also easy to extend as well.
If you create interesting Python scripts that run LAMMPS or interesting Python functions that can be called from a LAMMPS input script, that you think would be generally useful, please post them as a pull request to our GitHub site, and they can be added to the LAMMPS distribution or webpage.