{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# QCElemental\n", "\n", "QCElemental is a general purpose utility library that covers many fundamental areas of practical quantum chemistry:\n", "\n", "- QCSchema models for input and output\n", "- Molecule parsing\n", "- Unit support\n", "- Canonical physical quantities\n", "\n", "Full [QCElemental documentation](http://docs.qcarchive.molssi.org/projects/QCElemental) is available." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Molecule Parsing and Models" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import qcelemental as qcel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The [MolSSI QCSchema](https://github.com/MolSSI/QCSchema) has been implemented in utility classes within QCElemental. \n", "Models can be created in a number of different ways, here we pull caffeine from pubchem." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\tSearching PubChem database for caffeine (single best match returned)\n", "\tFound 1 result(s)\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qcel.models.Molecule.from_data(\"pubchem:caffeine\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "More canonical forms are also available, for example we can import a geometry from a string:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "water = qcel.models.Molecule.from_data(\"\"\"\n", "-1 2\n", "O 0 0 0\n", "H 0 0 1\n", "H 0 1 0\n", "\"\"\")\n", "water" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition to visualization, there are many helper functions which can provide data about the molecule or can perform a variety of actions. \n", "It should be noted that all quantities are in atomic units." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Molecular Charge: -1.0\n", "Molecular Multiplicity: 2\n", "O-H distance (Bohr): 1.88972613\n", "H-O-H angle (degrees): 90.0\n", "\n", "Water coordinates (Bohr):\n", "[[0. 0. 0. ]\n", " [0. 0. 1.88972613]\n", " [0. 1.88972613 0. ]]\n" ] } ], "source": [ "print(f\"Molecular Charge: {water.molecular_charge}\")\n", "print(f\"Molecular Multiplicity: {water.molecular_multiplicity}\")\n", "print(f\"O-H distance (Bohr): {water.measure([0, 1])}\")\n", "print(f\"H-O-H angle (degrees): {water.measure([1, 0, 2])}\")\n", "print(\"\\nWater coordinates (Bohr):\")\n", "print(water.geometry)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Unit Support\n", "\n", "Unit conversion between arbitrary units is supported out of the box. \n", "By default, [2014 CODATA](https://ws680.nist.gov/publication/get_pdf.cfm?pub_id=920686) is used." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.52917721067" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qcel.constants.conversion_factor(\"bohr\", \"Angstrom\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.52917721067" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qcel.constants.bohr2angstroms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compound units are input with python-like syntax. " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.269253498179915e+18" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qcel.constants.conversion_factor(\"hartree / bohr ** 2\", \"eV / inches ** 2\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition to straight conversion factors, QCElemental supports [Pint](https://pint.readthedocs.io/en/0.9/) `Quantity` objects.\n", "Python floats and numpy arrays are supported for values." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3 bohr\n", "9.864464228965342e-14 mile\n" ] } ], "source": [ "distance = qcel.constants.Quantity(\"3 Bohr\")\n", "print(distance)\n", "print(distance.to(\"mile\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QCElemental's implementation of a Pint context includes many computational chemistry specific translations." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hartree -> kelvin: 315775.13\n", "hartree -> kilogram: 4.850870129000001e-35\n" ] } ], "source": [ "print(f\"hartree -> kelvin: {qcel.constants.conversion_factor('hartree', 'kelvin')}\")\n", "print(f\"hartree -> kilogram: {qcel.constants.conversion_factor('hartree', 'kilogram')}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Physical Quantities\n", "\n", "QCElemental can provide many canonical quantities from a variety of standard names:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12.0\n", "12.0\n", "12.0\n", "12.0\n" ] } ], "source": [ "print(qcel.periodictable.to_mass(6))\n", "print(qcel.periodictable.to_mass(\"C\"))\n", "print(qcel.periodictable.to_mass(\"C12\"))\n", "print(qcel.periodictable.to_mass(\"Carbon\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusion\n", "\n", "These are some of the capabilities QCElemental offers, check out more [documentation](http://docs.qcarchive.molssi.org/projects/QCElemental). \n", "If you like the project, consider starring us on [GitHub](https://github.com/MolSSI/QCElemental) or if you have any questions, join our [Slack](https://join.slack.com/t/qcdb/shared_invite/enQtNDIzNTQ2OTExODk0LWM3OTgxN2ExYTlkMTlkZjA0OTExZDlmNGRlY2M4NWJlNDlkZGQyYWUxOTJmMzc3M2VlYzZjMjgxMDRkYzFmOTE) channel." ] } ], "metadata": { "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" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 2 }