{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Building Systems with Roto-Translations\n", "For building systems programatically, PyBigDFT offers some helper routines based on the concept of rototranslations. Using these features, we can easily align molecules in space." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Rotations and Translations\n", "Let's begin by showing the basics of rotating and translating molecules." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from BigDFT.IO import XYZReader\n", "from BigDFT.Systems import System\n", "from BigDFT.Fragments import Fragment\n", "\n", "sys = System()\n", "sys[\"WAT:0\"] = Fragment()\n", "with XYZReader(\"H2O\") as ifile:\n", " for at in ifile:\n", " sys[\"WAT:0\"] += Fragment([at])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Translation. Note that the units are atomic units." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from copy import deepcopy\n", "sys[\"WAT:1\"] = deepcopy(sys[\"WAT:0\"])\n", "sys[\"WAT:1\"].translate([-10, 0, 0])" ] }, { "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" } ], "source": [ "from BigDFT.Visualization import InlineVisualizer\n", "viz = InlineVisualizer(400,300)\n", "viz.display_system(sys)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Rotation. We can pick our units of degrees or angstroems." ] }, { "cell_type": "code", "execution_count": 4, "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" } ], "source": [ "sys[\"WAT:1\"].rotate(x=90, units=\"degrees\")\n", "viz = InlineVisualizer(400,300)\n", "viz.display_system(sys)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fragment Interpolation\n", "We can interpolate between two fragments if we wish to examine some intermediary states." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from BigDFT.Fragments import interpolate_fragments\n", "steps = interpolate_fragments(sys[\"WAT:0\"], sys[\"WAT:1\"], steps=3)\n", "\n", "sys2 = System()\n", "for i, s in enumerate(steps):\n", " sys2[\"WAT:\"+str(i)] = s" ] }, { "cell_type": "code", "execution_count": 6, "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" } ], "source": [ "viz = InlineVisualizer(400,300)\n", "viz.display_system(sys2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lining Up Fragments\n", "Sometimes we have two fragments which are made of the same atoms, but one geometry is perturbed from another. We might wish to try lining up those fragments so we can figure out how big that pertubation is." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from BigDFT.Fragments import RotoTranslation\n", "rtsys = System()\n", "rtsys[\"WAT:0\"] = deepcopy(sys[\"WAT:0\"])\n", "rtsys[\"WAT:1\"] = deepcopy(sys[\"WAT:0\"])\n", "rtsys[\"WAT:1\"].translate([-5.0, 0, 0])\n", "pos = rtsys[\"WAT:0\"][0].get_position()\n", "pos[1] -= 0.75\n", "rtsys[\"WAT:0\"][0].set_position(pos)" ] }, { "cell_type": "code", "execution_count": 8, "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" } ], "source": [ "viz = InlineVisualizer(400,300)\n", "viz.display_system(rtsys)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the lineup freature, we can find the best matching between these two systems." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "from BigDFT.Fragments import lineup_fragment\n", "rtsys[\"WAT:0\"] = lineup_fragment(rtsys[\"WAT:0\"])\n", "rtsys[\"WAT:1\"] = lineup_fragment(rtsys[\"WAT:1\"])" ] }, { "cell_type": "code", "execution_count": 10, "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" } ], "source": [ "viz = InlineVisualizer(400,300)\n", "viz.display_system(rtsys)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now compute the RMSD." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.681664737333418\n" ] } ], "source": [ "from numpy import array\n", "from numpy.linalg import norm\n", "\n", "rmsd = 0\n", "for at1, at2 in zip(rtsys[\"WAT:0\"], rtsys[\"WAT:1\"]):\n", " rmsd += norm(array(at1.get_position(\"angstroem\")) - array(at2.get_position(\"angstroem\")))\n", " \n", "print(rmsd)" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 4 }