{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"\n",
"(sec:mol-hessian)=\n",
"# Molecular Hessians\n",
"\n",
"This section deals with the calculation of second derivatives of the electronic energy with respect to nuclear coordinates.\n",
"While the numerical calculation of the Hessian based on an analytical gradient follows the same procedure as for the \n",
"[numerical gradient](sec:numerical-gradients),\n",
"the analytical calculation is in general much more involved than for first derivatives.\n",
"After some special aspects of the numerical calculation of second derivatives,\n",
"the calculation of the analytic Hessian at the Hartree--Fock (HF) or self-consistent field (SCF)\n",
"level of theory is described as an example, followed by the required terms for methods\n",
"based on density functional theory (DFT).\n",
"Furthermore, the calculation of other second derivatives of the energy is described briefly,\n",
"taking the example of electric field perturbations.\n",
"\n",
"\n",
"## Numerical Hessians\n",
"\n",
"If the analytical gradient is not available (and both first and second derivatives are needed),\n",
"it is more efficient to resort to an equation for the second derivative\n",
"that depends on the energy $E$ only, rather than employing one of the equations [here](sec:numerical-gradients)\n",
"with the energy itself replaced by its numerical gradient.\n",
"Assuming the energy depends on (at least) two distinct nuclear coordinates $\\xi$ and $\\chi$, the second derivative of $E$\n",
"can be calculated as\n",
"\n",
"$$\n",
"\\frac{\\mathrm{d}^2 E}{\\mathrm{d} \\chi \\mathrm{d} \\xi} \\approx \\frac{E(\\xi + \\xi_0, \\chi + \\chi_0) - E(\\xi + \\xi_0, \\chi) - E(\\xi, \\chi + \\chi_0) + 2 E(\\xi, \\chi) - E(\\xi - \\xi_0, \\chi) - E(\\xi, \\chi - \\chi_0) + E(\\xi - \\xi_0, \\chi - \\chi_0)}{2 \\xi_0 \\chi_0} \\, ,\n",
"$$\n",
"\n",
"where $\\chi_0$ and $\\xi_0$ are some small changes in the respective variable.\n",
"For the case that the deritative is taken with respect to the same nuclear coordinate, the formula simplifies to\n",
"\n",
"$$\n",
"\\frac{\\mathrm{d}^2 E}{\\mathrm{d} \\xi^2} \\approx \\frac{E(\\xi + \\xi_0, \\chi) - 2 E(\\xi, \\chi) + E(\\xi - \\xi_0, \\chi)}{\\xi_0^2} \\, .\n",
"$$\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Analytical Hessians\n",
"\n",
"The calculation of analytical second derivatives of the energy is much more involved\n",
"than for first derivatives, even for variational methods.\n",
"We restrict ourselves to SCF methods here, i.e., Hartree--Fock (HF) and density functional theory (DFT).\n",
"The difficulty comes from the fact that the derivative of the MO coefficients $\\mathbf{C}$\n",
"with respect to the perturbation $\\xi$ cannot be avoided anymore, leading to the so-called\n",
"_coupled-perturbed_ SCF equations, as shown in the following.\n",
"\n",
"### HF\n",
"\n",
"The [analytic gradient of the HF energy](sec:hf-gradients) $E_{\\text{HF}}$ with respect to a nuclear coordinate $\\xi$,\n",
"which was [previously given](eq:HF_grad_final) in MO basis, can equivalently be written in AO basis as {cite}`Pople1979`\n",
"(eq:HF_gradient_in_ao)=\n",
"```{math}\n",
"%:label: eq:HF_gradient_in_ao\n",
" \\frac{\\mathrm{d} E_{\\text{HF}}}{\\mathrm{d} \\xi} = \\sum_{\\mu \\nu} P_{\\mu \\nu} h_{\\mu \\nu}^{\\xi}\n",
"\t\t+ \\frac12 \\sum_{\\mu \\nu \\kappa \\lambda} P_{\\mu \\nu} P_{\\kappa \\lambda} \\langle \\mu \\kappa || \\nu \\lambda \\rangle^\\xi\n",
"\t\t+ \\sum_{\\mu \\nu} \\omega_{\\mu \\nu} S_{\\mu \\nu}^{\\xi} + \\frac{\\mathrm{d} V_{nn}}{\\mathrm{d} \\xi} \\, ,\n",
"```\n",
"where the HF density matrix $\\mathbf{P}$ and energy-weighted density matrix $\\boldsymbol{\\omega}$ in a real AO basis are defined as\n",
"```{math}\n",
" P_{\\mu \\nu} &= \\sum_{i} C_{\\mu i} C_{\\nu i} \\\\\n",
" \\omega_{\\mu \\nu} &= - \\sum_{i} \\varepsilon_i C_{\\mu i} C_{\\nu i}\n",
"```\n",
"\n",
"Straightforward differentiation of the [above equation](eq:HF_gradient_in_ao) with respect to another nuclear coordinate $\\chi$ gives second derivatives of the HF energy:\n",
"(eq:hf-hessian-pople)=\n",
"```{math}\n",
"%:label: eq:HF_Hessian_Pople\n",
" \\frac{\\mathrm{d}^2 E_{\\text{HF}}}{\\mathrm{d} \\chi \\mathrm{d} \\xi} &= \\sum_{\\mu \\nu} P_{\\mu \\nu} h_{\\mu \\nu}^{\\xi \\chi} + \\frac12 \\sum_{\\mu \\nu \\lambda \\sigma} P_{\\mu \\nu} P_{\\lambda \\sigma} \\langle \\mu \\lambda || \\nu \\sigma \\rangle^{\\xi \\chi} + \\sum_{\\mu \\nu} \\omega_{\\mu \\nu} S_{\\mu \\nu}^{\\xi \\chi} + \\frac{\\mathrm{d}^2 V_{nn}}{\\mathrm{d} \\chi \\mathrm{d} \\xi} \\\\\n",
" &+ \\sum_{\\mu \\nu} \\frac{\\mathrm{d} P_{\\mu \\nu}}{\\mathrm{d} \\chi} h_{\\mu \\nu}^{\\xi} + \\sum_{\\mu \\nu \\lambda \\sigma} \\frac{\\mathrm{d} P_{\\mu \\nu}}{\\mathrm{d} \\chi} P_{\\lambda \\sigma} \\langle \\mu \\lambda || \\nu \\sigma \\rangle^{\\xi} + \\sum_{\\mu \\nu} \\frac{\\mathrm{d} \\omega_{\\mu \\nu}}{\\mathrm{d} \\chi} S_{\\mu \\nu}^{\\xi}\n",
"```\n",
"\n",
"Now, the calculation of the perturbed density, which boils down to the calculation\n",
"of the perturbed MO coefficients $C_{\\mu p}^{\\chi}$, can no longer be avoided {cite}`Pople1979`.\n",
"This leads to the so-called *coupled-perturbed Hartree--Fock* (CPHF) equations,\n",
"as will be described in the following.\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(sec:cphf)=\n",
"#### CPHF equations\n",
"\n",
"The starting point are the HF equations in their basis-set form,\n",
"```{math}\n",
" \\sum_{\\nu} F_{\\mu \\nu} (\\mathbf{C}) C_{\\nu i} = \\varepsilon_i \\sum_{\\nu} S_{\\mu \\nu} C_{\\nu i} \\, ,\n",
"```\n",
"which can be differentiated and rearranged, such that one obtains {cite}`Neese2009`\n",
"(eq:derivative_hf_equations)=\n",
"```{math}\n",
"%:label: eq:derivative_hf_equations\n",
" \\sum_{\\nu} \\bigg[ \\frac{\\mathrm{d} F_{\\mu \\nu} (\\mathbf{C})}{\\mathrm{d} \\chi} C_{\\nu i}\n",
" + \\Big( F_{\\mu \\nu} (\\mathbf{C}) - \\varepsilon_i S_{\\mu \\nu} \\Big) \\frac{\\mathrm{d} C_{\\nu i}}{\\mathrm{d} \\chi} \\bigg]\n",
" = \\frac{\\mathrm{d} \\varepsilon_i}{\\mathrm{d} \\chi} \\sum_{\\nu} S_{\\mu \\nu} C_{\\nu i}\n",
" + \\varepsilon_i \\sum_{\\nu} \\frac{\\mathrm{d} S_{\\mu \\nu}}{\\mathrm{d} \\chi} C_{\\nu i} \\, .\n",
"```\n",
"\n",
"Next, an ansatz for the perturbed MO coefficients $C_{\\mu p}^{\\chi} = \\frac{\\mathrm{d} C_{\\mu p}}{\\mathrm{d} \\chi}$ needs to be made.\n",
"Since the unperturbed MOs span the same space as the AOs, but form an orthonormal set,\n",
"the perturbed MO coefficients are expanded in the basis of the unperturbed ones {cite}`Pople1979`,\n",
"(eq:perturbed_mo_coefficients)=\n",
"```{math}\n",
"%:label: eq:perturbed_mo_coefficients\n",
" C_{\\mu p}^{\\chi} &= \\sum_{q} C_{\\mu q} U_{q p}^{\\chi} \\, , \\\\\n",
"```\n",
"where the matrix $\\mathbf{U}^\\chi$ contains the unknown expansion coefficients.\n",
"By taking the derivative of the orthonormality condition $\\mathbf{C}^\\text{T} \\mathbf{SC} = \\mathbf{1}$,\n",
"or in subscript notation {cite}`Neese2009`,\n",
"```{math}\n",
" \\sum_{\\mu \\nu} C_{\\mu p} S_{\\mu \\nu} C_{\\nu q} = \\delta_{pq} \\, ,\n",
"```\n",
"it can be shown that the occupied-occupied block of $\\mathbf{U}^\\chi$\n",
"is proportional to the partial derivative of the overlap matrix,\n",
"\\begin{equation*}\n",
" U_{ij}^{\\chi} = - \\frac12 S_{ij}^{(\\chi)} \\, .\n",
"\\end{equation*}\n",
"\n",
"The virtual-virtual block $U_{ab}^{\\chi}$ is not required, and hence only the occupied-virtual block $U_{ai}^\\chi$ needs to be determined.\n",
"The total derivative of the Fock matrix $F_{\\mu \\nu}^{\\chi} = \\frac{\\mathrm{d} F_{\\mu \\nu} (\\mathbf{C})}{\\mathrm{d} \\chi}$ is given by\n",
"(eq:derivative_fock_matrix)=\n",
"```{math}\n",
"%:label: eq:derivative_fock_matrix\n",
" F_{\\mu \\nu}^{\\chi} = h_{\\mu \\nu}^{\\chi}\n",
" + \\sum_{\\kappa \\lambda} P_{\\kappa \\lambda} \\langle \\mu \\kappa || \\nu \\lambda \\rangle^{\\chi}\n",
" + \\sum_{qi} \\sum_{\\kappa \\lambda} (U_{qi}^{\\chi} C_{\\kappa q} C_{\\lambda i}\n",
" + U_{qi}^{\\chi} C_{\\kappa i} C_{\\lambda q} ) \\langle \\mu \\kappa || \\nu \\lambda \\rangle \\, ,\n",
"```\n",
"where it can be seen that the derivative of the Fock matrix also depends on the unknowns $\\mathbf{U}^{\\chi}$.\n",
"The **coupled-perturbed Hartree--Fock** (CPHF) equations are obtained by multiplying the [derivative of the HF equations](eq:derivative_hf_equations)\n",
"from the left by $C_{\\mu a}$ and summing over all $\\mu$ {cite}`Neese2009`.\n",
"The CPHF equations, whose solution yields the $U_{ai}^{\\chi}$, can be written as {cite}`Deglmann2002`\n",
"(eq:cphf-equations)=\n",
"\\begin{align*}\n",
" (\\varepsilon_i - \\varepsilon_a) U_{ai}^{\\chi} - 2 G_{ai}[U_{bj}^{\\chi}] = R_{ai}^{\\chi} \\, ,\n",
"\\end{align*}\n",
"where the right-hand side (RHS), which depends on the perturbation $\\chi$, is given by\n",
"(eq:cphf-rhs)=\n",
"\\begin{equation*}\n",
" R_{ai}^{\\chi} = F_{ai}^{(\\chi)} - \\varepsilon_{i} S_{ai}^{(\\chi)} - G_{ai}[S_{jk}^{(\\chi)}] \\, ,\n",
"\\end{equation*}\n",
"\n",
"with the partial derivative of the Fock matrix being given by\n",
"\n",
"$$\n",
"F_{pq}^{(\\chi)} = h_{pq}^{(\\chi)} + \\sum_{j} \\langle pj||qj \\rangle^{(\\chi)} \\, ,\n",
"$$\n",
"\n",
"and the matrices $\\mathbf{G}[M_{rs}^{\\chi}]$ are defined for arbitrary $M_{rs}^{\\chi}$ as {cite}`Deglmann2002`\n",
"\\begin{equation*}\n",
" G_{pq}[M_{rs}^{\\chi}] = \\sum_{\\mu \\nu} C_{\\mu p} C_{\\nu q} \\bigg[ \\sum_{\\kappa \\lambda} \\langle \\mu \\kappa || \\nu \\lambda \\rangle \\Big( \\sum_{rs} C_{\\kappa r} M_{rs}^{\\chi} C_{\\lambda s} \\Big) \\bigg] \\, .\n",
"\\end{equation*}\n",
"\n",
"It should be noted that in contrast to the first derivative of the [MP2](sec:mp2-gradients)\n",
"or [CIS](cis:label) energy, where only a single orbital-response equation had to be solved,\n",
"a response equation needs to be solved for every perturbation $\\chi$, i.e., the $3N$ Cartesian nuclear coordinates of a molecule containing $N$ atoms,\n",
"to obtain the second derivative of the HF energy.\n",
"\n",
"#### Perturbed density\n",
"Having solved for the CPHF coefficients $\\mathbf{U}^{\\chi}$, the perturbed density matrix \n",
"$\\mathbf{P}^\\chi$ can be calculated by using the chosen [ansatz](eq:perturbed_mo_coefficients) as\n",
"(eq:perturbed_density)=\n",
"```{math}\n",
"%:label: eq:perturbed_density\n",
" \\frac{\\mathrm{d} P_{\\mu \\nu}}{\\mathrm{d} \\chi} &= \\sum_{i} \\frac{\\mathrm{d}}{\\mathrm{d} \\chi} (C_{\\mu i} C_{\\nu i}) = \\sum_{i} ( C_{\\mu i}^\\chi C_{\\nu i} + C_{\\mu i} C_{\\nu i}^\\chi ) \\\\\n",
" &= - \\frac12 \\sum_{ij} ( C_{\\mu i} C_{\\nu j} S_{ij}^{(\\chi)} + C_{\\mu j} C_{\\nu i} S_{ij}^{(\\chi)} ) + \\sum_{ia} ( C_{\\mu a} C_{\\nu i} + C_{\\mu i} C_{\\nu a} ) U_{ai}^{\\chi} \\\\\n",
"```\n",
"\n",
"\n",
"As an alternative to [this equation](eq:hf-hessian-pople), the second derivatives of the HF energy can then be written\n",
"in terms of the RHS $R_{ai}^{\\chi}$, the CPHF coefficients $U_{ai}^{\\xi}$, and partial derivatives of the Fock and overlap matrices as {cite}`Deglmann2002`\n",
"```{math}\n",
"%:label: eq:HF_Hessian_Furche\n",
" \\frac{\\mathrm{d}^2 E_{\\text{HF}}}{\\mathrm{d} \\chi \\mathrm{d} \\xi} &= \\sum_{\\mu \\nu} P_{\\mu \\nu} h_{\\mu \\nu}^{\\chi \\xi}\n",
"\t+ \\frac12 \\sum_{\\mu \\nu \\lambda \\sigma} P_{\\mu \\nu} P_{\\lambda \\sigma} \\langle \\mu \\lambda || \\nu \\sigma \\rangle^{\\xi \\chi}\n",
"\t+ \\sum_{\\mu \\nu} \\omega_{\\mu \\nu} S_{\\mu \\nu}^{\\chi \\xi} + \\frac{\\mathrm{d}^2 V_{nn}}{\\mathrm{d} \\chi \\mathrm{d} \\xi} \\\\\n",
" &+ 2 \\sum_{ia} R_{ai}^{\\chi} U_{ai}^{\\xi} - \\sum_{ij} \\Big( F_{ij}^{(\\chi)} S_{ij}^{(\\xi)} + F_{ij}^{(\\xi)} S_{ij}^{(\\chi)}\n",
"\t- 2 \\varepsilon_i S_{ij}^{(\\chi)} S_{ij}^{(\\xi)} - 2 G_{ij}[S_{kl}^{(\\chi)}] S_{ij}^{(\\xi)} \\Big) \\, ,\n",
"```\n",
"where the explicit construction of the perturbed $\\mathbf{P}$ and $\\boldsymbol{\\omega}$ matrices is avoided."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### DFT\n",
"\n",
"Analogous to the case of the [ground-state gradient](sec:dft-gradients),\n",
"only some additional exchange-correlation (xc) contributions need to be considered for the\n",
"analytic DFT Hessian {cite}`Deglmann2002` compared to HF.\n",
"First of all, the Fock matrix needs to be replaced by the Kohn--Sham matrix $\\mathbf{F}$,\n",
"such that the partial derivative of the latter for a hybrid functional is given by\n",
"\n",
"$$\n",
"F_{pq}^{(\\xi)} = h_{pq}^{(\\xi)} + \\sum_{j} \\big( \\langle pj|qj \\rangle^{(\\xi)} - c_{\\text{x}} \\langle pj|jq \\rangle^{(\\xi)} \\big) + v_{pq}^{\\text{xc}(\\xi)} \\, ,\n",
"$$\n",
"\n",
"where the derivative of the xc potential $v_{pq}^{\\text{xc}}$ is given [here](eq:vxc-deriv),\n",
"and the matrices $\\mathbf{G}[M_{rs}^{\\chi}]$ also need to include a contraction with\n",
"the [xc kernel](eq:xc-potential-kernel) $f^{\\text{xc}}_{\\mu\\nu\\kappa\\lambda}$ in the same way as the Coulomb integral.\n",
"Finally, the second partial derivative of the [xc energy contribution](eq:xc-energy) $E_\\text{xc}$\n",
"with respect to two nuclear coordinates $\\xi$ and $\\zeta$ is needed, which is given as\n",
"\n",
"$$\n",
"\\frac{\\partial^2 E_\\text{xc}}{\\partial \\zeta \\partial \\xi} &= \\frac{\\partial}{\\partial \\zeta}\n",
"\\int \\frac{\\partial e_{\\text{xc}}}{\\partial \\rho} \\rho^{(\\xi)} \\mathrm{d} \\mathbf{r}\n",
"= \\frac{\\partial}{\\partial \\zeta}\n",
"\\int \\frac{\\partial e_{\\text{xc}}}{\\partial \\rho} \\sum_{\\mu\\nu} P_{\\mu\\nu} \\frac{\\partial (\\chi_{\\mu} \\chi_{\\nu})}{\\partial \\xi} \\mathrm{d} \\mathbf{r} \\\\\n",
"&= \\frac{\\partial}{\\partial \\zeta}\n",
"\\int \\frac{\\partial e_{\\text{xc}}}{\\partial \\rho} \\sum_{\\mu\\nu} P_{\\mu\\nu} \\frac{\\partial^2 (\\chi_{\\mu} \\chi_{\\nu})}{\\partial \\zeta \\partial \\xi} \\mathrm{d} \\mathbf{r}\n",
"+ \\int \\frac{\\partial^2 e_{\\text{xc}}}{\\partial \\rho \\partial \\rho'} \\rho^{(\\xi)} \\rho^{(\\zeta)} \\mathrm{d} \\mathbf{r} \\, ,\n",
"$$\n",
"\n",
"where we made use of the partial derivative of the ground-state density $\\rho^{(\\xi)}$ as given [here](eq:density-partial-deriv)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(sec:second-order-prop)=\n",
"### Second-order properties\n",
"\n",
"Analogous to the case of [first-order properties](sec:first-order-prop),\n",
"some other time-independent molecular properties can be calculated as second derivatives\n",
"of the energy $E$. As an example, consider the static dipole polarizability $\\boldsymbol{\\alpha}$,\n",
"which corresponds to the derivative of the dipole moment $\\boldsymbol{\\mu}$\n",
"with respect to an external electric field $\\boldsymbol{\\mathcal{F}}$,\n",
"\n",
"$$\n",
"\\boldsymbol{\\alpha} = \\frac{\\mathrm{d} \\boldsymbol{\\mu}}{\\mathrm{d} \\boldsymbol{\\mathcal{F}}}\n",
"\\approx \\frac{\\boldsymbol{\\mu}(\\boldsymbol{\\mathcal{F}}) - \\boldsymbol{\\mu}(-\\boldsymbol{\\mathcal{F}})}{2 \\boldsymbol{\\mathcal{F}}} \\, ,\n",
"$$\n",
"\n",
"which can be obtained numerically by calculating the (analytical) dipole moment in presence of\n",
"an external field in positive and negative direction.\n",
"Since the dipole moment is already the first derivative of the energy $E$ with respect to the field,\n",
"the polarizability is actually a second derivative,\n",
"\n",
"$$\n",
"\\boldsymbol{\\alpha} = \\frac{\\mathrm{d}^2 E}{\\mathrm{d} \\boldsymbol{\\mathcal{F}}^2} \\, ,\n",
"$$\n",
"\n",
"and as such can be referred to as a **second-order property**.\n",
"The analytic calculation at the HF or DFT level procedes analogously to the nuclear Hessian,\n",
"meaning that the [CPHF equations](eq:cphf-equations) need to be solved for the unknowns\n",
"$U_{ia}^{\\mathcal{F}}$. However, since the basis functions do not depend on the electric field,\n",
"the RHS is in this case simply given by a component $\\{ x,y,z \\}$ of the dipole integrals, $R_{ia}^{\\mathcal{F}} = \\mu_{ia}$.\n",
"As a matter of fact, this equation is then equivalent to the linear response equation with $\\omega = 0$.\n",
"Having solved for the unknown CPHF coefficients, the perturbed density is obtained from\n",
"\n",
"$$\n",
"P_{\\lambda \\kappa}^{\\mathcal{F}} = \\frac{\\mathrm{d} P_{\\lambda \\kappa}}{\\mathrm{d} \\mathcal{F}} = \\sum_{ia} \\big( C_{\\lambda i} C_{\\kappa a} + C_{\\lambda a} C_{\\kappa i} \\big) U_{ia}^{\\mathcal{F}}\n",
"$$\n",
"\n",
"and the polarizability components can be calculated as\n",
"\n",
"$$\n",
"\\alpha = \\sum_{\\kappa \\lambda} P_{\\lambda \\kappa}^{\\mathcal{F}} \\, \\mu_{\\kappa \\lambda}\n",
"$$\n",
"\n",
"for each component of the perturbed density and dipole integrals.\n",
"Another example of a second-order property is the derivative of the dipole moment with respect to\n",
"nuclear coordinates, which is needed for IR intensities.\n",
"This can be seen as a mixed second energy derivative (once with respect to nuclear coordinates, once with respect to an electric field), and is discussed in more detail [here](dipole_mom_gradient:label)."
]
},
{
"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.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}