{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Extraction of cluster geometries from a trajectory" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from exa.util import isotopes\n", "import exatomic\n", "from exatomic.core.two import compute_atom_two_out_of_core # If we need to compute atom_two out of core (low RAM)\n", "from exatomic.algorithms.neighbors import periodic_nearest_neighbors_by_atom # Only valid for simple cubic periodic cells\n", "from exatomic.base import resource # Helper function to find the path to an example file" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "xyzpath = resource(\"rh2.traj.xyz\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "xyz = exatomic.XYZ(xyzpath) # Editor that can parse the XYZ file and build a universe!" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "u = xyz.to_universe() # Parse the XYZ data to a universe" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sizetype
object
METADATA48-
WIDGET0-
atom985706exatomic.core.atom.Atom
frame1616exatomic.core.frame.Frame
\n", "
" ], "text/plain": [ " size type\n", "object \n", "METADATA 48 -\n", "WIDGET 0 -\n", "atom 985706 exatomic.core.atom.Atom\n", "frame 1616 exatomic.core.frame.Frame" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u.info() # Current tables" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Add the unit cell dimensions to the frame table of the universe\n", "a = 37.08946302\n", "for i, q in enumerate((\"x\", \"y\", \"z\")):\n", " for j, r in enumerate((\"i\", \"j\", \"k\")):\n", " if i == j:\n", " u.frame[q+r] = a\n", " else:\n", " u.frame[q+r] = 0.0\n", " u.frame[\"o\"+q] = 0.0\n", "u.frame['periodic'] = True" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "101" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(u) # Number of steps in this trajectory (small for example purposes)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.3621574999999995" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isotopes.Rh.radius # Default Rh (covalent) radius" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### To extract clusters from the trajectory, we don't need to pre-compute atom_two" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
symbolxyzframe
atom
0Rh19.325120.9949012.92530
1Rh20.860519.4047017.04750
2Cl32.79039.4890927.43560
3Cl27.201710.5992026.47680
4Cl39.122425.7562013.65180
\n", "
" ], "text/plain": [ "DataFrame(5, 5)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u.atom.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, description='Slicing:')" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 2min 20s, sys: 2min 35s, total: 4min 56s\n", "Wall time: 5min 20s\n" ] } ], "source": [ "%%time\n", "dct = periodic_nearest_neighbors_by_atom(u, # Universe with all frames from which we want to extract clusters\n", " \"Rh\", # Source atom from which we will search for neighbors\n", " a, # Cubic cell dimension\n", " # Cluster sizes we want\n", " [0, 1, 2, 3, 4, 8, 12, 16],\n", " # Additional arguments to be passed to the atomic two body calculation\n", " # Note that it is critical to increase dmax (in compute_atom_two)!!!\n", " Rh=2.6, dmax=a/2)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['nearest', 0, 1, 2, 3, 4, 8, 12, 16])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dct.keys() # 'dct' is a dictionary containing our clustered universes as well as the sorted neighbor list (per frame)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
frameidxtwoatommolecule
00184210555186890
10264207224930879
20304209975083859
30344208015090857
40354208345155881
\n", "
" ], "text/plain": [ " frame idx two atom molecule\n", "0 0 18 421055 5186 890\n", "1 0 26 420722 4930 879\n", "2 0 30 420997 5083 859\n", "3 0 34 420801 5090 857\n", "4 0 35 420834 5155 881" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dct['nearest'].head() # Table of sorted indexes of nearest molecules to \"Rh\" in each frame" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "exatomic.UniverseWidget(dct[0]) # Just the analyte" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "exatomic.UniverseWidget(dct[16]) # View the universe with 16 nearest molecules" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If we had wanted to view the entire universe..." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 3.17 s, sys: 281 ms, total: 3.45 s\n", "Wall time: 3.51 s\n" ] } ], "source": [ "%time u.compute_atom_two(Rh=2.6) # Compute atom two body data with slightly larger Rh radius\n", "# OR\n", "#%time compute_atom_two_out_of_core(\"atom_two.hdf\", u, a, Rh=2.6) # Writes the two body data to \"atom_two.hdf\" with keys \"frame_{index}/atom_two\"" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10.53761100769043" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u.memory_usage().sum()/1024**2 # RAM usage (MB)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "exatomic.UniverseWidget(u)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.4" } }, "nbformat": 4, "nbformat_minor": 4 }