{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Single DNA Solenoids\n", "\n", "This example shows how to generate single DNA Solenoids, and either plot them in MayaVI\n", "or export them to text\n", "\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`# Generating Geometries for Geant4\n", "\n", "This notebook contains code blocks used to generate sample\n", "geometries used in Geant4 simulations." ] }, { "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", " sys.path.append(str(Path.cwd().parent.parent.parent))\n", " from fractaldna.dna_models import dnachain as dna\n", "\n", "import matplotlib.pyplot as plt\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 a straight Solenoidal DNA strand" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Make a straight solenoid in a 750 Å box\n", "chain = dna.Solenoid(voxelheight=750)\n", "# MayaVI plots are best for visualisation here\n", "plot = chain.to_strand_plot()\n", "\n", "# Save the figure\n", "plot.scene.save_jpg(\"single_solenoid_strand_plot.jpg\")\n", "\n", "# In an interactive notebook, you can refer to the figure to\n", "# interact with it.\n", "# plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = chain.to_line_plot()\n", "plot.scene.save_jpg(\"single_solenoid_line_plot.jpg\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![single_solenoid_strand_plot](single_solenoid_strand_plot.jpg) ![single_solenoid_line_plot](single_solenoid_line_plot.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Making a turned Solenoidal DNA Strand" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Make a turned solenoid in a 750 Å box\n", "chain = dna.TurnedSolenoid(voxelheight=750)\n", "# MayaVI plots are best for visualisation here\n", "plot = chain.to_strand_plot()\n", "plot.scene.save_jpg(\"single_solenoid_strand_plot_turned.jpg\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![single_solenoid_strand_plot_turned](single_solenoid_strand_plot_turned.jpg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The line plot method is well adapted to plotting chromatin\n", "plot = chain.to_line_plot()\n", "plot.scene.save_jpg(\"single_solenoid_line_plot_turned.jpg\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![single_solenoid_line_plot_turned](single_solenoid_line_plot_turned.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Centering the DNA\n", "By default, solenoids are generated starting near (0, 0, 0). If you are running a simulation in \n", "Geant4, you will want to use the chain.translate method to move the whole unit down." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Default bounds\")\n", "print(chain.to_frame()[[\"pos_x\", \"pos_y\", \"pos_z\"]].min())\n", "\n", "print(\"After Translation\")\n", "chain.translate([0, 0, -750.0 / 2])\n", "print(chain.to_frame()[[\"pos_x\", \"pos_y\", \"pos_z\"]].min())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exporting Solenoidal DNA to CSV" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This too can be exported to a dataframe of basepairs\n", "chain.to_frame()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# And a second data frame of histones\n", "# This can be joined to the base pairs frame, assuming a sufficient handling of\n", "# the missing strand index, and the relation between the base pair and histone index.\n", "chain.histones_to_frame()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.7.6 ('base')", "language": "python", "name": "python3" }, "language_info": { "name": "python", "pygments_lexer": "ipython3", "version": "3.7.6" }, "vscode": { "interpreter": { "hash": "75ac00008631022ac6f4cbcea553bf54efd26e8bc76b4bf4e91e5d02b78f2682" } } }, "nbformat": 4, "nbformat_minor": 4 }