Using LAMMPS with iPython and Jupyter

LAMMPS can be run interactively using iPython easily. This tutorial shows how to set this up.

Installation

  1. Download the latest version of LAMMPS into a folder (we will calls this $LAMMPS_DIR from now on)
  2. Compile LAMMPS as a shared library and enable exceptions and PNG support

    cd $LAMMPS_DIR/src
    make mpi mode=shlib LMP_INC="-DLAMMPS_PNG -DLAMMPS_EXCEPTIONS" JPG_LIB="-lpng"
    
  3. Create a python virtualenv

    virtualenv testing
    source testing/bin/activate
    
  4. Inside the virtualenv install the lammps package

    (testing) cd $LAMMPS_DIR/python
    (testing) python install.py
    (testing) cd   # move to your working directory
  5. Install jupyter and ipython in the virtualenv

    (testing) pip install ipython jupyter
    
  6. Run jupyter notebook

    (testing) jupyter notebook
    

Example


In [ ]:
from lammps import IPyLammps

In [ ]:
L = IPyLammps()

In [ ]:
import math

# 3d Lennard-Jones melt

L.units("lj")
L.atom_style("atomic")
L.atom_modify("map array")

L.lattice("fcc", 0.8442)
L.region("box", "block", 0, 4, 0, 4, 0, 4)
L.create_box(1, "box")
L.create_atoms(1, "box")
L.mass(1, 1.0)

L.velocity("all", "create", 1.44, 87287, "loop geom")

L.pair_style("lj/cut", 2.5)
L.pair_coeff(1, 1, 1.0, 1.0, 2.5)

L.neighbor(0.3, "bin")
L.neigh_modify("delay", 0, "every", 20, "check no")

L.fix("1 all nve")

L.variable("fx atom fx")

L.info("all")

L.run(10)

In [ ]:
L.image(zoom=1.0)