{
"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",
" size | \n",
" type | \n",
"
\n",
" \n",
" object | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" METADATA | \n",
" 48 | \n",
" - | \n",
"
\n",
" \n",
" WIDGET | \n",
" 0 | \n",
" - | \n",
"
\n",
" \n",
" atom | \n",
" 985706 | \n",
" exatomic.core.atom.Atom | \n",
"
\n",
" \n",
" frame | \n",
" 1616 | \n",
" exatomic.core.frame.Frame | \n",
"
\n",
" \n",
"
\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",
" symbol | \n",
" x | \n",
" y | \n",
" z | \n",
" frame | \n",
"
\n",
" \n",
" atom | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Rh | \n",
" 19.3251 | \n",
" 20.99490 | \n",
" 12.9253 | \n",
" 0 | \n",
"
\n",
" \n",
" 1 | \n",
" Rh | \n",
" 20.8605 | \n",
" 19.40470 | \n",
" 17.0475 | \n",
" 0 | \n",
"
\n",
" \n",
" 2 | \n",
" Cl | \n",
" 32.7903 | \n",
" 9.48909 | \n",
" 27.4356 | \n",
" 0 | \n",
"
\n",
" \n",
" 3 | \n",
" Cl | \n",
" 27.2017 | \n",
" 10.59920 | \n",
" 26.4768 | \n",
" 0 | \n",
"
\n",
" \n",
" 4 | \n",
" Cl | \n",
" 39.1224 | \n",
" 25.75620 | \n",
" 13.6518 | \n",
" 0 | \n",
"
\n",
" \n",
"
\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",
" frame | \n",
" idx | \n",
" two | \n",
" atom | \n",
" molecule | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 18 | \n",
" 421055 | \n",
" 5186 | \n",
" 890 | \n",
"
\n",
" \n",
" 1 | \n",
" 0 | \n",
" 26 | \n",
" 420722 | \n",
" 4930 | \n",
" 879 | \n",
"
\n",
" \n",
" 2 | \n",
" 0 | \n",
" 30 | \n",
" 420997 | \n",
" 5083 | \n",
" 859 | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" 34 | \n",
" 420801 | \n",
" 5090 | \n",
" 857 | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" 35 | \n",
" 420834 | \n",
" 5155 | \n",
" 881 | \n",
"
\n",
" \n",
"
\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
}