{
"cells": [
{
"cell_type": "markdown",
"id": "909cd1e2",
"metadata": {},
"source": [
"# Use mdapy efficiently"
]
},
{
"cell_type": "markdown",
"id": "bcaee006",
"metadata": {},
"source": [
"## The key point is re-using the neighborlist information."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c12f2890",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Taichi] version 1.7.1, llvm 15.0.1, commit 0f143b2f, win, python 3.10.14\n",
"[Taichi] Starting on arch=x64\n"
]
}
],
"source": [
"import mdapy as mp\n",
"mp.init()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fd819d69",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.11.1'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mp.__version__"
]
},
{
"cell_type": "markdown",
"id": "22d00857",
"metadata": {},
"source": [
"## Build a FCC lattice with 4,000,000 atoms."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fc775eec",
"metadata": {},
"outputs": [],
"source": [
"FCC = mp.LatticeMaker(3.615, 'FCC', 100, 100, 100)\n",
"FCC.compute()"
]
},
{
"cell_type": "markdown",
"id": "210f5d7d",
"metadata": {},
"source": [
"## Generate a system class."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "538324d5",
"metadata": {},
"outputs": [],
"source": [
"system = mp.System(pos=FCC.pos, box=FCC.box, boundary=[1, 1, 1])"
]
},
{
"cell_type": "markdown",
"id": "a7b67b89",
"metadata": {},
"source": [
"## Check the system information."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8ca9c22e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Filename: None\n",
"Atom Number: 4000000\n",
"Simulation Box:\n",
"[[361.5 0. 0. ]\n",
" [ 0. 361.5 0. ]\n",
" [ 0. 0. 361.5]\n",
" [ 0. 0. 0. ]]\n",
"TimeStep: 0\n",
"Boundary: [1, 1, 1]\n",
"Particle Information:\n",
"shape: (4_000_000, 5)\n",
"┌─────────┬──────┬──────────┬──────────┬──────────┐\n",
"│ id ┆ type ┆ x ┆ y ┆ z │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ i32 ┆ i32 ┆ f64 ┆ f64 ┆ f64 │\n",
"╞═════════╪══════╪══════════╪══════════╪══════════╡\n",
"│ 1 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 0.0 │\n",
"│ 2 ┆ 1 ┆ 1.8075 ┆ 1.8075 ┆ 0.0 │\n",
"│ 3 ┆ 1 ┆ 1.8075 ┆ 0.0 ┆ 1.8075 │\n",
"│ 4 ┆ 1 ┆ 0.0 ┆ 1.8075 ┆ 1.8075 │\n",
"│ 5 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 3.615 │\n",
"│ … ┆ … ┆ … ┆ … ┆ … │\n",
"│ 3999996 ┆ 1 ┆ 357.885 ┆ 359.6925 ┆ 356.0775 │\n",
"│ 3999997 ┆ 1 ┆ 357.885 ┆ 357.885 ┆ 357.885 │\n",
"│ 3999998 ┆ 1 ┆ 359.6925 ┆ 359.6925 ┆ 357.885 │\n",
"│ 3999999 ┆ 1 ┆ 359.6925 ┆ 357.885 ┆ 359.6925 │\n",
"│ 4000000 ┆ 1 ┆ 357.885 ┆ 359.6925 ┆ 359.6925 │\n",
"└─────────┴──────┴──────────┴──────────┴──────────┘"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system"
]
},
{
"cell_type": "markdown",
"id": "2d77a526",
"metadata": {},
"source": [
"If we want to do a series of analysis, we can re-use the neighbor to save time."
]
},
{
"cell_type": "markdown",
"id": "fece836f",
"metadata": {},
"source": [
"## Direct calculation."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c07b1fa1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 2min 15s\n",
"Wall time: 10.3 s\n"
]
}
],
"source": [
"%%time\n",
"system.cal_centro_symmetry_parameter(12)\n",
"system.cal_ackland_jones_analysis()\n",
"system.cal_atomic_entropy()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5020e204",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
shape: (5, 8)| id | type | x | y | z | csp | aja | atomic_entropy |
|---|
| i32 | i32 | f64 | f64 | f64 | f64 | i32 | f64 |
| 1 | 1 | 0.0 | 0.0 | 0.0 | 3.2952e-26 | 1 | -8.645166 |
| 2 | 1 | 1.8075 | 1.8075 | 0.0 | 1.0984e-26 | 1 | -8.645166 |
| 3 | 1 | 1.8075 | 0.0 | 1.8075 | 1.0984e-26 | 1 | -8.645166 |
| 4 | 1 | 0.0 | 1.8075 | 1.8075 | 1.0984e-26 | 1 | -8.645166 |
| 5 | 1 | 0.0 | 0.0 | 3.615 | 2.1968e-26 | 1 | -8.645166 |
"
],
"text/plain": [
"shape: (5, 8)\n",
"┌─────┬──────┬────────┬────────┬────────┬────────────┬─────┬────────────────┐\n",
"│ id ┆ type ┆ x ┆ y ┆ z ┆ csp ┆ aja ┆ atomic_entropy │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ i32 ┆ i32 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ i32 ┆ f64 │\n",
"╞═════╪══════╪════════╪════════╪════════╪════════════╪═════╪════════════════╡\n",
"│ 1 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 0.0 ┆ 3.2952e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 2 ┆ 1 ┆ 1.8075 ┆ 1.8075 ┆ 0.0 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 3 ┆ 1 ┆ 1.8075 ┆ 0.0 ┆ 1.8075 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 4 ┆ 1 ┆ 0.0 ┆ 1.8075 ┆ 1.8075 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 5 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 3.615 ┆ 2.1968e-26 ┆ 1 ┆ -8.645166 │\n",
"└─────┴──────┴────────┴────────┴────────┴────────────┴─────┴────────────────┘"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system.data.head()"
]
},
{
"cell_type": "markdown",
"id": "b90a344b",
"metadata": {},
"source": [
"## Re-use neighborlist information."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7e7bdecf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: total: 1min 32s\n",
"Wall time: 6.99 s\n"
]
}
],
"source": [
"%%time\n",
"system.build_neighbor(rc=5.0, max_neigh=50) # Obtain the neighbor first, the following calculation can use it.\n",
"system.cal_atomic_entropy()\n",
"system.cal_ackland_jones_analysis()\n",
"system.cal_centro_symmetry_parameter(12)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ecefac5e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
shape: (5, 8)| id | type | x | y | z | csp | aja | atomic_entropy |
|---|
| i32 | i32 | f64 | f64 | f64 | f64 | i32 | f64 |
| 1 | 1 | 0.0 | 0.0 | 0.0 | 3.2952e-26 | 1 | -8.645166 |
| 2 | 1 | 1.8075 | 1.8075 | 0.0 | 1.0984e-26 | 1 | -8.645166 |
| 3 | 1 | 1.8075 | 0.0 | 1.8075 | 1.0984e-26 | 1 | -8.645166 |
| 4 | 1 | 0.0 | 1.8075 | 1.8075 | 1.0984e-26 | 1 | -8.645166 |
| 5 | 1 | 0.0 | 0.0 | 3.615 | 2.1968e-26 | 1 | -8.645166 |
"
],
"text/plain": [
"shape: (5, 8)\n",
"┌─────┬──────┬────────┬────────┬────────┬────────────┬─────┬────────────────┐\n",
"│ id ┆ type ┆ x ┆ y ┆ z ┆ csp ┆ aja ┆ atomic_entropy │\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ i32 ┆ i32 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ i32 ┆ f64 │\n",
"╞═════╪══════╪════════╪════════╪════════╪════════════╪═════╪════════════════╡\n",
"│ 1 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 0.0 ┆ 3.2952e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 2 ┆ 1 ┆ 1.8075 ┆ 1.8075 ┆ 0.0 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 3 ┆ 1 ┆ 1.8075 ┆ 0.0 ┆ 1.8075 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 4 ┆ 1 ┆ 0.0 ┆ 1.8075 ┆ 1.8075 ┆ 1.0984e-26 ┆ 1 ┆ -8.645166 │\n",
"│ 5 ┆ 1 ┆ 0.0 ┆ 0.0 ┆ 3.615 ┆ 2.1968e-26 ┆ 1 ┆ -8.645166 │\n",
"└─────┴──────┴────────┴────────┴────────┴────────────┴─────┴────────────────┘"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system.data.head()"
]
}
],
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}