Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 19, 2024
1 parent b298efd commit 07f54f7
Show file tree
Hide file tree
Showing 5 changed files with 2,425 additions and 36 deletions.
257 changes: 256 additions & 1 deletion notebooks/bulk_modulus_with_gpaw.ipynb

Large diffs are not rendered by default.

116 changes: 84 additions & 32 deletions notebooks/free_energy_calculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@
"source": [
"from ase.build import bulk\n",
"import numpy as np\n",
"from atomistics.workflows import optimize_positions_and_volume, LangevinWorkflow, PhonopyWorkflow, QuasiHarmonicWorkflow\n",
"from atomistics.calculators import evaluate_with_lammps_library, evaluate_with_lammps, get_potential_by_name, evaluate_with_hessian\n",
"from atomistics.workflows import (\n",
" optimize_positions_and_volume,\n",
" LangevinWorkflow,\n",
" PhonopyWorkflow,\n",
" QuasiHarmonicWorkflow,\n",
")\n",
"from atomistics.calculators import (\n",
" evaluate_with_lammps_library,\n",
" evaluate_with_lammps,\n",
" get_potential_by_name,\n",
" evaluate_with_hessian,\n",
")\n",
"from pylammpsmpi import LammpsASELibrary\n",
"from phonopy.units import VaspToTHz\n",
"from tqdm import tqdm\n",
"import matplotlib.pyplot as plt\n",
"import pandas\n",
"import scipy.constants "
"import scipy.constants"
]
},
{
Expand All @@ -52,16 +62,17 @@
"outputs": [],
"source": [
"structure_bulk = bulk(\"Al\", cubic=True)\n",
"df_pot_selected = pandas.DataFrame({\n",
" \"Config\": [[\n",
" \"pair_style morse/smooth/linear 9.0\",\n",
" \"pair_coeff * * 0.5 1.8 2.95\"\n",
" ]],\n",
" \"Filename\": [[]],\n",
" \"Model\": [\"Morse\"],\n",
" \"Name\": [\"Morse\"],\n",
" \"Species\": [[\"Al\"]],\n",
"})"
"df_pot_selected = pandas.DataFrame(\n",
" {\n",
" \"Config\": [\n",
" [\"pair_style morse/smooth/linear 9.0\", \"pair_coeff * * 0.5 1.8 2.95\"]\n",
" ],\n",
" \"Filename\": [[]],\n",
" \"Model\": [\"Morse\"],\n",
" \"Name\": [\"Morse\"],\n",
" \"Species\": [[\"Al\"]],\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -372,9 +383,19 @@
],
"source": [
"plt.title(\"Helmholtz Free Energy\")\n",
"plt.plot(term_base_dict['temperatures'], term_base_dict['free_energy'], label=\"Harmonic\")\n",
"plt.plot(term_qh_dict['temperatures'], term_qh_dict['free_energy'], label=\"Quasi-Harmonic (qm)\")\n",
"plt.plot(term_qh_cl_dict['temperatures'], term_qh_cl_dict['free_energy'], label=\"Quasi-Harmonic (cl)\")\n",
"plt.plot(\n",
" term_base_dict[\"temperatures\"], term_base_dict[\"free_energy\"], label=\"Harmonic\"\n",
")\n",
"plt.plot(\n",
" term_qh_dict[\"temperatures\"],\n",
" term_qh_dict[\"free_energy\"],\n",
" label=\"Quasi-Harmonic (qm)\",\n",
")\n",
"plt.plot(\n",
" term_qh_cl_dict[\"temperatures\"],\n",
" term_qh_cl_dict[\"free_energy\"],\n",
" label=\"Quasi-Harmonic (cl)\",\n",
")\n",
"plt.xlabel(\"Temperature (K)\")\n",
"plt.ylabel(\"Helmholtz Free Energy (eV)\")\n",
"plt.legend()"
Expand Down Expand Up @@ -409,8 +430,10 @@
],
"source": [
"plt.title(\"Entropy\")\n",
"plt.plot(term_base_dict['temperatures'], term_base_dict['entropy'], label=\"harmonic\")\n",
"plt.plot(term_qh_dict['temperatures'], term_qh_dict['entropy'], label=\"quasi-harmonic (qm)\")\n",
"plt.plot(term_base_dict[\"temperatures\"], term_base_dict[\"entropy\"], label=\"harmonic\")\n",
"plt.plot(\n",
" term_qh_dict[\"temperatures\"], term_qh_dict[\"entropy\"], label=\"quasi-harmonic (qm)\"\n",
")\n",
"plt.xlabel(\"Temperature (K)\")\n",
"plt.ylabel(\"Entropy (J/K/mol)\")\n",
"plt.legend()"
Expand Down Expand Up @@ -445,9 +468,18 @@
],
"source": [
"plt.title(\"Heat Capacity\")\n",
"plt.plot(term_base_dict['temperatures'], term_base_dict['heat_capacity'], label=\"harmonic\")\n",
"plt.plot(term_qh_dict['temperatures'], term_qh_dict['heat_capacity'], label=\"quasi-harmonic\")\n",
"plt.axhline(3 * scipy.constants.Boltzmann * scipy.constants.Avogadro * len(structure_opt), color=\"black\", linestyle=\"--\", label=\"$3Nk_B$\")\n",
"plt.plot(\n",
" term_base_dict[\"temperatures\"], term_base_dict[\"heat_capacity\"], label=\"harmonic\"\n",
")\n",
"plt.plot(\n",
" term_qh_dict[\"temperatures\"], term_qh_dict[\"heat_capacity\"], label=\"quasi-harmonic\"\n",
")\n",
"plt.axhline(\n",
" 3 * scipy.constants.Boltzmann * scipy.constants.Avogadro * len(structure_opt),\n",
" color=\"black\",\n",
" linestyle=\"--\",\n",
" label=\"$3Nk_B$\",\n",
")\n",
"plt.xlabel(\"Temperature (K)\")\n",
"plt.ylabel(\"Heat Capacity (J/K/mol)\")\n",
"plt.legend()"
Expand Down Expand Up @@ -496,8 +528,8 @@
"metadata": {},
"outputs": [],
"source": [
"lattice_constant_lst = np.array(term_qh_dict['volumes']) ** (1/3)\n",
"temperature_lst = term_qh_dict['temperatures']"
"lattice_constant_lst = np.array(term_qh_dict[\"volumes\"]) ** (1 / 3)\n",
"temperature_lst = term_qh_dict[\"temperatures\"]"
]
},
{
Expand Down Expand Up @@ -560,7 +592,9 @@
"free_energy_lst, eng_lambda_dependence_lst = [], []\n",
"for lattice_constant, temperature in zip(lattice_constant_lst, temperature_lst):\n",
" structure = bulk(\"Al\", a=lattice_constant, cubic=True).repeat([3, 3, 3])\n",
" equilibrium_lammps = evaluate_with_lammps(task_dict={\"calc_energy\": structure}, potential_dataframe=df_pot_selected)['energy']\n",
" equilibrium_lammps = evaluate_with_lammps(\n",
" task_dict={\"calc_energy\": structure}, potential_dataframe=df_pot_selected\n",
" )[\"energy\"]\n",
" workflow_fix = PhonopyWorkflow(\n",
" structure=structure,\n",
" interaction_range=10,\n",
Expand All @@ -577,7 +611,7 @@
" )\n",
" workflow_fix.analyse_structures(output_dict=result_dict)\n",
" energy_pot_all_lst, energy_mean_lst, energy_kin_all_lst = [], [], []\n",
" for lambda_parameter in lambda_lst: \n",
" for lambda_parameter in lambda_lst:\n",
" thermo_eng_pot_lst, thermo_eng_kin_lst = [], []\n",
" workflow_md_thermo = LangevinWorkflow(\n",
" structure=structure,\n",
Expand Down Expand Up @@ -610,10 +644,18 @@
" lmp=lmp,\n",
" )\n",
" result_dict = {\n",
" \"forces\": {0: (1-lambda_parameter) * hessian_dict[\"forces\"][0] + lambda_parameter * lammps_dict[\"forces\"][0]},\n",
" \"energy\": {0: (1-lambda_parameter) * hessian_dict[\"energy\"][0] + lambda_parameter * (lammps_dict[\"energy\"][0] - equilibrium_lammps)},\n",
" \"forces\": {\n",
" 0: (1 - lambda_parameter) * hessian_dict[\"forces\"][0]\n",
" + lambda_parameter * lammps_dict[\"forces\"][0]\n",
" },\n",
" \"energy\": {\n",
" 0: (1 - lambda_parameter) * hessian_dict[\"energy\"][0]\n",
" + lambda_parameter * (lammps_dict[\"energy\"][0] - equilibrium_lammps)\n",
" },\n",
" }\n",
" eng_pot, eng_kin = workflow_md_thermo.analyse_structures(output_dict=result_dict)\n",
" eng_pot, eng_kin = workflow_md_thermo.analyse_structures(\n",
" output_dict=result_dict\n",
" )\n",
" thermo_eng_pot_lst.append(eng_pot)\n",
" thermo_eng_kin_lst.append(eng_kin)\n",
" lmp.close()\n",
Expand All @@ -622,7 +664,9 @@
" energy_pot_all_lst.append(thermo_eng_pot_lst)\n",
" energy_kin_all_lst.append(thermo_eng_kin_lst)\n",
" eng_lambda_dependence_lst.append(np.array(energy_mean_lst) / len(structure) * 1000)\n",
" fit = np.poly1d(np.polyfit(lambda_lst, np.array(energy_mean_lst) / len(structure) * 1000, 3))\n",
" fit = np.poly1d(\n",
" np.polyfit(lambda_lst, np.array(energy_mean_lst) / len(structure) * 1000, 3)\n",
" )\n",
" integral = np.polyint(fit)\n",
" free_energy_lst.append(integral(1.0) - integral(0.0))"
]
Expand Down Expand Up @@ -672,9 +716,17 @@
],
"source": [
"plt.title(\"Helmholtz Free Energy\")\n",
"plt.plot(term_base_dict['temperatures'], term_base_dict['free_energy'], label=\"Harmonic\")\n",
"plt.plot(term_qh_dict['temperatures'], term_qh_dict['free_energy'], label=\"Quasi-Harmonic\")\n",
"plt.plot(term_qh_dict['temperatures'], term_qh_dict['free_energy'] - np.array(free_energy_lst) / 1000, label=\"Thermodynamic Integration\")\n",
"plt.plot(\n",
" term_base_dict[\"temperatures\"], term_base_dict[\"free_energy\"], label=\"Harmonic\"\n",
")\n",
"plt.plot(\n",
" term_qh_dict[\"temperatures\"], term_qh_dict[\"free_energy\"], label=\"Quasi-Harmonic\"\n",
")\n",
"plt.plot(\n",
" term_qh_dict[\"temperatures\"],\n",
" term_qh_dict[\"free_energy\"] - np.array(free_energy_lst) / 1000,\n",
" label=\"Thermodynamic Integration\",\n",
")\n",
"plt.xlabel(\"Temperature (K)\")\n",
"plt.ylabel(\"Helmholtz Free Energy (eV)\")\n",
"plt.legend()"
Expand Down
1,228 changes: 1,227 additions & 1 deletion notebooks/lammps_workflows.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 07f54f7

Please sign in to comment.