Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m_add_label() prints label at wrong position #52

Open
senanu opened this issue Oct 24, 2023 · 1 comment
Open

m_add_label() prints label at wrong position #52

senanu opened this issue Oct 24, 2023 · 1 comment

Comments

@senanu
Copy link

senanu commented Oct 24, 2023

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.

@swsoyee
Copy link
Owner

swsoyee commented Oct 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants