Skip to content

Commit

Permalink
Add dependencies installation instructions for colab (#117)
Browse files Browse the repository at this point in the history
* Add dependencies installation for colab.

* Minor update to molecular coordinates file path.

* Fix path to H2O dimer coordinates to work locally and with colab.

* Fix typo and cleaning up

* Cleaning up promolecule nci notebook

---------

Co-authored-by: Gabriela Sánchez Díaz <[email protected]>, Fanwang Meng <[email protected]>
  • Loading branch information
gabrielasd and FanwangM authored Oct 5, 2024
1 parent 18f3c93 commit ecddd4b
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 77 deletions.
25 changes: 20 additions & 5 deletions website/examples/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -344,11 +362,8 @@
}
],
"metadata": {
"interpreter": {
"hash": "4846203d052f4918654383d2fa4dc83e5f0e073317ccb4eea0fa3b82d0bd9d45"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "dbtest",
"language": "python",
"name": "python3"
},
Expand All @@ -362,7 +377,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
64 changes: 34 additions & 30 deletions website/examples/hello_atomdb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Packages isntall for Google Colab"
"## Packages installation for Google Colab"
]
},
{
Expand Down Expand Up @@ -89,7 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"# import sys \n",
"# import sys\n",
"# sys.path.insert(0, '../../')"
]
},
Expand Down Expand Up @@ -118,7 +118,7 @@
"\n",
"# Optional modules\n",
"import numpy as np\n",
"from matplotlib import pyplot\n"
"from matplotlib import pyplot"
]
},
{
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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\"])"
]
},
{
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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\")"
]
},
{
Expand Down Expand Up @@ -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())"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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\")"
]
},
{
Expand All @@ -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()"
]
Expand Down
90 changes: 58 additions & 32 deletions website/examples/promolecule_intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()}\")"
]
},
{
Expand Down Expand Up @@ -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)}\")"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit ecddd4b

Please sign in to comment.