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

Sync camera with different view and with itself #826

Merged
merged 18 commits into from
Jun 22, 2019
Merged

Conversation

hainm
Copy link
Collaborator

@hainm hainm commented Jun 21, 2019

  • With other views
import nglview as nv

v0 = nv.demo()
v1 = nv.demo()

v0._set_sync_camera([v1])
v1._set_sync_camera([v0])
  • With itself
v0._set_sync_camera([v0]) # v0 here, not v1

The sync is done in frontend, there is no roundtrip that causes lagging.

@hainm hainm merged commit 622de5e into nglviewer:master Jun 22, 2019
@hainm hainm deleted the v-id branch June 22, 2019 00:57
@hainm
Copy link
Collaborator Author

hainm commented Jun 22, 2019

Another code example (for this PR) (the layout is suck but we have the idea).

import nglview as nv
from nglview.sandbox.grid_view import *
from nglview.sandbox.grid_view import _code_set_size
from nglview.sandbox import grid_view as gv
from ipywidgets import *

view = nv.NGLWidget()
view.add_pdbid('1tsu')
view.add_pdbid('1l2y')
p = view.player._display()
p.layout.align_self = 'stretch'
b = grid_view([view, view, view, p], 2, sync_camera=True)
b

sync

@hainm hainm mentioned this pull request Jun 23, 2019
@gbayarri
Copy link

gbayarri commented Jun 25, 2019

Here you have another code with HBox that can be useful to someone:

import re
import os
import numpy as np
import nglview
import time
import math
import ipywidgets

selection = '49:A'
view1 = nglview.show_pdbid('2ki5')
view2 = nglview.show_pdbid('2ki5')
view3 = nglview.show_pdbid('2ki5')
view1.clear_representations()
view2.clear_representations()
view3.clear_representations()
view1.add_cartoon(color="sstruc", selection='/0')
view2.add_cartoon(color="sstruc")
view3.add_cartoon(color="sstruc", selection='/0')
view1.add_representation(repr_type='ball+stick',selection= selection)
view2.add_representation(repr_type='ball+stick',selection= selection)
view3.add_representation(repr_type='ball+stick',selection= selection)
view1.add_label(selection+'.CA' ,color='blue', label_type='bondname', radius=5)
view2.add_label(selection+'.CA' ,color='blue', label_type='bondname', radius=5)
view3.add_label(selection+'.CA' ,color='blue', label_type='bondname', radius=5)
view1.camera = 'orthographic'
view2.camera = 'orthographic'
view3.camera = 'orthographic'
view1._remote_call("setSize", target="Widget", args=["500px", "100%"])
view2._remote_call("setSize", target="Widget", args=["500px", "100%"])
view3._remote_call("setSize", target="Widget", args=["500px", "100%"])
view1.center(selection)
view2.center(selection)
view3.center(selection)

hbox = ipywidgets.HBox([view1,view2,view3])
view1._set_sync_camera([view2, view3])
view2._set_sync_camera([view1, view3])
view3._set_sync_camera([view1, view2])
hbox

@hainm
Copy link
Collaborator Author

hainm commented Jun 25, 2019

thanks @gbayarri
I just have a few minor suggestions:

add_representation(repr_type='ball+stick' -> add_ball_and_stick

view1._remote_call("setSize", target="Widget", args=["500px", "100%"])
-> view1.layout.width = '500px' (and so on), this is new feature.

view3.clear_representations()

may be "view3.clear()"

view1 = nglview.show_pdbid('2ki5')
view1.clear_representations()

can be (new feature)

view1 = nglview.show_pdbid('2ki5', default=False) # avoid using the default repr
view1._set_sync_camera([view2, view3])
view2._set_sync_camera([view1, view3])
view3._set_sync_camera([view1, view2])

can be

views = [view1, view2, view3]
view1._set_sync_camera(views) # and so on. You can sync `view`'s camera with its mirrors too.

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

Successfully merging this pull request may close these issues.

None yet

2 participants