{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using LAMMPS with iPython and Jupyter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "LAMMPS can be run interactively using iPython easily. This tutorial shows how to set this up." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Download the latest version of LAMMPS into a folder (we will calls this `$LAMMPS_DIR` from now on)\n", "2. Compile LAMMPS as a shared library and enable PNG support\n", " ```bash\n", " cd $LAMMPS_DIR/src\n", " python2 Make.py -m mpi -png -a file\n", " make mode=shlib auto\n", " ```\n", "\n", "3. Create a python virtualenv\n", " ```bash\n", " virtualenv testing\n", " source testing/bin/activate\n", " ```\n", "\n", "4. Inside the virtualenv install the lammps package\n", " ```\n", " (testing) cd $LAMMPS_DIR/python\n", " (testing) python install.py\n", " (testing) cd # move to your working directory\n", " ```\n", "\n", "5. Install jupyter and ipython in the virtualenv\n", " ```bash\n", " (testing) pip install ipython jupyter\n", " ```\n", "\n", "6. Run jupyter notebook\n", " ```bash\n", " (testing) jupyter notebook\n", " ```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from lammps import IPyLammps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "L = IPyLammps()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import math\n", "\n", "# 3d Lennard-Jones melt\n", "\n", "L.units(\"lj\")\n", "L.atom_style(\"atomic\")\n", "L.atom_modify(\"map array\")\n", "\n", "L.lattice(\"fcc\", 0.8442)\n", "L.region(\"box\", \"block\", 0, 4, 0, 4, 0, 4)\n", "L.create_box(1, \"box\")\n", "L.create_atoms(1, \"box\")\n", "L.mass(1, 1.0)\n", "\n", "L.velocity(\"all\", \"create\", 1.44, 87287, \"loop geom\")\n", "\n", "L.pair_style(\"lj/cut\", 2.5)\n", "L.pair_coeff(1, 1, 1.0, 1.0, 2.5)\n", "\n", "L.neighbor(0.3, \"bin\")\n", "L.neigh_modify(\"delay\", 0, \"every\", 20, \"check no\")\n", "\n", "L.fix(\"1 all nve\")\n", "\n", "L.variable(\"fx atom fx\")\n", "\n", "L.info(\"all\")\n", "\n", "L.run(10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "L.image(zoom=1.0)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 0 }