{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# XYG3 型密度泛函" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "这一节我们讨论 XYG3 型密度泛函 (XYG3 type of Double Hybrid density functional, xDH)。后续文档的目标就是推导 XYG3 型泛函的一阶梯度与二阶梯度。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyscf import scf, gto, dft, mp\n", "import numpy as np\n", "from functools import partial\n", "import warnings\n", "\n", "from pkg_resources import resource_filename\n", "from pyxdh.Utilities import FormchkInterface\n", "from pyxdh.Utilities.test_molecules import Mol_H2O2\n", "from pyxdh.DerivOnce import GradXDH\n", "\n", "warnings.filterwarnings(\"ignore\")\n", "np.einsum = partial(np.einsum, optimize=[\"greedy\", 1024 ** 3 * 2 / 8])\n", "np.set_printoptions(5, linewidth=150, suppress=True)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "mol = Mol_H2O2().mol\n", "grids = Mol_H2O2().gen_grids()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 量化软件的 XYG3 计算" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Gaussian 计算" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "在一个内部版本的 Gaussian 中,我们可以获得 H2O2 分子的 XYG3 下,6-31G 基组、(99, 590) 格点的非冻核近似的计算结果;这个结果的输入卡与 formchk 文件也已经在 pyxdh 的库中。调取方式如下:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-151.1962822786802" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ref_fchk = FormchkInterface(resource_filename(\"pyxdh\", \"Validation/gaussian/H2O2-XYG3-force.fchk\"))\n", "ref_fchk.total_energy()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### PySCF 计算" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "为了实现 XYG3 的计算,我们需要对 B2PLYP 与非自洽泛函的计算过程有大致印象;但我们将为了方便后文,重新定义记号。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "**记号说明**\n", "\n", "为了记号简便,在一篇文档讨论确定的泛函时 (这篇文档讨论 XYG3 泛函),会将泛函名称忽略不写。\n", "\n", "- XYG3 包含 PT2 与普通非自洽泛函的贡献部分,分别记作 $c_\\mathrm{c} E_\\mathrm{c, PT2}$ 与 $E_\\mathrm{xc, n}$。其中,$c_\\mathrm{c}$ 是 PT2 贡献的系数。\n", "\n", "- 普通非自洽泛函 $E_\\mathrm{xc, n}$ 可以分为 HF 型交换能 $c_\\mathrm{x}^\\mathrm{n} E_\\mathrm{x, exact}$ 与纯 GGA 交换相关能 $E_\\mathrm{GGA, n}$。\n", "\n", "- 相应地,自洽泛函 $E_\\mathrm{xc}$ 可以分为 HF 型交换能 $c_\\mathrm{x} E_\\mathrm{x, exact}$ 与纯 GGA 交换相关能 $E_\\mathrm{GGA}$。\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "对于 XYG3 而言,自洽泛函 `scf_eng` 是 B3LYP:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-151.37754356054216" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scf_eng = dft.RKS(mol)\n", "scf_eng.conv_tol = 1e-11\n", "scf_eng.conv_tol_grad = 1e-9\n", "scf_eng.xc = \"B3LYPg\"\n", "scf_eng.grids = grids\n", "scf_eng.kernel()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "其非自洽泛函的形式根据文献 式 (12),为\n", "\n", "$$\n", "E_\\mathrm{xc, xDH} = E_\\mathrm{xc, LDA} + c_1 (E_\\mathrm{x, exact} - E_\\mathrm{x, LDA}) + c_2 \\Delta E_\\mathrm{x, GGA} + c_3 (E_\\mathrm{c, PT2} - E_\\mathrm{c, LDA}) + c_4 \\Delta E_\\mathrm{c, GGA}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "上式是一个普遍的双杂化泛函的框架。对于 XYG3 泛函本身而言,\n", "\n", "$$\n", "c_1 = c_\\mathrm{x}^\\mathrm{n} = 0.8033, \\quad c_2 = 0.2107, \\quad c_3 = c_\\mathrm{c} = 0.3211\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "因此有\n", "\n", "$$\n", "\\begin{align}\n", "E_\\mathrm{xc, XYG3} &= 0.3211 E_\\mathrm{c, PT2} + E_\\mathrm{xc, n} \\\\\n", "E_\\mathrm{xc, n} &= 0.8033 E_\\mathrm{x, exact} + E_\\mathrm{GGA, n} \\\\\n", "E_\\mathrm{GGA, n} &= 0.2107 E_\\mathrm{x, B88} - 0.0140 E_\\mathrm{x, LDA} + 0.6789 E_\\mathrm{c, LYP}\n", "\\end{align}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "通过上述关系,我们可以定义与 $E_\\mathrm{xc, n}$ 有关的 `nc_eng`:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "nc_eng = dft.RKS(mol)\n", "nc_eng.xc = \"0.8033*HF - 0.0140*LDA + 0.2107*B88, 0.6789*LYP\"\n", "nc_eng.grids = grids" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "以及与 $E_\\mathrm{c, PT2}$ 有关的 `mp2_eng` 和 PT2 相关系数 `c_c` $\\mathrm{c_c}$:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c_c = 0.3211\n", "mp2_eng = mp.MP2(scf_eng)\n", "mp2_eng.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "我们将非自洽普通交换相关能量与 PT2 部分能量求和,得到 XYG3 能量:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-151.1962818850459" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e_XYG3 = nc_eng.energy_tot(dm=scf_eng.make_rdm1()) + c_c * mp2_eng.e_corr\n", "e_XYG3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "我们可以与 Gaussian 计算结果进行比较:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(e_XYG3, ref_fchk.total_energy())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### pyxdh 计算" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "pyxdh 计算 XYG3 的单点能与 HF-B3LYP、B2PLYP 仍然是很类似的。但我们需要注意到,我们同时需要像 HF-B3LYP 一样给出自洽泛函部分与非自洽泛函部分;同时需要指定 PT2 相关系数 $c_\\mathrm{c} = 0.3211$。" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "config = {\n", " \"scf_eng\": scf_eng,\n", " \"nc_eng\": nc_eng,\n", " \"cc\": 0.3211\n", "}\n", "xyg3h = GradXDH(config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "随后就可以立即获得 XYG3 的总能量了:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-151.1962818850459" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xyg3h.eng" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "显然上述的 XYG3 确实是基本正确的:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(xyg3h.eng, ref_fchk.total_energy())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 参考文献" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. bibliography:: basic_xyg3.bib\n", " :cited:\n", " :style: alpha" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3", "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.7.3" }, "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": false } }, "nbformat": 4, "nbformat_minor": 2 }