This notebook outlines the features available in Bio3DView.jl, a viewer for molecular structures in Julia. It is a wrapper round the excellent 3Dmol.js package. When used from the REPL or a file, the viewer shows in a popup using Blink.jl. When used from IJulia running in a Jupyter notebook or JupyterLab, or from Pluto.jl, the viewer shows in the output cell. You can also use Bio3DView.jl to generate standalone HTML, e.g. for use in a web page.
See the installation instructions to install Bio3DView.jl.
More documentation on each function can be found using ?
, e.g. ?IsoSurface
.
There is a known bug where rendering a surface/box removes these from previous cells. This affects the below tutorial.
using Bio3DView
View a file in a given file format. Click, drag and zoom with the mouse to move the molecule. Available formats are "pdb", "sdf", "xyz" and "mol2". The second argument is optional and is inferred from the file extension if not given.
viewfile("benzene.sdf", "sdf")
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
.
View a PDB file by PDB ID (requires an internet connection):
viewpdb("1CRN")
Pass a Style
to style the display:
style = Style("sphere", Dict("colorscheme"=> "greenCarbon"))
viewfile("benzene.sdf", style=style)
Styling options can be found at the 3Dmol documentation.
View a string in a given file format:
s = """
ATOM 72 N ALA A 11 16.899 42.259 22.187 1.00 16.83 N
ATOM 73 CA ALA A 11 15.960 42.201 23.284 1.00 18.31 C
ATOM 74 C ALA A 11 15.625 43.630 23.738 1.00 17.96 C
ATOM 75 O ALA A 11 14.821 43.804 24.675 1.00 22.53 O
ATOM 76 CB ALA A 11 16.528 41.416 24.561 1.00 15.72 C
"""
viewstring(s, "pdb", style=Style("sphere"))
View a structural object from BioStructures.jl:
using BioStructures
struc = read("1AKE.pdb", PDB)
ProteinStructure 1AKE.pdb with 1 models, 2 chains (A,B), 428 residues, 3804 atoms
viewstruc(struc['A'])
Selectors can be passed to the view function as additional arguments. Selectors are described in the BioStructures documentation.
viewstruc(struc, disorderselector, style=Style("sphere"))
To view a VDW surface:
surface = Surface(Dict("colorscheme"=> "greenCarbon"))
viewstruc(struc['A'], surface=surface)
Surface options can be found at the 3Dmol documentation.
To view a box:
box = Box([0.0, 0.0, 0.0], [6.0, 6.0, 6.0]) # Center and dimensions
viewfile("benzene.sdf", "sdf", box=box)
To view lines and cylinders:
lines = [
Line([ 0.0, 1.0, 2.0], [2.0, 7.0, 7.0]),
Line([-3.0, -2.0, -1.0], [1.0, 4.0, 5.0])
]
cylinders = [
Cylinder([ 0.0, 1.0, 2.0], [6.0, 7.0, 7.0]),
Cylinder([-3.0, -2.0, -1.0], [3.0, 4.0, 5.0];
startcap=RoundCap, stopcap=FlatCap),
]
viewfile("benzene.sdf", "sdf", lines=lines, cylinders=cylinders)
To view an isosurface with data provided in a "cube" file:
isosurface = IsoSurface("benzene.cube", 0.01)
viewfile("benzene.sdf", "sdf", isosurface=isosurface)
Visualise the structure of metal-organic framework IRMOF-1:
viewfile("IRMOF-1.xyz", "xyz"; style=Style("stick"))
The unit cell box contained in a "vtk" file can be drawn:
isosurface = IsoSurface("IRMOF-1.cube", -5.0) # contours at -5 kJ/mol
viewfile("IRMOF-1.xyz", "xyz", isosurface=isosurface, vtkcell="IRMOF-1.vtk")
Another example, SBMOF-1, this time with a slanted unit cell. This example also shows how to add arrows representing the axes and provide a custom camera angle.
isosurface = IsoSurface("SBMOF-1.cube", 100.0, wireframe=true,
color="green") # contours at -5 kJ/mol
viewfile("SBMOF-1.xyz", "xyz"; isosurface=isosurface, vtkcell="SBMOF-1.vtk",
axes=Axes(5, 0.3), cameraangle=CameraAngle(0, 0, 0, 0, 0, 0, 0, 1))