{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Building a Nanotube\n", "\n", "> ### In this tutorial we will cover:\n", "> - how we can create molecules completely from scratch\n", "> - how we may use BuildAMol to create a nanotube" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nanotubes are polymers that form a large tube-like structure which have some nice structural properties. \n", "\n", "\n", "\n", "There are excellent nanotube building applications around, so feel free to use one of these instead of BuildAMol. Because from BuildAMol's perspective nanotubes are a bit of challenge. The problem with nanotubes is that they are not only circular but are so regularly structured that it is difficult to find a suitable \"fragment\" molecule to start with. \n", "\n", "So, if we want to build a nanotube in BuildAMol it is probably easier to assemble the entire tube-molecule from scratch; i.e. without any template molecules! \n", "\n", "In this tutorial we will be assembling a nanotube atom by atom! \n", "Sounds like a major headache, right? Well, it was a bit for me when making this tutorial but the final procedure actually turned out simpler than expected.\n", "\n", "Let's dive into it..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> ### Disclaimer:\n", "> If you just want to make a nanotube but don't care about the tutorial part about making it from scratch you can\n", "> use the `polymers` extension to get a nanotube like this:\n", "> ```python\n", "> from buildamol.extensions.polymers import nanotube\n", "> length = 20\n", "> width = 10\n", "> my_nanotube = nanotube(length, width)\n", "> ```\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building one unit-ring \n", "\n", "Let's start by making one unit-ring which we can then stack to generate a tube. \n", "\n", "In order to do this, we have to start with some math, unfortunately. This is because in order to make a molecule, we need to know where the atoms should be. In the case of nanotubes we can use the math relating to circles and triangles that we all know from high school to compute the respective atom coordinates. Here's how:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "import buildamol as bam\n", "import numpy as np\n", "# the number of carbons in the ring...\n", "ring_size = 50\n", "\n", "# we can use geometric reasoning to first build some ring coordinates\n", "# for the atoms to occupy\n", "length = 1.54\n", "\n", "# the angle between the xy plane and elevated atoms from the later hexagons\n", "# (don't worry about it too much, it's just a geometric trick to make the\n", "# 120° angles in the final molecule work out nicely)\n", "angle = np.radians(30)\n", "\n", "# we can approximate the ring radius by the length and number of carbon atoms\n", "# given the formula: u = 2 * r * pi , where the circumference u is roughly \n", "# length * ring_size * cos(angle) (otherwise the bond lengths would be off)\n", "radius = (np.cos(angle) * length) * (ring_size+1) / (2 * np.pi)\n", "\n", "# now we can calculate the coordinates for the carbon and hydrogen atoms\n", "# in the ring\n", "theta = np.linspace(0, 2 * np.pi, ring_size, endpoint=False)\n", "\n", "X = radius * np.cos(theta)\n", "Y = radius * np.sin(theta)\n", "\n", "# as mentioned, every second atom will be slightly elevated to form an angle of\n", "# 30° relative to the xy-plane which will later be flipped to make \n", "# 120° angles in the final molecule\n", "Z = np.zeros(ring_size)\n", "Z[1::2] = np.sin(angle) * length" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Phew, that was a lot of math just now. But these computations are what allow us to now fairly easily assemble the unit ring for our nanotube. Here's how:" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
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
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
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
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
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
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