Title: | Create Interactive 3D Visualizations of Molecular Data |
---|---|
Description: | Create rich and fully interactive 3D visualizations of molecular data. Visualizations can be included in Shiny apps and R markdown documents, or viewed from the R console and 'RStudio' Viewer. 'r3dmol' includes an extensive API to manipulate the visualization after creation, and supports getting data out of the visualization into R. Based on the '3dmol.js' and the 'htmlwidgets' R package. |
Authors: | Wei Su [aut, cre] , Brady Johnston [aut] |
Maintainer: | Wei Su <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-31 16:34:00 UTC |
Source: | https://github.com/swsoyee/r3dmol |
Cif file example
cif_254385
cif_254385
cif format
https://github.com/3dmol/3Dmol.js/blob/master/tests/auto/data/254385.cif
Gaussian cube file example
cube_benzene_homo
cube_benzene_homo
Gaussian cube format
https://github.com/3dmol/3Dmol.js/blob/master/tests/test_structs/benzene-homo.cube
Create and initialize an appropriate viewer at supplied HTML element using specification in config
r3dmol( id = NULL, viewer_spec = m_viewer_spec(), ..., width = NULL, height = NULL, elementId = NULL )
r3dmol( id = NULL, viewer_spec = m_viewer_spec(), ..., width = NULL, height = NULL, elementId = NULL )
id |
HTML element id of viewer. |
viewer_spec |
Some useful viewer input specifications. Additional options pass in via ... will override options set in viewer_spec. |
... |
Additional, more niche viewer input specification, see http://3dmol.csb.pitt.edu/doc/types.html#ViewerSpec for more details. |
width |
Fixed width for viewer (in css units). Ignored when used in a
Shiny app – use the |
height |
Fixed height for viewer (in css units). It is recommended to not use this parameter since the widget knows how to adjust its height automatically. |
elementId |
Use an explicit element ID for the widget (rather than an automatically generated one). Ignored when used in a Shiny app. |
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() # Viewer configs setting r3dmol( backgroundColor = "black", lowerZoomLimit = 1, upperZoomLimit = 350 ) %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() # Viewer configs setting r3dmol( backgroundColor = "black", lowerZoomLimit = 1, upperZoomLimit = 350 ) %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to()
Add an arrow from start to end, additional customisation through
m_shape_spec()
.
m_add_arrow( id, start, end, radius = 0.2, radiusRatio = 1.62, mid = 0.62, spec = m_shape_spec(), hidden = FALSE )
m_add_arrow( id, start, end, radius = 0.2, radiusRatio = 1.62, mid = 0.62, spec = m_shape_spec(), hidden = FALSE )
id |
R3dmol |
start |
Start location of arrow Can be either |
end |
End location of arrow. Can be either |
radius |
Radius of base cylinder for arrow. |
radiusRatio |
Ratio of arrow point to the base cylinder. Default 1.618034. |
mid |
Relative position of the arrow point base, along the length of arrow object. Default to 0.618034. |
spec |
Additional shape specifications defined with
|
Hide object if TRUE. |
## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_zoom_to(sel = m_sel(resi = 1)) %>% m_add_arrow( start = m_sel(resi = 1), end = m_sel(resi = 3), spec = m_shape_spec(color = "green") ) ## End(Not run)
## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_zoom_to(sel = m_sel(resi = 1)) %>% m_add_arrow( start = m_sel(resi = 1), end = m_sel(resi = 3), spec = m_shape_spec(color = "green") ) ## End(Not run)
Given multimodel file and its format, all atoms are added to one model
m_add_as_one_molecule(id, data, format)
m_add_as_one_molecule(id, data, format)
id |
R3dmol |
data |
Input data |
format |
Input format |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Create and add shape
m_add_box(id, spec = list()) m_add_curve(id, spec = list())
m_add_box(id, spec = list()) m_add_curve(id, spec = list())
id |
R3dmol |
spec |
Shape style specification. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Add arrow r3dmol() %>% m_add_arrow( start = m_vector3(-10, 0, 0), end = m_vector3(0, -10, 0), radius = 1, radiusRatio = 1, mid = 1, spec = m_shape_spec( clickable = TRUE, callback = "function() { this.color.setHex(0xFF0000FF); viewer.render() }" ) ) # Add curve r3dmol() %>% m_add_curve( spec = list( points = list( m_vector3(0, 0, 0), m_vector3(5, 3, 0), m_vector3(5, 7, 0), m_vector3(0, 10, 0) ), radius = 0.5, smooth = 10, fromArrow = FALSE, toArrow = TRUE, color = "orange" ) ) # Add cylinder r3dmol() %>% m_add_cylinder( start = list(x = 0.0, y = 0.0, z = 0.0), end = list(x = 10.0, y = 0.0, z = 0.0), radius = 1.0, fromCap = 1, toCap = 2, spec = m_shape_spec( color = "red", hoverable = TRUE, clickable = TRUE, callback = " function() { this.color.setHex(0x00FFFF00); viewer.render(); }", hover_callback = " function() { viewer.render(); }", unhover_callback = " function() { this.color.setHex(0xFF000000); viewer.render(); }" ) ) # Add line r3dmol() %>% m_add_line( dashed = TRUE, start = m_vector3(0, 0, 0), end = m_vector3(30, 30, 30) ) # Add box r3dmol() %>% m_add_box(spec = list( center = m_vector3(0, 5, 0), demensions = list(w = 3, h = 4, d = 2), color = "magenta" )) # Add sphere r3dmol() %>% m_add_sphere( center = m_vector3(0, 0, 0), radius = 10, spec = m_shape_spec(color = "red") )
library(r3dmol) # Add arrow r3dmol() %>% m_add_arrow( start = m_vector3(-10, 0, 0), end = m_vector3(0, -10, 0), radius = 1, radiusRatio = 1, mid = 1, spec = m_shape_spec( clickable = TRUE, callback = "function() { this.color.setHex(0xFF0000FF); viewer.render() }" ) ) # Add curve r3dmol() %>% m_add_curve( spec = list( points = list( m_vector3(0, 0, 0), m_vector3(5, 3, 0), m_vector3(5, 7, 0), m_vector3(0, 10, 0) ), radius = 0.5, smooth = 10, fromArrow = FALSE, toArrow = TRUE, color = "orange" ) ) # Add cylinder r3dmol() %>% m_add_cylinder( start = list(x = 0.0, y = 0.0, z = 0.0), end = list(x = 10.0, y = 0.0, z = 0.0), radius = 1.0, fromCap = 1, toCap = 2, spec = m_shape_spec( color = "red", hoverable = TRUE, clickable = TRUE, callback = " function() { this.color.setHex(0x00FFFF00); viewer.render(); }", hover_callback = " function() { viewer.render(); }", unhover_callback = " function() { this.color.setHex(0xFF000000); viewer.render(); }" ) ) # Add line r3dmol() %>% m_add_line( dashed = TRUE, start = m_vector3(0, 0, 0), end = m_vector3(30, 30, 30) ) # Add box r3dmol() %>% m_add_box(spec = list( center = m_vector3(0, 5, 0), demensions = list(w = 3, h = 4, d = 2), color = "magenta" )) # Add sphere r3dmol() %>% m_add_sphere( center = m_vector3(0, 0, 0), radius = 10, spec = m_shape_spec(color = "red") )
Add custom shape component from user supplied function
m_add_custom(id, spec)
m_add_custom(id, spec)
id |
R3dmol |
spec |
Style specification (see: http://3dmol.csb.pitt.edu/doc/types.html#CustomShapeSpec). |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r <- 20 vertices <- list( m_vector3(0, 0, 0), m_vector3(r, 0, 0), m_vector3(0, r, 0) ) normals <- list( m_vector3(0, 0, 1), m_vector3(0, 0, 1), m_vector3(0, 0, 1) ) colors <- list( list(r = 1, g = 0, b = 0), list(r = 0, g = 1, b = 0), list(r = 0, g = 0, b = 1) ) faces <- 0:2 r3dmol() %>% m_add_custom(spec = list( vertexArr = vertices, normalArr = normals, faceArr = faces, color = colors ))
library(r3dmol) r <- 20 vertices <- list( m_vector3(0, 0, 0), m_vector3(r, 0, 0), m_vector3(0, r, 0) ) normals <- list( m_vector3(0, 0, 1), m_vector3(0, 0, 1), m_vector3(0, 0, 1) ) colors <- list( list(r = 1, g = 0, b = 0), list(r = 0, g = 1, b = 0), list(r = 0, g = 0, b = 1) ) faces <- 0:2 r3dmol() %>% m_add_custom(spec = list( vertexArr = vertices, normalArr = normals, faceArr = faces, color = colors ))
Add cynliders between the given points. Will match starting point/s with ending point/s to create a line between each point. Styling options can be supplied as one option, or a vector of length equal to the number of lines.
m_add_cylinder( id, start, end, radius = 0.1, fromCap = 1, toCap = 1, dashed = FALSE, color = "black", alpha = FALSE, wireframe = FALSE, hidden = FALSE, spec = m_shape_spec() )
m_add_cylinder( id, start, end, radius = 0.1, fromCap = 1, toCap = 1, dashed = FALSE, color = "black", alpha = FALSE, wireframe = FALSE, hidden = FALSE, spec = m_shape_spec() )
id |
R3dmol |
start |
Starting position (or |
end |
Ending position (or |
radius |
Radius of cylinder. |
fromCap |
Cap at start of cylinder. 0 for none, 1 for flat, 2 for rounded. |
toCap |
Cap at end of cylinder. 0 for none, 1 for flat, 2 for rounded. |
dashed |
Boolean, dashed style cylinder instead of solid. |
color |
Color value for cylinders. Either 1 or vector of colors equal
in length to |
alpha |
Alpha value for transparency. |
wireframe |
Logical, display as wireframe. |
Logical, whether or not to hide the cylinder. |
|
spec |
Additional shape specifications defined with
|
## Add a cylinder between residue 1 & 2 of Chain "A" r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1)) %>% m_add_cylinder( start = m_sel(resi = 1, chain = "A"), end = m_sel(resi = 2, chain = "A"), dashed = TRUE, radius = 0.1 ) # Add two cylinders. # Blue cylinder is between residues 1 & 2 # Green cylinder is between residues 3 & 4 r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1:4, chain = "A")) %>% m_add_cylinder( start = list( m_sel(resi = 1, chain = "A"), m_sel(resi = 3, chain = "A") ), end = list( m_sel(resi = 2, chain = "A"), m_sel(resi = 4, chain = "A") ), dashed = TRUE, radius = 0.1, color = c("blue", "green") ) %>% m_add_res_labels(m_sel(resi = 1:4, chain = "A")) # The same scene achieved with m_multi_resi_sel() r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1:4, chain = "A")) %>% m_add_cylinder( start = m_multi_resi_sel(resi = c(1, 3), chain = "A"), end = list( m_sel(resi = 2, chain = "A"), m_sel(resi = 4, chain = "A") ), dashed = TRUE, radius = 0.1, color = c("blue", "green") ) %>% m_add_res_labels(m_sel(resi = 1:4, chain = "A"))
## Add a cylinder between residue 1 & 2 of Chain "A" r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1)) %>% m_add_cylinder( start = m_sel(resi = 1, chain = "A"), end = m_sel(resi = 2, chain = "A"), dashed = TRUE, radius = 0.1 ) # Add two cylinders. # Blue cylinder is between residues 1 & 2 # Green cylinder is between residues 3 & 4 r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1:4, chain = "A")) %>% m_add_cylinder( start = list( m_sel(resi = 1, chain = "A"), m_sel(resi = 3, chain = "A") ), end = list( m_sel(resi = 2, chain = "A"), m_sel(resi = 4, chain = "A") ), dashed = TRUE, radius = 0.1, color = c("blue", "green") ) %>% m_add_res_labels(m_sel(resi = 1:4, chain = "A")) # The same scene achieved with m_multi_resi_sel() r3dmol() %>% m_add_model(pdb_6zsl) %>% m_zoom_to(sel = m_sel(resi = 1:4, chain = "A")) %>% m_add_cylinder( start = m_multi_resi_sel(resi = c(1, 3), chain = "A"), end = list( m_sel(resi = 2, chain = "A"), m_sel(resi = 4, chain = "A") ), dashed = TRUE, radius = 0.1, color = c("blue", "green") ) %>% m_add_res_labels(m_sel(resi = 1:4, chain = "A"))
Construct isosurface from volumetric data in gaussian cube format
m_add_isosurface(id, data, isoSpec)
m_add_isosurface(id, data, isoSpec)
id |
R3dmol |
data |
Path of input data path or a vector of data. |
isoSpec |
Volumetric data shape specification |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_isosurface( data = cube_benzene_homo, isoSpec = list( isoval = -0.01, color = "red", opacity = 0.95 ) ) %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_isosurface( data = cube_benzene_homo, isoSpec = list( isoval = -0.01, color = "red", opacity = 0.95 ) ) %>% m_zoom_to()
Add label to viewer
m_add_label(id, text, style = m_style_label(), sel = m_sel(), noshow = TRUE)
m_add_label(id, text, style = m_style_label(), sel = m_sel(), noshow = TRUE)
id |
R3dmol |
text |
Label text |
style |
Label style specification |
sel |
Set position of label to center of this selection |
noshow |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_add_label( text = "Label", sel = m_vector3(-6.89, 0.75, 0.35), style = m_style_label( backgroundColor = "#666666", backgroundOpacity = 0.9 ) ) %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_add_label( text = "Label", sel = m_vector3(-6.89, 0.75, 0.35), style = m_style_label( backgroundColor = "#666666", backgroundOpacity = 0.9 ) ) %>% m_zoom_to()
Add lines between the given points. Will match starting point/s with ending point/s to create a line between each point. Styling options can be supplied as one option, or a vector of length equal to the number of lines.
m_add_line( id, start, end, dashed = TRUE, color = "black", opacity = 1, hidden = FALSE )
m_add_line( id, start, end, dashed = TRUE, color = "black", opacity = 1, hidden = FALSE )
id |
R3dmol |
start |
Starting position (or |
end |
Ending position (or |
dashed |
Logical whether the lines are dashed. |
color |
Either single or list of color values equal to number of lines. |
opacity |
Either single or list of opacity values equal to number of lines. |
Either single or list of hidden values equal to number of lines. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl) %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_add_style( sel = m_sel(resi = 1:10), style = c( m_style_stick(), m_style_sphere(scale = 0.3) ) ) %>% m_add_line( start = list( m_sel(resi = 1, chain = "A"), m_sel(resi = 1, chain = "A") ), end = list( m_sel(resi = 10, chain = "A"), m_sel(resi = 10, chain = "B") ), dashed = TRUE )
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl) %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_add_style( sel = m_sel(resi = 1:10), style = c( m_style_stick(), m_style_sphere(scale = 0.3) ) ) %>% m_add_line( start = list( m_sel(resi = 1, chain = "A"), m_sel(resi = 1, chain = "A") ), end = list( m_sel(resi = 10, chain = "A"), m_sel(resi = 10, chain = "B") ), dashed = TRUE )
Create and add model to viewer, given molecular data and its format. If
multi-model file is provided, use m_add_models
adding atom data
to the viewer as separate models.
m_add_model( id, data, format = c("pdb", "sdf", "xyz", "pqr", "mol2", "cif"), keepH = FALSE, options = list() ) m_add_models(id, data, format = c("pdb", "sdf", "xyz", "pqr", "mol2", "cif"))
m_add_model( id, data, format = c("pdb", "sdf", "xyz", "pqr", "mol2", "cif"), keepH = FALSE, options = list() ) m_add_models(id, data, format = c("pdb", "sdf", "xyz", "pqr", "mol2", "cif"))
id |
R3dmol |
data |
Path of input data path or a vector of data. |
format |
Input format ( |
keepH |
Default to FALSE, whether to keep or strip hydrogens from imported model. |
options |
Format dependent options. Attributes depend on the input file format. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Single-model file with m_add_model() function r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") # Multi-model file with m_add_models() function r3dmol() %>% m_add_models(data = sdf_multiple, "sdf") %>% m_zoom_to() # Multi-model file with m_add_model() function r3dmol() %>% m_add_model(data = sdf_multiple, "sdf") %>% m_zoom_to() # Add model and keep hydrogens. ## Not run: r3dmol() %>% m_add_model(m_fetch_pdb("5D8V"), keepH = TRUE) %>% m_set_style(m_style_sphere()) %>% m_zoom_to() %>% m_spin() ## End(Not run)
library(r3dmol) # Single-model file with m_add_model() function r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") # Multi-model file with m_add_models() function r3dmol() %>% m_add_models(data = sdf_multiple, "sdf") %>% m_zoom_to() # Multi-model file with m_add_model() function r3dmol() %>% m_add_model(data = sdf_multiple, "sdf") %>% m_zoom_to() # Add model and keep hydrogens. ## Not run: r3dmol() %>% m_add_model(m_fetch_pdb("5D8V"), keepH = TRUE) %>% m_set_style(m_style_sphere()) %>% m_zoom_to() %>% m_spin() ## End(Not run)
Create and add model to viewer. Given multimodel file and its format, different atomlists are stored in model's frame property and model's atoms are set to the 0th frame
m_add_models_as_frames(id, data, format)
m_add_models_as_frames(id, data, format)
id |
R3dmol |
data |
Path of input data path or a vector of data. |
format |
Input format (see http://3dmol.csb.pitt.edu/doc/types.html#FileFormats). |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_models_as_frames(data = xyz_multiple, format = "xyz") %>% m_animate(options = list(loop = "forward", reps = 1)) %>% m_set_style(style = m_style_stick(colorScheme = "magentaCarbon")) %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_models_as_frames(data = xyz_multiple, format = "xyz") %>% m_animate(options = list(loop = "forward", reps = 1)) %>% m_set_style(style = m_style_stick(colorScheme = "magentaCarbon")) %>% m_zoom_to()
Adds a colored outline to all objects in the scene, helping the viewer to distinguish depth in often complex molecular scenes.
m_add_outline(id, width = 0.1, color = "black")
m_add_outline(id, width = 0.1, color = "black")
id |
R3dmol |
width |
Width of the outline, defaults to 0.1 |
color |
Color of the outline, defaults to black. |
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72) %>% m_set_style(style = m_style_stick()) %>% m_add_outline()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72) %>% m_set_style(style = m_style_stick()) %>% m_add_outline()
This will generate one label per a selected atom at the atom's coordinates with the property value as the label text.
m_add_property_labels(id, prop, sel = m_sel(), style = m_style_label())
m_add_property_labels(id, prop, sel = m_sel(), style = m_style_label())
id |
R3dmol |
prop |
Property name () |
sel |
Atom selection specification |
style |
Style spec to add to specified atoms |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") %>% m_set_style(style = m_style_stick(radius = 2)) %>% m_zoom_to() %>% m_add_property_labels( prop = "index", sel = list(not = list(elem = "H")), style = m_style_label( fontColor = "black", font = "sans-serif", fontSize = 28, showBackground = FALSE, alignment = "center" ) )
library(r3dmol) r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") %>% m_set_style(style = m_style_stick(radius = 2)) %>% m_zoom_to() %>% m_add_property_labels( prop = "index", sel = list(not = list(elem = "H")), style = m_style_label( fontColor = "black", font = "sans-serif", fontSize = 28, showBackground = FALSE, alignment = "center" ) )
Add residue labels. This will generate one label per a
residue within the selected atoms. The label will be at the
centroid of the atoms and styled according to the passed style.
The label text will be resn
resi
m_add_res_labels(id, sel = m_sel(), style = m_style_label(), byframe)
m_add_res_labels(id, sel = m_sel(), style = m_style_label(), byframe)
id |
R3dmol |
sel |
Atom selection specification |
style |
Style spec to add to specified atoms |
byframe |
if true, create labels for every individual frame, not just current |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style( style = c( m_style_stick(radius = 0.15), m_style_cartoon() ) ) %>% m_add_res_labels( sel = m_sel(resn = "GLY"), style = m_style_label( font = "Arial", fontColor = "white", backgroundColor = "black", showBackground = TRUE ) ) %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style( style = c( m_style_stick(radius = 0.15), m_style_cartoon() ) ) %>% m_add_res_labels( sel = m_sel(resn = "GLY"), style = m_style_label( font = "Arial", fontColor = "white", backgroundColor = "black", showBackground = TRUE ) ) %>% m_zoom_to()
Add shape object to viewer
m_add_shape(id, shapeSpec = list())
m_add_shape(id, shapeSpec = list())
id |
R3dmol |
shapeSpec |
Style specification for label |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Adds sphere at given location, with given radius.
m_add_sphere(id, center, radius = 1, spec = m_shape_spec(), ...)
m_add_sphere(id, center, radius = 1, spec = m_shape_spec(), ...)
id |
R3dmol |
center |
center point of sphere. Can be |
radius |
radius of sphere. |
spec |
Additional shape specifications defined with
|
... |
Additional shape specifcations, that can be called outside of
|
r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_sphere( center = m_sel(resi = 1), spec = m_shape_spec(color = "green", wireframe = TRUE) ) %>% m_zoom_to(sel = m_sel(resi = 1))
r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_sphere( center = m_sel(resi = 1), spec = m_shape_spec(color = "green", wireframe = TRUE) ) %>% m_zoom_to(sel = m_sel(resi = 1))
Takes a selection and adds additional styling to it.
m_add_style(id, style = m_style_cartoon(), sel = m_sel())
m_add_style(id, style = m_style_cartoon(), sel = m_sel())
id |
R3dmol |
style |
Style spec to apply to specified atoms using m_style_*() |
sel |
Atom selection specification with |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Add style to model r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_add_style(style = m_style_cartoon()) %>% m_zoom_to() # Set style to model r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_style( sel = m_sel(chain = "A"), style = m_style_stick( radius = 0.5, colorScheme = "magentaCarbon" ) ) %>% m_zoom_to()
library(r3dmol) # Add style to model r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_add_style(style = m_style_cartoon()) %>% m_zoom_to() # Set style to model r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_style( sel = m_sel(chain = "A"), style = m_style_stick( radius = 0.5, colorScheme = "magentaCarbon" ) ) %>% m_zoom_to()
Add surface representation to atoms
m_add_surface( id, type, style = m_style_surface(), atomsel = m_sel(), allsel, focus, surfacecallback )
m_add_surface( id, type, style = m_style_surface(), atomsel = m_sel(), allsel, focus, surfacecallback )
id |
R3dmol |
type |
Surface type ('VDW', 'MS', 'SAS', or 'SES') |
style |
Optional style specification for surface material (e.g. for different coloring scheme, etc). |
atomsel |
Show surface for atoms in this selection. |
allsel |
Use atoms in this selection to calculate surface; may be larger
group than |
focus |
Optionally begin rendering surface specified atoms. |
surfacecallback |
function to be called after setting the surface. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Use m_add_unit_cell
to create and add unit cell visualization,
and m_remove_unit_cell
to remove it from model. Use
m_replicate_unit_cell
to replicate atoms in model to form a
super cell of the specified dimensions. Original cell will be centered as
much as possible.
m_add_unit_cell(id, model, spec) m_replicate_unit_cell(id, a, b, c, model) m_remove_unit_cell(id, model)
m_add_unit_cell(id, model, spec) m_replicate_unit_cell(id, a, b, c, model) m_remove_unit_cell(id, model)
id |
R3dmol |
model |
Model with unit cell information (e.g., pdb derived). If omitted uses most recently added model. |
spec |
Visualization style. |
a |
number of times to replicate cell in X dimension. |
b |
number of times to replicate cell in Y dimension. If absent, X value is used. |
c |
number of times to replicate cell in Z dimension. If absent, Y value is used. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Create model mol <- r3dmol() %>% m_add_model( data = cif_254385, "cif", options = list(doAssembly = TRUE, normalizeAssembly = TRUE) ) %>% m_set_style(style = c( m_style_sphere(colorScheme = "Jmol", scale = 0.25), m_style_stick(colorScheme = "Jmol") )) %>% m_add_unit_cell(spec = list( alabel = "x", blabel = "y", clabel = "z", box = list(hidden = TRUE) )) %>% m_zoom_to() # Render model mol # Remove unit cell mol %>% m_remove_unit_cell() # Replicate atoms in model to form a super cell r3dmol() %>% m_add_model(data = cif_254385, format = "cif") %>% m_set_style(style = m_style_sphere(scale = 0.25)) %>% m_add_unit_cell() %>% m_zoom_to() %>% m_replicate_unit_cell(a = 3, b = 2, c = 1)
library(r3dmol) # Create model mol <- r3dmol() %>% m_add_model( data = cif_254385, "cif", options = list(doAssembly = TRUE, normalizeAssembly = TRUE) ) %>% m_set_style(style = c( m_style_sphere(colorScheme = "Jmol", scale = 0.25), m_style_stick(colorScheme = "Jmol") )) %>% m_add_unit_cell(spec = list( alabel = "x", blabel = "y", clabel = "z", box = list(hidden = TRUE) )) %>% m_zoom_to() # Render model mol # Remove unit cell mol %>% m_remove_unit_cell() # Replicate atoms in model to form a super cell r3dmol() %>% m_add_model(data = cif_254385, format = "cif") %>% m_set_style(style = m_style_sphere(scale = 0.25)) %>% m_add_unit_cell() %>% m_zoom_to() %>% m_replicate_unit_cell(a = 3, b = 2, c = 1)
Animate all models in viewer from their respective frames
m_animate(id, options)
m_animate(id, options)
id |
R3dmol |
options |
can specify |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol( width = 400, height = 400, backgroundColor = "0xeeeeee" ) %>% m_add_model( data = xyz, format = "xyz", options = list(vibrate = list(frames = 10, amplitude = 1)) ) %>% m_set_style(style = m_style_stick()) %>% m_animate(list(loop = "backAndForth")) %>% m_zoom_to()
library(r3dmol) xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol( width = 400, height = 400, backgroundColor = "0xeeeeee" ) %>% m_add_model( data = xyz, format = "xyz", options = list(vibrate = list(frames = 10, amplitude = 1)) ) %>% m_set_style(style = m_style_stick()) %>% m_animate(list(loop = "backAndForth")) %>% m_zoom_to()
Function to take bio3d structure and use in the r3dmol app.
m_bio3d(pdb)
m_bio3d(pdb)
pdb |
bio3d object containing coordinates for desired structure |
library(bio3d) library(r3dmol) # create bio3d object pdb <- read.pdb("1bna") # inspect bio3d object pdb # load bio3d object into r3dmol r3dmol() %>% m_add_model(data = m_bio3d(pdb)) %>% m_zoom_to()
library(bio3d) library(r3dmol) # create bio3d object pdb <- read.pdb("1bna") # inspect bio3d object pdb # load bio3d object into r3dmol r3dmol() %>% m_add_model(data = m_bio3d(pdb)) %>% m_zoom_to()
Add a button for adding residue labels
m_button_add_res_labels( id, sel = m_sel(), style = m_style_label(), label = "Show Labels", byframe = FALSE, hideButton = TRUE, hideLabel = "Hide Labels" )
m_button_add_res_labels( id, sel = m_sel(), style = m_style_label(), label = "Show Labels", byframe = FALSE, hideButton = TRUE, hideLabel = "Hide Labels" )
id |
R3dmol |
sel |
Atom selection specification with |
style |
Style spec to add to specified atoms created with |
label |
String for button label. |
byframe |
if TRUE, create labels for every individual frame in an animation, not just the current. |
hideButton |
Logical, whether to also create a button for removing all labels from the viewer. |
hideLabel |
String for hide labels button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to add and clear surface representations r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_res_labels(sel = m_sel(resi = c(70, 80, 90)))
# Add buttons to add and clear surface representations r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_res_labels(sel = m_sel(resi = c(70, 80, 90)))
Creates a button that will add the given style to the selection when pressed.
m_button_add_style( id, style = m_style_cartoon(), sel = m_sel(), label = "Style" )
m_button_add_style( id, style = m_style_cartoon(), sel = m_sel(), label = "Style" )
id |
R3dmol |
style |
Style spec to apply to specified atoms using |
sel |
Atom selection specification with |
label |
String for button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to show and hide sticks r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_button_add_style(m_style_stick(), label = "Show Sticks") %>% m_button_add_style(m_style_stick(hidden = TRUE), label = "Hide Sticks")
# Add buttons to show and hide sticks r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_button_add_style(m_style_stick(), label = "Show Sticks") %>% m_button_add_style(m_style_stick(hidden = TRUE), label = "Hide Sticks")
Add a button for adding a surface
m_button_add_surface( id, label = "Surface", type = "VDW", style = m_style_surface(), atomsel = m_sel(), allsel = NULL, removeSurface = TRUE, removeLabel = "Clear Surfaces" )
m_button_add_surface( id, label = "Surface", type = "VDW", style = m_style_surface(), atomsel = m_sel(), allsel = NULL, removeSurface = TRUE, removeLabel = "Clear Surfaces" )
id |
R3dmol |
label |
String for button label. |
type |
Surface type ('VDW', 'MS', 'SAS', or 'SES') |
style |
Optional style specification for surface material created with |
atomsel |
Show surface for atoms in this selection. |
allsel |
Use different atoms to calculate the surface than to display
it. May be a larger selection than |
removeSurface |
Logical, whether to also create a button that will remove all surfaces from the viewer. |
removeLabel |
String for clear surface button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to add and clear surface representations r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_surface( style = m_style_surface(opacity = 0.4), atomsel = m_sel(resi = 70:110) ) %>% m_button_add_surface( style = m_style_surface(opacity = 1), atomsel = m_sel(resi = 70:110, invert = TRUE), label = "Rest of Protein", removeSurface = FALSE )
# Add buttons to add and clear surface representations r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_surface( style = m_style_surface(opacity = 0.4), atomsel = m_sel(resi = 70:110) ) %>% m_button_add_surface( style = m_style_surface(opacity = 1), atomsel = m_sel(resi = 70:110, invert = TRUE), label = "Rest of Protein", removeSurface = FALSE )
Add a button for starting and stopping animations
m_button_animate( id, interval = 50, loop = "backAndForth", step = 1, reps = 0, label = "Play Animation", stopButton = TRUE, stopLabel = "Stop Animation" )
m_button_animate( id, interval = 50, loop = "backAndForth", step = 1, reps = 0, label = "Play Animation", stopButton = TRUE, stopLabel = "Stop Animation" )
id |
R3dmol |
interval |
Time in milliseconds between frames. |
loop |
Direction of animation loop. |
step |
How many frames to step through. 1 plays every frame, 2 skips every second frame etc. |
reps |
How many times to repeat the animation. 0 loops indefinitely. |
label |
String for button label. |
stopButton |
Logical, whether to also create a button to stop the currently playing animation. |
stopLabel |
String for stop for stop animation button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol( backgroundColor = "0xeeeeee" ) %>% m_add_model( data = xyz, format = "xyz", options = list(vibrate = list(frames = 10, amplitude = 1)) ) %>% m_set_style(style = m_style_stick()) %>% m_animate(list(loop = "backAndForth")) %>% m_zoom_to() %>% m_button_animate(step = 1, reps = 0, interval = 50)
xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol( backgroundColor = "0xeeeeee" ) %>% m_add_model( data = xyz, format = "xyz", options = list(vibrate = list(frames = 10, amplitude = 1)) ) %>% m_set_style(style = m_style_stick()) %>% m_animate(list(loop = "backAndForth")) %>% m_zoom_to() %>% m_button_animate(step = 1, reps = 0, interval = 50)
Add additional buttons to the viewer and manually pass in JavaScript functions to enable additional actions to be done when the button is clicked (such as styling changes to the model). You can also use css flex layout to control the layout of all added buttons.
m_button_manual( id, name, label, func, align_items = "flex-start", justify_content = "center" )
m_button_manual( id, name, label, func, align_items = "flex-start", justify_content = "center" )
id |
R3dmol |
name |
Name for button. |
label |
Label for button. |
func |
The function executed when the button is clicked. |
align_items |
The css |
justify_content |
The css |
If more than one button is set, only the layout
(justify-content
and align-items
) of the first button will be
used.
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_button_manual( name = "cartoon", label = "Cartoon", align_items = "flex-end", justify_content = "center", func = " function() { viewer.setStyle({cartoon:{}}); viewer.render(); } " ) %>% m_button_manual( name = "stick", label = "Stick", func = " function() { viewer.setStyle({stick:{}}); viewer.render(); } " )
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_button_manual( name = "cartoon", label = "Cartoon", align_items = "flex-end", justify_content = "center", func = " function() { viewer.setStyle({cartoon:{}}); viewer.render(); } " ) %>% m_button_manual( name = "stick", label = "Stick", func = " function() { viewer.setStyle({stick:{}}); viewer.render(); } " )
Adds a button that will overwrite the style for the given selection with the new given styles.
m_button_set_style( id, style = m_style_cartoon(), sel = m_sel(), label = "Style" )
m_button_set_style( id, style = m_style_cartoon(), sel = m_sel(), label = "Style" )
id |
R3dmol |
style |
Style spec to apply to specified atoms using |
sel |
Atom selection specification with |
label |
String for button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to show and hide sticks r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_style(m_style_stick(), label = "Add Sticks") %>% m_button_add_style(m_style_sphere(scale = 0.3), label = "Add Spheres") %>% m_button_set_style(m_style_cartoon(), label = "Set Cartoon")
# Add buttons to show and hide sticks r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_add_style(m_style_stick(), label = "Add Sticks") %>% m_button_add_style(m_style_sphere(scale = 0.3), label = "Add Spheres") %>% m_button_set_style(m_style_cartoon(), label = "Set Cartoon")
Add a button for spinning the scene
m_button_spin( id, speed = 1, axis = "y", label = "Spin", stopButton = TRUE, stopLabel = "Stop" )
m_button_spin( id, speed = 1, axis = "y", label = "Spin", stopButton = TRUE, stopLabel = "Stop" )
id |
R3dmol |
speed |
Speed multiplier for spin animation. Defaults to 1. Negative value reverses the direction of spin. |
axis |
Axis ( |
label |
String for button label. |
stopButton |
Logical, whether to also create a button to stop the spin. |
stopLabel |
String for the stop button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to start and stop spin r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_spin() # Add buttons to stop already spinning scene r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_spin() %>% m_button_spin()
# Add buttons to start and stop spin r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_button_spin() # Add buttons to stop already spinning scene r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_spin() %>% m_button_spin()
Add a button for zooming to a selection
m_button_zoom_to( id, sel = m_sel(), label = "Zoom", duration = 500, zoomOut = TRUE, zoomOutLabel = "Zoom Out" )
m_button_zoom_to( id, sel = m_sel(), label = "Zoom", duration = 500, zoomOut = TRUE, zoomOutLabel = "Zoom Out" )
id |
R3dmol |
sel |
Atom selection specification with |
label |
String for button label. |
duration |
Duration of the zoom animation in milliseconds. (Default 500) |
zoomOut |
Logical, whether to also create a button that will reset the view to encompass the entire scene. |
zoomOutLabel |
String for zoom out button label. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
# Add buttons to zoom in and out of a specific selection r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_add_style(m_style_stick(), m_sel(resi = 100:110)) %>% m_button_zoom_to(sel = m_sel(resi = 100:110))
# Add buttons to zoom in and out of a specific selection r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_zoom_to() %>% m_set_style(m_style_cartoon()) %>% m_add_style(m_style_stick(), m_sel(resi = 100:110)) %>% m_button_zoom_to(sel = m_sel(resi = 100:110))
Re-center the viewer around the provided selection (unlike zoomTo, does not zoom).
m_center(id, sel, animationDuration, fixedPath)
m_center(id, sel, animationDuration, fixedPath)
id |
R3dmol |
sel |
Selection specification specifying model and atom properties to select. Default: all atoms in viewer |
animationDuration |
an optional parameter of milliseconds |
fixedPath |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_center(animationDuration = 1000)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_center(animationDuration = 1000)
Clear scene of all objects
m_clear(id)
m_clear(id)
id |
R3dmol |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Enable/disable fog for content far from the camera
m_enable_fog(id, fog = TRUE)
m_enable_fog(id, fog = TRUE)
id |
R3dmol |
fog |
whether to enable or disable the fog, default is |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_enable_fog(fog = FALSE)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_enable_fog(fog = FALSE)
Using specified pdb id, retrieved .pdb file using bio3d::get.pdb() function. Will always query the only PDB for structure, and not store on local drive. May take some time to fetch information, every time it is run.
m_fetch_pdb(pdb, save.pdb = FALSE, path = NULL)
m_fetch_pdb(pdb, save.pdb = FALSE, path = NULL)
pdb |
PDB ID string for structure. |
save.pdb |
Logical, whether or not to save the PDB to local drive. Will
speed up subsequent load times. Defaults to |
path |
If |
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_zoom_to() ## End(Not run)
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_zoom_to() ## End(Not run)
Creates a scene with a number of simple defaults in order to quickly view the structure without having to write multiple lines of code.
m_glimpse( model, highlight = m_sel(), zoom = TRUE, spin = FALSE, nomouse = FALSE, ribbon = FALSE, outline = TRUE, backgroundColor = "white" )
m_glimpse( model, highlight = m_sel(), zoom = TRUE, spin = FALSE, nomouse = FALSE, ribbon = FALSE, outline = TRUE, backgroundColor = "white" )
model |
Model to add to scene. Can be |
highlight |
Given selection will additionally have 'ball-n-stick' representation. View will also zoom to selection. |
zoom |
Logical. FALSE will not zoom onto highlighted selection. |
spin |
TRUE / FALSE will enable or disable spin. A numeric value will change spin speed and negative will reverse the direction. |
nomouse |
Logical. Enables / disables mouse input. |
ribbon |
Logical. Enables / disables ribbon representation. |
outline |
Logical. Enables / disables black outline. |
backgroundColor |
String of simple colour names or hex code to change background color of viewer. |
library(r3dmol) # write/read demo structure as {bio3d} object tmp <- tempfile() write(pdb_6zsl, tmp) pdb <- bio3d::read.pdb(tmp) # quickly preview structure pdb %>% m_glimpse() # preview structure, highlighting particular region. pdb %>% m_glimpse(m_sel(resi = 1:10, chain = "A"), spin = 0.2) ## Not run: # Fetch given PDB string and quickly preview structure "4ozs" %>% m_glimpse(spin = TRUE) ## End(Not run)
library(r3dmol) # write/read demo structure as {bio3d} object tmp <- tempfile() write(pdb_6zsl, tmp) pdb <- bio3d::read.pdb(tmp) # quickly preview structure pdb %>% m_glimpse() # preview structure, highlighting particular region. pdb %>% m_glimpse(m_sel(resi = 1:10, chain = "A"), spin = 0.2) ## Not run: # Fetch given PDB string and quickly preview structure "4ozs" %>% m_glimpse(spin = TRUE) ## End(Not run)
Create a grid of viewers that share a WebGL canvas
m_grid( viewer, element_id, rows = NULL, cols = NULL, control_all = TRUE, viewer_config = m_viewer_spec(), width = NULL, height = NULL )
m_grid( viewer, element_id, rows = NULL, cols = NULL, control_all = TRUE, viewer_config = m_viewer_spec(), width = NULL, height = NULL )
viewer |
A list contains sub-viewers. |
element_id |
HTML string identifier. |
rows |
Number of rows in viewer grid. |
cols |
Number of columns in viewer grid. |
control_all |
Logical, simaultaneous mouse control of all windows in the grid. |
viewer_config |
Viewer specification to apply to all subviewers. |
width |
Fixed width for combined viewer (in css units). Ignored when
used in a Shiny app – use the |
height |
Fixed height for combined viewer (in css units). It is recommended to not use this parameter since the widget knows how to adjust its height automatically. |
An r3dmol
object (the output from r3dmol()
).
library(r3dmol) m1 <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() m2 <- m1 %>% m_set_style(style = m_style_cartoon(color = "spectrum")) m3 <- m1 %>% m_set_style(style = m_style_stick()) m4 <- m1 %>% m_set_style(style = m_style_sphere()) m_grid( viewer = list(m1, m2, m3, m4), control_all = TRUE, viewer_config = m_viewer_spec( backgroundColor = "black" ) )
library(r3dmol) m1 <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() m2 <- m1 %>% m_set_style(style = m_style_cartoon(color = "spectrum")) m3 <- m1 %>% m_set_style(style = m_style_stick()) m4 <- m1 %>% m_set_style(style = m_style_sphere()) m_grid( viewer = list(m1, m2, m3, m4), control_all = TRUE, viewer_config = m_viewer_spec( backgroundColor = "black" ) )
Behaves just like the m_sel()
, but returns a new selection for each
residue specified with resi
.
m_multi_resi_sel( resi = NULL, resn = NULL, chain = NULL, model = NULL, elem = NULL, atom = NULL, invert = NULL, byres = NULL, b = NULL, expand = NULL, bonds = NULL, ss = NULL, clickable = NULL, callback = NULL )
m_multi_resi_sel( resi = NULL, resn = NULL, chain = NULL, model = NULL, elem = NULL, atom = NULL, invert = NULL, byres = NULL, b = NULL, expand = NULL, bonds = NULL, ss = NULL, clickable = NULL, callback = NULL )
resi |
Residue number/s. (vector) |
resn |
Parent residue name as 3-letter code (e.g. "ALA", "GLY", "CYS"...) |
chain |
String, chain this atom belongs to (e.g. 'A' for chain A) |
model |
a single model or list of models from which atoms should be selected. Can also specify by numerical creation order. Reverse indexing is allowed (-1 specifies last added model). |
elem |
element abbreviation (e.g 'H', 'Ca', etc) |
atom |
Atom name, may be more specific than 'elem' (e.g. 'CA' for alpha carbon) |
invert |
Logical, if |
byres |
Logical, if |
b |
Atom b factor data |
expand |
Expand selection to include atoms within a specified distance from current selection. all atoms of any residue that has any atom already selected. |
bonds |
overloaded to select number of bonds, e.g. |
ss |
Secondary structure identifier. 'h' for helix, 's' for beta-sheet. |
clickable |
Set this flag to true to enable click selection handling for this atom |
callback |
Callback click handler function to be executed on this atom and its parent viewer. |
The m_sel(resi = 1:10)
returns a selection of all 10 residues.
The m_multi_resi_sel(resi = 1:10)
returns 10 individual selections,
each containing only 1 of the residues.
sel list()
for selecting atoms.
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl) %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_add_style( sel = m_sel(resi = 1:10), style = c( m_style_stick(), m_style_sphere(scale = 0.3) ) ) %>% m_add_line( start = m_multi_resi_sel(resi = rep(1, 9), chain = "A"), end = m_multi_resi_sel( resi = 2:10, chain = "B" ) )
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl) %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_add_style( sel = m_sel(resi = 1:10), style = c( m_style_stick(), m_style_sphere(scale = 0.3) ) ) %>% m_add_line( start = m_multi_resi_sel(resi = rep(1, 9), chain = "A"), end = m_multi_resi_sel( resi = 2:10, chain = "B" ) )
Convert widgets to PNG image
m_png(id, width, height, captureDelay = 2000)
m_png(id, width, height, captureDelay = 2000)
id |
R3dmol |
width , height
|
image width and height. |
captureDelay |
Image conversion delay setting. This argument is only
needed in some cases where the rendering is time-consuming (e.g. with
|
Base64 encoded png image wrapped by <img>
tag.
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_png()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_png()
Remove all labels from viewer
m_remove_all_labels(id)
m_remove_all_labels(id)
id |
R3dmol |
id R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") %>% m_set_style(style = m_style_stick(radius = 2)) %>% m_zoom_to() %>% m_add_property_labels( prop = "index", sel = list(not = list(elem = "H")), style = m_style_label( fontColor = "black", font = "sans-serif", fontSize = 28, showBackground = FALSE, alignment = "center" ) ) # Render model with labels mol # Remove all labels mol %>% m_remove_all_labels()
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") %>% m_set_style(style = m_style_stick(radius = 2)) %>% m_zoom_to() %>% m_add_property_labels( prop = "index", sel = list(not = list(elem = "H")), style = m_style_label( fontColor = "black", font = "sans-serif", fontSize = 28, showBackground = FALSE, alignment = "center" ) ) # Render model with labels mol # Remove all labels mol %>% m_remove_all_labels()
Delete all existing models
m_remove_all_models(id)
m_remove_all_models(id)
id |
R3dmol |
id R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") # Render model mol # Remove all labels mol %>% m_remove_all_models()
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = "data-raw/Conformer3D_CID_5291.sdf", format = "sdf") # Render model mol # Remove all labels mol %>% m_remove_all_models()
Remove all shape objects from viewer
m_remove_all_shapes(id)
m_remove_all_shapes(id)
id |
R3dmol |
id R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_add_sphere( center = list(x = 0, y = 0, z = 0), radius = 10.0, color = "red" ) # Render model with shape mol # Remove shape mol %>% m_remove_all_shapes()
library(r3dmol) mol <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_add_sphere( center = list(x = 0, y = 0, z = 0), radius = 10.0, color = "red" ) # Render model with shape mol # Remove shape mol %>% m_remove_all_shapes()
Remove all labels from viewer
m_remove_all_surfaces(id)
m_remove_all_surfaces(id)
id |
R3dmol |
id R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Remove label from viewer
m_remove_label(id, label)
m_remove_label(id, label)
id |
R3dmol |
label |
R3dmol object label |
id R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Render current state of viewer, after adding/removing models, applying styles, etc. In most cases, the model will render automatically, only call it when manual rendering is required.
m_render(id)
m_render(id)
id |
R3dmol |
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_render()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_render()
Rotate scene by angle degrees around axis
m_rotate(id, angle, axis = "v", animationDuration = 0, fixedPath)
m_rotate(id, angle, axis = "v", animationDuration = 0, fixedPath)
id |
R3dmol |
angle |
Angle, in degrees |
axis |
Axis ( |
animationDuration |
an optional parameter of milliseconds |
fixedPath |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_rotate(angle = 90, axis = "y", animationDuration = 1000)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_rotate(angle = 90, axis = "y", animationDuration = 1000)
Provides documentation for some basic useful selection criteria. For more advanced selection options, see the Official Documenation
m_sel( model = NULL, resi = NULL, resn = NULL, invert = NULL, chain = NULL, elem = NULL, atom = NULL, byres = NULL, b = NULL, expand = NULL, bonds = NULL, ss = NULL, clickable = NULL, callback = NULL )
m_sel( model = NULL, resi = NULL, resn = NULL, invert = NULL, chain = NULL, elem = NULL, atom = NULL, byres = NULL, b = NULL, expand = NULL, bonds = NULL, ss = NULL, clickable = NULL, callback = NULL )
model |
a single model or list of models from which atoms should be selected. Can also specify by numerical creation order. Reverse indexing is allowed (-1 specifies last added model). |
resi |
Residue number/s. (vector) |
resn |
Parent residue name as 3-letter code (e.g. "ALA", "GLY", "CYS"...) |
invert |
Logical, if |
chain |
String, chain this atom belongs to (e.g. 'A' for chain A) |
elem |
element abbreviation (e.g 'H', 'Ca', etc) |
atom |
Atom name, may be more specific than 'elem' (e.g. 'CA' for alpha carbon) |
byres |
Logical, if |
b |
Atom b factor data |
expand |
Expand selection to include atoms within a specified distance from current selection. all atoms of any residue that has any atom already selected. |
bonds |
overloaded to select number of bonds, e.g. |
ss |
Secondary structure identifier. 'h' for helix, 's' for beta-sheet. |
clickable |
Set this flag to true to enable click selection handling for this atom |
callback |
Callback click handler function to be executed on this atom and its parent viewer. |
sel list()
for selecting atoms.
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_style( style = m_style_stick(), sel = m_sel(resi = 1:2) ) %>% m_zoom_to(sel = m_sel(resi = 1)) # Expand example r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_style( style = m_style_stick(), sel = m_sel( resi = 1, expand = 10, byres = TRUE ) ) %>% m_zoom_to(sel = m_sel(resi = 1)) ## End(Not run)
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_style( style = m_style_stick(), sel = m_sel(resi = 1:2) ) %>% m_zoom_to(sel = m_sel(resi = 1)) # Expand example r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_style( style = m_style_stick(), sel = m_sel( resi = 1, expand = 10, byres = TRUE ) ) %>% m_zoom_to(sel = m_sel(resi = 1)) ## End(Not run)
Set color by element
m_set_color_by_element(id, sel, colors)
m_set_color_by_element(id, sel, colors)
id |
R3dmol |
sel |
Atom selection. |
colors |
Color hex code or name. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Set the default cartoon quality for newly created models. Default is
5
.
Current models are not affected.
m_set_default_cartoon_quality(id, quality)
m_set_default_cartoon_quality(id, quality)
id |
R3dmol |
quality |
Default cartoon quality. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_set_default_cartoon_quality(20) %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_set_default_cartoon_quality(20) %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to()
Set the duration of the hover delay
m_set_hover_duration(id, hoverDuration)
m_set_hover_duration(id, hoverDuration)
id |
R3dmol |
hoverDuration |
an optional parameter that denotes the duration of the hover delay (in milliseconds) before the hover action is called |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Essentially zooming. Useful while stereo rendering.
m_set_preceived_distance(id, dist)
m_set_preceived_distance(id, dist)
id |
R3dmol |
dist |
Numeric distance. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_preceived_distance(dist = 200)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_preceived_distance(dist = 200)
Set view projection scheme
m_set_projection(id, scheme = c("perspective", "orthographic"))
m_set_projection(id, scheme = c("perspective", "orthographic"))
id |
R3dmol |
scheme |
Either |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_projection(scheme = "orthographic")
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_projection(scheme = "orthographic")
Set slab of view (contents outside of slab are clipped).
m_set_slab(id, near, far)
m_set_slab(id, near, far)
id |
R3dmol |
near |
near clipping plane distance |
far |
far clipping plane distance |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_set_slab(near = -90, far = 0)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_zoom_to() %>% m_set_slab(near = -90, far = 0)
Takes a selection and overwrites previous styling with given styles.
m_set_style(id, style = m_style_cartoon(), sel = m_sel())
m_set_style(id, style = m_style_cartoon(), sel = m_sel())
id |
R3dmol |
style |
Style spec to apply to specified atoms using m_style_*() |
sel |
Atom selection specification with |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Add style to model r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_add_style(style = m_style_cartoon()) %>% m_zoom_to()
library(r3dmol) # Add style to model r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_add_style(style = m_style_cartoon()) %>% m_zoom_to()
Sets the view to the specified translation, zoom, rotation and style
m_set_view(id, arg, style)
m_set_view(id, arg, style)
id |
R3dmol |
arg |
Vector formatted view setting,
|
style |
css style object in list. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_view(arg = c(20, -20, 10, -200, 0, 1, 0, 0)) %>% m_add_outline(color = "blue")
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon()) %>% m_set_view(arg = c(20, -20, 10, -200, 0, 1, 0, 0)) %>% m_add_outline(color = "blue")
Functions of setting viewer properties, such as width, height, background color, etc. The viewer size can be adjusted automatically under normal circumstances.
m_set_width(id, width) m_set_height(id, height) m_set_background_color(id, hex, alpha)
m_set_width(id, width) m_set_height(id, height) m_set_background_color(id, hex, alpha)
id |
R3dmol |
width , height
|
Weight and height |
hex |
Hex code specified background color, or standard color spec
|
alpha |
Alpha level |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() %>% m_set_width(300) %>% m_set_background_color("#666666", alpha = 0.9)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() %>% m_set_width(300) %>% m_set_background_color("#666666", alpha = 0.9)
Set lower and upper limit stops for zoom
m_set_zoom_limits(id, lower = 0, upper = Inf)
m_set_zoom_limits(id, lower = 0, upper = Inf)
id |
R3dmol |
lower |
limit on zoom in (positive |
upper |
limit on zoom out (positive |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
Styling options for the various shapes. Used inside m_add_sphere()
,
m_add_arrow()
, m_add_cylinder()
etc.
m_shape_spec( color = NULL, opacity = 1, wireframe = FALSE, hidden = FALSE, frame = NULL, clickable = FALSE, callback = NULL, hoverable = FALSE, hover_callback = NULL, unhover_callback = NULL )
m_shape_spec( color = NULL, opacity = 1, wireframe = FALSE, hidden = FALSE, frame = NULL, clickable = FALSE, callback = NULL, hoverable = FALSE, hover_callback = NULL, unhover_callback = NULL )
color |
Solid color values. |
opacity |
Transparency value. 1 for opaque, 0 for invisible. |
wireframe |
Draw as wireframe, not solid surface. |
If true, do not display object. |
|
frame |
If set, only display in this frame of an animation. |
clickable |
If true, user can click on object to trigger callback. |
callback |
Function to call on click. |
hoverable |
Logical, enabling hover_callback and unhover_callback functions to be called. Set hoverDuration in the viewer_spec() of r3dmol(). |
hover_callback |
Function to be called upon hover. |
unhover_callback |
Function to be called upon hover stopping. |
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_sphere( center = m_sel(resi = 1), spec = m_shape_spec(color = "green", wireframe = TRUE) ) %>% m_zoom_to(sel = m_sel(resi = 1)) ## End(Not run)
library(r3dmol) ## Not run: r3dmol() %>% m_add_model(data = m_fetch_pdb("1bna")) %>% m_add_sphere( center = m_sel(resi = 1), spec = m_shape_spec(color = "green", wireframe = TRUE) ) %>% m_zoom_to(sel = m_sel(resi = 1)) ## End(Not run)
r3dmol
in a Shiny appRun examples of using r3dmol
in a Shiny app
m_shiny_demo()
m_shiny_demo()
if (interactive()) { m_shiny_demo() }
if (interactive()) { m_shiny_demo() }
Continuously rotate a scene around the specified axis
m_spin(id, axis = "y", speed = 1)
m_spin(id, axis = "y", speed = 1)
id |
R3dmol |
axis |
Axis ( |
speed |
Speed multiplier for spin animation. Defaults to 1. Negative value reverses the direction of spin. |
R3dmol id or a r3dmol
object (the output from r3dmol()
)
library(r3dmol) model <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon(color = "spectrum")) %>% m_zoom_to() # spin the model model %>% m_spin() # reverses the direction of spin model %>% m_spin(speed = -0.5)
library(r3dmol) model <- r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_set_style(style = m_style_cartoon(color = "spectrum")) %>% m_zoom_to() # spin the model model %>% m_spin() # reverses the direction of spin model %>% m_spin(speed = -0.5)
Stop animation of all models in viewer
m_stop_animate(id)
m_stop_animate(id)
id |
R3dmol |
Styling options for ball and stick representations.
m_style_ballnstick( sphereScale = 0.3, colorScheme = NULL, color = NULL, sphereRadius = NULL, stickRadius = 0.25, hidden = FALSE, opacity = 1, colorfunc = NULL )
m_style_ballnstick( sphereScale = 0.3, colorScheme = NULL, color = NULL, sphereRadius = NULL, stickRadius = 0.25, hidden = FALSE, opacity = 1, colorfunc = NULL )
sphereScale |
Relative scaling of sphere atomic radii. |
colorScheme |
Specify scheme to color the atoms by. Default is "default". Other choices are "Carbon", "ssPyMOL", "ssJmol", "Jmol", "default", "amino", "shapely", "nucleic", "chain", "chainHetatm", "prop". |
color |
Specific coloring for everything in selection, overrides any specified colorScheme. |
sphereRadius |
Set absolute radius for all spheres in selection (overriding the atomic raddii)l |
stickRadius |
Set absolute radius for all sticks in the selection. |
Boolean - do not show atoms in selection. Default |
|
opacity |
Opacity of spheres and sticks, 0 being invisible, 1 being opaque. Must be the same for all atoms in the model. |
colorfunc |
Allows the user to provide a function for setting the colorSchemes, written in javascript. Official Documentation |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_ballnstick()) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_ballnstick()) %>% m_zoom_to()
Styling options for the cartoon representation. Used inside
m_add_style()
and m_set_style()
.
m_style_cartoon( color = NULL, style = "rectangle", ribbon = FALSE, arrows = TRUE, tubes = FALSE, thickness = 0.4, width = NULL, opacity = 1, colorfunc = NULL )
m_style_cartoon( color = NULL, style = "rectangle", ribbon = FALSE, arrows = TRUE, tubes = FALSE, thickness = 0.4, width = NULL, opacity = 1, colorfunc = NULL )
color |
Block color values. Strand color, may specify as 'spectrum' which will apply reversed gradient based on residue number. |
style |
style of cartoon rendering ("trace", "oval", "rectangle" (default), "parabola", "edged"). |
ribbon |
whether to use constant strand width, disregarding secondary structure; use thickness to adjust radius. |
arrows |
whether to add arrows showing beta-sheet directionality; does not apply to trace or ribbon. |
tubes |
whether to display alpha helices as simple cylinders; does not apply to trace. |
thickness |
cartoon strand thickness, default is 0.4. |
width |
cartoon strand width, default is secondary structure-dependent; does not apply to trace or ribbon. |
opacity |
set opacity from 0-1; transparency is set per-chain with a warning outputted in the event of ambiguity. |
colorfunc |
Allows the user to provide a function for setting the colorSchemes, written in javascript. Official Documentation |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon(color = "spectrum")) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_cartoon(color = "spectrum")) %>% m_zoom_to()
Styling options for the labels. Used inside m_add_label()
,
m_add_res_labels()
and m_add_property_labels()
.
m_style_label( font = "sans-serif", fontSize = 18, fontColor = "white", fontOpacity = 1, backgroundColor = "black", backgroundOpacity = 1, borderOpacity = 1, borderThickness = 0, borderColor = backgroundColor, inFront = TRUE, showBackground = TRUE, fixed = FALSE, alignment = c("topLeft", "topCenter", "topRight", "centerLeft", "center", "centerRight", "bottomLeft", "bottomCenter", "bottomRight"), position = NULL, frame = NULL )
m_style_label( font = "sans-serif", fontSize = 18, fontColor = "white", fontOpacity = 1, backgroundColor = "black", backgroundOpacity = 1, borderOpacity = 1, borderThickness = 0, borderColor = backgroundColor, inFront = TRUE, showBackground = TRUE, fixed = FALSE, alignment = c("topLeft", "topCenter", "topRight", "centerLeft", "center", "centerRight", "bottomLeft", "bottomCenter", "bottomRight"), position = NULL, frame = NULL )
font |
Font name, default sans-serif. |
fontSize |
Height of text, default 18. |
fontColor |
Font color, default white. |
fontOpacity |
Font opacity, default 1. |
backgroundColor |
Color of background, default black. |
backgroundOpacity |
Opacity of background, default 1. |
borderOpacity |
Opacity of border, default 1. |
borderThickness |
Line width of border around label, default 0. |
borderColor |
Color of border, default backgroundColor. |
inFront |
Logical, if |
showBackground |
Logical, show background rounded rectangle, default
|
fixed |
Logical, setes the label to change with the model when zooming. |
alignment |
String, how to orient the label with respect to position: 'topLeft' (default), 'topCenter', 'topRight', 'centerLeft', 'center', 'centerRight', 'bottomLeft', 'bottomCenter', 'bottomRight'. |
position |
x,y,z coordinates for label (for custom positioning). |
frame |
If set, only display in this frame of an animation. |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick()) %>% m_add_res_labels(style = m_style_label( fontSize = 14, backgroundColor = "green" )) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick()) %>% m_add_res_labels(style = m_style_label( fontSize = 14, backgroundColor = "green" )) %>% m_zoom_to()
Styling options for the line representation. Used inside
m_add_style()
and m_set_style()
. Can also be used for styling
when adding individual lines with m_add_line()
.
m_style_line(colorScheme = NULL, color = NULL, opacity = 1, hidden = FALSE)
m_style_line(colorScheme = NULL, color = NULL, opacity = 1, hidden = FALSE)
colorScheme |
Specify scheme to color the atoms by. Default is "default". Other choices are "Carbon", "ssPyMOL", "ssJmol", "Jmol", "default", "amino", "shapely", "nucleic", "chain", "chainHetatm", "prop". |
color |
Fixed coloring, overrides |
opacity |
Opacity, must be the same for all atoms in the model. |
Logical, do not show line. |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_line(color = "blue")) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_line(color = "blue")) %>% m_zoom_to()
Styling options for the sphere representation. Used inside
m_add_style()
and m_set_style()
.
m_style_sphere( scale = 1, colorScheme = NULL, color = NULL, radius = NULL, hidden = FALSE, opacity = 1, colorfunc = NULL )
m_style_sphere( scale = 1, colorScheme = NULL, color = NULL, radius = NULL, hidden = FALSE, opacity = 1, colorfunc = NULL )
scale |
Scale radius by specified amount. |
colorScheme |
Specify scheme to color the atoms by. Default is "default". Other choices are "Carbon", "ssPyMOL", "ssJmol", "Jmol", "default", "amino", "shapely", "nucleic", "chain", "chainHetatm", "prop". |
color |
Discrete, fixed coloring, overrides any colorScheme. |
radius |
Override van der waals radius. |
Boolean - do not show atom. Default |
|
opacity |
Opacity of spheres, 0 being invisible. Must be the same for all atoms in the model. |
colorfunc |
Allows the user to provide a function for setting the colorSchemes, written in javascript. Official Documentation |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_sphere(radius = 0.5)) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_sphere(radius = 0.5)) %>% m_zoom_to()
Styling options for the stick representation. Used inside
m_add_style()
and m_set_style()
.
m_style_stick( radius = 0.3, singleBonds = FALSE, colorScheme = NULL, color = NULL, opacity = 1, hidden = FALSE, colorfunc = NULL )
m_style_stick( radius = 0.3, singleBonds = FALSE, colorScheme = NULL, color = NULL, opacity = 1, hidden = FALSE, colorfunc = NULL )
radius |
Radius of sticks. |
singleBonds |
Draw all bonds as single bonds if |
colorScheme |
Specify scheme to color the atoms by. Default is "default". Other choices are "Carbon", "ssPyMOL", "ssJmol", "Jmol", "default", "amino", "shapely", "nucleic", "chain", "chainHetatm", "prop". |
color |
Fixed coloring, overrides colorScheme. |
opacity |
Opacity, must be the same for all atoms in the model. |
Do not show. |
|
colorfunc |
Allows the user to provide a function for setting the colorSchemes, written in javascript. Official Documentation |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick(opacity = 0.4)) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick(opacity = 0.4)) %>% m_zoom_to()
Styling options for the surface representation. Used inside
m_add_surface()
.
m_style_surface(opacity = 1, colorScheme = NULL, color = NULL)
m_style_surface(opacity = 1, colorScheme = NULL, color = NULL)
opacity |
Opacity, 0 for transparent, 1 for opaque. |
colorScheme |
Specify scheme to color the atoms by. Default is "default". Other choices are "Carbon", "ssPyMOL", "ssJmol", "Jmol", "default", "amino", "shapely", "nucleic", "chain", "chainHetatm", "prop". |
color |
Fixed coloring, overrides colorScheme. |
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick()) %>% m_add_surface(style = m_style_surface(opacity = 0.4)) %>% m_zoom_to()
r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = m_style_stick()) %>% m_add_surface(style = m_style_surface(opacity = 0.4)) %>% m_zoom_to()
m_translate()
pans the camera rather than translating the model.
m_translate_scene()
translates the models relative to the current
view. It does not change the center of rotation.
m_translate(id, x, y, animationDuration, fixedPath) m_translate_scene(id, x, y, animationDuration, fixedPath)
m_translate(id, x, y, animationDuration, fixedPath) m_translate_scene(id, x, y, animationDuration, fixedPath)
id |
R3dmol |
x |
Relative change |
y |
Relative change |
animationDuration |
an optional parameter of milliseconds |
fixedPath |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) # Translate current view by x,y screen coordinates r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_translate( x = 200, y = 50, animationDuration = 1000 ) %>% m_rotate( angle = 90, axis = "z", animationDuration = 1000 ) %>% m_zoom_to() # Translate current models by x,y screen coordinates r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_translate_scene( x = 200, y = 50, animationDuration = 1000 ) %>% m_rotate( angle = 90, axis = "z", animationDuration = 1000 ) %>% m_zoom_to()
library(r3dmol) # Translate current view by x,y screen coordinates r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_translate( x = 200, y = 50, animationDuration = 1000 ) %>% m_rotate( angle = 90, axis = "z", animationDuration = 1000 ) %>% m_zoom_to() # Translate current models by x,y screen coordinates r3dmol() %>% m_add_model(data = pdb_1j72, format = "pdb") %>% m_set_style(style = c(m_style_cartoon(), m_style_stick())) %>% m_translate_scene( x = 200, y = 50, animationDuration = 1000 ) %>% m_rotate( angle = 90, axis = "z", animationDuration = 1000 ) %>% m_zoom_to()
Create a 3 dimensional vector
m_vector3(x = 0, y = 0, z = 0)
m_vector3(x = 0, y = 0, z = 0)
x |
x coordinate, |
y |
y coordinate, |
z |
z coordinate, |
3 dimensional list object
library(r3dmol) m_vector3(1, 2, 3)
library(r3dmol) m_vector3(1, 2, 3)
If atoms have dx, dy, dz properties (in some xyz files), vibrate populates each model's frame property based on parameters. Models can then be animated.
m_vibrate(id, numFrames, amplitude, bothWays, arrowSpec)
m_vibrate(id, numFrames, amplitude, bothWays, arrowSpec)
id |
R3dmol |
numFrames |
Number of frames to be created, default to 10 |
amplitude |
Amplitude of distortion, default to 1 (full) |
bothWays |
If true, extend both in positive and negative directions by numFrames |
arrowSpec |
Specification for drawing animated arrows. If color isn't specified, atom color (sphere, stick, line preference) is used. |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol() %>% m_add_model(data = xyz, format = "xyz") %>% m_set_style(style = m_style_stick()) %>% m_vibrate(numFrames = 10, amplitude = 1) %>% m_animate(options = list(loop = "backAndForth", reps = 0)) %>% m_zoom_to()
library(r3dmol) xyz <- "4 * (null), Energy -1000.0000000 N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746 H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108 H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024 H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260 " r3dmol() %>% m_add_model(data = xyz, format = "xyz") %>% m_set_style(style = m_style_stick()) %>% m_vibrate(numFrames = 10, amplitude = 1) %>% m_animate(options = list(loop = "backAndForth", reps = 0)) %>% m_zoom_to()
Returns a list for the setup r3dmol()
function, to set
overall settings for the viewer going forward.
m_viewer_spec( id = NULL, defaultcolors = NULL, cartoonQuality = 5, antialias = TRUE, nomouse = FALSE, backgroundColor = "white", lowerZoomLimit = 5, upperZoomLimit = 400, orthographic = FALSE, disableFog = FALSE )
m_viewer_spec( id = NULL, defaultcolors = NULL, cartoonQuality = 5, antialias = TRUE, nomouse = FALSE, backgroundColor = "white", lowerZoomLimit = 5, upperZoomLimit = 400, orthographic = FALSE, disableFog = FALSE )
id |
id of the canvas. |
defaultcolors |
Object defining default atom colors as atom => color property value pairs for all models within this viewer. |
cartoonQuality |
Defaults to |
antialias |
Logical, disable to decrease quality but improve performance. |
nomouse |
Whether to disable handling of mouse events. Disabled will prevent user interaction. |
backgroundColor |
color of the canvas's background. |
lowerZoomLimit |
Specify how far the user can zoom in. |
upperZoomLimit |
Specify how far the user can zoom out. |
orthographic |
Logical. Setting orthographic instead of perspective representation. |
disableFog |
Logical, disable fog, defaults to |
Zoom current view by a constant factor
m_zoom(id, factor = 2, animationDuration, fixedPath)
m_zoom(id, factor = 2, animationDuration, fixedPath)
id |
R3dmol |
factor |
Magnification |
animationDuration |
an optional parameter of milliseconds |
fixedPath |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() %>% m_zoom(factor = 2, animationDuration = 1000)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to() %>% m_zoom(factor = 2, animationDuration = 1000)
Zoom to center of atom selection. The slab will be set appropriately for the selection, unless an empty selection is provided, in which case there will be no slab.
m_zoom_to(id, sel, animationDuration, fixedPath)
m_zoom_to(id, sel, animationDuration, fixedPath)
id |
R3dmol |
sel |
Selection specification specifying model and atom properties to select. Default: all atoms in viewer. |
animationDuration |
an optional parameter of milliseconds |
fixedPath |
if |
R3dmol id
or a r3dmol
object (the output from
r3dmol()
)
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to()
library(r3dmol) r3dmol() %>% m_add_model(data = pdb_6zsl, format = "pdb") %>% m_zoom_to()
Crystal Structure of Mutant Macrophage Capping Protein (Cap G) with Actin-severing Activity in the Ca2+-Free Form in PDB format
pdb_1j72
pdb_1j72
PDB Format.
DOI: 10.2210/pdb1J72/pdb. https://www.rcsb.org/structure/1J72
Crystal structure of the SARS-CoV-2 helicase at 1.94 Angstrom resolution in PDB format
pdb_6zsl
pdb_6zsl
PDB Format.
DOI: 10.2210/pdb6ZSL/pdb. https://www.rcsb.org/structure/6zsl
Output and render functions for using r3dmol within Shiny applications and interactive Rmd documents.
r3dmolOutput(outputId, width = "100%", height = "400px") renderR3dmol(expr, env = parent.frame(), quoted = FALSE)
r3dmolOutput(outputId, width = "100%", height = "400px") renderR3dmol(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a r3dmol |
env |
The environment in which to evaluate |
quoted |
Is |
Multiple sdf file example
sdf_multiple
sdf_multiple
sdf format
https://github.com/3dmol/3Dmol.js/blob/master/tests/test_structs/multiple.sdf
Multiple xyz file example
xyz_multiple
xyz_multiple
xyz format
https://github.com/3dmol/3Dmol.js/blob/master/tests/test_structs/multiple2.xyz