diff --git a/website/examples/getting_started.ipynb b/website/examples/getting_started.ipynb index c399d814..2221595f 100644 --- a/website/examples/getting_started.ipynb +++ b/website/examples/getting_started.ipynb @@ -22,6 +22,24 @@ "AtomDB is tailored for accessing atomic properties and, in some cases, leveraging them to obtain approximate molecular properties (pro-molecule models). The library is designed to be lightweight and easy to use with the goal of providing first approximation when the cost of more accurate calculations is prohibitive (e.g. high size of the system like in proteins with thousands of atoms or in cases where there are thousands of different atomic species like in high-throughput screening or molecular dynamics simulations). This notebook provides a quick overview of the main features of AtomDB and how to use it as a Python script or library.\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Install dependencies\n", + "\n", + "To run this notebook in Google Colab, the AtomDB library and its dependencies need to be installed. This can be done by uncommenting and running the following cell." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ! python -m pip install git+https://github.com/theochem/AtomDB.git" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -344,11 +362,8 @@ } ], "metadata": { - "interpreter": { - "hash": "4846203d052f4918654383d2fa4dc83e5f0e073317ccb4eea0fa3b82d0bd9d45" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "dbtest", "language": "python", "name": "python3" }, @@ -362,7 +377,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/website/examples/hello_atomdb.ipynb b/website/examples/hello_atomdb.ipynb index fb916608..e6a85292 100644 --- a/website/examples/hello_atomdb.ipynb +++ b/website/examples/hello_atomdb.ipynb @@ -39,7 +39,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Packages isntall for Google Colab" + "## Packages installation for Google Colab" ] }, { @@ -89,7 +89,7 @@ "metadata": {}, "outputs": [], "source": [ - "# import sys \n", + "# import sys\n", "# sys.path.insert(0, '../../')" ] }, @@ -118,7 +118,7 @@ "\n", "# Optional modules\n", "import numpy as np\n", - "from matplotlib import pyplot\n" + "from matplotlib import pyplot" ] }, { @@ -159,10 +159,10 @@ "outputs": [], "source": [ "# Define species and load data\n", - "element = 'Cl'\n", + "element = \"Cl\"\n", "charge = 0\n", "mult = 2\n", - "dataset = 'slater'\n", + "dataset = \"slater\"\n", "\n", "chl = atomdb.load(element, charge, mult, dataset=dataset)" ] @@ -228,7 +228,7 @@ "print(\"Atomic number: \", chl.natom)\n", "print(\"Number of electrons: \", chl.nelec)\n", "print(\"Mass [a.u.]: \", chl.mass)\n", - "print(\"Atomic radius [a.u.]: \", chl.vdw_radii['bondi'])" + "print(\"Atomic radius [a.u.]: \", chl.vdw_radii[\"bondi\"])" ] }, { @@ -289,7 +289,7 @@ "outputs": [], "source": [ "# Define a uniform radial grid and evaluate density\n", - "rad_grid = np.linspace(0., 6., num=100)\n", + "rad_grid = np.linspace(0.0, 6.0, num=100)\n", "dens_spline = chl.interpolate_dens(log=True)\n", "\n", "dens = dens_spline(rad_grid)" @@ -337,26 +337,28 @@ } ], "source": [ - "pyplot.figure(figsize = (8, 6), dpi=300)\n", + "pyplot.figure(figsize=(8, 6), dpi=300)\n", "\n", "# pyplot.rcParams.update({'font.size': 16})\n", - "params = {'legend.fontsize': 'x-large',\n", - " 'axes.labelsize': 12,\n", - " 'axes.titlesize':16,\n", - " 'xtick.labelsize':10,\n", - " 'ytick.labelsize':10}\n", + "params = {\n", + " \"legend.fontsize\": \"x-large\",\n", + " \"axes.labelsize\": 12,\n", + " \"axes.titlesize\": 16,\n", + " \"xtick.labelsize\": 10,\n", + " \"ytick.labelsize\": 10,\n", + "}\n", "pyplot.rcParams.update(params)\n", "\n", "\n", "fig, ax = pyplot.subplots()\n", "\n", - "ax.plot(rad_grid, dens, '-r', linewidth=2)\n", + "ax.plot(rad_grid, dens, \"-r\", linewidth=2)\n", "\n", "ax.set(xlabel=\"Radial distance [Bohr]\", ylabel=\"Density [Bohr$^{-3}$]\")\n", - "ax.set_yscale('log')\n", + "ax.set_yscale(\"log\")\n", "ax.set_ylim(top=1000, bottom=0.00001)\n", - "ax.set_xlim(left=0., right=6)\n", - "fig.suptitle(f'Spherically averaged density')" + "ax.set_xlim(left=0.0, right=6)\n", + "fig.suptitle(f\"Spherically averaged density\")" ] }, { @@ -428,13 +430,13 @@ ], "source": [ "# Define the molecule (atoms and coordinates)\n", - "fname = 'h2o'\n", - "mol = load_one(f'data/{fname}_dimer.xyz')\n", + "fname = \"h2o\"\n", + "mol = load_one(f\"data/{fname}_dimer.xyz\")\n", "atnums = mol.atnums\n", "atcoords = mol.atcoords\n", "\n", "# Build de promolecule\n", - "dimer_promol = make_promolecule(atnums, atcoords, dataset='slater')\n", + "dimer_promol = make_promolecule(atnums, atcoords, dataset=\"slater\")\n", "\n", "print(\"Atomic mass: \", dimer_promol.mass())\n", "print(\"Electronic energy: \", -dimer_promol.energy())" @@ -454,7 +456,9 @@ "outputs": [], "source": [ "# Generate a grid\n", - "cubgrid = UniformGrid.from_molecule(atnums, atcoords, spacing=0.2, extension=5.0, rotate=False, weight=\"Trapezoid\")\n", + "cubgrid = UniformGrid.from_molecule(\n", + " atnums, atcoords, spacing=0.2, extension=5.0, rotate=False, weight=\"Trapezoid\"\n", + ")\n", "\n", "# Evaluate the pormolecule's density\n", "dimer_promol_rho = dimer_promol.density(cubgrid.points, log=True)\n", @@ -469,7 +473,7 @@ "source": [ "# Reduced density gradient\n", "def reduced_density_gradient(rho, nablarho):\n", - " coeff = 2 * (3 * np.pi ** 2) ** (1 / 3)\n", + " coeff = 2 * (3 * np.pi**2) ** (1 / 3)\n", " gradnorm = np.linalg.norm(nablarho, axis=1)\n", " return gradnorm / (coeff * rho ** (4 / 3))\n", "\n", @@ -484,8 +488,8 @@ "outputs": [], "source": [ "# Load desnity and reduced density data for a single H2O molecule\n", - "h2o_promol_rho = np.load(f'data/{fname}_promol_rho.npy')\n", - "h2o_red_gradient = np.load(f'data/{fname}_promol_reducedgradient.npy')" + "h2o_promol_rho = np.load(f\"data/{fname}_promol_rho.npy\")\n", + "h2o_red_gradient = np.load(f\"data/{fname}_promol_reducedgradient.npy\")" ] }, { @@ -512,12 +516,12 @@ "#\n", "import matplotlib.pyplot as plt\n", "\n", - "plt.scatter(dimer_promol_rho, dimer_red_gradient, label='H2O dimer')\n", - "plt.scatter(h2o_promol_rho, h2o_red_gradient, label='H2O')\n", - "plt.xlim(0., 0.3)\n", - "plt.ylim(0., 1.0)\n", - "plt.xlabel(r'$\\rho(R)$')\n", - "plt.ylabel(r'Reduced gradient')\n", + "plt.scatter(dimer_promol_rho, dimer_red_gradient, label=\"H2O dimer\")\n", + "plt.scatter(h2o_promol_rho, h2o_red_gradient, label=\"H2O\")\n", + "plt.xlim(0.0, 0.3)\n", + "plt.ylim(0.0, 1.0)\n", + "plt.xlabel(r\"$\\rho(R)$\")\n", + "plt.ylabel(r\"Reduced gradient\")\n", "plt.legend()\n", "plt.show()" ] diff --git a/website/examples/promolecule_intro.ipynb b/website/examples/promolecule_intro.ipynb index 03c8f63c..b15d8f97 100644 --- a/website/examples/promolecule_intro.ipynb +++ b/website/examples/promolecule_intro.ipynb @@ -4,11 +4,30 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Promolecule properties: Introduction\n", + "# Promolecule properties: introduction\n", "\n", "AtomDB provides basic functionality to compute promolecular properties from the atomic data. The tool is called `promolecule`.\n", "The module offers evaluation of intensive and extensive properties with the tool function `make_promolecule`.\n", "\n", + "\n", + "## Install dependencies\n", + "\n", + "To run this notebook in Google Colab, the AtomDB library and its dependencies need to be installed. This can be done by uncommenting and running the next cell." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ! python -m pip install git+https://github.com/theochem/AtomDB.git" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", "## Building a promolecule\n", "\n", @@ -42,14 +61,17 @@ "atnums = [4, 4]\n", "\n", "# Spatial coordinates of each center\n", - "atcoords = np.array( [\n", - " [-1., 0., 0.],\n", - " [1., 0., 0. ],\n", - "], dtype=float)\n", + "atcoords = np.array(\n", + " [\n", + " [-1.0, 0.0, 0.0],\n", + " [1.0, 0.0, 0.0],\n", + " ],\n", + " dtype=float,\n", + ")\n", "\n", "\n", "# Make promolecule instance\n", - "be2_promol = make_promolecule(atnums=atnums, coords=atcoords, dataset='slater')\n", + "be2_promol = make_promolecule(atnums=atnums, coords=atcoords, dataset=\"slater\")\n", "\n", "print(\"Be_{2} promolecule:\")\n", "print(\"Atomic numbers:\\n\", atnums)\n", @@ -93,10 +115,10 @@ } ], "source": [ - "print(f'Mass of Be2: {be2_promol.mass()} a.u.')\n", - "print(f'Charge of Be2: {be2_promol.charge()}')\n", - "print(f'Energies of Be2: {be2_promol.energy()} a.u.')\n", - "print(f'Number of electrons in Be2: {be2_promol.nelec()}')\n" + "print(f\"Mass of Be2: {be2_promol.mass()} a.u.\")\n", + "print(f\"Charge of Be2: {be2_promol.charge()}\")\n", + "print(f\"Energies of Be2: {be2_promol.energy()} a.u.\")\n", + "print(f\"Number of electrons in Be2: {be2_promol.nelec()}\")" ] }, { @@ -148,15 +170,15 @@ "grad_rho = be2_promol.gradient(points)\n", "ked = be2_promol.ked(points)\n", "\n", - "print(f'Electron density shape: {rho.shape}')\n", - "print(f'Electron density max: {np.max(rho)}')\n", - "print(f'Electron density min: {np.min(rho)}\\n')\n", - "print(f'Gradient of electron density shape: {grad_rho.shape}')\n", - "print(f'Gradient of electron density max: {np.max(grad_rho)}')\n", - "print(f'Gradient of electron density min: {np.min(grad_rho)}\\n')\n", - "print(f'Kinetic energy density shape: {ked.shape}')\n", - "print(f'Kinetic energy density max: {np.max(ked)}')\n", - "print(f'Kinetic energy density min: {np.min(ked)}')\n" + "print(f\"Electron density shape: {rho.shape}\")\n", + "print(f\"Electron density max: {np.max(rho)}\")\n", + "print(f\"Electron density min: {np.min(rho)}\\n\")\n", + "print(f\"Gradient of electron density shape: {grad_rho.shape}\")\n", + "print(f\"Gradient of electron density max: {np.max(grad_rho)}\")\n", + "print(f\"Gradient of electron density min: {np.min(grad_rho)}\\n\")\n", + "print(f\"Kinetic energy density shape: {ked.shape}\")\n", + "print(f\"Kinetic energy density max: {np.max(ked)}\")\n", + "print(f\"Kinetic energy density min: {np.min(ked)}\")" ] }, { @@ -192,11 +214,15 @@ "fig = plt.figure(figsize=(6, 6))\n", "ax = fig.add_subplot()\n", "rad_grid = np.linspace(-3.01, 3, 100)\n", - "promol_dens = be2_promol.density(np.array([rad_grid, np.zeros_like(rad_grid), np.zeros_like(rad_grid)]).T)\n", - "promol_grad = be2_promol.gradient(np.array([rad_grid, np.zeros_like(rad_grid), np.zeros_like(rad_grid)]).T)\n", + "promol_dens = be2_promol.density(\n", + " np.array([rad_grid, np.zeros_like(rad_grid), np.zeros_like(rad_grid)]).T\n", + ")\n", + "promol_grad = be2_promol.gradient(\n", + " np.array([rad_grid, np.zeros_like(rad_grid), np.zeros_like(rad_grid)]).T\n", + ")\n", "\n", "ax.plot(rad_grid, promol_dens, color=\"blue\", label=\"Density\")\n", - "ax.plot(rad_grid, promol_grad[:,0], color=\"red\", label=\"Gradient\")\n", + "ax.plot(rad_grid, promol_grad[:, 0], color=\"red\", label=\"Gradient\")\n", "\n", "ax.set_xlabel(\"Radial distance (a.u.)\")\n", "ax.set_ylabel(\"Property value\")\n", @@ -244,22 +270,22 @@ "# Add electron density subplot\n", "ax1 = fig.add_subplot(121)\n", "density_plot = ax1.contourf(X, Y, rho.reshape(X.shape), levels=density_levels)\n", - "ax1.set_title('Electron density of Be2')\n", - "ax1.set_xlabel('x')\n", - "ax1.set_ylabel('y')\n", - "ax1.set_aspect('equal')\n", + "ax1.set_title(\"Electron density of Be2\")\n", + "ax1.set_xlabel(\"x\")\n", + "ax1.set_ylabel(\"y\")\n", + "ax1.set_aspect(\"equal\")\n", "ax1.grid(True)\n", - "fig.colorbar(density_plot, ax=ax1, label='Electron Density')\n", + "fig.colorbar(density_plot, ax=ax1, label=\"Electron Density\")\n", "\n", "# Add kinetic energy density subplot\n", "ax2 = fig.add_subplot(122)\n", "ked_plot = ax2.contourf(X, Y, ked.reshape(X.shape), levels=ked_levels)\n", - "ax2.set_title('Kinetic energy density of Be2')\n", - "ax2.set_xlabel('x')\n", - "ax2.set_ylabel('y')\n", - "ax2.set_aspect('equal')\n", + "ax2.set_title(\"Kinetic energy density of Be2\")\n", + "ax2.set_xlabel(\"x\")\n", + "ax2.set_ylabel(\"y\")\n", + "ax2.set_aspect(\"equal\")\n", "ax2.grid(True)\n", - "fig.colorbar(ked_plot, ax=ax2, label='Kinetic Energy Density')\n", + "fig.colorbar(ked_plot, ax=ax2, label=\"Kinetic Energy Density\")\n", "\n", "# Adjust layout to prevent overlapping of labels\n", "plt.tight_layout()\n", diff --git a/website/examples/promolecule_nci.ipynb b/website/examples/promolecule_nci.ipynb index 0c97638a..812c2814 100644 --- a/website/examples/promolecule_nci.ipynb +++ b/website/examples/promolecule_nci.ipynb @@ -13,6 +13,43 @@ "The `promolecule` module in QC-AtomDB constructs approximate molecular (promolecular) properties as linear combinations of atomic properties. This allows for the fast calculation of the reduced density gradient for large molecular systems. The following examples show how to calculate several molecular properties. As model systems the water molecule dimer will be used:\n", "\n", "\"drawing\"\n", + "\n", + "\n", + "## Install dependencies and download example files\n", + "\n", + "To run this notebook in Google Colab, the AtomDB, IOData and Grid libraries need to be installed. This can be done by uncommenting and running the next cell." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# # Install packages in Google Colab.\n", + "# # Don't run this cell if packages/data is already in your environment\n", + "# ! pip install git+https://github.com/theochem/iodata.git\n", + "# ! pip install git+https://github.com/theochem/grid.git\n", + "# ! python -m pip install git+https://github.com/theochem/AtomDB.git\n", + "\n", + "# # Download the example files\n", + "# import os\n", + "# from urllib.request import urlretrieve\n", + "\n", + "# fpath = \"data/\"\n", + "# if not os.path.exists(fpath):\n", + "# os.makedirs(fpath, exist_ok=True)\n", + "\n", + "# urlretrieve(\n", + "# \"https://raw.githubusercontent.com/theochem/AtomDB/refs/heads/master/website/examples/data/h2o_dimer.xyz\",\n", + "# os.path.join(fpath, \"h2o_dimer.xyz\")\n", + "# )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", "## Loading the water dimer data:\n", "\n", @@ -28,6 +65,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "Package 'qc-AtomDB' is not installed.\n", "Atomic numbers dimer:\n", " [8. 8. 1. 1. 1. 1.]\n", "Atomic coordinates dimer:\n", @@ -53,7 +91,7 @@ "from importlib_resources import files\n", "\n", "# Load the H2O dimer from a .xyz file\n", - "data_file=files(atomdb).joinpath('../docs/notebooks/data/h2o_dimer.xyz')\n", + "data_file = files(atomdb).joinpath(\"../docs/notebooks/data/h2o_dimer.xyz\")\n", "mol_data = iodata.load_one(data_file)\n", "\n", "atnums = mol_data.atcorenums\n", @@ -66,8 +104,7 @@ "print(\"Atomic coordinates dimer:\\n\", atcoords)\n", "\n", "print(\"Atomic numbers monomer:\\n\", atnums_mono)\n", - "print(\"Atomic coordinates monomer:\\n\", atcoords_mono)\n", - "\n" + "print(\"Atomic coordinates monomer:\\n\", atcoords_mono)" ] }, { @@ -136,8 +173,8 @@ "source": [ "import numpy as np\n", "\n", - "dimer_promol = atomdb.make_promolecule(atnums=atnums, coords=atcoords, dataset='slater')\n", - "mono_promol = atomdb.make_promolecule(atnums=atnums_mono, coords=atcoords_mono, dataset='slater')\n", + "dimer_promol = atomdb.make_promolecule(atnums=atnums, coords=atcoords, dataset=\"slater\")\n", + "mono_promol = atomdb.make_promolecule(atnums=atnums_mono, coords=atcoords_mono, dataset=\"slater\")\n", "\n", "# compute the density and gradient of the density at the grid points\n", "dimer_rho = dimer_promol.density(cubgrid.points, log=True)\n", @@ -195,7 +232,7 @@ "import matplotlib.pyplot as plt\n", "\n", "# compute the reduced density gradient for the dimer\n", - "coeff = 2 * (3 * np.pi ** 2) ** (1 / 3)\n", + "coeff = 2 * (3 * np.pi**2) ** (1 / 3)\n", "dimer_grad_norm = np.linalg.norm(dimer_grad_rho, axis=1)\n", "dimer_rdg = dimer_grad_norm / (coeff * dimer_rho ** (4 / 3))\n", "\n", @@ -206,10 +243,10 @@ "import matplotlib.pyplot as plt\n", "\n", "# Plot the reduced gradient as a function of the density\n", - "plt.scatter(dimer_rho, dimer_rdg, label='Water dimer')\n", - "plt.scatter(mono_rho, mono_rdg, label='Water monomer')\n", - "plt.xlabel(r'$\\rho(R)$')\n", - "plt.ylabel(r'Reduced gradient')\n", + "plt.scatter(dimer_rho, dimer_rdg, label=\"Water dimer\")\n", + "plt.scatter(mono_rho, mono_rdg, label=\"Water monomer\")\n", + "plt.xlabel(r\"$\\rho(R)$\")\n", + "plt.ylabel(r\"Reduced gradient\")\n", "\n", "# Set y-axis limits from 0 to 1\n", "plt.ylim(0, 2)\n",