-
Notifications
You must be signed in to change notification settings - Fork 131
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
Conversation
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 |
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 |
thanks @gbayarri
may be "view3.clear()"
can be (new feature)
can be
|
The sync is done in frontend, there is no roundtrip that causes lagging.