Skip to content
Snippets Groups Projects
02-scf.ipynb 3.3 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# B.CTC: SCF\n",
    "\n",
    "In diesem Notebook werden wir einen auf das Nötigste reduzierten SCF-Code verwenden, um einen Einblick in die einzelnen Iterationen zu gewinnen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scf\n",
    "import numpy as np\n",
    "from pyscf import gto\n",
    "import plotly.graph_objects as go"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
moritz.buchhorn's avatar
moritz.buchhorn committed
    "# To build such a molecule object, specific information is required, which is defined in the following code line. (In this oversimplified case, only the molecular coordinates and the basis set are used.) With this information, PySCF can now calculate the individual system-dependent parameters.\n",
    "\n",
    "coordinates='''\n",
    "    C  0.00  0.00  0.00\n",
    "    O  0.00  1.54  0.00\n",
    "    O  0.00 -1.54  0.00\n",
    "'''\n",
    "\n",
    "mol = gto.M(atom=coordinates, basis='sto-3g')\n",
    "\n",
    "# nuclei-nuclei potential\n",
    "E_nuc  = mol.energy_nuc()\n",
    "\n",
    "# number of atomic orbitals\n",
    "NAO = mol.nao\n",
    "# number of electrons\n",
    "NEL = mol.nelectron\n",
    "\n",
    "# overlap integrals\n",
moritz.buchhorn's avatar
moritz.buchhorn committed
    "S = mol.intor('int1e_ovlp')\n",
    "# kinetic energy integrals\n",
    "T_e = mol.intor('int1e_kin')\n",
    "# electrons-nuclei potential energy integrals\n",
    "V_ne = mol.intor('int1e_nuc')\n",
    "\n",
    "# two electron Coulomb integrals\n",
    "J = mol.intor('int2e')\n",
    "\n",
    "\n",
    "Hc = scf.build_hc(T_e, V_ne)\n",
    "X = scf.build_ortho_mat(S)\n",
    "finished_scf = scf.scf(Hc,X,J, E_nuc, NAO, NEL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = go.Figure()\n",
    "\n",
    "fig.add_trace(go.Scatter(\n",
    "    x = list(range(finished_scf[\"iterations\"])),\n",
    "    y = finished_scf[\"tot_energies\"],\n",
    "))\n",
    "\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = go.Figure()\n",
    "\n",
    "orb_eigenvalues = finished_scf[\"orb_eigenvalues\"].T\n",
    "for i in range(len(orb_eigenvalues)):\n",
    "    fig.add_trace(go.Scatter(\n",
    "        x = list(range(finished_scf[\"iterations\"])),\n",
    "        y = orb_eigenvalues[i],\n",
    "    ))\n",
    "\n",
    "fig.show()"
   ]
moritz.buchhorn's avatar
moritz.buchhorn committed
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.set_printoptions(suppress=True, precision=2)\n",
    "[print((\"{:6.2f}\"*len(line)).format(*line)) for line in finished_scf[\"coefficients\"][-1].T]\n",
    "# finished_scf[\"coefficients\"][70].T"
   ]
  "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",
moritz.buchhorn's avatar
moritz.buchhorn committed
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}