nvelden / NGLVieweR

Visualize and interact with Protein Data Bank (pdb) and structural files in R and Shiny
https://nvelden.github.io/NGLVieweR/
Other
45 stars 3 forks source link

only color more than 2 residues in shiny (cartoon)? #10

Open juan2089 opened 1 year ago

juan2089 commented 1 year ago

Hello there, I am trying to use NGLViewer in Shiny. I want to color a specific amino acid in the cartoon representation. However, it seems that NGL is only able to color the selection if I select more than one residue. Is anybody having the same issue? Here is the code im using:

library(shiny)
library(NGLVieweR)

ui <- fluidPage(
          NGLVieweROutput("structure")
  )
server <- function(input, output) {
   output$structure <- renderNGLVieweR({
     NGLVieweR("3RY2") %>%
        addRepresentation("cartoon",
                         param = list(
                           name = "test",
                           colorValue = "red",
                           colorScheme = "element",
                           sele = "( 20 or 30 or 100 )"
                         )
       )

   })

 }
shinyApp(ui, server)

Also, do you know how to color by residue in a ball+stick or surface representation? I would like to color all atoms in a residue using the same color in any of those two representations.

Thank you in advance, NGLVieweR rocks!!

nvelden commented 1 year ago

Unfortunately, you need to select at least three consecutive residues to display the protein in the cartoon representation due to a restriction in the NGL.js library. However, for the ball and stick representation, you can select a single residue.

I hope the below example also answers your second question. For more examples see: link

library(shiny)
library(NGLVieweR)

ui <- fluidPage(NGLVieweROutput("structure"))
server <- function(input, output) {
  output$structure <- renderNGLVieweR({
    NGLVieweR("3RY2") %>%
      addRepresentation("cartoon",
                        param = list(
                          name = "test",
                          colorValue = "red",
                          colorScheme = "element"
                        )) %>%
      addRepresentation(
        "ball+stick",
        param = list(
          name = "test",
          colorValue = "green",
          colorScheme = "element",
          sele = "20"
        )) %>%
          addRepresentation(
            "ball+stick",
            param = list(
              name = "test",
              colorValue = "yellow",
              colorScheme = "element",
              sele = "19"
            ))

  })

}
shinyApp(ui, server)