{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing custom periodic tables\n", "\n", "In this tutorial you'll how to use `mendeleev` to create customized visualizations of the periodic table.\n", "\n", "The most convenient method to use for this is `periodic_table` function from `mendeleev.vis` module." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from mendeleev.vis import periodic_table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make sure you you have optional `vis` dependencies installed when installing `mendeleev`. If you are using [pip](https://pip.pypa.io/en/stable/) install with\n", "\n", "```bash\n", "pip install mendeleev[vis]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To see the default visualization of the periodic table simply call the imported function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`mendeleev` stores also two color schemes for atoms that are frequently used for visualizing molecular structures. One set is stored in the `cpk_color` column and refers to [CPK](https://en.wikipedia.org/wiki/CPK_coloring) coloring, another is stored in `jmol_color` column and is used by the [Jmol program](http://jmol.sourceforge.net/jscolors/), finally there is also coloring scheme from [MOLCAS GV](http://www.molcas.org/GV/) program store in the `molcas_gv_color` attribute. They can be displayed either by hovering of the element to display a tooltip or used directly to color the element cells." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(colorby='jmol_color', title=\"JMol Colors\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(colorby='cpk_color', title='CPK Colors')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(colorby='molcas_gv_color', title='MOLCAS GV Colors')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing properties \n", "\n", "Any of the properties in `mendeleev` can now be visualized and color coded. This means that the value of selected attribute will be visible on each element and also it is possible to use the attribute to color code the background of each element. \n", "\n", "Let's first use the `covalent_radius_pyykko` and display the values with the default color coding by `series`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='covalent_radius_pyykko', title=\"Covalent Radii of Pyykko\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's use the same attribute but in addition color code by the actual values, by adding `colorby='attribute'` argument" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='covalent_radius_pyykko', colorby='attribute', title=\"Covalent Radii of Pyykko\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The color map can aslo be csutomized using the `cmap` argument to any of the [standard colormaps](http://matplotlib.org/users/colormaps.html) available in matplotlib" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='covalent_radius_pyykko', colorby='attribute',\n", " cmap='spring', title=\"Covalent Radii of Pyykko\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let also see one of the more modern colormaps: `viridis`, `plasma`, `inferno` and `magma`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='covalent_radius_pyykko', colorby='attribute',\n", " cmap='inferno', title=\"Covalent Radii of Pyykko\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets try a different property: `atomic_volume`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='atomic_volume', colorby='attribute', title='Atomic Volume')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(attribute='en_pauling', colorby='attribute',\n", " title=\"Pauling's Electronegativity\", cmap='viridis')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Wide 32-column version\n", "\n", "The `periodic_table` function can also present the periodic table in the so-called wide format with the *f*-block between the *s*- and *d*-blocks resulting in 32 columns." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "periodic_table(height=600, width=1500, wide_layout=True)" ] } ], "metadata": { "anaconda-cloud": {}, "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.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }