Created PyLammps documentation
Based on material presented during MD Workshop at Temple University in August 2016.
This commit is contained in:
1
python/examples/pylammps/.gitignore
vendored
Normal file
1
python/examples/pylammps/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.orig
|
||||
28
python/examples/pylammps/README
Normal file
28
python/examples/pylammps/README
Normal file
@ -0,0 +1,28 @@
|
||||
# Compile LAMMPS as shared library
|
||||
|
||||
git clone https://github.com/lammps/lammps.git
|
||||
cd lammps/src
|
||||
python Make.py -m mpi -png -s ffmpeg exceptions -a file
|
||||
|
||||
make -j 4 mode=shlib auto
|
||||
cd ../..
|
||||
|
||||
# Install Python package
|
||||
|
||||
virtualenv testing
|
||||
source testing/bin/activate
|
||||
|
||||
(testing) cd lammps/python
|
||||
(testing) python install.py
|
||||
(testing) pip install jupyter matplotlib mpi4py
|
||||
|
||||
(testing) cd ../../examples
|
||||
|
||||
# Launch jupter and work inside browser
|
||||
|
||||
(testing) jupyter notebook
|
||||
|
||||
# Use Ctrl+c to stop jupyter
|
||||
|
||||
# finally exit the virtualenv
|
||||
(testing) deactivate
|
||||
34
python/examples/pylammps/dihedrals/data.dihedral
Normal file
34
python/examples/pylammps/dihedrals/data.dihedral
Normal file
@ -0,0 +1,34 @@
|
||||
Comment line
|
||||
|
||||
4 atoms
|
||||
0 bonds
|
||||
0 angles
|
||||
1 dihedrals
|
||||
0 impropers
|
||||
|
||||
1 atom types
|
||||
0 bond types
|
||||
0 angle types
|
||||
1 dihedral types
|
||||
0 improper types
|
||||
|
||||
-5.0 5.0 xlo xhi
|
||||
-5.0 5.0 ylo yhi
|
||||
-5.0 5.0 zlo zhi
|
||||
0.0 0.0 0.0 xy xz yz
|
||||
|
||||
Atoms # molecular
|
||||
|
||||
1 1 1 -1.00000 1.00000 0.00000
|
||||
2 1 1 -0.50000 0.00000 0.00000
|
||||
3 1 1 0.50000 0.00000 0.00000
|
||||
4 1 1 1.00000 1.00000 0.00000
|
||||
|
||||
Dihedral Coeffs
|
||||
|
||||
1 80.0 1 2
|
||||
|
||||
Dihedrals
|
||||
|
||||
1 1 1 2 3 4
|
||||
|
||||
1168
python/examples/pylammps/dihedrals/dihedral.ipynb
Normal file
1168
python/examples/pylammps/dihedrals/dihedral.ipynb
Normal file
File diff suppressed because one or more lines are too long
517
python/examples/pylammps/interface_usage.ipynb
Normal file
517
python/examples/pylammps/interface_usage.ipynb
Normal file
@ -0,0 +1,517 @@
|
||||
{
|
||||
"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 exceptions and PNG support\n",
|
||||
" ```bash\n",
|
||||
" cd $LAMMPS_DIR/src\n",
|
||||
" python Make.py -m mpi -png -s exceptions -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": [
|
||||
"# 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.run(10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.image(zoom=1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Queries about LAMMPS simulation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system.natoms"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.communication"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.fixes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.computes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.dumps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.groups"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Working with LAMMPS Variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"a index 2\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"t equal temp\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if sys.version_info < (3, 0):\n",
|
||||
" # In Python 2 'print' is a restricted keyword, which is why you have to use the lmp_print function instead.\n",
|
||||
" x = float(L.lmp_print('\"${a}\"'))\n",
|
||||
"else:\n",
|
||||
" # In Python 3 the print function can be redefined.\n",
|
||||
" # x = float(L.print('\"${a}\"')\")\n",
|
||||
" \n",
|
||||
" # To avoid a syntax error in Python 2 executions of this notebook, this line is packed into an eval statement\n",
|
||||
" x = float(eval(\"L.print('\\\"${a}\\\"')\"))\n",
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['t'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"v_t/2.0\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"b index a b c\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['b'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"v_b\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['b'].definition"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"i loop 10\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['i'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.next(\"i\")\n",
|
||||
"L.variables['i'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"ke\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Accessing Atom data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"[x for x in dir(L.atoms[0]) if not x.startswith('__')]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].position"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].velocity"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].force"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['fx'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Accessing thermo data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.runs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.runs[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.runs[0].thermo"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.runs[0].thermo.Temp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Saving session to as LAMMPS input file"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.write_script(\"in.output\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
498
python/examples/pylammps/interface_usage_bonds.ipynb
Normal file
498
python/examples/pylammps/interface_usage_bonds.ipynb
Normal file
@ -0,0 +1,498 @@
|
||||
{
|
||||
"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 exceptions and PNG support\n",
|
||||
" ```bash\n",
|
||||
" cd $LAMMPS_DIR/src\n",
|
||||
" make yes-molecule\n",
|
||||
" python Make.py -m mpi -png -s exceptions -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": [
|
||||
"# 2d circle of particles inside a box with LJ walls\n",
|
||||
"import math\n",
|
||||
"\n",
|
||||
"b = 0\n",
|
||||
"x = 50\n",
|
||||
"y = 20\n",
|
||||
"d = 20\n",
|
||||
"\n",
|
||||
"# careful not to slam into wall too hard\n",
|
||||
"\n",
|
||||
"v = 0.3\n",
|
||||
"w = 0.08\n",
|
||||
" \n",
|
||||
"L.units(\"lj\")\n",
|
||||
"L.dimension(2)\n",
|
||||
"L.atom_style(\"bond\")\n",
|
||||
"L.boundary(\"f f p\")\n",
|
||||
"\n",
|
||||
"L.lattice(\"hex\", 0.85)\n",
|
||||
"L.region(\"box\", \"block\", 0, x, 0, y, -0.5, 0.5)\n",
|
||||
"L.create_box(1, \"box\", \"bond/types\", 1, \"extra/bond/per/atom\", 6)\n",
|
||||
"L.region(\"circle\", \"sphere\", d/2.0+1.0, d/2.0/math.sqrt(3.0)+1, 0.0, d/2.0)\n",
|
||||
"L.create_atoms(1, \"region\", \"circle\")\n",
|
||||
"L.mass(1, 1.0)\n",
|
||||
"\n",
|
||||
"L.velocity(\"all create 0.5 87287 loop geom\")\n",
|
||||
"L.velocity(\"all set\", v, w, 0, \"sum yes\")\n",
|
||||
"\n",
|
||||
"L.pair_style(\"lj/cut\", 2.5)\n",
|
||||
"L.pair_coeff(1, 1, 10.0, 1.0, 2.5)\n",
|
||||
"\n",
|
||||
"L.bond_style(\"harmonic\")\n",
|
||||
"L.bond_coeff(1, 10.0, 1.2)\n",
|
||||
"\n",
|
||||
"L.create_bonds(\"all\", \"all\", 1, 1.0, 1.5)\n",
|
||||
"\n",
|
||||
"L.neighbor(0.3, \"bin\")\n",
|
||||
"L.neigh_modify(\"delay\", 0, \"every\", 1, \"check yes\")\n",
|
||||
"\n",
|
||||
"L.fix(1, \"all\", \"nve\")\n",
|
||||
"\n",
|
||||
"L.fix(2, \"all wall/lj93 xlo 0.0 1 1 2.5 xhi\", x, \"1 1 2.5\")\n",
|
||||
"L.fix(3, \"all wall/lj93 ylo 0.0 1 1 2.5 yhi\", y, \"1 1 2.5\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.image(zoom=1.8)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.thermo_style(\"custom step temp epair press\")\n",
|
||||
"L.thermo(100)\n",
|
||||
"output = L.run(40000)\n",
|
||||
"L.image(zoom=1.8)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Queries about LAMMPS simulation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system.natoms"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system.nbonds"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.system.nbondtypes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.communication"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.fixes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.computes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.dumps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.groups"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Working with LAMMPS Variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"a index 2\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"t equal temp\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if sys.version_info < (3, 0):\n",
|
||||
" # In Python 2 'print' is a restricted keyword, which is why you have to use the lmp_print function instead.\n",
|
||||
" x = float(L.lmp_print('\"${a}\"'))\n",
|
||||
"else:\n",
|
||||
" # In Python 3 the print function can be redefined.\n",
|
||||
" # x = float(L.print('\"${a}\"')\")\n",
|
||||
" \n",
|
||||
" # To avoid a syntax error in Python 2 executions of this notebook, this line is packed into an eval statement\n",
|
||||
" x = float(eval(\"L.print('\\\"${a}\\\"')\"))\n",
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['t'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"v_t/2.0\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"b index a b c\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['b'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"v_b\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['b'].definition"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variable(\"i loop 10\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.variables['i'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.next(\"i\")\n",
|
||||
"L.variables['i'].value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.eval(\"ke\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Accessing Atom data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"[x for x in dir(L.atoms[0]) if not x.startswith('__')]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].position"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].velocity"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].force"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.atoms[0].type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
1303
python/examples/pylammps/montecarlo/mc.ipynb
Normal file
1303
python/examples/pylammps/montecarlo/mc.ipynb
Normal file
File diff suppressed because one or more lines are too long
4
python/examples/pylammps/mpi4py/hello.py
Normal file
4
python/examples/pylammps/mpi4py/hello.py
Normal file
@ -0,0 +1,4 @@
|
||||
from mpi4py import MPI
|
||||
|
||||
comm=MPI.COMM_WORLD
|
||||
print("Hello from rank %d of %d" % (comm.rank, comm.size))
|
||||
33
python/examples/pylammps/mpi4py/in.melt
Normal file
33
python/examples/pylammps/mpi4py/in.melt
Normal file
@ -0,0 +1,33 @@
|
||||
# 3d Lennard-Jones melt
|
||||
|
||||
units lj
|
||||
atom_style atomic
|
||||
|
||||
lattice fcc 0.8442
|
||||
region box block 0 10 0 10 0 10
|
||||
create_box 1 box
|
||||
create_atoms 1 box
|
||||
mass 1 1.0
|
||||
|
||||
velocity all create 3.0 87287
|
||||
|
||||
pair_style lj/cut 2.5
|
||||
pair_coeff 1 1 1.0 1.0 2.5
|
||||
|
||||
neighbor 0.3 bin
|
||||
neigh_modify every 20 delay 0 check no
|
||||
|
||||
fix 1 all nve
|
||||
|
||||
#dump id all atom 50 dump.melt
|
||||
|
||||
#dump 2 all image 25 image.*.jpg type type &
|
||||
# axes yes 0.8 0.02 view 60 -30
|
||||
#dump_modify 2 pad 3
|
||||
|
||||
#dump 3 all movie 25 movie.mpg type type &
|
||||
# axes yes 0.8 0.02 view 60 -30
|
||||
#dump_modify 3 pad 3
|
||||
|
||||
thermo 50
|
||||
run 250
|
||||
10
python/examples/pylammps/mpi4py/melt.py
Normal file
10
python/examples/pylammps/mpi4py/melt.py
Normal file
@ -0,0 +1,10 @@
|
||||
from mpi4py import MPI
|
||||
from lammps import PyLammps
|
||||
|
||||
L = PyLammps()
|
||||
L.file('in.melt')
|
||||
|
||||
|
||||
if MPI.COMM_WORLD.rank == 0:
|
||||
pe = L.eval("pe")
|
||||
print("Potential Energy:", pe)
|
||||
152
python/examples/pylammps/simple.ipynb
Normal file
152
python/examples/pylammps/simple.ipynb
Normal file
@ -0,0 +1,152 @@
|
||||
{
|
||||
"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 exceptions and PNG support\n",
|
||||
" ```bash\n",
|
||||
" cd $LAMMPS_DIR/src\n",
|
||||
" python Make.py -m mpi -png -s exceptions -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
|
||||
}
|
||||
Reference in New Issue
Block a user