Skip to content

Instantly share code, notes, and snippets.

@lan496
Created January 12, 2022 05:56
Show Gist options
  • Save lan496/e9dff8449cd7489f6722b276282e66a0 to your computer and use it in GitHub Desktop.
Save lan496/e9dff8449cd7489f6722b276282e66a0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "8ef59252",
"metadata": {},
"source": [
"# Anisotropic Structural Relaxation with LAMMPS\n",
"\n",
"This notebook shows how to relax a structure with changing its cell volume and shape."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "046b5cc2",
"metadata": {},
"outputs": [],
"source": [
"from string import Template\n",
"\n",
"import numpy as np\n",
"from pymatgen.core import Structure\n",
"from pymatgen.io.lammps.data import LammpsData\n",
"from pymatgen.io.lammps.outputs import parse_lammps_log, parse_lammps_dumps"
]
},
{
"cell_type": "markdown",
"id": "40d70b15",
"metadata": {},
"source": [
"## Preparing input files"
]
},
{
"cell_type": "markdown",
"id": "8a0eed04",
"metadata": {},
"source": [
"### Structure"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "423b2e41",
"metadata": {},
"outputs": [],
"source": [
"def get_hcp(a, c=None):\n",
" if c is None:\n",
" # ideal ratio\n",
" c_by_a = np.sqrt(8 / 3)\n",
" else:\n",
" c_by_a = c / a\n",
" \n",
" matrix = a * np.array(\n",
" [\n",
" [1, 0, 0],\n",
" [-0.5, np.sqrt(3) / 2, 0],\n",
" [0, 0, c_by_a],\n",
" ]\n",
" )\n",
" species = ['Mg'] * 2\n",
" frac_coords = np.array([\n",
" [0, 0, 0],\n",
" [1 / 3, 2 / 3, 1 / 2],\n",
" ])\n",
" \n",
" structure = Structure(matrix, species, frac_coords)\n",
" return structure"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2b5c6a03",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Full Formula (Mg2)\n",
"Reduced Formula: Mg\n",
"abc : 3.200000 3.200000 5.225578\n",
"angles: 90.000000 90.000000 120.000000\n",
"Sites (2)\n",
" # SP a b c\n",
"--- ---- -------- -------- ---\n",
" 0 Mg 0 0 0\n",
" 1 Mg 0.333333 0.666667 0.5\n"
]
}
],
"source": [
"mg_hcp = get_hcp(3.2)\n",
"print(mg_hcp)\n",
"LammpsData.from_structure(mg_hcp, atom_style='atomic').write_file('atom.dat')"
]
},
{
"cell_type": "markdown",
"id": "40ad9c7e",
"metadata": {},
"source": [
"### Input script"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c2b6d168",
"metadata": {},
"outputs": [],
"source": [
"TEMPLATE = Template(\"\"\"# When input lattice is highly tiled, uncomment the below line\n",
"box tilt large\n",
"\n",
"${system_pair_info}\n",
"\n",
"# monitoring \"fnorm\" during minimization\n",
"thermo 1\n",
"thermo_style custom step temp pe etotal press fnorm\n",
"thermo_modify norm no\n",
"\n",
"# rebuild neighbor list at every timestep\n",
"neigh_modify delay 0 every 1 check yes\n",
"\n",
"# atoms only\n",
"minimize ${etol} ${ftol} ${maxiter} ${maxeval}\n",
"reset_timestep 0\n",
"\n",
"# isotropic volume relaxation\n",
"fix fiso all box/relax iso ${pressure}\n",
"minimize ${etol} ${ftol} ${maxiter} ${maxeval}\n",
"unfix fiso\n",
"reset_timestep 0\n",
"\n",
"# If the initial structure is orthogonal, uncomment the below line\n",
"# change_box all triclinic\n",
"\n",
"# anisotropic volume relaxation without shear\n",
"fix faniso all box/relax aniso ${pressure}\n",
"minimize ${etol} ${ftol} ${maxiter} ${maxeval}\n",
"unfix faniso\n",
"reset_timestep 0\n",
"\n",
"# anisotropic volume relaxation with shear\n",
"fix ftri all box/relax tri ${pressure}\n",
"minimize ${etol} ${ftol} ${maxiter} ${maxeval}\n",
"unfix ftri\n",
"reset_timestep 0\n",
"\n",
"# Futher refinement may need with positive \"nreset\" value\n",
"fix frefine all box/relax tri ${pressure} nreset ${nreset}\n",
"minimize ${etol} ${ftol} ${maxiter} ${maxeval}\n",
"unfix frefine\n",
"reset_timestep 0\n",
"\n",
"# Output\n",
"write_data dump.structure\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "27edbd0b",
"metadata": {},
"outputs": [],
"source": [
"system_pair_info = \"\"\"units metal\n",
"atom_style atomic\n",
"\n",
"boundary p p p\n",
"read_data atom.dat\n",
"\n",
"pair_style eam/fs\n",
"pair_coeff * * Mg_mm.eam.fs Mg\n",
"\"\"\"\n",
"\n",
"pressure = 0.0\n",
"# energy tolerance\n",
"etol = 0.0\n",
"# force tolerance\n",
"ftol = 1e-8\n",
"# max iteratations for minimization\n",
"maxiter = 1000\n",
"# max number of energy/force evaluations\n",
"maxeval = 100000\n",
"# how often reset reference cell\n",
"nreset = 100\n",
"\n",
"script = TEMPLATE.safe_substitute(system_pair_info=system_pair_info, pressure=pressure, etol=etol, ftol=ftol, maxiter=maxiter, maxeval=maxeval, nreset=nreset)\n",
"\n",
"with open(\"in.lammps\", 'w') as f:\n",
" f.write(script)"
]
},
{
"cell_type": "markdown",
"id": "cf9ca3f3",
"metadata": {},
"source": [
"### Potential file"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "85b08238",
"metadata": {},
"outputs": [],
"source": [
"# !cp ~/.local/share/lammps/potentials/Mg_mm.eam.fs ."
]
},
{
"cell_type": "markdown",
"id": "6e419fbb",
"metadata": {},
"source": [
"## Running LAMMPS"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1a7b6ee3",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LAMMPS (29 Sep 2021)\r\n",
"Reading data file ...\r\n",
" triclinic box = (0.0000000 0.0000000 0.0000000) to (3.2000000 2.7712810 5.2255780) with tilt (-1.6000000 0.0000000 0.0000000)\r\n",
" 1 by 1 by 1 MPI processor grid\r\n",
" reading atoms ...\r\n",
" 2 atoms\r\n",
" read_data CPU = 0.000 seconds\r\n",
"Reading eam/fs potential file Mg_mm.eam.fs with DATE: 2007-06-11\r\n",
"Neighbor list info ...\r\n",
" update every 1 steps, delay 0 steps, check yes\r\n",
" max neighbors/atom: 2000, page size: 100000\r\n",
" master list distance cutoff = 9.5\r\n",
" ghost atom cutoff = 9.5\r\n",
" binsize = 4.75, bins = 2 1 2\r\n",
" 1 neighbor lists, perpetual/occasional/extra = 1 0 0\r\n",
" (1) pair eam/fs, perpetual\r\n",
" attributes: half, newton on\r\n",
" pair build: half/bin/newton/tri\r\n",
" stencil: half/bin/3d/tri\r\n",
" bin: standard\r\n",
"Setting up cg style minimization ...\r\n",
" Unit style : metal\r\n",
" Current step : 0\r\n",
"Per MPI rank memory allocation (min/avg/max) = 4.371 | 4.371 | 4.371 Mbytes\r\n",
"Step Temp PotEng TotEng Press Fnorm \r\n",
" 0 0 -3.0557179 -3.0557179 -6380.4536 3.1838572e-07 \r\n",
" 1 0 -3.0557179 -3.0557179 -6380.4536 5.5502776e-14 \r\n",
"Loop time of 0.000100851 on 1 procs for 1 steps with 2 atoms\r\n",
"\r\n",
"515.6% CPU use with 1 MPI tasks x no OpenMP threads\r\n",
"\r\n",
"Minimization stats:\r\n",
" Stopping criterion = force tolerance\r\n",
" Energy initial, next-to-last, final = \r\n",
" -3.05571790907723 -3.05571790907723 -3.05571790907727\r\n",
" Force two-norm initial, final = 3.1838572e-07 5.5502776e-14\r\n",
" Force max component initial, final = 2.2513270e-07 3.9260262e-14\r\n",
" Final line search alpha, max atom move = 1.0000000 3.9260262e-14\r\n",
" Iterations, force evaluations = 1 2\r\n",
"\r\n",
"MPI task timing breakdown:\r\n",
"Section | min time | avg time | max time |%varavg| %total\r\n",
"---------------------------------------------------------------\r\n",
"Pair | 2.5034e-05 | 2.5034e-05 | 2.5034e-05 | 0.0 | 24.82\r\n",
"Neigh | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Comm | 5.2214e-05 | 5.2214e-05 | 5.2214e-05 | 0.0 | 51.77\r\n",
"Output | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Modify | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Other | | 2.36e-05 | | | 23.40\r\n",
"\r\n",
"Nlocal: 2.00000 ave 2 max 2 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Nghost: 574.000 ave 574 max 574 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Neighs: 146.000 ave 146 max 146 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"\r\n",
"Total # of neighbors = 146\r\n",
"Ave neighs/atom = 73.000000\r\n",
"Neighbor list builds = 0\r\n",
"Dangerous builds = 0\r\n",
"Setting up cg style minimization ...\r\n",
" Unit style : metal\r\n",
" Current step : 0\r\n",
"WARNING: Energy due to 1 extra global DOFs will be included in minimizer energies\r\n",
"Per MPI rank memory allocation (min/avg/max) = 4.371 | 4.371 | 4.371 Mbytes\r\n",
"Step Temp PotEng TotEng Press Fnorm \r\n",
" 0 0 -3.0557179 -3.0557179 -6380.4536 5.519407e-14 \r\n",
" 1 0 -3.0557728 -3.0557728 -6270.022 2.4723674e-09 \r\n",
" 2 0 -3.0558267 -3.0558267 -6159.6328 2.8827259e-09 \r\n",
" 3 0 -3.0558796 -3.0558796 -6048.3157 2.4838977e-12 \r\n",
" 4 0 -3.0559316 -3.0559316 -5937.7315 2.9991066e-09 \r\n",
" 5 0 -3.0559826 -3.0559826 -5828.2195 4.538299e-10 \r\n",
" 6 0 -3.0560326 -3.0560326 -5718.4149 1.2640946e-09 \r\n",
" 7 0 -3.0560817 -3.0560817 -5608.0291 5.2966979e-10 \r\n",
" 8 0 -3.0561298 -3.0561298 -5496.8856 8.9952237e-10 \r\n",
" 9 0 -3.056177 -3.056177 -5387.5304 7.6435158e-10 \r\n",
" 10 0 -3.0562232 -3.0562232 -5277.5457 3.179755e-09 \r\n",
" 11 0 -3.0562684 -3.0562684 -5168.18 1.4581867e-10 \r\n",
" 12 0 -3.0563126 -3.0563126 -5057.7346 2.3265121e-10 \r\n",
" 13 0 -3.0563559 -3.0563559 -4947.1919 6.0728301e-09 \r\n",
" 14 0 -3.0563983 -3.0563983 -4838.307 1.6552364e-09 \r\n",
" 15 0 -3.0564397 -3.0564397 -4729.1398 1.8256399e-09 \r\n",
" 16 0 -3.0564801 -3.0564801 -4619.3461 4.2077429e-09 \r\n",
" 17 0 -3.0565196 -3.0565196 -4510.1507 3.0295205e-09 \r\n",
" 18 0 -3.0565581 -3.0565581 -4398.9989 6.536155e-09 \r\n",
" 19 0 -3.0565957 -3.0565957 -4290.0736 4.5693695e-09 \r\n",
" 20 0 -3.0566323 -3.0566323 -4181.2978 5.4656462e-09 \r\n",
" 21 0 -3.0566679 -3.0566679 -4071.7723 4.49997e-09 \r\n",
" 22 0 -3.0567026 -3.0567026 -3961.446 5.7486607e-09 \r\n",
" 23 0 -3.0567364 -3.0567364 -3852.4486 7.828661e-09 \r\n",
" 24 0 -3.0567692 -3.0567692 -3743.9395 7.7945108e-09 \r\n",
" 25 0 -3.056801 -3.056801 -3634.0345 5.272637e-09 \r\n",
" 26 0 -3.0568319 -3.0568319 -3526.1074 6.1987539e-09 \r\n",
" 27 0 -3.0568619 -3.0568619 -3416.9798 1.0283832e-08 \r\n",
" 28 0 -3.0568909 -3.0568909 -3306.8527 9.034103e-09 \r\n",
" 29 0 -3.056919 -3.056919 -3198.2571 6.553084e-09 \r\n",
" 30 0 -3.0569461 -3.0569461 -3089.5528 1.0689915e-08 \r\n",
" 31 0 -3.0569723 -3.0569723 -2980.5227 9.7203327e-09 \r\n",
" 32 0 -3.0569975 -3.0569975 -2871.7815 8.3699292e-09 \r\n",
" 33 0 -3.0570218 -3.0570218 -2763.1366 1.3419641e-08 \r\n",
" 34 0 -3.0570451 -3.0570451 -2654.3887 1.0208149e-08 \r\n",
" 35 0 -3.0570675 -3.0570675 -2545.4914 1.1381395e-08 \r\n",
" 36 0 -3.057089 -3.057089 -2438.4312 1.0231484e-08 \r\n",
" 37 0 -3.0571095 -3.0571095 -2328.4536 1.3135494e-08 \r\n",
" 38 0 -3.0571291 -3.0571291 -2220.3715 1.1108231e-08 \r\n",
" 39 0 -3.0571478 -3.0571478 -2112.5667 1.3085286e-08 \r\n",
" 40 0 -3.0571655 -3.0571655 -2004.0746 1.3774263e-08 \r\n",
" 41 0 -3.0571823 -3.0571823 -1895.5639 1.4342961e-08 \r\n",
" 42 0 -3.0571981 -3.0571981 -1786.3287 1.4803814e-08 \r\n",
" 43 0 -3.057213 -3.057213 -1678.0813 1.378602e-08 \r\n",
" 44 0 -3.057227 -3.057227 -1571.0212 1.4896027e-08 \r\n",
" 45 0 -3.0572401 -3.0572401 -1462.3177 1.6237741e-08 \r\n",
" 46 0 -3.0572522 -3.0572522 -1354.4614 1.5579005e-08 \r\n",
" 47 0 -3.0572633 -3.0572633 -1245.945 1.456495e-08 \r\n",
" 48 0 -3.0572736 -3.0572736 -1137.9026 1.7689842e-08 \r\n",
" 49 0 -3.0572829 -3.0572829 -1029.9136 1.8415286e-08 \r\n",
" 50 0 -3.0572913 -3.0572913 -921.82734 1.5708783e-08 \r\n",
" 51 0 -3.0572987 -3.0572987 -814.50548 2.000803e-08 \r\n",
" 52 0 -3.0573053 -3.0573053 -706.83364 1.6366245e-08 \r\n",
" 53 0 -3.0573109 -3.0573109 -598.72293 2.0384871e-08 \r\n",
" 54 0 -3.0573156 -3.0573156 -490.6092 1.7099091e-08 \r\n",
" 55 0 -3.0573193 -3.0573193 -383.01218 2.1297431e-08 \r\n",
" 56 0 -3.0573221 -3.0573221 -275.16062 1.7997242e-08 \r\n",
" 57 0 -3.057324 -3.057324 -167.33569 2.232708e-08 \r\n",
" 58 0 -3.057325 -3.057325 -59.837124 2.0269632e-08 \r\n",
" 59 0 -3.0573251 -3.0573251 0.047298296 1.9210356e-08 \r\n",
" 60 0 -3.0573251 -3.0573251 1.4111493e-06 1.891036e-08 \r\n",
" 61 0 -3.0573251 -3.0573251 -8.8803737e-05 4.8736028e-11 \r\n",
"Loop time of 0.00247884 on 1 procs for 61 steps with 2 atoms\r\n",
"\r\n",
"465.4% CPU use with 1 MPI tasks x no OpenMP threads\r\n",
"\r\n",
"Minimization stats:\r\n",
" Stopping criterion = force tolerance\r\n",
" Energy initial, next-to-last, final = \r\n",
" -3.05571790907727 -3.05732514075972 -3.05732514075973\r\n",
" Force two-norm initial, final = 0.55363983 7.6157810e-09\r\n",
" Force max component initial, final = 0.55363983 7.6156251e-09\r\n",
" Final line search alpha, max atom move = 1.0000000 7.6156251e-09\r\n",
" Iterations, force evaluations = 61 64\r\n",
"\r\n",
"MPI task timing breakdown:\r\n",
"Section | min time | avg time | max time |%varavg| %total\r\n",
"---------------------------------------------------------------\r\n",
"Pair | 0.00072646 | 0.00072646 | 0.00072646 | 0.0 | 29.31\r\n",
"Neigh | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Comm | 0.00029588 | 0.00029588 | 0.00029588 | 0.0 | 11.94\r\n",
"Output | 0.0008328 | 0.0008328 | 0.0008328 | 0.0 | 33.60\r\n",
"Modify | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Other | | 0.0006237 | | | 25.16\r\n",
"\r\n",
"Nlocal: 2.00000 ave 2 max 2 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Nghost: 574.000 ave 574 max 574 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Neighs: 146.000 ave 146 max 146 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"\r\n",
"Total # of neighbors = 146\r\n",
"Ave neighs/atom = 73.000000\r\n",
"Neighbor list builds = 0\r\n",
"Dangerous builds = 0\r\n",
"Setting up cg style minimization ...\r\n",
" Unit style : metal\r\n",
" Current step : 0\r\n",
"WARNING: Energy due to 3 extra global DOFs will be included in minimizer energies\r\n",
"Per MPI rank memory allocation (min/avg/max) = 4.371 | 4.371 | 4.371 Mbytes\r\n",
"Step Temp PotEng TotEng Press Fnorm \r\n",
" 0 0 -3.0573251 -3.0573251 -8.8803568e-05 4.8736038e-11 \r\n",
" 1 0 -3.0573298 -3.0573298 -3.5579966 2.7079712e-09 \r\n",
" 2 0 -3.0573342 -3.0573342 -6.4868576 4.8868158e-09 \r\n",
" 3 0 -3.0573383 -3.0573383 -8.7567738 6.4283119e-09 \r\n",
" 4 0 -3.0573422 -3.0573422 -10.929627 8.1630217e-09 \r\n",
" 5 0 -3.0573458 -3.0573458 -12.888521 1.0273947e-08 \r\n",
" 6 0 -3.0573492 -3.0573492 -14.274983 1.3612821e-08 \r\n",
" 7 0 -3.0573524 -3.0573524 -15.360367 1.6981411e-08 \r\n",
" 8 0 -3.0573553 -3.0573553 -16.206608 2.0341035e-08 \r\n",
" 9 0 -3.0573579 -3.0573579 -17.008611 2.3061549e-08 \r\n",
" 10 0 -3.0573604 -3.0573604 -17.284813 2.5260756e-08 \r\n",
" 11 0 -3.0573626 -3.0573626 -16.839329 2.7599376e-08 \r\n",
" 12 0 -3.0573645 -3.0573645 -16.378552 3.0048683e-08 \r\n",
" 13 0 -3.0573663 -3.0573663 -15.908962 3.2875082e-08 \r\n",
" 14 0 -3.0573678 -3.0573678 -14.761979 3.5984542e-08 \r\n",
" 15 0 -3.0573691 -3.0573691 -13.147234 3.9003e-08 \r\n",
" 16 0 -3.0573701 -3.0573701 -11.268141 4.1924168e-08 \r\n",
" 17 0 -3.0573709 -3.0573709 -9.1716557 4.4695368e-08 \r\n",
" 18 0 -3.0573716 -3.0573716 -6.648033 4.7142217e-08 \r\n",
" 19 0 -3.057372 -3.057372 -3.7934502 4.9415547e-08 \r\n",
" 20 0 -3.0573721 -3.0573721 -1.0481423 5.0945588e-08 \r\n",
" 21 0 -3.0573721 -3.0573721 0.11460677 4.9022935e-08 \r\n",
" 22 0 -3.0573721 -3.0573721 -0.0039948499 4.6990027e-08 \r\n",
" 23 0 -3.0573721 -3.0573721 -3.472035e-05 4.3189914e-08 \r\n",
" 24 0 -3.0573721 -3.0573721 0.00089804543 3.2663549e-09 \r\n",
" 25 0 -3.0573721 -3.0573721 -3.2060432e-05 4.0418243e-10 \r\n",
"Loop time of 0.00108695 on 1 procs for 25 steps with 2 atoms\r\n",
"\r\n",
"518.2% CPU use with 1 MPI tasks x no OpenMP threads\r\n",
"\r\n",
"Minimization stats:\r\n",
" Stopping criterion = force tolerance\r\n",
" Energy initial, next-to-last, final = \r\n",
" -3.05732514075973 -3.05737214009496 -3.05737214009496\r\n",
" Force two-norm initial, final = 0.038881803 6.3732081e-09\r\n",
" Force max component initial, final = 0.031746862 4.1049993e-09\r\n",
" Final line search alpha, max atom move = 1.0000000 4.1049993e-09\r\n",
" Iterations, force evaluations = 25 30\r\n",
"\r\n",
"MPI task timing breakdown:\r\n",
"Section | min time | avg time | max time |%varavg| %total\r\n",
"---------------------------------------------------------------\r\n",
"Pair | 0.0003171 | 0.0003171 | 0.0003171 | 0.0 | 29.17\r\n",
"Neigh | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Comm | 0.00011349 | 0.00011349 | 0.00011349 | 0.0 | 10.44\r\n",
"Output | 0.00033212 | 0.00033212 | 0.00033212 | 0.0 | 30.55\r\n",
"Modify | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Other | | 0.0003242 | | | 29.83\r\n",
"\r\n",
"Nlocal: 2.00000 ave 2 max 2 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Nghost: 574.000 ave 574 max 574 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Neighs: 146.000 ave 146 max 146 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"\r\n",
"Total # of neighbors = 146\r\n",
"Ave neighs/atom = 73.000000\r\n",
"Neighbor list builds = 0\r\n",
"Dangerous builds = 0\r\n",
"Setting up cg style minimization ...\r\n",
" Unit style : metal\r\n",
" Current step : 0\r\n",
"WARNING: Energy due to 6 extra global DOFs will be included in minimizer energies\r\n",
"Per MPI rank memory allocation (min/avg/max) = 4.371 | 4.371 | 4.371 Mbytes\r\n",
"Step Temp PotEng TotEng Press Fnorm \r\n",
" 0 0 -3.0573721 -3.0573721 -3.2060432e-05 4.0418348e-10 \r\n",
" 1 0 -3.0573721 -3.0573721 7.6968961e-05 3.3244894e-08 \r\n",
" 2 0 -3.0573721 -3.0573721 -0.0011222123 8.4906932e-09 \r\n",
" 3 0 -3.0573721 -3.0573721 0.00012694329 1.0483892e-09 \r\n",
" 4 0 -3.0573721 -3.0573721 1.1731023e-05 2.1422666e-10 \r\n",
"Loop time of 0.000291109 on 1 procs for 4 steps with 2 atoms\r\n",
"\r\n",
"503.6% CPU use with 1 MPI tasks x no OpenMP threads\r\n",
"\r\n",
"Minimization stats:\r\n",
" Stopping criterion = force tolerance\r\n",
" Energy initial, next-to-last, final = \r\n",
" -3.05737214009496 -3.05737214009497 -3.05737214009497\r\n",
" Force two-norm initial, final = 4.2804174e-07 2.9901242e-09\r\n",
" Force max component initial, final = 4.2799427e-07 2.0253918e-09\r\n",
" Final line search alpha, max atom move = 1.0000000 2.0253918e-09\r\n",
" Iterations, force evaluations = 4 8\r\n",
"\r\n",
"MPI task timing breakdown:\r\n",
"Section | min time | avg time | max time |%varavg| %total\r\n",
"---------------------------------------------------------------\r\n",
"Pair | 0.00010896 | 0.00010896 | 0.00010896 | 0.0 | 37.43\r\n",
"Neigh | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Comm | 6.6996e-05 | 6.6996e-05 | 6.6996e-05 | 0.0 | 23.01\r\n",
"Output | 3.4809e-05 | 3.4809e-05 | 3.4809e-05 | 0.0 | 11.96\r\n",
"Modify | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Other | | 8.035e-05 | | | 27.60\r\n",
"\r\n",
"Nlocal: 2.00000 ave 2 max 2 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Nghost: 574.000 ave 574 max 574 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Neighs: 146.000 ave 146 max 146 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"\r\n",
"Total # of neighbors = 146\r\n",
"Ave neighs/atom = 73.000000\r\n",
"Neighbor list builds = 0\r\n",
"Dangerous builds = 0\r\n",
"Setting up cg style minimization ...\r\n",
" Unit style : metal\r\n",
" Current step : 0\r\n",
"WARNING: Energy due to 6 extra global DOFs will be included in minimizer energies\r\n",
"Per MPI rank memory allocation (min/avg/max) = 4.371 | 4.371 | 4.371 Mbytes\r\n",
"Step Temp PotEng TotEng Press Fnorm \r\n",
" 0 0 -3.0573721 -3.0573721 1.1731135e-05 2.1422693e-10 \r\n",
" 1 0 -3.0573721 -3.0573721 -1.9197147e-05 6.3097309e-11 \r\n",
"Loop time of 0.000106096 on 1 procs for 1 steps with 2 atoms\r\n",
"\r\n",
"503.3% CPU use with 1 MPI tasks x no OpenMP threads\r\n",
"\r\n",
"Minimization stats:\r\n",
" Stopping criterion = force tolerance\r\n",
" Energy initial, next-to-last, final = \r\n",
" -3.05737214009497 -3.05737214009497 -3.05737214009497\r\n",
" Force two-norm initial, final = 2.9901258e-09 1.4201787e-09\r\n",
" Force max component initial, final = 2.0253931e-09 9.8852492e-10\r\n",
" Final line search alpha, max atom move = 1.0000000 9.8852492e-10\r\n",
" Iterations, force evaluations = 1 2\r\n",
"\r\n",
"MPI task timing breakdown:\r\n",
"Section | min time | avg time | max time |%varavg| %total\r\n",
"---------------------------------------------------------------\r\n",
"Pair | 6.1274e-05 | 6.1274e-05 | 6.1274e-05 | 0.0 | 57.75\r\n",
"Neigh | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Comm | 1.0729e-05 | 1.0729e-05 | 1.0729e-05 | 0.0 | 10.11\r\n",
"Output | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Modify | 0 | 0 | 0 | 0.0 | 0.00\r\n",
"Other | | 3.409e-05 | | | 32.13\r\n",
"\r\n",
"Nlocal: 2.00000 ave 2 max 2 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Nghost: 574.000 ave 574 max 574 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"Neighs: 146.000 ave 146 max 146 min\r\n",
"Histogram: 1 0 0 0 0 0 0 0 0 0\r\n",
"\r\n",
"Total # of neighbors = 146\r\n",
"Ave neighs/atom = 73.000000\r\n",
"Neighbor list builds = 0\r\n",
"Dangerous builds = 0\r\n",
"System init for write_data ...\r\n",
"Total wall time: 0:00:00\r\n"
]
}
],
"source": [
"# !conda install -c conda-forge lammps\n",
"!lmp_serial -in in.lammps"
]
},
{
"cell_type": "markdown",
"id": "d50adbdf",
"metadata": {},
"source": [
"## Post processing"
]
},
{
"cell_type": "markdown",
"id": "98f3cfe7",
"metadata": {},
"source": [
"### Checking minization result"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9454ccae",
"metadata": {},
"outputs": [],
"source": [
"logs = parse_lammps_log('log.lammps')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "578a8498",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Step</th>\n",
" <th>Temp</th>\n",
" <th>PotEng</th>\n",
" <th>TotEng</th>\n",
" <th>Press</th>\n",
" <th>Fnorm</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>-3.057372</td>\n",
" <td>-3.057372</td>\n",
" <td>0.000012</td>\n",
" <td>2.142269e-10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>-3.057372</td>\n",
" <td>-3.057372</td>\n",
" <td>-0.000019</td>\n",
" <td>6.309731e-11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Step Temp PotEng TotEng Press Fnorm\n",
"0 0 0 -3.057372 -3.057372 0.000012 2.142269e-10\n",
"1 1 0 -3.057372 -3.057372 -0.000019 6.309731e-11"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"logs[-1]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "34c399f2",
"metadata": {},
"outputs": [],
"source": [
"def check_minimization_converged(log, ftol, maxiter):\n",
" # check force tolerance\n",
" max_force = log.iloc[-1]['Fnorm']\n",
" if max_force > ftol:\n",
" return False\n",
" \n",
" # check if number of iterations was sufficient\n",
" num_iter = log['Step'].max()\n",
" if num_iter >= maxiter:\n",
" return False\n",
" \n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8ecc7ac2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"check_minimization_converged(logs[-1], ftol, maxiter)"
]
},
{
"cell_type": "markdown",
"id": "9327de8c",
"metadata": {},
"source": [
"### Loading relaxed structure"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d6f7d208",
"metadata": {},
"outputs": [],
"source": [
"relaxed = LammpsData.from_file('dump.structure', atom_style='atomic').structure"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "52949395",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Structure Summary\n",
"Lattice\n",
" abc : 3.1842140125247846 3.184214012277814 5.184423275690312\n",
" angles : 90.0 90.00000000000001 119.99999999578445\n",
" volume : 45.52349340554951\n",
" A : 3.1842140125247846 0.0 0.0\n",
" B : -1.5921070059360156 2.757610225836101 0.0\n",
" C : -1.1152687798361318e-15 -5.742390917892048e-16 5.184423275690312\n",
"PeriodicSite: Mg (-0.0000, 0.0000, -0.0000) [0.0000, 0.0000, -0.0000]\n",
"PeriodicSite: Mg (0.0000, 1.8384, 2.5922) [0.3333, 0.6667, 0.5000]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# https://www.ctcms.nist.gov/potentials/entry/2006--Sun-D-Y-Mendelev-M-I-Becker-C-A-et-al--Mg/2006--Sun-D-Y--Mg--LAMMPS--ipr1.html\n",
"relaxed"
]
},
{
"cell_type": "markdown",
"id": "fdeedfc9",
"metadata": {},
"source": [
"## References\n",
"- https://docs.lammps.org/fix_box_relax.html\n",
"- https://docs.lammps.org/Howto_triclinic.html\n",
"- https://docs.lammps.org/box.html\n",
"- https://github.com/lammps/lammps/blob/develop/examples/min/in.min.box"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "db57438d",
"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.7"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment