Files
lammps-gran-kokkos/python/examples/pylammps
2021-06-30 20:39:17 -04:00
..
2021-03-16 15:18:07 -04:00
2021-03-19 13:23:15 -04:00
2021-03-16 14:38:26 -04:00
2016-11-18 23:58:57 -07:00
2021-06-30 20:39:17 -04:00
2021-05-24 16:19:37 -04:00

PyLammps and Jupyter Notebooks

This folder contains examples showcasing the usage of the PyLammps Python interface and Jupyter notebooks. To use this you will need LAMMPS compiled as a shared library and the LAMMPS Python package installed.

An extensive guide on how to achieve this is documented in the LAMMPS manual. There is also a PyLammps tutorial.

The following will show one way of creating a Python virtual environment which has both LAMMPS and its Python package installed:

  1. Clone the LAMMPS source code

    $ git clone -b stable https://github.com/lammps/lammps.git
    $ cd lammps
    
  2. Create a build folder

    $ mkdir build
    $ cd build
    
  3. Create a virtual environment for Python

    $ python3 -m venv myenv
    
  4. Extend LD_LIBRARY_PATH (Unix/Linux) or DYLD_LIBRARY_PATH (MacOS)

    On Unix/Linux:

    $ echo 'export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH' >> myenv/bin/activate
    

    On MacOS:

    echo 'export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$DYLD_LIBRARY_PATH' >> myenv/bin/activate
    
  5. Activate the virtual environment

    $ source myenv/bin/activate
    (myenv)$
    
  6. Configure LAMMPS compilation (CMake)

    (myenv)$ cmake -C ../cmake/presets/basic.cmake \
                   -D BUILD_SHARED_LIBS=on \
                   -D LAMMPS_EXCEPTIONS=on -D PKG_PYTHON=on \
                   -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV \
                   ../cmake
    
  7. Compile LAMMPS

    (myenv)$ cmake --build .
    
  8. Install LAMMPS and Python package into virtual environment

    (myenv)$ cmake --install .
    
  9. Install other Python packages into virtual environment

    (myenv)$ pip install jupyter matplotlib mpi4py
    
  10. Navigate to pylammps examples folder

    (myenv)$ cd ../python/examples/pylammmps
    
  11. Launch Jupyter and work inside browser

    (myenv)$ jupyter notebook