Some useful functions I created for working between bio3d and r3dmol. The most difficult part was getting the bio3d object read properly, which is just solved via capture.output(write.pdb(pdb = pdb, file = "")) which parses the structure as a text .pdb formatted file.

m_add_bio3d <- function(
  pdb
) {
  capture.output(write.pdb(pdb = pdb, file = ""))
}

m_vector3_convert <- function (
  vector
) {
  if(!is.numeric(vector))
    stop("Vector must be numeric.")
  if(length(vector) != 3)
    stop("Vector must be of length 3.")
  m_vector3(
    x = vector[1], 
    y = vector[2], 
    z = vector[3]
  )
}

Testing out a couple of different functions.

r3dmol() %>%
  m_add_model(data = m_add_bio3d(apo_pdb)) %>%
  m_zoom_to() %>%
  m_set_style(style = list(
    cartoon = list(
      color = "#00f5ff"
    )
  )) %>%
  m_add_label(text = "dPPR10 Structure", options = list(
    fontColor = "#00f5ff", 
    alignment = "center", 
    inFront = FALSE
  )) %>%
  m_add_model(data = m_add_bio3d(bound_pdb)) %>%
  m_set_style(sel = list(model = 1), 
              style = list(
                cartoon = list(
                  color = "#98cb99"
                )
              )) %>% 
  m_add_label(text = "dPPR10 Bound Structure", 
              options = list(
                fontColor = "#98cb99", 
                inFront = FALSE, 
                alignment = "center"
              ), 
              sel = list(
                model = 1
              ))

Testing an alignment.

Can I do analysis in bio3d and then present this information using r3dmol?

Just going to trial doing an alignment using the last 245 residues in the strcutures.

new_bound <- bound_pdb
new_bound$xyz <-
  fit.xyz(apo_pdb$xyz,
          bound_pdb$xyz,
          fixed.inds = atom.select.pdb(apo_pdb, resno = (610-35*7):610)$xyz,
          mobile.inds = atom.select.pdb(apo_pdb, resno = (610-35*7):610)$xyz)

models <- r3dmol() %>%
  m_add_model(data = m_add_bio3d(apo_pdb), format = "pdb") %>%
  m_add_model(data = m_add_bio3d(new_bound), format = "pdb") %>%
  m_zoom_to()
  


models

Looks are everything.

The alignment seems to have worked, but can we make things look a bit prettier.

models <- models %>%
  m_set_style(style = list(cartoon = list(color = "#98cb99")), sel = list(model = 1)) %>%
  m_set_style(style = list(cartoon = list(color = "#00f5ff")), sel = list(model = 0))
models

Surfaces

What about the addition of a surface representation?

models <- models %>%
    m_add_surface(type = "SES", style = list(color = "#98cb99", opacity = 0.5), atomsel = list(model = c(0,1)))

models