Files
lammps-gran-kokkos/python/examples/ipython/atoms.ipynb
2024-12-12 23:27:07 -07:00

225 lines
4.5 KiB
Plaintext

{
"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 3: Working with Per-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": [
"## 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.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}