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 rotate the view? #11

Open
slowkow opened this issue Jun 24, 2023 · 6 comments
Open

How to rotate the view? #11

slowkow opened this issue Jun 24, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@slowkow
Copy link

slowkow commented Jun 24, 2023

Hi Niels,

Thank you for sharing this wonderful package. It's a joy to be able to visualize PDB structures with just a few lines of R code.

I'm writing to ask for your help with a simple question: how can we rotate the view of our structure?

Here is the example I am working with:

library(NGLVieweR)
library(magrittr)
my_sele <- "9:A"
NGLVieweR("2bvp") %>%
  stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
  addRepresentation(
    type = "cartoon"
  ) %>%
  addRepresentation(
    type = "ball+stick",
    param = list(
      sele = my_sele
    )
  ) %>%
  addRepresentation(
    type = "label",
    param = list(
      sele = my_sele,
      labelType = "format",
      labelFormat = "[%(resname)s]%(resno)s", # or enter custom text
      labelGrouping = "residue", # or "atom" (eg. sele = "20:A.CB")
      color = "black",
      fontFamiliy = "sans-serif",
      xOffset = 1,
      yOffset = 0,
      zOffset = 0,
      fixedSize = TRUE,
      radiusType = 1,
      radiusSize = 5.5, # Label size
      showBackground = TRUE
      # backgroundColor="black",
      # backgroundOpacity=0.5
    )
  ) %>%
  zoomMove(
    center = my_sele,
    zoom = my_sele,
    duration = 0, # animation time in ms
    z_offSet = -20
  )

Below, the left panel shows the view that I see. The right panel shows the view that I want, after using the mouse to rotate the view 180 degrees.

In other words, I am seeing the "back" of the structure when I want to see the "front" instead.

Back of the structure (default output) Front of the structure (after rotating 180 degrees with the mouse)

What's the simplest way to rotate the view?

@slowkow
Copy link
Author

slowkow commented Jun 24, 2023

This issue from the python package nglview looks related to mine. Is there a similar way we can rotate the view in R?

nglviewer/nglview#900

@nvelden nvelden added the enhancement New feature or request label Jun 27, 2023
@nvelden
Copy link
Owner

nvelden commented Jun 27, 2023

At the moment this is not possible but I will have a look if I can implements this.

@slowkow
Copy link
Author

slowkow commented Jun 27, 2023

Thank you, Niels!

nvelden added a commit that referenced this issue Jul 1, 2023
…rolling scale, rotation, and position of representations (#11).
@nvelden
Copy link
Owner

nvelden commented Jul 1, 2023

I pushed an update to github that adds setScale, setRotation, and setPosition functions for controlling scale, rotation, and position of representations.

Let me know if this works for you.

library(NGLVieweR)

my_sele <- "9:A"
NGLVieweR("2bvp") %>%
  stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
  addRepresentation(
    type = "cartoon"
  ) %>%
  addRepresentation(
    type = "ball+stick",
    param = list(
      sele = my_sele
    )
  ) %>%
  addRepresentation(
    type = "label",
    param = list(
      sele = my_sele,
      labelType = "format",
      labelFormat = "[%(resname)s]%(resno)s", # or enter custom text
      labelGrouping = "residue", # or "atom" (eg. sele = "20:A.CB")
      color = "black",
      fontFamiliy = "sans-serif",
      xOffset = 1,
      yOffset = 0,
      zOffset = 0,
      fixedSize = TRUE,
      radiusType = 1,
      radiusSize = 1, # Label size
      showBackground = TRUE
      # backgroundColor="black",
      # backgroundOpacity=0.5
    )
  ) %>%
  setRotation(190,0,200) %>%
  setPosition(5,5,0) %>%
  setScale(1.5)

@slowkow
Copy link
Author

slowkow commented Jul 1, 2023

Thank you! After installing from github, your example works.

But I didn't notice any difference after deleting this line: setPosition(5,5,0)

@nvelden
Copy link
Owner

nvelden commented Jul 1, 2023

Ah yes sorry. I just put it for demonstration purposes. It allows you to move the whole structure in the x, y, z position. The numbers are in angstroms so a move of 5 is very small. Try to change it to for instance 50 and you should see a change.

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

No branches or pull requests

2 participants