{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bio3DView.jl tutorial\n", "\n", "This notebook outlines the features available in [Bio3DView.jl](https://github.com/jgreener64/Bio3DView.jl), a viewer for molecular structures in [Julia](https://julialang.org).\n", "It is a wrapper round the excellent [3Dmol.js](http://3dmol.csb.pitt.edu) package.\n", "When used from the REPL or a file, the viewer shows in a popup using [Blink.jl](https://github.com/JunoLab/Blink.jl).\n", "When used from [IJulia](https://github.com/JuliaLang/IJulia.jl) running in a [Jupyter](http://jupyter.org) notebook or JupyterLab, or from [Pluto.jl](https://github.com/fonsp/Pluto.jl), the viewer shows in the output cell.\n", "You can also use Bio3DView.jl to generate standalone HTML, e.g. for use in a web page.\n", "\n", "See the [installation instructions](https://github.com/jgreener64/Bio3DView.jl#installation) to install Bio3DView.jl.\n", "More documentation on each function can be found using `?`, e.g. `?IsoSurface`.\n", "\n", "There is a known bug where rendering a surface/box removes these from previous cells.\n", "This affects the below tutorial." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using Bio3DView" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "View a file in a given file format.\n", "Click, drag and zoom with the mouse to move the molecule.\n", "Available formats are \"pdb\", \"sdf\", \"xyz\" and \"mol2\".\n", "The second argument is optional and is inferred from the file extension if not given." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "viewfile(\"benzene.sdf\", \"sdf\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to return the HTML as a `String` to open in a browser or use in your own web pages, set the `html` keyword argument to `true`.\n", "\n", "View a PDB file by PDB ID (requires an internet connection):" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "viewpdb(\"1CRN\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pass a `Style` to style the display:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "style = Style(\"sphere\", Dict(\"colorscheme\"=> \"greenCarbon\"))\n", "viewfile(\"benzene.sdf\", style=style)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Styling options can be found at the [3Dmol documentation](http://3dmol.csb.pitt.edu/doc/AtomStyleSpec.html).\n", "\n", "View a string in a given file format:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = \"\"\"\n", "ATOM 72 N ALA A 11 16.899 42.259 22.187 1.00 16.83 N\n", "ATOM 73 CA ALA A 11 15.960 42.201 23.284 1.00 18.31 C\n", "ATOM 74 C ALA A 11 15.625 43.630 23.738 1.00 17.96 C\n", "ATOM 75 O ALA A 11 14.821 43.804 24.675 1.00 22.53 O\n", "ATOM 76 CB ALA A 11 16.528 41.416 24.561 1.00 15.72 C\n", "\"\"\"\n", "viewstring(s, \"pdb\", style=Style(\"sphere\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "View a structural object from [BioStructures.jl](http://biojulia.net/BioStructures.jl/stable):" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ProteinStructure 1AKE.pdb with 1 models, 2 chains (A,B), 428 residues, 3804 atoms" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using BioStructures\n", "struc = read(\"1AKE.pdb\", PDB)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "viewstruc(struc['A'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Selectors can be passed to the view function as additional arguments. Selectors are described in the [BioStructures documentation](https://biojulia.net/BioStructures.jl/stable/documentation#Manipulating-structures-1)." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "viewstruc(struc, disorderselector, style=Style(\"sphere\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To view a VDW surface:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "surface = Surface(Dict(\"colorscheme\"=> \"greenCarbon\"))\n", "viewstruc(struc['A'], surface=surface)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Surface options can be found at the [3Dmol documentation](http://3dmol.csb.pitt.edu/doc/SurfaceStyleSpec.html).\n", "\n", "To view a box:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "box = Box([0.0, 0.0, 0.0], [6.0, 6.0, 6.0]) # Center and dimensions\n", "viewfile(\"benzene.sdf\", \"sdf\", box=box)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To view lines and cylinders:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lines = [\n", " Line([ 0.0, 1.0, 2.0], [2.0, 7.0, 7.0]),\n", " Line([-3.0, -2.0, -1.0], [1.0, 4.0, 5.0])\n", "]\n", "cylinders = [\n", " Cylinder([ 0.0, 1.0, 2.0], [6.0, 7.0, 7.0]),\n", " Cylinder([-3.0, -2.0, -1.0], [3.0, 4.0, 5.0];\n", " startcap=RoundCap, stopcap=FlatCap),\n", "]\n", "viewfile(\"benzene.sdf\", \"sdf\", lines=lines, cylinders=cylinders)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To view an isosurface with data provided in a \"cube\" file:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isosurface = IsoSurface(\"benzene.cube\", 0.01)\n", "viewfile(\"benzene.sdf\", \"sdf\", isosurface=isosurface)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualise the structure of metal-organic framework IRMOF-1:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "viewfile(\"IRMOF-1.xyz\", \"xyz\"; style=Style(\"stick\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The unit cell box contained in a \"vtk\" file can be drawn:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isosurface = IsoSurface(\"IRMOF-1.cube\", -5.0) # contours at -5 kJ/mol\n", "viewfile(\"IRMOF-1.xyz\", \"xyz\", isosurface=isosurface, vtkcell=\"IRMOF-1.vtk\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another example, SBMOF-1, this time with a slanted unit cell.\n", "This example also shows how to add arrows representing the axes and provide a custom camera angle." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n" ], "text/plain": [ "HTML{String}(\"\\n\\n\\n
\\n\\n\")" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isosurface = IsoSurface(\"SBMOF-1.cube\", 100.0, wireframe=true,\n", " color=\"green\") # contours at -5 kJ/mol\n", "\n", "viewfile(\"SBMOF-1.xyz\", \"xyz\"; isosurface=isosurface, vtkcell=\"SBMOF-1.vtk\",\n", " axes=Axes(5, 0.3), cameraangle=CameraAngle(0, 0, 0, 0, 0, 0, 0, 1))" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.5.0", "language": "julia", "name": "julia-1.5" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.5.0" } }, "nbformat": 4, "nbformat_minor": 4 }