{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "10444b16-f852-48eb-ab46-b5ce43e962b3",
   "metadata": {},
   "source": [
    "<table border=\"0\">\n",
    " <tr>\n",
    "    <td style=\"width:30%\"><img src=\"img/potentials_logo.png\" width=\"100%\" align=\"justify\"></td>\n",
    "    <td style=\"width:70%\"> <p style=\"width:100%;color:#B71C1C;font-size:24px;text-align:justify\"> From electrons to phase diagrams </p> <p style=\"width:100%,font-size:16px\">Day 03 Tutorial</td>\n",
    " </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad615a36-1703-4c42-822f-062109a99e3b",
   "metadata": {},
   "source": [
    "In this notebook, we will use the potentials fitted in the previous days for the calculation of thermodynamic properties such as Helmholtz and Gibbs free energies, which in turn can be used for the calculation of phase diagrams. We will discuss calphy, the tool for automated calculation of free energies, and the methology involved.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b8152d6-5edb-4be2-9d7b-2b80017f70bb",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfdfcbbf-cc13-4b43-8b6e-31bc25cd4212",
   "metadata": {},
   "source": [
    "### <font style=\"color:#B71C1C\" face=\"Helvetica\" > Phase diagrams and how to calculate them </font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c53d510c-cd30-4e38-9a42-1d84132c0e19",
   "metadata": {},
   "source": [
    "<table border=\"0\">\n",
    " <tr>\n",
    "    <td style=\"width:40%\"><img src=\"img/phase_dia_1.png\" width=\"100%\" align=\"justify\"></td>\n",
    "    <td style=\"width:60%\"> <p style=\"font-size:14px\">Phase diagrams provide a wealth of information such as: coexisting lines, melting temperature, phase stability, nucleation mechanism. </p></td>\n",
    " </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61ecb35b-a285-45d8-a8e5-a6a1f62d6459",
   "metadata": {},
   "source": [
    "### <font style=\"color:#B71C1C\" face=\"Helvetica\" > Calculation of phase diagrams: the essential ingredients</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d819917-9a56-4589-9627-baff1e4296f3",
   "metadata": {},
   "source": [
    "<table border=\"0\">\n",
    " <tr>\n",
    "    <td style=\"width:50%\"><img src=\"img/cimg4.png\" width=\"100%\" align=\"justify\"></td>\n",
    "    <td style=\"width:50%\"> <p style=\"font-size:14px\">Phase diagrams can be evaluated from free energy diagrams. <br> <br>\n",
    "        The required input are: <br> <br>\n",
    "        &#9679; $G(P, T)$ for unary systems <br>\n",
    "        &#9679; $G(x, T)$ for binary systems </p></td>\n",
    " </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6198fc41-3bc2-4436-a272-1a168e44307a",
   "metadata": {},
   "source": [
    "### <font style=\"color:#B71C1C\" face=\"Helvetica\" > Calculation of free energies: Thermodynamic integration </font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "607f3c8d-4e49-4fb6-be8d-39999eba5f7b",
   "metadata": {},
   "source": [
    "<img src=\"img/fig1.png\" width=\"1000\">"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bab199b-a1a0-42eb-a595-cd545d23873a",
   "metadata": {},
   "source": [
    "- free energy of reference system are known: Einstein crystal, [Uhlenbeck-Ford model](https://doi.org/10.1063/1.4967775)\n",
    "- the two systems are coupled by \n",
    "$$\n",
    "H(\\lambda) = \\lambda H_f + (1-\\lambda)\\lambda H_i\n",
    "$$\n",
    "- Run calculations for each $\\lambda$ and integrate \n",
    "$$\n",
    "G_f = G_i + \\int_{\\lambda=0}^1 d\\lambda \\bigg \\langle  \\frac{\\partial H(\\lambda)}{\\partial \\lambda } \\bigg \\rangle\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4756bb61-6a01-48f8-98b1-9d076b7dccc0",
   "metadata": {},
   "source": [
    "To calculate $F$,\n",
    "\n",
    "- for each phase\n",
    "    - for each pressure\n",
    "        - for each temperature\n",
    "            - for each $\\lambda$\n",
    "\n",
    "If we choose 100 different $\\lambda$ values; 100 calculations are needed for each temperature and pressure! \n",
    "\n",
    "**Dimensionality: (phase, $P$, $T$, $\\lambda$)**\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ab61ee6-2273-408b-aad5-329601bf79a3",
   "metadata": {},
   "source": [
    "### <font style=\"color:#B71C1C\" face=\"Helvetica\" > Speeding things up: Non-equilibrium calculations </font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4a61c05-3f8c-47ff-b01a-8ae2c3672998",
   "metadata": {},
   "source": [
    "##### Non-Equilibrium Hamiltonian Interpolation\n",
    "\n",
    "<img src=\"img/cimg5.png\" width=\"600\">"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb228e05-ae48-4150-a033-9e0004f09db6",
   "metadata": {},
   "source": [
    "In this method:\n",
    "\n",
    "- Discrete $\\lambda$ parameter is replaced by a time dependent $\\lambda(t)$\n",
    "- Instead of running calculations at each $\\lambda$, run a single, short, non-equilibrium calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7968c6d8-f410-499f-9341-5abb6243f0a2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pyiron-atom-dev",
   "language": "python",
   "name": "pyiron-atom-dev"
  },
  "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.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}