{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Create a molecule\n", "In this tutorial we present how to create a molecule and run the SCF calculation. First, the `Molecule` class must be imported :" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:09.247655Z", "iopub.status.busy": "2023-12-05T08:36:09.247417Z", "iopub.status.idle": "2023-12-05T08:36:13.594982Z", "shell.execute_reply": "2023-12-05T08:36:13.593903Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch| ____ __ ______________ _\n", "INFO:QMCTorch| / __ \\ / |/ / ___/_ __/__ ________/ / \n", "INFO:QMCTorch|/ /_/ / / /|_/ / /__ / / / _ \\/ __/ __/ _ \\ \n", "INFO:QMCTorch|\\___\\_\\/_/ /_/\\___/ /_/ \\___/_/ \\__/_//_/ \n", "INFO:QMCTorch|\n", "INFO:QMCTorch|0.4.0\n" ] } ], "source": [ "from qmctorch.scf import Molecule" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This class can interface with `pyscf` and `ADF` to perform SCF calculations. Of course both software use different types of\n", "atomic orbitals, respectively Gaussian type orbitals for `pyscf` and Slater type orbitals for `ADF`." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Geometry of the molecule\n", "\n", "\n", "The geometry of the molecule can be specified through the `atom` keyword of the `Molecule` class. The units of the positions, `bohr` or `angs` (default is 'bohr')\n", "can also be specified via the `unit` keyword argument. The geometry can be passed as a single string" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:13.598953Z", "iopub.status.busy": "2023-12-05T08:36:13.598568Z", "iopub.status.idle": "2023-12-05T08:36:14.242173Z", "shell.execute_reply": "2023-12-05T08:36:14.241415Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch|\n", "INFO:QMCTorch| SCF Calculation\n", "INFO:QMCTorch| Reusing scf results from H2_pyscf_dzp.hdf5\n" ] } ], "source": [ "mol = Molecule(atom = 'H 0. 0. 0; H 0. 0. 1.', calculator='pyscf', unit='bohr')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "or via an XYZ file containing the geomtry of the molecular structure. Note that by default `QMCTorch` will try to reuse previous calculations that might be stored in an hdf5 file. To redo the scf calculation we can use the `redo_scf=True` argument. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:14.244567Z", "iopub.status.busy": "2023-12-05T08:36:14.244372Z", "iopub.status.idle": "2023-12-05T08:36:14.980847Z", "shell.execute_reply": "2023-12-05T08:36:14.980134Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch|\n", "INFO:QMCTorch| SCF Calculation\n", "INFO:QMCTorch| Removing H2_pyscf_dzp.hdf5 and redo SCF calculations\n", "INFO:QMCTorch| Running scf calculation\n", "converged SCF energy = -1.07280585930373\n", "INFO:QMCTorch| Molecule name : H2\n", "INFO:QMCTorch| Number of electrons : 2\n", "INFO:QMCTorch| SCF calculator : pyscf\n", "INFO:QMCTorch| Basis set : dzp\n", "INFO:QMCTorch| SCF : HF\n", "INFO:QMCTorch| Number of AOs : 10\n", "INFO:QMCTorch| Number of MOs : 10\n", "INFO:QMCTorch| SCF Energy : -1.073 Hartree\n" ] } ], "source": [ "mol = Molecule(atom='h2.xyz', unit='bohr', calculator='pyscf', redo_scf=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## SCF calculations\n", "\n", "\n", "As mentionned above `QMCTorch` can use `pyscf` or `ADF` to perform SCF calculation on the molecular structure. At the moment only Hartree-Fock calculations\n", "are supported but DFT calculations will be implemented later. We present here how to perform these SCF calculations.\n", "\n", "\n", "### Gaussian orbitals with pyscf\n", "\n", "\n", "As seen above the code use by default `pyscf` to compute the atomic and molecular orbitals of the system using a `sto-3g` basis set. The default behavior is equivlament to setting `calculator=pyscf` and `basis='sto-3g'`. Let's switch to another basis, e.g. `sto-6g`" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:14.983439Z", "iopub.status.busy": "2023-12-05T08:36:14.983263Z", "iopub.status.idle": "2023-12-05T08:36:15.749731Z", "shell.execute_reply": "2023-12-05T08:36:15.748867Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch|\n", "INFO:QMCTorch| SCF Calculation\n", "INFO:QMCTorch| Removing H2_pyscf_sto-6g.hdf5 and redo SCF calculations\n", "INFO:QMCTorch| Running scf calculation\n", "converged SCF energy = -1.07589040772972\n", "INFO:QMCTorch| Molecule name : H2\n", "INFO:QMCTorch| Number of electrons : 2\n", "INFO:QMCTorch| SCF calculator : pyscf\n", "INFO:QMCTorch| Basis set : sto-6g\n", "INFO:QMCTorch| SCF : HF\n", "INFO:QMCTorch| Number of AOs : 2\n", "INFO:QMCTorch| Number of MOs : 2\n", "INFO:QMCTorch| SCF Energy : -1.076 Hartree\n" ] } ], "source": [ "mol = Molecule(atom='H 0. 0. 0; H 0. 0. 1.', unit='bohr', calculator='pyscf', basis='sto-6g', redo_scf=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The exhaustive list of supported basis set can be found here : https://pyscf.org/user/gto.html" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Slater orbitals with ADF\n", "\n", "If a valid SCM license is found QMCTorch can use `ADF`. Two calculators are available depending on the version of ADF installed:\n", "* ADF 2020+ : `calculator = 'adf'`\n", "* ADF 2019 : `calculator = 'adf2019'`\n", "\n", "So for example if ADF is installed the following command will use ADF to compute the electronic structure of the molecule." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:15.752772Z", "iopub.status.busy": "2023-12-05T08:36:15.752506Z", "iopub.status.idle": "2023-12-05T08:36:21.285175Z", "shell.execute_reply": "2023-12-05T08:36:21.284137Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch|\n", "INFO:QMCTorch| SCF Calculation\n", "INFO:QMCTorch| Running scf calculation\n", "[15.04|14:20:08] PLAMS working folder: /home/nico/QMCTorch/docs/notebooks/plams_workdir\n", "INFO:QMCTorch| Molecule name : H2\n", "INFO:QMCTorch| Number of electrons : 2\n", "INFO:QMCTorch| SCF calculator : adf\n", "INFO:QMCTorch| Basis set : dzp\n", "INFO:QMCTorch| SCF : HF\n", "INFO:QMCTorch| Number of AOs : 10\n", "INFO:QMCTorch| Number of MOs : 10\n", "INFO:QMCTorch| SCF Energy : -1.082 Hartree\n" ] } ], "source": [ "try:\n", " mol = Molecule(atom='H 0. 0. 0; H 0. 0. 1.', unit='bohr', calculator='adf', basis='dzp')\n", "except Exception as expt:\n", " print(expt)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here as well the ``basis`` keyword argument specifies the basis set used in the scf calculation.\n", "The list of supported basis set can be found here : https://www.scm.com/doc/ADF/Input/Basis_sets_and_atomic_fragments.html\n", "\n", "Additional basis sets, namely VB1, VB2, VB3, CVB1, CVB2 and CVB3, are available. These are STO valence and core-valence basis set presented by Ema et. al\n", "in \"Polarized basis sets for Slater-type orbitals: H to Ne atoms\", https://doi.org/10.1002/jcc.10227. Changing the ``basis``\n", " keyword argument to : ``basis=VB1``` will for examle use the small VB1 basis set during the SCF calculation." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Loading a SCF calculation\n", "\n", "\n", "By default QMCTorch will create a HDF5 file containing all the required information about the molecule and SCF calculation. The name of\n", "this file is given by the name of the molecule, the calculator name and the basis set, e.g. `LiH_adf_dz.hdf5` or `water_pyscf_sto3g.xyz`. This files\n", "can be loaded to instanciate the molecule object through the `load` keyword argument:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2023-12-05T08:36:21.288625Z", "iopub.status.busy": "2023-12-05T08:36:21.288333Z", "iopub.status.idle": "2023-12-05T08:36:21.308278Z", "shell.execute_reply": "2023-12-05T08:36:21.307294Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:QMCTorch|\n", "INFO:QMCTorch| SCF Calculation\n", "INFO:QMCTorch| Loading data from ./hdf5/LiH_adf_dz.hdf5\n" ] } ], "source": [ "mol = Molecule(load='./hdf5/LiH_adf_dz.hdf5')" ] } ], "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.8.0" } }, "nbformat": 4, "nbformat_minor": 4 }