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

How to set the amino acid with special color? #33

Closed
virologist opened this issue May 14, 2021 · 2 comments · Fixed by #34
Closed

How to set the amino acid with special color? #33

virologist opened this issue May 14, 2021 · 2 comments · Fixed by #34
Assignees
Labels
bug Something isn't working

Comments

@virologist
Copy link

Hi, Su

How to set certain amino acids with a special color?
See this demo trimer protein with 6 chains, including HA1: A, C, and E; HA2: B, D, and F.
My purpose is set the 206:220 on HA1 with red color (#e41a1c).
So, I try to use m_add_style and m_add_surface. But they look like do not as work as my desire.
Is there something wrong with my code?
image

rm(list=ls()); gc()
library(bio3d)
library(r3dmol)

p <- r3dmol() %>%
  m_add_model(data = m_fetch_pdb("6D7U", save.pdb = TRUE)) %>%
  m_add_model(data = m_bio3d(pdb)) %>%
#   m_set_style(style = m_style_cartoon(color = 'spectrum', ribbon = TRUE)) %>%
  m_set_style(style = m_style_cartoon()) %>% 
  m_add_outline() %>% 
#   m_set_style(style = c(m_style_cartoon(color = "spectrum", ribbon = TRUE), m_style_line())) %>% 
  m_add_surface(atomsel = m_sel(chain =c('A', 'B')), style = m_style_surface(opacity = 0.9, colorScheme="chain")) %>% 
  m_add_style(sel = m_sel(resi = c(206:220), chain="E"), style = m_style_sphere(scale = 0.5, color = "#e41a1c")) %>%
#   m_set_style(sel = m_sel(resi = c(206:220), chain = "A", byres = TRUE), style = m_style_cartoon(color = "red")) %>%
  m_add_surface(atomsel = m_sel(resi = c(206:220), chain = "C"), style = m_style_surface(opacity = 0.9, color = "#e41a1c")) %>%
#   m_add_line(start = m_sel(resi = 1:10, chain = "A"), end = m_sel(resi = 1:10, chain = "B"), spec = list(dashed = TRUE)) %>%
  m_add_label(text = "Site A", sel = m_sel( resi = 206:220, chain = "C"), style = m_style_label(borderColor = "green", borderThickness = 1, inFront = FALSE)) %>%
#   m_zoom_to(sel = m_sel(resi = c(206:220), chain = "A"))
#   m_set_zoom_limits(upper = 200, lower = 30)
    m_zoom_to()
p

Thanks,
Yang

@BradyAJohnston BradyAJohnston self-assigned this May 14, 2021
@BradyAJohnston BradyAJohnston added the bug Something isn't working label May 14, 2021
@BradyAJohnston
Copy link
Collaborator

Hi Yang!

Thanks for the bug report. I've poked around and found that the problem is not your code, but a bug. It seems to be coming a result of the default that we have set for the colorscheme.

At the moment for all of the m_style_*() functions it is:

colorScheme="default"

So when you are setting the style with:

m_style_sphere(scale = 0.5, color = "#e41a1c")

Even though you have set a specific colour it is being overriden by the default colorScheme = "default".

I will fix this, but as a workaround for you code at the moment to get it working, you can override the colorScheme
default by:

m_style_sphere(scale = 0.5, color = "#e41a1c", colorScheme = NULL)

Adjusting your code with the workaround:

rm(list = ls())
gc()
library(bio3d)
library(r3dmol)

p <- r3dmol() %>%
  m_add_model(data = m_fetch_pdb("6D7U", save.pdb = TRUE)) %>%
  m_add_model(data = m_bio3d(pdb)) %>%
  #   m_set_style(style = m_style_cartoon(color = 'spectrum', ribbon = TRUE)) %>%
  m_set_style(style = m_style_cartoon()) %>% 
  m_add_outline() %>% 
  #   m_set_style(style = c(m_style_cartoon(color = "spectrum", ribbon = TRUE), m_style_line())) %>% 
  m_add_surface(atomsel = m_sel(chain =c('A', 'B')), style = m_style_surface(opacity = 0.9, colorScheme="chain")) %>% 
  m_add_style(sel = m_sel(resi = c(206:220), chain="E"), style = m_style_sphere(scale = 0.5, color = "#e41a1c", colorScheme = NULL)) %>%
  #   m_set_style(sel = m_sel(resi = c(206:220), chain = "A", byres = TRUE), style = m_style_cartoon(color = "red")) %>%
  m_add_surface(atomsel = m_sel(resi = c(206:220), chain = "C"), style = m_style_surface(opacity = 0.9, color = "#e41a1c", colorScheme = NULL)) %>%
  #   m_add_line(start = m_sel(resi = 1:10, chain = "A"), end = m_sel(resi = 1:10, chain = "B"), spec = list(dashed = TRUE)) %>%
  m_add_label(text = "Site A", sel = m_sel( resi = 206:220, chain = "C"), style = m_style_label(borderColor = "green", borderThickness = 1, inFront = FALSE)) %>%
  #   m_zoom_to(sel = m_sel(resi = c(206:220), chain = "A"))
  #   m_set_zoom_limits(upper = 200, lower = 30)
  m_zoom_to()
p

image

I hope this is what you are after at the moment, and thanks so much for the bug report! We really appreciate it :)

@virologist
Copy link
Author

works for me, thank you very much.

@swsoyee swsoyee linked a pull request May 14, 2021 that will close this issue
swsoyee added a commit that referenced this issue May 14, 2021
change to colorScheme = NULL fixing #33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants