{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing System objects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook, experimental plotting methods of `pyscal` is illustrated. The plotting functionality works only through jupyter notebooks or jupyter lab. It depends on ipywidgets and plotly to render the output. There is some extra configuration that needs to be done which can be found [here](https://plotly.com/python/getting-started/).\n", "\n", "In short, for jupyter lab (>3):\n", "\n", "```\n", "pip install \"jupyterlab>=3\" \"ipywidgets>=7.6\" \n", "pip install jupyter-dash \n", "```\n", "\n", "In notebooks:\n", "\n", "```\n", "pip install \"notebook>=5.3\" \"ipywidgets>=7.5\" \n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by importing the necessary modules" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pyscal as pc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can set up a system and read in a file to be visualized" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sys = pc.System()\n", "sys.read_inputfile(\"conf8k.dump\", customkeys=[\"vx\", \"vy\", \"vz\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will further calculate some q values and also the solid particles in the system which will be used later for visualization" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "448" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.find_neighbors(method=\"cutoff\", cutoff=0)\n", "sys.calculate_q([4, 5, 6], averaged=True)\n", "sys.find_solids()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to visualize the system, the `show` method can be used. This method renders a widget which a slider for the radius of atoms and a text box for entering the colormap to be used for coloring atoms. A list of colormaps can be [found here](https://plotly.com/python/builtin-colorscales/). The widget also has a `Render plot` button which will generate the plot." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "002847d946fa4b4f91924792f950a5dd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=1.0, description='radius', max=30.0, min=1.0, step=1.0), Text(value='S…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sys.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is just a general rendering of the system. Further customization can be done. For example, we can color the atoms using the averaged q6 values." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1b5e39c638be41caac1f6c52d3460086", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=1.0, description='radius', max=30.0, min=1.0, step=1.0), Text(value='S…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sys.show(colorby=\"aq6\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also select which atoms are to be plotted. For example we can refine the figure to only plot the atoms that are identified as solid in the `find_solids` method." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dfe06ea403b841edbd0ac043b9bdf28c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=1.0, description='radius', max=30.0, min=1.0, step=1.0), Text(value='S…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sys.show(colorby=\"aq6\", filterby=\"solid\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Any atom property can used to color the map. These include any [Atom attribute](https://docs.pyscal.org/en/latest/pyscal.html#pyscal.catom.Atom), calculated q values which can be accessed by `qx` or `aqx`, for traditional and averaged Steinhardts parameters respectively. `x` stands for the number of q. It can also be attributes that are stored in the [Atom.custom](https://docs.pyscal.org/en/latest/pyscal.html#pyscal.catom.Atom.custom) variable. In the above code bit, when the file was read in, the custom variable was used to read in the velocities for each atom. We will color atoms using the velocity in x direction, that is `vx` attribute." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c6e0881cda6f46dbb012b3c2f7fd66f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=1.0, description='radius', max=30.0, min=1.0, step=1.0), Text(value='S…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sys.show(colorby=\"vx\")" ] } ], "metadata": { "kernelspec": { "display_name": "pyscal-test", "language": "python", "name": "pyscal-test" }, "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.9.7" } }, "nbformat": 4, "nbformat_minor": 4 }