{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Make and visualise DNA Models\n", "*It is recommended that you run this example inside a Jupyter environment*\n", "*rather than a VSCode or similar environment*\n", "\n", "This requires the mayavi jupyter extension\n", "`jupyter nbextension install --py mayavi --user`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys\n", "from pathlib import Path\n", "\n", "try:\n", " from fractaldna.dna_models import dnachain as dna\n", "except (ImportError, ModuleNotFoundError):\n", " # Path modifications for when running out of git repo\n", " sys.path.append(str(Path.cwd().parent.parent.parent))\n", " from fractaldna.dna_models import dnachain as dna\n", "\n", "from mayavi import mlab\n", "\n", "# Disable this option for interactive rendering\n", "mlab.options.offscreen = True\n", "\n", "# Enable this option for an interactive notebook\n", "# mlab.init_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Making Multi-Strand DNA\n", "The module currently supports 2-, 4- and 8- strand multi-chains in different configurations" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Make a 40 base pair long DNA Strand\n", "chain = dna.FourStrandDNAChain(\"GTAC\" * 50, 50)\n", "# Generate a simple Matplotlib visualisation\n", "# The basic plot shows each molecule as a point\n", "plot = chain.to_plot()\n", "plot.gca().set_title(\"Basic Plot\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generating nicer plots with MayaVI" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# MayaVI can generate nicer plots, joining the strands together\n", "plot = chain.to_strand_plot()\n", "plot.scene.save_jpg(\"multi_strand_strand_plot.jpg\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![multi_strand_strand_plot](multi_strand_strand_plot.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generating curved strands" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# These can also be curved\n", "chain = dna.FourStrandTurnedDNAChain(\"GTAC\" * 50, 50)\n", "plot = chain.to_strand_plot()\n", "plot.scene.save_jpg(\"multi_strand_turned_strand_plot.jpg\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![multi_strand_turned_strand_plot](multi_strand_turned_strand_plot.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exporting to dataframe or text\n", "\n", "The export dataframe has the following columns\n", "\n", "- name: molecule name\n", "- shape: molecule shape (sphere or ellipse)\n", "- chain_idx: The index of the DNA chain of the molecule (chains are double helices)\n", "- strand_idx: An index to indicate which side of the double helix a molecule is on.\n", "- bp_idx: The index of the base pair\n", "- size_x: semi-major x axis in Angstom\n", "- size_y: semi-major y axis in Angstom\n", "- size_z: semi-major z axis in Angstom\n", "- pos_x: x-position in Angstrom\n", "- pos_y: y-position in Angstrom\n", "- pos_z: z-position in Angstrom\n", "- rot_x: Euler rotation of molecule about the x-axis (radians)\n", "- rot_y: Euler rotation of molecule about the y-axis (radians)\n", "- rot_z: Euler rotation of molecule about the z-axis (radians)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# And then loaded into a data frame\n", "chain.to_frame()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }