python: update examples and docs
This commit is contained in:
committed by
Richard Berger
parent
9da58b3ffc
commit
24a4ff78b6
4
python/examples/ipython/.gitignore
vendored
Normal file
4
python/examples/ipython/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.orig
|
||||
*-checkpoint.ipynb
|
||||
*.png
|
||||
*.mp4
|
||||
89
python/examples/ipython/README.md
Normal file
89
python/examples/ipython/README.md
Normal file
@ -0,0 +1,89 @@
|
||||
# IPython and Jupyter Notebooks
|
||||
|
||||
This folder contains examples showcasing the usage of the LAMMPS 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](https://docs.lammps.org/Python_install.html). There is also a [LAMMPS Python tutorial](https://docs.lammps.org/Howto_python.html).
|
||||
|
||||
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
|
||||
|
||||
```shell
|
||||
$ git clone -b stable https://github.com/lammps/lammps.git
|
||||
$ cd lammps
|
||||
```
|
||||
|
||||
2. Create a build folder
|
||||
|
||||
```shell
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
```
|
||||
|
||||
3. Create a virtual environment for Python
|
||||
|
||||
```shell
|
||||
$ python3 -m venv myenv
|
||||
```
|
||||
|
||||
4. Extend `LD_LIBRARY_PATH` (Unix/Linux) or `DYLD_LIBRARY_PATH` (MacOS)
|
||||
|
||||
On Unix/Linux:
|
||||
```shell
|
||||
$ echo 'export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$LD_LIBRARY_PATH' >> myenv/bin/activate
|
||||
```
|
||||
|
||||
On MacOS:
|
||||
```shell
|
||||
echo 'export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib:$DYLD_LIBRARY_PATH' >> myenv/bin/activate
|
||||
```
|
||||
|
||||
5. Activate the virtual environment
|
||||
|
||||
```shell
|
||||
$ source myenv/bin/activate
|
||||
(myenv)$
|
||||
```
|
||||
|
||||
6. Configure LAMMPS compilation (CMake)
|
||||
|
||||
```shell
|
||||
(myenv)$ cmake -C ../cmake/presets/basic.cmake \
|
||||
-D BUILD_SHARED_LIBS=on \
|
||||
-D PKG_PYTHON=on \
|
||||
-D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV \
|
||||
../cmake
|
||||
```
|
||||
|
||||
7. Compile LAMMPS
|
||||
|
||||
```shell
|
||||
(myenv)$ cmake --build .
|
||||
```
|
||||
|
||||
8. Install LAMMPS and Python package into virtual environment
|
||||
|
||||
```shell
|
||||
(myenv)$ make install-python
|
||||
```
|
||||
|
||||
9. Install other Python packages into virtual environment
|
||||
|
||||
```shell
|
||||
(myenv)$ pip install jupyter matplotlib pandas mpi4py
|
||||
```
|
||||
|
||||
10. Navigate to ipython examples folder
|
||||
|
||||
```shell
|
||||
(myenv)$ cd ../python/examples/ipython
|
||||
```
|
||||
|
||||
11. Launch Jupyter and work inside browser
|
||||
|
||||
```shell
|
||||
(myenv)$ jupyter notebook
|
||||
```
|
||||
459
python/examples/ipython/atoms.ipynb
Normal file
459
python/examples/ipython/atoms.ipynb
Normal file
@ -0,0 +1,459 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Example 3: Example 3: Using Atom Data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Author: [Richard Berger](mailto:richard.berger@outlook.com)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2D circle of particles inside of box with LJ walls"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup system"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from lammps import lammps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L = lammps()\n",
|
||||
"cmd = L.cmd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"cmd.units(\"lj\")\n",
|
||||
"cmd.dimension(2)\n",
|
||||
"cmd.atom_style(\"bond\")\n",
|
||||
"cmd.boundary(\"f f p\")\n",
|
||||
"\n",
|
||||
"cmd.lattice(\"hex\", 0.85)\n",
|
||||
"cmd.region(\"box\", \"block\", 0, x, 0, y, -0.5, 0.5)\n",
|
||||
"cmd.create_box(1, \"box\", \"bond/types\", 1, \"extra/bond/per/atom\", 6)\n",
|
||||
"cmd.region(\"circle\", \"sphere\", d/2.0+1.0, d/2.0/math.sqrt(3.0)+1, 0.0, d/2.0)\n",
|
||||
"cmd.create_atoms(1, \"region\", \"circle\")\n",
|
||||
"cmd.mass(1, 1.0)\n",
|
||||
"\n",
|
||||
"cmd.velocity(\"all create 0.5 87287 loop geom\")\n",
|
||||
"cmd.velocity(\"all set\", v, w, 0, \"sum yes\")\n",
|
||||
"\n",
|
||||
"cmd.pair_style(\"lj/cut\", 2.5)\n",
|
||||
"cmd.pair_coeff(1, 1, 10.0, 1.0, 2.5)\n",
|
||||
"\n",
|
||||
"cmd.bond_style(\"harmonic\")\n",
|
||||
"cmd.bond_coeff(1, 10.0, 1.2)\n",
|
||||
"\n",
|
||||
"cmd.create_bonds(\"many\", \"all\", \"all\", 1, 1.0, 1.5)\n",
|
||||
"\n",
|
||||
"cmd.neighbor(0.3, \"bin\")\n",
|
||||
"cmd.neigh_modify(\"delay\", 0, \"every\", 1, \"check yes\")\n",
|
||||
"\n",
|
||||
"cmd.fix(1, \"all\", \"nve\")\n",
|
||||
"\n",
|
||||
"cmd.fix(2, \"all wall/lj93 xlo 0.0 1 1 2.5 xhi\", x, \"1 1 2.5\")\n",
|
||||
"cmd.fix(3, \"all wall/lj93 ylo 0.0 1 1 2.5 yhi\", y, \"1 1 2.5\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Visualize initial state"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.8)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Run simulation and visualize new state"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.thermo_style(\"custom step temp epair press\")\n",
|
||||
"cmd.thermo(100)\n",
|
||||
"output = cmd.run(40000)\n",
|
||||
"L.ipython.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.expand(\"ke\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Accessing Atom data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.numpy.extract_atom(\"x\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.numpy.extract_atom(\"id\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.numpy.extract_atom(\"v\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.numpy.extract_atom(\"f\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.numpy.extract_atom(\"type\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
34
python/examples/ipython/dihedrals/data.dihedral
Normal file
34
python/examples/ipython/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
|
||||
|
||||
240
python/examples/ipython/dihedrals/dihedral.ipynb
Normal file
240
python/examples/ipython/dihedrals/dihedral.ipynb
Normal file
@ -0,0 +1,240 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Validating a dihedral potential"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from lammps import lammps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L = lammps()\n",
|
||||
"cmd = L.cmd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import math\n",
|
||||
"\n",
|
||||
"cmd.units(\"real\")\n",
|
||||
"cmd.atom_style(\"molecular\")\n",
|
||||
"\n",
|
||||
"cmd.boundary(\"f f f\")\n",
|
||||
"cmd.neighbor(0.3, \"bin\")\n",
|
||||
"\n",
|
||||
"cmd.dihedral_style(\"harmonic\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.read_data(\"data.dihedral\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.pair_style(\"zero\", 5)\n",
|
||||
"cmd.pair_coeff(\"*\", \"*\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.mass(1, 1.0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.velocity(\"all\", \"set\", 0.0, 0.0, 0.0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.run(0);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.0,size=[320,320])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"x = L.numpy.extract_atom(\"x\")\n",
|
||||
"print(x[3])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"x[3] = (1.0, 0.0, 1.0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.0,size=[320,320])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.get_thermo(\"pe\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"x[3] = (1.0, 0.0, -1.0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.run(0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"phi = [d * math.pi / 180 for d in range(360)]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pos = [(1.0, math.cos(p), math.sin(p)) for p in phi]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"K = 80.0\n",
|
||||
"d = 1\n",
|
||||
"n = 2\n",
|
||||
"E_analytical = [K * (1 + d * math.cos(n*p)) for p in phi]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pe = []\n",
|
||||
"for p in pos:\n",
|
||||
" x[3] = p\n",
|
||||
" cmd.run(0);\n",
|
||||
" pe.append(L.get_thermo(\"pe\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(range(360), pe, range(360), E_analytical)\n",
|
||||
"plt.xlabel('angle')\n",
|
||||
"plt.ylabel('E')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
515
python/examples/ipython/elastic/Au.data
Normal file
515
python/examples/ipython/elastic/Au.data
Normal file
@ -0,0 +1,515 @@
|
||||
#Generated by cif2cell 1.2.10 from COD reference: 9008463. : Wyckoff, R. W. G., Crystal Structures 1, 7-83 (1963).
|
||||
|
||||
500 atoms
|
||||
1 atom types
|
||||
|
||||
0.0 20.391250 xlo xhi
|
||||
0.0 20.391250 ylo yhi
|
||||
0.0 20.391250 zlo zhi
|
||||
|
||||
Masses
|
||||
|
||||
1 100
|
||||
|
||||
Atoms
|
||||
|
||||
1 1 0.000000000000000 0.000000000000000 0.000000000000000
|
||||
2 1 0.000000000000000 2.039125000000000 2.039125000000000
|
||||
3 1 2.039125000000000 0.000000000000000 2.039125000000000
|
||||
4 1 2.039125000000000 2.039125000000000 0.000000000000000
|
||||
5 1 8.156499999999999 16.312999999999995 0.000000000000000
|
||||
6 1 12.234750000000002 4.078249999999999 0.000000000000000
|
||||
7 1 12.234750000000002 12.234750000000002 12.234750000000002
|
||||
8 1 0.000000000000000 0.000000000000000 12.234750000000002
|
||||
9 1 8.156499999999999 12.234750000000002 8.156499999999998
|
||||
10 1 8.156499999999999 4.078249999999999 0.000000000000000
|
||||
11 1 16.312999999999999 0.000000000000000 12.234750000000002
|
||||
12 1 4.078250000000000 12.234750000000002 8.156499999999998
|
||||
13 1 8.156499999999999 0.000000000000000 8.156499999999998
|
||||
14 1 16.312999999999999 16.312999999999995 8.156499999999998
|
||||
15 1 4.078250000000000 4.078249999999999 0.000000000000000
|
||||
16 1 16.312999999999999 8.156499999999998 0.000000000000000
|
||||
17 1 12.234750000000002 4.078249999999999 4.078249999999999
|
||||
18 1 16.312999999999999 0.000000000000000 16.312999999999995
|
||||
19 1 0.000000000000000 12.234750000000002 8.156499999999998
|
||||
20 1 16.312999999999999 8.156499999999998 12.234750000000002
|
||||
21 1 0.000000000000000 4.078249999999999 0.000000000000000
|
||||
22 1 16.312999999999999 0.000000000000000 4.078249999999999
|
||||
23 1 12.234750000000002 16.312999999999995 8.156499999999998
|
||||
24 1 12.234750000000002 4.078249999999999 8.156499999999998
|
||||
25 1 0.000000000000000 4.078249999999999 12.234750000000002
|
||||
26 1 8.156499999999999 16.312999999999995 8.156499999999998
|
||||
27 1 12.234750000000002 8.156499999999998 16.312999999999995
|
||||
28 1 8.156499999999999 8.156499999999998 0.000000000000000
|
||||
29 1 12.234750000000002 16.312999999999995 12.234750000000002
|
||||
30 1 12.234750000000002 0.000000000000000 4.078249999999999
|
||||
31 1 4.078250000000000 16.312999999999995 8.156499999999998
|
||||
32 1 12.234750000000002 4.078249999999999 12.234750000000002
|
||||
33 1 4.078250000000000 8.156499999999998 0.000000000000000
|
||||
34 1 16.312999999999999 12.234750000000002 0.000000000000000
|
||||
35 1 8.156499999999999 0.000000000000000 16.312999999999995
|
||||
36 1 8.156499999999999 8.156499999999998 4.078249999999999
|
||||
37 1 16.312999999999999 12.234750000000002 12.234750000000002
|
||||
38 1 4.078250000000000 0.000000000000000 4.078249999999999
|
||||
39 1 12.234750000000002 4.078249999999999 16.312999999999995
|
||||
40 1 16.312999999999999 4.078249999999999 4.078249999999999
|
||||
41 1 0.000000000000000 8.156499999999998 12.234750000000002
|
||||
42 1 16.312999999999999 4.078249999999999 16.312999999999995
|
||||
43 1 0.000000000000000 0.000000000000000 4.078249999999999
|
||||
44 1 8.156499999999999 8.156499999999998 8.156499999999998
|
||||
45 1 8.156499999999999 12.234750000000002 0.000000000000000
|
||||
46 1 0.000000000000000 0.000000000000000 16.312999999999995
|
||||
47 1 8.156499999999999 12.234750000000002 12.234750000000002
|
||||
48 1 8.156499999999999 4.078249999999999 4.078249999999999
|
||||
49 1 4.078250000000000 12.234750000000002 0.000000000000000
|
||||
50 1 12.234750000000002 8.156499999999998 4.078249999999999
|
||||
51 1 16.312999999999999 16.312999999999995 0.000000000000000
|
||||
52 1 8.156499999999999 8.156499999999998 12.234750000000002
|
||||
53 1 8.156499999999999 4.078249999999999 16.312999999999995
|
||||
54 1 16.312999999999999 16.312999999999995 12.234750000000002
|
||||
55 1 12.234750000000002 16.312999999999995 4.078249999999999
|
||||
56 1 4.078250000000000 4.078249999999999 4.078249999999999
|
||||
57 1 16.312999999999999 8.156499999999998 4.078249999999999
|
||||
58 1 8.156499999999999 4.078249999999999 8.156499999999998
|
||||
59 1 8.156499999999999 8.156499999999998 16.312999999999995
|
||||
60 1 4.078250000000000 4.078249999999999 16.312999999999995
|
||||
61 1 0.000000000000000 16.312999999999995 4.078249999999999
|
||||
62 1 16.312999999999999 8.156499999999998 16.312999999999995
|
||||
63 1 0.000000000000000 4.078249999999999 4.078249999999999
|
||||
64 1 16.312999999999999 0.000000000000000 8.156499999999998
|
||||
65 1 8.156499999999999 0.000000000000000 4.078249999999999
|
||||
66 1 8.156499999999999 4.078249999999999 12.234750000000002
|
||||
67 1 0.000000000000000 4.078249999999999 16.312999999999995
|
||||
68 1 8.156499999999999 16.312999999999995 12.234750000000002
|
||||
69 1 4.078250000000000 16.312999999999995 0.000000000000000
|
||||
70 1 4.078250000000000 8.156499999999998 4.078249999999999
|
||||
71 1 4.078250000000000 16.312999999999995 12.234750000000002
|
||||
72 1 4.078250000000000 12.234750000000002 12.234750000000002
|
||||
73 1 0.000000000000000 16.312999999999995 0.000000000000000
|
||||
74 1 16.312999999999999 12.234750000000002 4.078249999999999
|
||||
75 1 12.234750000000002 0.000000000000000 16.312999999999995
|
||||
76 1 4.078250000000000 8.156499999999998 16.312999999999995
|
||||
77 1 4.078250000000000 8.156499999999998 8.156499999999998
|
||||
78 1 16.312999999999999 12.234750000000002 16.312999999999995
|
||||
79 1 0.000000000000000 8.156499999999998 4.078249999999999
|
||||
80 1 16.312999999999999 4.078249999999999 8.156499999999998
|
||||
81 1 0.000000000000000 8.156499999999998 16.312999999999995
|
||||
82 1 0.000000000000000 12.234750000000002 0.000000000000000
|
||||
83 1 12.234750000000002 0.000000000000000 12.234750000000002
|
||||
84 1 12.234750000000002 12.234750000000002 16.312999999999995
|
||||
85 1 0.000000000000000 0.000000000000000 8.156499999999998
|
||||
86 1 4.078250000000000 8.156499999999998 12.234750000000002
|
||||
87 1 8.156499999999999 12.234750000000002 4.078249999999999
|
||||
88 1 12.234750000000002 16.312999999999995 0.000000000000000
|
||||
89 1 8.156499999999999 12.234750000000002 16.312999999999995
|
||||
90 1 0.000000000000000 12.234750000000002 4.078249999999999
|
||||
91 1 4.078250000000000 12.234750000000002 4.078249999999999
|
||||
92 1 12.234750000000002 0.000000000000000 8.156499999999998
|
||||
93 1 16.312999999999999 16.312999999999995 4.078249999999999
|
||||
94 1 0.000000000000000 16.312999999999995 12.234750000000002
|
||||
95 1 4.078250000000000 12.234750000000002 16.312999999999995
|
||||
96 1 16.312999999999999 16.312999999999995 16.312999999999995
|
||||
97 1 0.000000000000000 8.156499999999998 0.000000000000000
|
||||
98 1 12.234750000000002 8.156499999999998 8.156499999999998
|
||||
99 1 4.078250000000000 4.078249999999999 8.156499999999998
|
||||
100 1 16.312999999999999 8.156499999999998 8.156499999999998
|
||||
101 1 4.078250000000000 4.078249999999999 12.234750000000002
|
||||
102 1 16.312999999999999 0.000000000000000 0.000000000000000
|
||||
103 1 0.000000000000000 12.234750000000002 16.312999999999995
|
||||
104 1 12.234750000000002 16.312999999999995 16.312999999999995
|
||||
105 1 12.234750000000002 12.234750000000002 0.000000000000000
|
||||
106 1 0.000000000000000 4.078249999999999 8.156499999999998
|
||||
107 1 8.156499999999999 16.312999999999995 4.078249999999999
|
||||
108 1 4.078250000000000 0.000000000000000 8.156499999999998
|
||||
109 1 12.234750000000002 0.000000000000000 0.000000000000000
|
||||
110 1 0.000000000000000 12.234750000000002 12.234750000000002
|
||||
111 1 0.000000000000000 16.312999999999995 8.156499999999998
|
||||
112 1 8.156499999999999 16.312999999999995 16.312999999999995
|
||||
113 1 12.234750000000002 8.156499999999998 12.234750000000002
|
||||
114 1 4.078250000000000 16.312999999999995 4.078249999999999
|
||||
115 1 12.234750000000002 12.234750000000002 4.078249999999999
|
||||
116 1 8.156499999999999 0.000000000000000 0.000000000000000
|
||||
117 1 0.000000000000000 8.156499999999998 8.156499999999998
|
||||
118 1 4.078250000000000 16.312999999999995 16.312999999999995
|
||||
119 1 8.156499999999999 0.000000000000000 12.234750000000002
|
||||
120 1 12.234750000000002 8.156499999999998 0.000000000000000
|
||||
121 1 16.312999999999999 12.234750000000002 8.156499999999998
|
||||
122 1 4.078250000000000 0.000000000000000 0.000000000000000
|
||||
123 1 12.234750000000002 12.234750000000002 8.156499999999998
|
||||
124 1 16.312999999999999 4.078249999999999 0.000000000000000
|
||||
125 1 0.000000000000000 16.312999999999995 16.312999999999995
|
||||
126 1 4.078250000000000 0.000000000000000 16.312999999999995
|
||||
127 1 4.078250000000000 0.000000000000000 12.234750000000002
|
||||
128 1 16.312999999999999 4.078249999999999 12.234750000000002
|
||||
129 1 8.156499999999999 18.352124999999997 2.039125000000000
|
||||
130 1 12.234750000000002 6.117374999999998 2.039125000000000
|
||||
131 1 12.234750000000002 14.273875000000000 14.273875000000000
|
||||
132 1 0.000000000000000 2.039125000000000 14.273875000000000
|
||||
133 1 8.156499999999999 14.273875000000000 10.195625000000000
|
||||
134 1 8.156499999999999 6.117374999999998 2.039125000000000
|
||||
135 1 16.312999999999999 2.039125000000000 14.273875000000000
|
||||
136 1 4.078250000000000 14.273875000000000 10.195625000000000
|
||||
137 1 8.156499999999999 2.039125000000000 10.195625000000000
|
||||
138 1 16.312999999999999 18.352124999999997 10.195625000000000
|
||||
139 1 4.078250000000000 6.117374999999998 2.039125000000000
|
||||
140 1 16.312999999999999 10.195625000000000 2.039125000000000
|
||||
141 1 12.234750000000002 6.117374999999998 6.117374999999998
|
||||
142 1 16.312999999999999 2.039125000000000 18.352124999999997
|
||||
143 1 0.000000000000000 14.273875000000000 10.195625000000000
|
||||
144 1 16.312999999999999 10.195625000000000 14.273875000000000
|
||||
145 1 0.000000000000000 6.117374999999998 2.039125000000000
|
||||
146 1 16.312999999999999 2.039125000000000 6.117374999999998
|
||||
147 1 12.234750000000002 18.352124999999997 10.195625000000000
|
||||
148 1 12.234750000000002 6.117374999999998 10.195625000000000
|
||||
149 1 0.000000000000000 6.117374999999998 14.273875000000000
|
||||
150 1 8.156499999999999 18.352124999999997 10.195625000000000
|
||||
151 1 12.234750000000002 10.195625000000000 18.352124999999997
|
||||
152 1 8.156499999999999 10.195625000000000 2.039125000000000
|
||||
153 1 12.234750000000002 18.352124999999997 14.273875000000000
|
||||
154 1 12.234750000000002 2.039125000000000 6.117374999999998
|
||||
155 1 4.078250000000000 18.352124999999997 10.195625000000000
|
||||
156 1 12.234750000000002 6.117374999999998 14.273875000000000
|
||||
157 1 4.078250000000000 10.195625000000000 2.039125000000000
|
||||
158 1 16.312999999999999 14.273875000000000 2.039125000000000
|
||||
159 1 8.156499999999999 2.039125000000000 18.352124999999997
|
||||
160 1 8.156499999999999 10.195625000000000 6.117374999999998
|
||||
161 1 16.312999999999999 14.273875000000000 14.273875000000000
|
||||
162 1 4.078250000000000 2.039125000000000 6.117374999999998
|
||||
163 1 12.234750000000002 6.117374999999998 18.352124999999997
|
||||
164 1 16.312999999999999 6.117374999999998 6.117374999999998
|
||||
165 1 0.000000000000000 10.195625000000000 14.273875000000000
|
||||
166 1 16.312999999999999 6.117374999999998 18.352124999999997
|
||||
167 1 0.000000000000000 2.039125000000000 6.117374999999998
|
||||
168 1 8.156499999999999 10.195625000000000 10.195625000000000
|
||||
169 1 8.156499999999999 14.273875000000000 2.039125000000000
|
||||
170 1 0.000000000000000 2.039125000000000 18.352124999999997
|
||||
171 1 8.156499999999999 14.273875000000000 14.273875000000000
|
||||
172 1 8.156499999999999 6.117374999999998 6.117374999999998
|
||||
173 1 4.078250000000000 14.273875000000000 2.039125000000000
|
||||
174 1 12.234750000000002 10.195625000000000 6.117374999999998
|
||||
175 1 16.312999999999999 18.352124999999997 2.039125000000000
|
||||
176 1 8.156499999999999 10.195625000000000 14.273875000000000
|
||||
177 1 8.156499999999999 6.117374999999998 18.352124999999997
|
||||
178 1 16.312999999999999 18.352124999999997 14.273875000000000
|
||||
179 1 12.234750000000002 18.352124999999997 6.117374999999998
|
||||
180 1 4.078250000000000 6.117374999999998 6.117374999999998
|
||||
181 1 16.312999999999999 10.195625000000000 6.117374999999998
|
||||
182 1 8.156499999999999 6.117374999999998 10.195625000000000
|
||||
183 1 8.156499999999999 10.195625000000000 18.352124999999997
|
||||
184 1 4.078250000000000 6.117374999999998 18.352124999999997
|
||||
185 1 0.000000000000000 18.352124999999997 6.117374999999998
|
||||
186 1 16.312999999999999 10.195625000000000 18.352124999999997
|
||||
187 1 0.000000000000000 6.117374999999998 6.117374999999998
|
||||
188 1 16.312999999999999 2.039125000000000 10.195625000000000
|
||||
189 1 8.156499999999999 2.039125000000000 6.117374999999998
|
||||
190 1 8.156499999999999 6.117374999999998 14.273875000000000
|
||||
191 1 0.000000000000000 6.117374999999998 18.352124999999997
|
||||
192 1 8.156499999999999 18.352124999999997 14.273875000000000
|
||||
193 1 4.078250000000000 18.352124999999997 2.039125000000000
|
||||
194 1 4.078250000000000 10.195625000000000 6.117374999999998
|
||||
195 1 4.078250000000000 18.352124999999997 14.273875000000000
|
||||
196 1 4.078250000000000 14.273875000000000 14.273875000000000
|
||||
197 1 0.000000000000000 18.352124999999997 2.039125000000000
|
||||
198 1 16.312999999999999 14.273875000000000 6.117374999999998
|
||||
199 1 12.234750000000002 2.039125000000000 18.352124999999997
|
||||
200 1 4.078250000000000 10.195625000000000 18.352124999999997
|
||||
201 1 4.078250000000000 10.195625000000000 10.195625000000000
|
||||
202 1 16.312999999999999 14.273875000000000 18.352124999999997
|
||||
203 1 0.000000000000000 10.195625000000000 6.117374999999998
|
||||
204 1 16.312999999999999 6.117374999999998 10.195625000000000
|
||||
205 1 0.000000000000000 10.195625000000000 18.352124999999997
|
||||
206 1 0.000000000000000 14.273875000000000 2.039125000000000
|
||||
207 1 12.234750000000002 2.039125000000000 14.273875000000000
|
||||
208 1 12.234750000000002 14.273875000000000 18.352124999999997
|
||||
209 1 0.000000000000000 2.039125000000000 10.195625000000000
|
||||
210 1 4.078250000000000 10.195625000000000 14.273875000000000
|
||||
211 1 8.156499999999999 14.273875000000000 6.117374999999998
|
||||
212 1 12.234750000000002 18.352124999999997 2.039125000000000
|
||||
213 1 8.156499999999999 14.273875000000000 18.352124999999997
|
||||
214 1 0.000000000000000 14.273875000000000 6.117374999999998
|
||||
215 1 4.078250000000000 14.273875000000000 6.117374999999998
|
||||
216 1 12.234750000000002 2.039125000000000 10.195625000000000
|
||||
217 1 16.312999999999999 18.352124999999997 6.117374999999998
|
||||
218 1 0.000000000000000 18.352124999999997 14.273875000000000
|
||||
219 1 4.078250000000000 14.273875000000000 18.352124999999997
|
||||
220 1 16.312999999999999 18.352124999999997 18.352124999999997
|
||||
221 1 0.000000000000000 10.195625000000000 2.039125000000000
|
||||
222 1 12.234750000000002 10.195625000000000 10.195625000000000
|
||||
223 1 4.078250000000000 6.117374999999998 10.195625000000000
|
||||
224 1 16.312999999999999 10.195625000000000 10.195625000000000
|
||||
225 1 4.078250000000000 6.117374999999998 14.273875000000000
|
||||
226 1 16.312999999999999 2.039125000000000 2.039125000000000
|
||||
227 1 0.000000000000000 14.273875000000000 18.352124999999997
|
||||
228 1 12.234750000000002 18.352124999999997 18.352124999999997
|
||||
229 1 12.234750000000002 14.273875000000000 2.039125000000000
|
||||
230 1 0.000000000000000 6.117374999999998 10.195625000000000
|
||||
231 1 8.156499999999999 18.352124999999997 6.117374999999998
|
||||
232 1 4.078250000000000 2.039125000000000 10.195625000000000
|
||||
233 1 12.234750000000002 2.039125000000000 2.039125000000000
|
||||
234 1 0.000000000000000 14.273875000000000 14.273875000000000
|
||||
235 1 0.000000000000000 18.352124999999997 10.195625000000000
|
||||
236 1 8.156499999999999 18.352124999999997 18.352124999999997
|
||||
237 1 12.234750000000002 10.195625000000000 14.273875000000000
|
||||
238 1 4.078250000000000 18.352124999999997 6.117374999999998
|
||||
239 1 12.234750000000002 14.273875000000000 6.117374999999998
|
||||
240 1 8.156499999999999 2.039125000000000 2.039125000000000
|
||||
241 1 0.000000000000000 10.195625000000000 10.195625000000000
|
||||
242 1 4.078250000000000 18.352124999999997 18.352124999999997
|
||||
243 1 8.156499999999999 2.039125000000000 14.273875000000000
|
||||
244 1 12.234750000000002 10.195625000000000 2.039125000000000
|
||||
245 1 16.312999999999999 14.273875000000000 10.195625000000000
|
||||
246 1 4.078250000000000 2.039125000000000 2.039125000000000
|
||||
247 1 12.234750000000002 14.273875000000000 10.195625000000000
|
||||
248 1 16.312999999999999 6.117374999999998 2.039125000000000
|
||||
249 1 0.000000000000000 18.352124999999997 18.352124999999997
|
||||
250 1 4.078250000000000 2.039125000000000 18.352124999999997
|
||||
251 1 4.078250000000000 2.039125000000000 14.273875000000000
|
||||
252 1 16.312999999999999 6.117374999999998 14.273875000000000
|
||||
253 1 10.195625000000000 16.312999999999995 2.039125000000000
|
||||
254 1 14.273875000000004 4.078249999999999 2.039125000000000
|
||||
255 1 14.273875000000004 12.234750000000002 14.273875000000000
|
||||
256 1 2.039125000000000 0.000000000000000 14.273875000000000
|
||||
257 1 10.195625000000000 12.234750000000002 10.195625000000000
|
||||
258 1 10.195625000000000 4.078249999999999 2.039125000000000
|
||||
259 1 18.352125000000001 0.000000000000000 14.273875000000000
|
||||
260 1 6.117375000000001 12.234750000000002 10.195625000000000
|
||||
261 1 10.195625000000000 0.000000000000000 10.195625000000000
|
||||
262 1 18.352125000000001 16.312999999999995 10.195625000000000
|
||||
263 1 6.117375000000001 4.078249999999999 2.039125000000000
|
||||
264 1 18.352125000000001 8.156499999999998 2.039125000000000
|
||||
265 1 14.273875000000004 4.078249999999999 6.117374999999998
|
||||
266 1 18.352125000000001 0.000000000000000 18.352124999999997
|
||||
267 1 2.039125000000000 12.234750000000002 10.195625000000000
|
||||
268 1 18.352125000000001 8.156499999999998 14.273875000000000
|
||||
269 1 2.039125000000000 4.078249999999999 2.039125000000000
|
||||
270 1 18.352125000000001 0.000000000000000 6.117374999999998
|
||||
271 1 14.273875000000004 16.312999999999995 10.195625000000000
|
||||
272 1 14.273875000000004 4.078249999999999 10.195625000000000
|
||||
273 1 2.039125000000000 4.078249999999999 14.273875000000000
|
||||
274 1 10.195625000000000 16.312999999999995 10.195625000000000
|
||||
275 1 14.273875000000004 8.156499999999998 18.352124999999997
|
||||
276 1 10.195625000000000 8.156499999999998 2.039125000000000
|
||||
277 1 14.273875000000004 16.312999999999995 14.273875000000000
|
||||
278 1 14.273875000000004 0.000000000000000 6.117374999999998
|
||||
279 1 6.117375000000001 16.312999999999995 10.195625000000000
|
||||
280 1 14.273875000000004 4.078249999999999 14.273875000000000
|
||||
281 1 6.117375000000001 8.156499999999998 2.039125000000000
|
||||
282 1 18.352125000000001 12.234750000000002 2.039125000000000
|
||||
283 1 10.195625000000000 0.000000000000000 18.352124999999997
|
||||
284 1 10.195625000000000 8.156499999999998 6.117374999999998
|
||||
285 1 18.352125000000001 12.234750000000002 14.273875000000000
|
||||
286 1 6.117375000000001 0.000000000000000 6.117374999999998
|
||||
287 1 14.273875000000004 4.078249999999999 18.352124999999997
|
||||
288 1 18.352125000000001 4.078249999999999 6.117374999999998
|
||||
289 1 2.039125000000000 8.156499999999998 14.273875000000000
|
||||
290 1 18.352125000000001 4.078249999999999 18.352124999999997
|
||||
291 1 2.039125000000000 0.000000000000000 6.117374999999998
|
||||
292 1 10.195625000000000 8.156499999999998 10.195625000000000
|
||||
293 1 10.195625000000000 12.234750000000002 2.039125000000000
|
||||
294 1 2.039125000000000 0.000000000000000 18.352124999999997
|
||||
295 1 10.195625000000000 12.234750000000002 14.273875000000000
|
||||
296 1 10.195625000000000 4.078249999999999 6.117374999999998
|
||||
297 1 6.117375000000001 12.234750000000002 2.039125000000000
|
||||
298 1 14.273875000000004 8.156499999999998 6.117374999999998
|
||||
299 1 18.352125000000001 16.312999999999995 2.039125000000000
|
||||
300 1 10.195625000000000 8.156499999999998 14.273875000000000
|
||||
301 1 10.195625000000000 4.078249999999999 18.352124999999997
|
||||
302 1 18.352125000000001 16.312999999999995 14.273875000000000
|
||||
303 1 14.273875000000004 16.312999999999995 6.117374999999998
|
||||
304 1 6.117375000000001 4.078249999999999 6.117374999999998
|
||||
305 1 18.352125000000001 8.156499999999998 6.117374999999998
|
||||
306 1 10.195625000000000 4.078249999999999 10.195625000000000
|
||||
307 1 10.195625000000000 8.156499999999998 18.352124999999997
|
||||
308 1 6.117375000000001 4.078249999999999 18.352124999999997
|
||||
309 1 2.039125000000000 16.312999999999995 6.117374999999998
|
||||
310 1 18.352125000000001 8.156499999999998 18.352124999999997
|
||||
311 1 2.039125000000000 4.078249999999999 6.117374999999998
|
||||
312 1 18.352125000000001 0.000000000000000 10.195625000000000
|
||||
313 1 10.195625000000000 0.000000000000000 6.117374999999998
|
||||
314 1 10.195625000000000 4.078249999999999 14.273875000000000
|
||||
315 1 2.039125000000000 4.078249999999999 18.352124999999997
|
||||
316 1 10.195625000000000 16.312999999999995 14.273875000000000
|
||||
317 1 6.117375000000001 16.312999999999995 2.039125000000000
|
||||
318 1 6.117375000000001 8.156499999999998 6.117374999999998
|
||||
319 1 6.117375000000001 16.312999999999995 14.273875000000000
|
||||
320 1 6.117375000000001 12.234750000000002 14.273875000000000
|
||||
321 1 2.039125000000000 16.312999999999995 2.039125000000000
|
||||
322 1 18.352125000000001 12.234750000000002 6.117374999999998
|
||||
323 1 14.273875000000004 0.000000000000000 18.352124999999997
|
||||
324 1 6.117375000000001 8.156499999999998 18.352124999999997
|
||||
325 1 6.117375000000001 8.156499999999998 10.195625000000000
|
||||
326 1 18.352125000000001 12.234750000000002 18.352124999999997
|
||||
327 1 2.039125000000000 8.156499999999998 6.117374999999998
|
||||
328 1 18.352125000000001 4.078249999999999 10.195625000000000
|
||||
329 1 2.039125000000000 8.156499999999998 18.352124999999997
|
||||
330 1 2.039125000000000 12.234750000000002 2.039125000000000
|
||||
331 1 14.273875000000004 0.000000000000000 14.273875000000000
|
||||
332 1 14.273875000000004 12.234750000000002 18.352124999999997
|
||||
333 1 2.039125000000000 0.000000000000000 10.195625000000000
|
||||
334 1 6.117375000000001 8.156499999999998 14.273875000000000
|
||||
335 1 10.195625000000000 12.234750000000002 6.117374999999998
|
||||
336 1 14.273875000000004 16.312999999999995 2.039125000000000
|
||||
337 1 10.195625000000000 12.234750000000002 18.352124999999997
|
||||
338 1 2.039125000000000 12.234750000000002 6.117374999999998
|
||||
339 1 6.117375000000001 12.234750000000002 6.117374999999998
|
||||
340 1 14.273875000000004 0.000000000000000 10.195625000000000
|
||||
341 1 18.352125000000001 16.312999999999995 6.117374999999998
|
||||
342 1 2.039125000000000 16.312999999999995 14.273875000000000
|
||||
343 1 6.117375000000001 12.234750000000002 18.352124999999997
|
||||
344 1 18.352125000000001 16.312999999999995 18.352124999999997
|
||||
345 1 2.039125000000000 8.156499999999998 2.039125000000000
|
||||
346 1 14.273875000000004 8.156499999999998 10.195625000000000
|
||||
347 1 6.117375000000001 4.078249999999999 10.195625000000000
|
||||
348 1 18.352125000000001 8.156499999999998 10.195625000000000
|
||||
349 1 6.117375000000001 4.078249999999999 14.273875000000000
|
||||
350 1 18.352125000000001 0.000000000000000 2.039125000000000
|
||||
351 1 2.039125000000000 12.234750000000002 18.352124999999997
|
||||
352 1 14.273875000000004 16.312999999999995 18.352124999999997
|
||||
353 1 14.273875000000004 12.234750000000002 2.039125000000000
|
||||
354 1 2.039125000000000 4.078249999999999 10.195625000000000
|
||||
355 1 10.195625000000000 16.312999999999995 6.117374999999998
|
||||
356 1 6.117375000000001 0.000000000000000 10.195625000000000
|
||||
357 1 14.273875000000004 0.000000000000000 2.039125000000000
|
||||
358 1 2.039125000000000 12.234750000000002 14.273875000000000
|
||||
359 1 2.039125000000000 16.312999999999995 10.195625000000000
|
||||
360 1 10.195625000000000 16.312999999999995 18.352124999999997
|
||||
361 1 14.273875000000004 8.156499999999998 14.273875000000000
|
||||
362 1 6.117375000000001 16.312999999999995 6.117374999999998
|
||||
363 1 14.273875000000004 12.234750000000002 6.117374999999998
|
||||
364 1 10.195625000000000 0.000000000000000 2.039125000000000
|
||||
365 1 2.039125000000000 8.156499999999998 10.195625000000000
|
||||
366 1 6.117375000000001 16.312999999999995 18.352124999999997
|
||||
367 1 10.195625000000000 0.000000000000000 14.273875000000000
|
||||
368 1 14.273875000000004 8.156499999999998 2.039125000000000
|
||||
369 1 18.352125000000001 12.234750000000002 10.195625000000000
|
||||
370 1 6.117375000000001 0.000000000000000 2.039125000000000
|
||||
371 1 14.273875000000004 12.234750000000002 10.195625000000000
|
||||
372 1 18.352125000000001 4.078249999999999 2.039125000000000
|
||||
373 1 2.039125000000000 16.312999999999995 18.352124999999997
|
||||
374 1 6.117375000000001 0.000000000000000 18.352124999999997
|
||||
375 1 6.117375000000001 0.000000000000000 14.273875000000000
|
||||
376 1 18.352125000000001 4.078249999999999 14.273875000000000
|
||||
377 1 10.195625000000000 18.352124999999997 0.000000000000000
|
||||
378 1 14.273875000000004 6.117374999999998 0.000000000000000
|
||||
379 1 14.273875000000004 14.273875000000000 12.234750000000002
|
||||
380 1 2.039125000000000 2.039125000000000 12.234750000000002
|
||||
381 1 10.195625000000000 14.273875000000000 8.156499999999998
|
||||
382 1 10.195625000000000 6.117374999999998 0.000000000000000
|
||||
383 1 18.352125000000001 2.039125000000000 12.234750000000002
|
||||
384 1 6.117375000000001 14.273875000000000 8.156499999999998
|
||||
385 1 10.195625000000000 2.039125000000000 8.156499999999998
|
||||
386 1 18.352125000000001 18.352124999999997 8.156499999999998
|
||||
387 1 6.117375000000001 6.117374999999998 0.000000000000000
|
||||
388 1 18.352125000000001 10.195625000000000 0.000000000000000
|
||||
389 1 14.273875000000004 6.117374999999998 4.078249999999999
|
||||
390 1 18.352125000000001 2.039125000000000 16.312999999999995
|
||||
391 1 2.039125000000000 14.273875000000000 8.156499999999998
|
||||
392 1 18.352125000000001 10.195625000000000 12.234750000000002
|
||||
393 1 2.039125000000000 6.117374999999998 0.000000000000000
|
||||
394 1 18.352125000000001 2.039125000000000 4.078249999999999
|
||||
395 1 14.273875000000004 18.352124999999997 8.156499999999998
|
||||
396 1 14.273875000000004 6.117374999999998 8.156499999999998
|
||||
397 1 2.039125000000000 6.117374999999998 12.234750000000002
|
||||
398 1 10.195625000000000 18.352124999999997 8.156499999999998
|
||||
399 1 14.273875000000004 10.195625000000000 16.312999999999995
|
||||
400 1 10.195625000000000 10.195625000000000 0.000000000000000
|
||||
401 1 14.273875000000004 18.352124999999997 12.234750000000002
|
||||
402 1 14.273875000000004 2.039125000000000 4.078249999999999
|
||||
403 1 6.117375000000001 18.352124999999997 8.156499999999998
|
||||
404 1 14.273875000000004 6.117374999999998 12.234750000000002
|
||||
405 1 6.117375000000001 10.195625000000000 0.000000000000000
|
||||
406 1 18.352125000000001 14.273875000000000 0.000000000000000
|
||||
407 1 10.195625000000000 2.039125000000000 16.312999999999995
|
||||
408 1 10.195625000000000 10.195625000000000 4.078249999999999
|
||||
409 1 18.352125000000001 14.273875000000000 12.234750000000002
|
||||
410 1 6.117375000000001 2.039125000000000 4.078249999999999
|
||||
411 1 14.273875000000004 6.117374999999998 16.312999999999995
|
||||
412 1 18.352125000000001 6.117374999999998 4.078249999999999
|
||||
413 1 2.039125000000000 10.195625000000000 12.234750000000002
|
||||
414 1 18.352125000000001 6.117374999999998 16.312999999999995
|
||||
415 1 2.039125000000000 2.039125000000000 4.078249999999999
|
||||
416 1 10.195625000000000 10.195625000000000 8.156499999999998
|
||||
417 1 10.195625000000000 14.273875000000000 0.000000000000000
|
||||
418 1 2.039125000000000 2.039125000000000 16.312999999999995
|
||||
419 1 10.195625000000000 14.273875000000000 12.234750000000002
|
||||
420 1 10.195625000000000 6.117374999999998 4.078249999999999
|
||||
421 1 6.117375000000001 14.273875000000000 0.000000000000000
|
||||
422 1 14.273875000000004 10.195625000000000 4.078249999999999
|
||||
423 1 18.352125000000001 18.352124999999997 0.000000000000000
|
||||
424 1 10.195625000000000 10.195625000000000 12.234750000000002
|
||||
425 1 10.195625000000000 6.117374999999998 16.312999999999995
|
||||
426 1 18.352125000000001 18.352124999999997 12.234750000000002
|
||||
427 1 14.273875000000004 18.352124999999997 4.078249999999999
|
||||
428 1 6.117375000000001 6.117374999999998 4.078249999999999
|
||||
429 1 18.352125000000001 10.195625000000000 4.078249999999999
|
||||
430 1 10.195625000000000 6.117374999999998 8.156499999999998
|
||||
431 1 10.195625000000000 10.195625000000000 16.312999999999995
|
||||
432 1 6.117375000000001 6.117374999999998 16.312999999999995
|
||||
433 1 2.039125000000000 18.352124999999997 4.078249999999999
|
||||
434 1 18.352125000000001 10.195625000000000 16.312999999999995
|
||||
435 1 2.039125000000000 6.117374999999998 4.078249999999999
|
||||
436 1 18.352125000000001 2.039125000000000 8.156499999999998
|
||||
437 1 10.195625000000000 2.039125000000000 4.078249999999999
|
||||
438 1 10.195625000000000 6.117374999999998 12.234750000000002
|
||||
439 1 2.039125000000000 6.117374999999998 16.312999999999995
|
||||
440 1 10.195625000000000 18.352124999999997 12.234750000000002
|
||||
441 1 6.117375000000001 18.352124999999997 0.000000000000000
|
||||
442 1 6.117375000000001 10.195625000000000 4.078249999999999
|
||||
443 1 6.117375000000001 18.352124999999997 12.234750000000002
|
||||
444 1 6.117375000000001 14.273875000000000 12.234750000000002
|
||||
445 1 2.039125000000000 18.352124999999997 0.000000000000000
|
||||
446 1 18.352125000000001 14.273875000000000 4.078249999999999
|
||||
447 1 14.273875000000004 2.039125000000000 16.312999999999995
|
||||
448 1 6.117375000000001 10.195625000000000 16.312999999999995
|
||||
449 1 6.117375000000001 10.195625000000000 8.156499999999998
|
||||
450 1 18.352125000000001 14.273875000000000 16.312999999999995
|
||||
451 1 2.039125000000000 10.195625000000000 4.078249999999999
|
||||
452 1 18.352125000000001 6.117374999999998 8.156499999999998
|
||||
453 1 2.039125000000000 10.195625000000000 16.312999999999995
|
||||
454 1 2.039125000000000 14.273875000000000 0.000000000000000
|
||||
455 1 14.273875000000004 2.039125000000000 12.234750000000002
|
||||
456 1 14.273875000000004 14.273875000000000 16.312999999999995
|
||||
457 1 2.039125000000000 2.039125000000000 8.156499999999998
|
||||
458 1 6.117375000000001 10.195625000000000 12.234750000000002
|
||||
459 1 10.195625000000000 14.273875000000000 4.078249999999999
|
||||
460 1 14.273875000000004 18.352124999999997 0.000000000000000
|
||||
461 1 10.195625000000000 14.273875000000000 16.312999999999995
|
||||
462 1 2.039125000000000 14.273875000000000 4.078249999999999
|
||||
463 1 6.117375000000001 14.273875000000000 4.078249999999999
|
||||
464 1 14.273875000000004 2.039125000000000 8.156499999999998
|
||||
465 1 18.352125000000001 18.352124999999997 4.078249999999999
|
||||
466 1 2.039125000000000 18.352124999999997 12.234750000000002
|
||||
467 1 6.117375000000001 14.273875000000000 16.312999999999995
|
||||
468 1 18.352125000000001 18.352124999999997 16.312999999999995
|
||||
469 1 2.039125000000000 10.195625000000000 0.000000000000000
|
||||
470 1 14.273875000000004 10.195625000000000 8.156499999999998
|
||||
471 1 6.117375000000001 6.117374999999998 8.156499999999998
|
||||
472 1 18.352125000000001 10.195625000000000 8.156499999999998
|
||||
473 1 6.117375000000001 6.117374999999998 12.234750000000002
|
||||
474 1 18.352125000000001 2.039125000000000 0.000000000000000
|
||||
475 1 2.039125000000000 14.273875000000000 16.312999999999995
|
||||
476 1 14.273875000000004 18.352124999999997 16.312999999999995
|
||||
477 1 14.273875000000004 14.273875000000000 0.000000000000000
|
||||
478 1 2.039125000000000 6.117374999999998 8.156499999999998
|
||||
479 1 10.195625000000000 18.352124999999997 4.078249999999999
|
||||
480 1 6.117375000000001 2.039125000000000 8.156499999999998
|
||||
481 1 14.273875000000004 2.039125000000000 0.000000000000000
|
||||
482 1 2.039125000000000 14.273875000000000 12.234750000000002
|
||||
483 1 2.039125000000000 18.352124999999997 8.156499999999998
|
||||
484 1 10.195625000000000 18.352124999999997 16.312999999999995
|
||||
485 1 14.273875000000004 10.195625000000000 12.234750000000002
|
||||
486 1 6.117375000000001 18.352124999999997 4.078249999999999
|
||||
487 1 14.273875000000004 14.273875000000000 4.078249999999999
|
||||
488 1 10.195625000000000 2.039125000000000 0.000000000000000
|
||||
489 1 2.039125000000000 10.195625000000000 8.156499999999998
|
||||
490 1 6.117375000000001 18.352124999999997 16.312999999999995
|
||||
491 1 10.195625000000000 2.039125000000000 12.234750000000002
|
||||
492 1 14.273875000000004 10.195625000000000 0.000000000000000
|
||||
493 1 18.352125000000001 14.273875000000000 8.156499999999998
|
||||
494 1 6.117375000000001 2.039125000000000 0.000000000000000
|
||||
495 1 14.273875000000004 14.273875000000000 8.156499999999998
|
||||
496 1 18.352125000000001 6.117374999999998 0.000000000000000
|
||||
497 1 2.039125000000000 18.352124999999997 16.312999999999995
|
||||
498 1 6.117375000000001 2.039125000000000 16.312999999999995
|
||||
499 1 6.117375000000001 2.039125000000000 12.234750000000002
|
||||
500 1 18.352125000000001 6.117374999999998 12.234750000000002
|
||||
4
python/examples/ipython/elastic/README
Normal file
4
python/examples/ipython/elastic/README
Normal file
@ -0,0 +1,4 @@
|
||||
conversion of lammps scripts to python code using PyLammps interface
|
||||
|
||||
Example for elastic.py
|
||||
python elastic.py Au.data EAM_Dynamo_Ackland_1987_Au__MO_754413982908_000 Au
|
||||
310
python/examples/ipython/elastic/elastic.py
Normal file
310
python/examples/ipython/elastic/elastic.py
Normal file
@ -0,0 +1,310 @@
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from lammps import PyLammps
|
||||
|
||||
def potential(lmp, args):
|
||||
""" set up potential and minimization """
|
||||
ff_string = ' '
|
||||
ff_string = ff_string.join(args.elements) # merge all element string to one string
|
||||
lmp.kim("interactions", ff_string)
|
||||
|
||||
# Setup neighbor style
|
||||
lmp.neighbor(1.0, "nsq")
|
||||
lmp.neigh_modify("once no every 1 delay 0 check yes")
|
||||
|
||||
# Setup minimization style
|
||||
lmp.min_style(args.min_style)
|
||||
lmp.min_modify("dmax ${dmax} line quadratic")
|
||||
|
||||
# Setup output
|
||||
lmp.thermo(1)
|
||||
lmp.thermo_style("custom step temp pe press pxx pyy pzz pxy pxz pyz lx ly lz")
|
||||
lmp.thermo_modify("norm no")
|
||||
|
||||
return
|
||||
|
||||
def displace(lmp, args, idir):
|
||||
"""computes the response to a small strain """
|
||||
|
||||
if idir == 1:
|
||||
lmp.variable("len0 equal {}".format(lmp.variables["lx0"].value))
|
||||
elif idir == 2 or idir == 6:
|
||||
lmp.variable("len0 equal {}".format(lmp.variables["ly0"].value))
|
||||
else:
|
||||
lmp.variable("len0 equal {}".format(lmp.variables["lz0"].value))
|
||||
|
||||
# Reset box and simulation parameters
|
||||
lmp.clear()
|
||||
lmp.box("tilt large")
|
||||
lmp.kim("init", args.kim_model, "metal", "unit_conversion_mode")
|
||||
lmp.read_restart("restart.equil")
|
||||
lmp.change_box("all triclinic")
|
||||
potential(lmp, args)
|
||||
|
||||
# Negative deformation
|
||||
lmp.variable("delta equal -${up}*${len0}")
|
||||
lmp.variable("deltaxy equal -${up}*xy")
|
||||
lmp.variable("deltaxz equal -${up}*xz")
|
||||
lmp.variable("deltayz equal -${up}*yz")
|
||||
|
||||
if idir == 1:
|
||||
lmp.change_box("all x delta 0 ${delta} xy delta ${deltaxy} xz delta ${deltaxz} remap units box")
|
||||
elif idir == 2:
|
||||
lmp.change_box("all y delta 0 ${delta} yz delta ${deltayz} remap units box")
|
||||
elif idir == 3:
|
||||
lmp.change_box("all z delta 0 ${delta} remap units box")
|
||||
elif idir == 4:
|
||||
lmp.change_box("all yz delta ${delta} remap units box")
|
||||
elif idir == 5:
|
||||
lmp.change_box("all xz delta ${delta} remap units box")
|
||||
else:
|
||||
lmp.change_box("all xy delta ${delta} remap units box")
|
||||
|
||||
# Relax atoms positions
|
||||
lmp.min_style(args.min_style)
|
||||
lmp.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3]))
|
||||
|
||||
# Obtain new stress tensor
|
||||
lmp.variable("pxx1 equal {}".format(lmp.eval("pxx")))
|
||||
lmp.variable("pyy1 equal {}".format(lmp.eval("pyy")))
|
||||
lmp.variable("pzz1 equal {}".format(lmp.eval("pzz")))
|
||||
lmp.variable("pxy1 equal {}".format(lmp.eval("pxy")))
|
||||
lmp.variable("pxz1 equal {}".format(lmp.eval("pxz")))
|
||||
lmp.variable("pyz1 equal {}".format(lmp.eval("pyz")))
|
||||
|
||||
# Compute elastic constant from pressure tensor
|
||||
c1neg = lmp.variables["d1"].value
|
||||
c2neg = lmp.variables["d2"].value
|
||||
c3neg = lmp.variables["d3"].value
|
||||
c4neg = lmp.variables["d4"].value
|
||||
c5neg = lmp.variables["d5"].value
|
||||
c6neg = lmp.variables["d6"].value
|
||||
|
||||
# Reset box and simulation parameters
|
||||
lmp.clear()
|
||||
lmp.box("tilt large")
|
||||
lmp.kim("init", args.kim_model, "metal", "unit_conversion_mode")
|
||||
lmp.read_restart("restart.equil")
|
||||
lmp.change_box("all triclinic")
|
||||
potential(lmp, args)
|
||||
|
||||
# Positive deformation
|
||||
lmp.variable("delta equal ${up}*${len0}")
|
||||
lmp.variable("deltaxy equal ${up}*xy")
|
||||
lmp.variable("deltaxz equal ${up}*xz")
|
||||
lmp.variable("deltayz equal ${up}*yz")
|
||||
|
||||
if idir == 1:
|
||||
lmp.change_box("all x delta 0 ${delta} xy delta ${deltaxy} xz delta ${deltaxz} remap units box")
|
||||
elif idir == 2:
|
||||
lmp.change_box("all y delta 0 ${delta} yz delta ${deltayz} remap units box")
|
||||
elif idir == 3:
|
||||
lmp.change_box("all z delta 0 ${delta} remap units box")
|
||||
elif idir == 4:
|
||||
lmp.change_box("all yz delta ${delta} remap units box")
|
||||
elif idir == 5:
|
||||
lmp.change_box("all xz delta ${delta} remap units box")
|
||||
else:
|
||||
lmp.change_box("all xy delta ${delta} remap units box")
|
||||
|
||||
# Relax atoms positions
|
||||
lmp.min_style(args.min_style)
|
||||
lmp.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3]))
|
||||
|
||||
# Obtain new stress tensor
|
||||
lmp.variable("pxx1 equal {}".format(lmp.eval("pxx")))
|
||||
lmp.variable("pyy1 equal {}".format(lmp.eval("pyy")))
|
||||
lmp.variable("pzz1 equal {}".format(lmp.eval("pzz")))
|
||||
lmp.variable("pxy1 equal {}".format(lmp.eval("pxy")))
|
||||
lmp.variable("pxz1 equal {}".format(lmp.eval("pxz")))
|
||||
lmp.variable("pyz1 equal {}".format(lmp.eval("pyz")))
|
||||
|
||||
# Compute elasic constant from pressure tensor
|
||||
c1pos = lmp.variables["d1"].value
|
||||
c2pos = lmp.variables["d2"].value
|
||||
c3pos = lmp.variables["d3"].value
|
||||
c4pos = lmp.variables["d4"].value
|
||||
c5pos = lmp.variables["d5"].value
|
||||
c6pos = lmp.variables["d6"].value
|
||||
|
||||
# Combine positive and negative
|
||||
lmp.variable("C1{} equal {}".format(idir, 0.5*(c1neg+c1pos)))
|
||||
lmp.variable("C2{} equal {}".format(idir, 0.5*(c2neg+c2pos)))
|
||||
lmp.variable("C3{} equal {}".format(idir, 0.5*(c3neg+c3pos)))
|
||||
lmp.variable("C4{} equal {}".format(idir, 0.5*(c4neg+c4pos)))
|
||||
lmp.variable("C5{} equal {}".format(idir, 0.5*(c5neg+c5pos)))
|
||||
lmp.variable("C6{} equal {}".format(idir, 0.5*(c6neg+c6pos)))
|
||||
|
||||
return
|
||||
|
||||
def elastic():
|
||||
""" Compute elastic constant tensor for a crystal
|
||||
|
||||
In order to calculate the elastic constants correctly, care must be taken to specify
|
||||
the correct units (units). It is also important to verify that the minimization of energy
|
||||
w.r.t atom positions in the deformed cell is fully converged.
|
||||
One indication of this is that the elastic constants are insensitive
|
||||
to the choice of the variable ${up}. Another is to check
|
||||
the final max and two-norm forces reported in the log file. If you know
|
||||
that minimization is not required, you can set maxiter = 0.0 """
|
||||
|
||||
parser = ArgumentParser(description='A python script to compute elastic properties of bulk materials')
|
||||
|
||||
parser.add_argument("input_data_file", help="The full path & name of the lammps data file.")
|
||||
parser.add_argument("kim_model", help="the KIM ID of the interatomic model archived in OpenKIM")
|
||||
parser.add_argument("elements", nargs='+', default=['Au'], help="a list of N chemical species, which defines a mapping between atom types in LAMMPS to the available species in the OpenKIM model")
|
||||
parser.add_argument("--min_style", default="cg", help="which algorithm will be used for minimization from lammps")
|
||||
parser.add_argument("--minimize", type=float, nargs=4, default=[1.0e-4, 1.0e-6, 100, 1000], help="minimization parameters")
|
||||
parser.add_argument("--up", type=float, default=1.0e-6, help="the deformation magnitude (in strain units)")
|
||||
args = parser.parse_args()
|
||||
|
||||
lmp = lammps()
|
||||
L = lmp.cmd
|
||||
|
||||
L.units("metal")
|
||||
|
||||
# Define the finite deformation size.
|
||||
#Try several values to verify that results do not depend on it.
|
||||
L.variable("up equal {}".format(args.up))
|
||||
|
||||
# Define the amount of random jiggle for atoms. It prevents atoms from staying on saddle points
|
||||
atomjiggle = 1.0e-5
|
||||
|
||||
# metal units, elastic constants in GPa
|
||||
cfac = 1.0e-4
|
||||
|
||||
# Define minimization parameters
|
||||
L.variable("dmax equal 1.0e-2")
|
||||
|
||||
L.boundary("p", "p", "p") # periodic boundary conditions in all three directions
|
||||
L.box("tilt large") # to avoid termination if the final simulation box has a high tilt factor
|
||||
|
||||
# use the OpenKIM model to set the energy interactions
|
||||
L.kim("init", args.kim_model, "metal", "unit_conversion_mode")
|
||||
|
||||
L.read_data(args.input_data_file)
|
||||
|
||||
potential(L, args)
|
||||
|
||||
# Need to set mass to something, just to satisfy LAMMPS
|
||||
mass_dictionary = {'H': 1.00797, 'He': 4.00260, 'Li': 6.941, 'Be': 9.01218, 'B': 10.81, 'C': 12.011, 'N': 14.0067, 'O': 15.9994, 'F': 18.998403, 'Ne': 20.179, 'Na': 22.98977, 'Mg': 24.305, 'Al': 26.98154, 'Si': 28.0855, 'P': 30.97376, 'S': 32.06, 'Cl': 35.453, 'K': 39.0983, 'Ar': 39.948, 'Ca': 40.08, 'Sc': 44.9559, 'Ti': 47.90, 'V': 50.9415, 'Cr': 51.996, 'Mn': 54.9380, 'Fe': 55.847, 'Ni': 58.70, 'Co': 58.9332, 'Cu': 63.546, 'Zn': 65.38, 'Ga': 69.72, 'Ge': 72.59, 'As': 74.9216, 'Se': 78.96, 'Br': 79.904, 'Kr': 83.80, 'Rb': 85.4678, 'Sr': 87.62, 'Y': 88.9059, 'Zr': 91.22, 'Nb': 92.9064, 'Mo': 95.94, 'Tc': 98, 'Ru': 101.07, 'Rh': 102.9055, 'Pd': 106.4, 'Ag': 107.868, 'Cd': 112.41, 'In': 114.82, 'Sn': 118.69, 'Sb': 121.75, 'I': 126.9045, 'Te': 127.60, 'Xe': 131.30, 'Cs': 132.9054, 'Ba': 137.33, 'La': 138.9055, 'Ce': 140.12, 'Pr': 140.9077, 'Nd': 144.24, 'Pm': 145, 'Sm': 150.4, 'Eu': 151.96, 'Gd': 157.25, 'Tb': 158.9254, 'Dy': 162.50, 'Ho': 164.9304, 'Er': 167.26, 'Tm': 168.9342, 'Yb': 173.04, 'Lu': 174.967, 'Hf': 178.49, 'Ta': 180.9479, 'W': 183.85, 'Re': 186.207, 'Os': 190.2, 'Ir': 192.22, 'Pt': 195.09, 'Au': 196.9665, 'Hg': 200.59, 'Tl': 204.37, 'Pb': 207.2, 'Bi': 208.9804, 'Po': 209, 'At': 210, 'Rn': 222, 'Fr': 223, 'Ra': 226.0254, 'Ac': 227.0278, 'Pa': 231.0359, 'Th': 232.0381, 'Np': 237.0482, 'U': 238.029}
|
||||
for itype in range(1, len(args.elements)+1):
|
||||
L.mass(itype, mass_dictionary.get(args.elements[itype-1], 1.0e-20))
|
||||
|
||||
# Compute initial state at zero pressure
|
||||
L.fix(3, "all", "box/relax", "aniso", 0.0)
|
||||
L.min_style(args.min_style)
|
||||
L.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3]))
|
||||
|
||||
L.variable("lx0 equal {}".format(L.eval("lx")))
|
||||
L.variable("ly0 equal {}".format(L.eval("ly")))
|
||||
L.variable("lz0 equal {}".format(L.eval("lz")))
|
||||
|
||||
# These formulas define the derivatives w.r.t. strain components
|
||||
L.variable("d1 equal -(v_pxx1-{})/(v_delta/v_len0)*{}".format(L.eval("pxx"), cfac))
|
||||
L.variable("d2 equal -(v_pyy1-{})/(v_delta/v_len0)*{}".format(L.eval("pyy"), cfac))
|
||||
L.variable("d3 equal -(v_pzz1-{})/(v_delta/v_len0)*{}".format(L.eval("pzz"), cfac))
|
||||
L.variable("d4 equal -(v_pyz1-{})/(v_delta/v_len0)*{}".format(L.eval("pyz"), cfac))
|
||||
L.variable("d5 equal -(v_pxz1-{})/(v_delta/v_len0)*{}".format(L.eval("pxz"), cfac))
|
||||
L.variable("d6 equal -(v_pxy1-{})/(v_delta/v_len0)*{}".format(L.eval("pxy"), cfac))
|
||||
|
||||
L.displace_atoms("all", "random", atomjiggle, atomjiggle, atomjiggle, 87287, "units box")
|
||||
|
||||
# Write restart
|
||||
L.unfix(3)
|
||||
L.write_restart("restart.equil")
|
||||
|
||||
for idir in range(1, 7):
|
||||
displace(L, args, idir)
|
||||
|
||||
postprocess_and_output(L)
|
||||
return
|
||||
|
||||
def postprocess_and_output(lmp):
|
||||
"""Compute the moduli and print everything to screen """
|
||||
|
||||
# Output final values
|
||||
c11all = lmp.variables["C11"].value
|
||||
c22all = lmp.variables["C22"].value
|
||||
c33all = lmp.variables["C33"].value
|
||||
|
||||
c12all = 0.5*(lmp.variables["C12"].value + lmp.variables["C21"].value)
|
||||
c13all = 0.5*(lmp.variables["C13"].value + lmp.variables["C31"].value)
|
||||
c23all = 0.5*(lmp.variables["C23"].value + lmp.variables["C32"].value)
|
||||
|
||||
c44all = lmp.variables["C44"].value
|
||||
c55all = lmp.variables["C55"].value
|
||||
c66all = lmp.variables["C66"].value
|
||||
|
||||
c14all = 0.5*(lmp.variables["C14"].value + lmp.variables["C41"].value)
|
||||
c15all = 0.5*(lmp.variables["C15"].value + lmp.variables["C51"].value)
|
||||
c16all = 0.5*(lmp.variables["C16"].value + lmp.variables["C61"].value)
|
||||
|
||||
c24all = 0.5*(lmp.variables["C24"].value + lmp.variables["C42"].value)
|
||||
c25all = 0.5*(lmp.variables["C25"].value + lmp.variables["C52"].value)
|
||||
c26all = 0.5*(lmp.variables["C26"].value + lmp.variables["C62"].value)
|
||||
|
||||
c34all = 0.5*(lmp.variables["C34"].value + lmp.variables["C43"].value)
|
||||
c35all = 0.5*(lmp.variables["C35"].value + lmp.variables["C53"].value)
|
||||
c36all = 0.5*(lmp.variables["C36"].value + lmp.variables["C63"].value)
|
||||
|
||||
c45all = 0.5*(lmp.variables["C45"].value + lmp.variables["C54"].value)
|
||||
c46all = 0.5*(lmp.variables["C46"].value + lmp.variables["C64"].value)
|
||||
c56all = 0.5*(lmp.variables["C56"].value + lmp.variables["C65"].value)
|
||||
|
||||
# Average moduli for cubic crystals
|
||||
c11cubic = (c11all + c22all + c33all)/3.0
|
||||
c12cubic = (c12all + c13all + c23all)/3.0
|
||||
c44cubic = (c44all + c55all + c66all)/3.0
|
||||
|
||||
bulkmodulus = (c11cubic + 2*c12cubic)/3.0
|
||||
shearmodulus1 = c44cubic
|
||||
shearmodulus2 = (c11cubic - c12cubic)/2.0
|
||||
poisson_ratio = 1.0/(1.0 + c11cubic/c12cubic)
|
||||
|
||||
# print results to screen
|
||||
print("=========================================")
|
||||
print("Components of the Elastic Constant Tensor")
|
||||
print("=========================================")
|
||||
|
||||
print("Elastic Constant C11all = {} GPa".format(c11all))
|
||||
print("Elastic Constant C22all = {} GPa".format(c22all))
|
||||
print("Elastic Constant C33all = {} GPa".format(c33all))
|
||||
|
||||
print("Elastic Constant C12all = {} GPa".format(c12all))
|
||||
print("Elastic Constant C13all = {} GPa".format(c13all))
|
||||
print("Elastic Constant C23all = {} GPa".format(c23all))
|
||||
|
||||
print("Elastic Constant C44all = {} GPa".format(c44all))
|
||||
print("Elastic Constant C55all = {} GPa".format(c55all))
|
||||
print("Elastic Constant C66all = {} GPa".format(c66all))
|
||||
|
||||
print("Elastic Constant C14all = {} GPa".format(c14all))
|
||||
print("Elastic Constant C15all = {} GPa".format(c15all))
|
||||
print("Elastic Constant C16all = {} GPa".format(c16all))
|
||||
|
||||
print("Elastic Constant C24all = {} GPa".format(c24all))
|
||||
print("Elastic Constant C25all = {} GPa".format(c25all))
|
||||
print("Elastic Constant C26all = {} GPa".format(c26all))
|
||||
|
||||
print("Elastic Constant C34all = {} GPa".format(c34all))
|
||||
print("Elastic Constant C35all = {} GPa".format(c35all))
|
||||
print("Elastic Constant C36all = {} GPa".format(c36all))
|
||||
|
||||
print("Elastic Constant C45all = {} GPa".format(c45all))
|
||||
print("Elastic Constant C46all = {} GPa".format(c46all))
|
||||
print("Elastic Constant C56all = {} GPa".format(c56all))
|
||||
|
||||
print("=========================================")
|
||||
print("Average properties for a cubic crystal")
|
||||
print("=========================================")
|
||||
|
||||
print("Bulk Modulus = {} GPa".format(bulkmodulus))
|
||||
print("Shear Modulus 1 = {} GPa".format(shearmodulus1))
|
||||
print("Shear Modulus 2 = {} GPa".format(shearmodulus2))
|
||||
print("Poisson Ratio = {}".format(poisson_ratio))
|
||||
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
elastic()
|
||||
61
python/examples/ipython/index.ipynb
Normal file
61
python/examples/ipython/index.ipynb
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "666d3036-47d5-44d2-bc1a-ca4b00a9e9b8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# LAMMPS IPython Tutorial"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f1422a43-f76b-456b-bf76-61ad92bd4ff0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Author: [Richard Berger](mailto:richard.berger@outlook.com)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8f2ea92d-8cc3-4999-81a0-79aa55bb66ab",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Contents\n",
|
||||
"\n",
|
||||
"- [Example 1: Using LAMMPS with Python](simple.ipynb)\n",
|
||||
"- [Example 2: Analyzing LAMMPS thermodynamic data](thermo.ipynb)\n",
|
||||
"- [Example 3: Using Atom Data](atom.ipynb)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b41dc533-be6d-4450-8ad7-7345e9f44ea3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
351
python/examples/ipython/montecarlo/mc.ipynb
Normal file
351
python/examples/ipython/montecarlo/mc.ipynb
Normal file
@ -0,0 +1,351 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Monte Carlo Relaxation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import random, math"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup perfect system"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from lammps import lammps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L = lammps()\n",
|
||||
"cmd = L.cmd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.units(\"lj\")\n",
|
||||
"cmd.atom_style(\"atomic\")\n",
|
||||
"cmd.atom_modify(\"map array sort\", 0, 0.0)\n",
|
||||
"\n",
|
||||
"cmd.dimension(2)\n",
|
||||
"\n",
|
||||
"cmd.lattice(\"hex\", 1.0)\n",
|
||||
"cmd.region(\"box block\", 0, 10, 0, 5, -0.5, 0.5)\n",
|
||||
"\n",
|
||||
"cmd.create_box(1, \"box\")\n",
|
||||
"cmd.create_atoms(1, \"box\")\n",
|
||||
"cmd.mass(1, 1.0)\n",
|
||||
"\n",
|
||||
"cmd.pair_style(\"lj/cut\", 2.5)\n",
|
||||
"cmd.pair_coeff(1, 1, 1.0, 1.0, 2.5)\n",
|
||||
"cmd.pair_modify(\"shift\", \"yes\")\n",
|
||||
"\n",
|
||||
"cmd.neighbor(0.3, \"bin\")\n",
|
||||
"cmd.neigh_modify(\"delay\", 0, \"every\", 1, \"check\", \"yes\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.6,size=[320,320])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.run(0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"emin = L.get_thermo(\"pe\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.dump(\"3 all movie 25 movie.mp4 type type zoom 1.6 adiam 1.0\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Disorder system"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"random.seed(27848)\n",
|
||||
"deltaperturb = 0.2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pos = L.numpy.extract_atom(\"x\")\n",
|
||||
"for i in range(len(pos)):\n",
|
||||
" x, y = pos[i][0], pos[i][1]\n",
|
||||
" dx = deltaperturb * random.uniform(-1, 1)\n",
|
||||
" dy = deltaperturb * random.uniform(-1, 1)\n",
|
||||
" pos[i] = (x+dx, y+dy, 0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd.run(0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.6,size=[320,320])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Minimize using Monte Carlo moves"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"estart = L.get_thermo(\"pe\")\n",
|
||||
"elast = estart"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"naccept = 0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"energies = [estart]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"niterations = 3000\n",
|
||||
"deltamove = 0.1\n",
|
||||
"kT = 0.05"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"natoms = L.extract_global(\"natoms\")\n",
|
||||
"\n",
|
||||
"for i in range(niterations):\n",
|
||||
" pos = L.numpy.extract_atom(\"x\")\n",
|
||||
" iatom = random.randrange(0, natoms)\n",
|
||||
" current_atom = pos[iatom]\n",
|
||||
" \n",
|
||||
" x0, y0 = current_atom[0], current_atom[1]\n",
|
||||
" \n",
|
||||
" dx = deltamove * random.uniform(-1, 1)\n",
|
||||
" dy = deltamove * random.uniform(-1, 1)\n",
|
||||
" \n",
|
||||
" pos[iatom] = (x0+dx, y0+dy, 0)\n",
|
||||
" \n",
|
||||
" cmd.run(1, \"pre no post no\")\n",
|
||||
" \n",
|
||||
" e = L.get_thermo(\"pe\")\n",
|
||||
" energies.append(e)\n",
|
||||
" \n",
|
||||
" if e <= elast:\n",
|
||||
" naccept += 1\n",
|
||||
" elast = e\n",
|
||||
" elif random.random() <= math.exp(natoms*(elast-e)/kT):\n",
|
||||
" naccept += 1\n",
|
||||
" elast = e\n",
|
||||
" else:\n",
|
||||
" pos[iatom] = (x0, y0, 0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.xlabel('iteration')\n",
|
||||
"plt.ylabel('potential energy')\n",
|
||||
"plt.plot(energies)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.get_thermo(\"pe\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"emin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"estart"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"naccept"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.6, size=[320,320])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# close dump file to access it\n",
|
||||
"cmd.undump(3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.video(\"movie.mp4\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
4
python/examples/ipython/mpi4py/hello.py
Normal file
4
python/examples/ipython/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/ipython/mpi4py/in.melt
Normal file
33
python/examples/ipython/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/ipython/mpi4py/melt.py
Normal file
10
python/examples/ipython/mpi4py/melt.py
Normal file
@ -0,0 +1,10 @@
|
||||
from mpi4py import MPI
|
||||
from lammps import lammps
|
||||
|
||||
L = lammps()
|
||||
L.file('in.melt')
|
||||
|
||||
|
||||
if MPI.COMM_WORLD.rank == 0:
|
||||
pe = L.get_thermo("pe")
|
||||
print("Potential Energy:", pe)
|
||||
306
python/examples/ipython/simple.ipynb
Normal file
306
python/examples/ipython/simple.ipynb
Normal file
@ -0,0 +1,306 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div style=\"text-align: center\"><a href=\"index.ipynb\">LAMMPS Python Tutorials</a></div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Example 1: Using LAMMPS with Python"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Author: [Richard Berger](mailto:richard.berger@outlook.com)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The LAMMPS Python package enables calling the LAMMPS C library API."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Prerequisites\n",
|
||||
"\n",
|
||||
"Before running this example, make sure your Python environment can find the LAMMPS shared library (`liblammps.so`) and the LAMMPS Python package is installed. If you followed the [README](README.md) in this folder, this should already be the case. You can also find more information about how to compile LAMMPS and install the LAMMPS Python package in the [LAMMPS manual](https://docs.lammps.org/Python_install.html). There is also a dedicated [LAMMPS Python HowTo](https://docs.lammps.org/Howto_python.html)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Creating a new simulation\n",
|
||||
"\n",
|
||||
"Once the LAMMPS shared library and the LAMMPS Python package are installed, you can create a new LAMMMPS instance in your Python interpreter as follows:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from lammps import lammps\n",
|
||||
"L = lammps()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"With the `lammps` class you can write LAMMPS simulations similar to the input script language. Take the following LAMMPS input script:\n",
|
||||
"\n",
|
||||
"```lammps\n",
|
||||
"# 3d Lennard-Jones melt\n",
|
||||
"\n",
|
||||
"units lj\n",
|
||||
"atom_style atomic\n",
|
||||
"\n",
|
||||
"lattice fcc 0.8442\n",
|
||||
"region box block 0 4 0 4 0 4\n",
|
||||
"create_box 1 box\n",
|
||||
"create_atoms 1 box\n",
|
||||
"mass 1 1.0\n",
|
||||
"\n",
|
||||
"velocity all create 1.44 87287 loop geom\n",
|
||||
"\n",
|
||||
"pair_style lj/cut 2.5\n",
|
||||
"pair_coeff 1 1 1.0 1.0 2.5\n",
|
||||
"\n",
|
||||
"neighbor 0.3 bin\n",
|
||||
"neigh_modify delay 0 every 20 check no\n",
|
||||
"\n",
|
||||
"fix 1 all nve\n",
|
||||
"\n",
|
||||
"thermo 50\n",
|
||||
"```\n",
|
||||
"The equivalent can be written in Python:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 3d Lennard-Jones melt\n",
|
||||
"\n",
|
||||
"L.cmd.units(\"lj\")\n",
|
||||
"L.cmd.atom_style(\"atomic\")\n",
|
||||
"\n",
|
||||
"L.cmd.lattice(\"fcc\", 0.8442)\n",
|
||||
"L.cmd.region(\"box\", \"block\", 0, 4, 0, 4, 0, 4)\n",
|
||||
"L.cmd.create_box(1, \"box\")\n",
|
||||
"L.cmd.create_atoms(1, \"box\")\n",
|
||||
"L.cmd.mass(1, 1.0)\n",
|
||||
"\n",
|
||||
"L.cmd.velocity(\"all\", \"create\", 1.44, 87287, \"loop geom\")\n",
|
||||
"\n",
|
||||
"L.cmd.pair_style(\"lj/cut\", 2.5)\n",
|
||||
"L.cmd.pair_coeff(1, 1, 1.0, 1.0, 2.5)\n",
|
||||
"\n",
|
||||
"L.cmd.neighbor(0.3, \"bin\")\n",
|
||||
"L.cmd.neigh_modify(\"delay\", 0, \"every\", 20, \"check no\")\n",
|
||||
"\n",
|
||||
"L.cmd.fix(\"1\", \"all\", \"nve\")\n",
|
||||
"\n",
|
||||
"L.cmd.thermo(50)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Some LAMMPS commands will produce output that will be visible in the notebook. However, due to buffering, it might not be shown right away. Use the `flush_buffers` method to see all the output that has been written so far."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.flush_buffers()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"An alternative to this is to enable auto flushing after each command by setting `cmd.auto_flush` to `True`. Each command will then call `flush_buffers()` automatically."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.cmd.auto_flush = True\n",
|
||||
"L.cmd.info(\"system\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In many cases the LAMMPS output will become excessive, which is why you may want to suppress it. For this purpose we provide a IPython extension in the `lammps.ipython` package. To load the extension, add a code cell with the following content:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%load_ext lammps.ipython"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Once the extension is loaded you have access to the `%%capture_lammps_output` magic. In its simplest form it can be used to supress LAMMPS output:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture_lammps_output\n",
|
||||
"L.cmd.info(\"system\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"You can also use the same `%%capture_lammps_output` magic to store the output in a variable by providing a variable name:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture_lammps_output out\n",
|
||||
"L.cmd.info(\"system\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In this case we are storing the output in a `out` variable. Note the output is only available after the cell has been executed, not within the same cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(out)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Visualizing the initial state\n",
|
||||
"\n",
|
||||
"The `lammps` class also has an `ipython` attribute which provides some basic visualization capabilities in IPython Jupyter notebooks. E.g., you can visualize the current simulation state with the [image](https://docs.lammps.org/Python_module.html#lammps.ipython_wrapper.image) command. Here we use it to create an image of the initial state of the system."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Running simulations\n",
|
||||
"\n",
|
||||
"Use the `run` command to start the simulation. It will print the output of the simulation."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.cmd.run(250)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Visualizing the system will now show us how the atoms have moved."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"L.ipython.image(zoom=1.0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Conclusion\n",
|
||||
"This covered the basics of creating an instance of LAMMPS from Python, passing commands to LAMMPS and potentially supressing or capturing its output, and visualizing the system. In the [following tutorial](thermo.ipynb) we will look at how to process thermodynamic output from LAMMPS.\n",
|
||||
"\n",
|
||||
"<div style=\"text-align:right\"><a href=\"thermo.ipynb\">Next</a>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
305
python/examples/ipython/thermo.ipynb
Normal file
305
python/examples/ipython/thermo.ipynb
Normal file
@ -0,0 +1,305 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Example 2: Analyzing LAMMPS thermodynamic data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Author: [Richard Berger](mailto:richard.berger@outlook.com)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This tutorial assumes you've completed the [first example](simple.ipynb) and understand the basics of running LAMMPS through Python. In this tutorial we will build on top of that example and look at how to extract thermodynamic data produced by LAMMPS into Python and visualize it. Let's first start by recreating our simple melt example:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%load_ext lammps.ipython"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from lammps import lammps\n",
|
||||
"L = lammps()\n",
|
||||
"L.cmd.auto_flush = True\n",
|
||||
"\n",
|
||||
"def init_melt_system(L):\n",
|
||||
" # 3d Lennard-Jones melt\n",
|
||||
" L.cmd.clear()\n",
|
||||
" L.cmd.units(\"lj\")\n",
|
||||
" L.cmd.atom_style(\"atomic\")\n",
|
||||
" \n",
|
||||
" L.cmd.lattice(\"fcc\", 0.8442)\n",
|
||||
" L.cmd.region(\"box\", \"block\", 0, 4, 0, 4, 0, 4)\n",
|
||||
" L.cmd.create_box(1, \"box\")\n",
|
||||
" L.cmd.create_atoms(1, \"box\")\n",
|
||||
" L.cmd.mass(1, 1.0)\n",
|
||||
" \n",
|
||||
" L.cmd.velocity(\"all\", \"create\", 1.44, 87287, \"loop geom\")\n",
|
||||
" \n",
|
||||
" L.cmd.pair_style(\"lj/cut\", 2.5)\n",
|
||||
" L.cmd.pair_coeff(1, 1, 1.0, 1.0, 2.5)\n",
|
||||
" \n",
|
||||
" L.cmd.neighbor(0.3, \"bin\")\n",
|
||||
" L.cmd.neigh_modify(\"delay\", 0, \"every\", 20, \"check no\")\n",
|
||||
" \n",
|
||||
" L.cmd.fix(\"1\", \"all\", \"nve\")\n",
|
||||
" \n",
|
||||
" L.cmd.thermo(50)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Here we take advantage of the fact that we can write regular Python functions to organize our LAMMPS simulation. This allows us to clear and initialize a new system by calling the `init_melt_system()` function. With this we can now go ahead an run this simulation for 100 steps."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"init_melt_system(L)\n",
|
||||
"L.cmd.run(100)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Extracting thermodynamic data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Looking at the above output we see that LAMMPS prints out thermodynamic data for steps 0, 50 and 100.\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
" Step Temp E_pair E_mol TotEng Press \n",
|
||||
" 0 1.44 -6.7733681 0 -4.6218056 -5.0244179 \n",
|
||||
" 50 0.70303849 -5.6796164 0 -4.629178 0.50453907 \n",
|
||||
" 100 0.72628044 -5.7150774 0 -4.6299123 0.29765862\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"We could parse the text output and extract the necessary information, but this has proven to be error-prone and clunky, especially in cases where other output gets interleaved with thermo output lines. Instead, we can make use of the Python integration within LAMMPS to execute arbitrary Python code during time steps using `fix python/invoke`. We can extract the thermodynamic data directly using the LAMMPS Python interface and process it in any way we want.\n",
|
||||
"\n",
|
||||
"For this we first define the data structure we want to use to store the data. For each column of the thermodynamic data we want to store a list of values for each time step. Let's use a Python `dict` with the following structure:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"{'Step': [0, 50, 100, ...], 'Temp': [...], 'E_pair': [...], 'E_mol': [...], 'TotEng': [...], 'Press': [...]}\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To start, let's define an empty `dict` and call it `current_run`. As the simulation progresses, we append new data into this dictionary:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_run = {}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Next, let's define a function that should be executed every time step a thermodynamic output line would be written. This function takes a `lammps` class instance and through it can access LAMMPS state and data. We can use the [`last_thermo()`](https://docs.lammps.org/Python_module.html#lammps.lammps.last_thermo) function of the `lammps` class to get the latest thermodynamic data as a dictionary. This data is all we need to populate our `current_run` data structure."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def append_thermo_data(lmp):\n",
|
||||
" for k, v in lmp.last_thermo().items():\n",
|
||||
" current_run.setdefault(k, []).append(v)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"With these two pieces in place, it is now time to tell LAMMPS about how we want to call this function.\n",
|
||||
"\n",
|
||||
"First, let's suppress any LAMMPS output via `%%capture_lammps_output` and reinitialize our system with `init_melt_system()` so our system is back in its initial state and the time step is back to 0.\n",
|
||||
"\n",
|
||||
"Next, we add a new fix `python/invoke` that should execute every 50 time steps, the same as our `thermo 50` command above. At the end of every 50 time steps (including the first one), it should call the `append_thermo_data` function we just defined. Notice we can just pass the function as parameter. Finally, we tell LAMMPS to run for 250 steps."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture_lammps_output\n",
|
||||
"init_melt_system(L)\n",
|
||||
"L.cmd.fix(\"myfix\", \"all\", \"python/invoke\", 50, \"end_of_step\", append_thermo_data)\n",
|
||||
"L.cmd.run(250)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Let's inspect our `current_run` dictionary after the run has completed:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_run"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"As we can see, the time steps 0, 50, 100, 150, and 200 were added to dictionary. However, the last time step 250 is still missing. For this we need to manually add a final call to our `append_thermo_data()` helper function."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"append_thermo_data(L)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"With this our `current_run` dictionary now has all the data of the completed run:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_run"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Plotting thermodynamic data with matplotlib\n",
|
||||
"\n",
|
||||
"Now that we have our data available as Python variables, we can easily use other libraries for visualization."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"plt.xlabel('time step')\n",
|
||||
"plt.ylabel('Total Energy')\n",
|
||||
"plt.plot(current_run['Step'], current_run['TotEng'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Using Pandas library\n",
|
||||
"\n",
|
||||
"Since we can call any Python code from LAMMPS, the above example can also be rewritten using the Pandas library:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%capture_lammps_output\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"current_run = pd.DataFrame()\n",
|
||||
"\n",
|
||||
"def append_thermo_data(lmp):\n",
|
||||
" global current_run\n",
|
||||
" current_time_step = pd.DataFrame.from_records([lmp.last_thermo()])\n",
|
||||
" current_run = pd.concat([current_run, current_time_step], ignore_index=True)\n",
|
||||
"\n",
|
||||
"init_melt_system(L)\n",
|
||||
"L.cmd.fix(\"myfix\", \"all\", \"python/invoke\", 50, \"end_of_step\", append_thermo_data)\n",
|
||||
"L.cmd.run(250)\n",
|
||||
"append_thermo_data(L)\n",
|
||||
"current_run"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_run.plot(x='Step', y='TotEng')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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",
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
Reference in New Issue
Block a user