r3dmol icon indicating copy to clipboard operation
r3dmol copied to clipboard

m_add_label() prints label at wrong position

Open senanu opened this issue 2 years ago • 1 comments

Thank you for such a useful package -- I've found it much easier to use than some of the alternatives.

m_add_label prints a label, but if given m_vector3 coordinates, the label prints at the wrong position.

The following reprex shows this, using the example code from the help file. Here, I print 2 labels, at different positions (I just changed the signs of the coordinates and label colors) but the labels end up in the same position.

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_add_label(
    text = "Label2",
    sel = m_vector3(6.89, -0.75, -0.35),
    style = m_style_label(
      backgroundColor = "#000000",
      backgroundOpacity = 0.9
    )
  ) %>%
  m_zoom_to()

The positioning seems to work fine when given a residue number, but I'd like to be able to place labels outside of the molecular structure and connect them to the relevant location with an arrow. Also, m_vector3 works fine in other situations.

senanu avatar Oct 24 '23 15:10 senanu

Thank you for using this broken package. I have just noticed that 3Dmol has been upgrade to v2.x and has many break changes. I don't have time to upgrade r3dmol for now, but there is a very tricky way to partially accomplish your goal

style <-  m_style_label(
  backgroundColor = "#666666",
  backgroundOpacity = 0.9
)
style$screenOffset <- list(x = 0, y = 100) # Add this option with a X and Y. Z did not work.

r3dmol() %>%
  m_add_model(data = pdb_6zsl, format = "pdb") %>%
  m_add_label(
    text = "Label",
    sel = m_vector3(3, 0, 1),
    style = style
  ) |> 
  m_add_arrow(
    start = m_vector3(3, 10, 1),
    end = m_sel(resi = 3),
    spec = m_shape_spec(color = "green")
  ) |> 
  m_zoom_to()

image

Based on the view, the arrow's end coordinates don't always seem to be in the same fixed position as the label. So maybe you need to have several attempts at the coordinates to get an optimal value.

swsoyee avatar Oct 25 '23 09:10 swsoyee