Introduction to r3dmol (original) (raw)
This is an R package that provides support for 3Dmol.jsas a htmlwidgets.
Important: This package is still very early in its development stages. Please give the repository a star on Github if you find the package is useful. In addition, we need your feedback to improve the package, feel free to create an issue if you have any question or feature requirement. You are more than welcome to submit a PR to make any feasible improvements.
# install.packages("devtools")
devtools::install_github("swsoyee/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",
id = "demo_xyz",
elementId = "demo_xyz"
) %>%
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()
benz <- "
RDKit 3D
6 6 0 0 0 0 0 0 0 0999 V2000
-0.9517 0.7811 -0.6622 C 0 0 0 0 0 0 0 0 0 0 0 0
0.2847 1.3329 -0.3121 C 0 0 0 0 0 0 0 0 0 0 0 0
1.2365 0.5518 0.3512 C 0 0 0 0 0 0 0 0 0 0 0 0
0.9517 -0.7811 0.6644 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.2847 -1.3329 0.3144 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.2365 -0.5518 -0.3489 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0
2 3 1 0
3 4 2 0
4 5 1 0
5 6 2 0
6 1 1 0
M END <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotation encoding="application/x-tex"></annotation></semantics></math></span><span class="katex-html" aria-hidden="true"></span></span>$$"
r3dmol(id = "demo_sdf", elementId = "demo_sdf") %>%
m_add_model(data = benz, format = "sdf") %>%
m_set_style(style = m_style_stick()) %>%
m_set_style(
sel = m_sel(model = 0),
style = m_style_stick(colorScheme = "cyanCarbon")
) %>%
m_zoom_to()
Dynamic Styles
If you know some JavaScript, then you are able to write a function to set dynamic styles. The following code shows how to color atoms based on their positions. You can also use [m_png()](../reference/m%5Fpng.html)
to convert the widget to a png image.