nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
657 stars 168 forks source link

Change visuals when clicked #967

Closed DA-L3 closed 1 year ago

DA-L3 commented 1 year ago

Hello,

I would like to customize the click event. I am displaying a cif-file of a protein structure. Per default if I click into the Stage, more precisely onto one residue, the widget is centered around the selection.

Now I would like to modify this click event a bit. First, I would like to color every amino acid white except the selection (so, I want to highlight the selection by color). Second I would like to add additional Shapes, e.g. lets say I have a list of residue indices for which I want to add a line / cylinder from the selection to every residue index in this list --- i.e. list of indices = [2, 4, 10], selected atom is at position 24, then I would like to add a line / cylinder from 24 to the positions 2, 4 and 10.

Is there a way to do this? I am using the nglview-package (python) which does not seem to support this out of the box, therefore I need to use the _execute_js_code method to execute JS code. However since I am not sure what is handled by nglview, I don't know which objects / variables exist and how to access them.

Thanks a lot in advance!

ppillot commented 1 year ago

Hello! That's a lot of different pieces, you'd need to make this work. I don't know how nglview works nor the JS objects it gives access to in the _execute_js_code routine.

hainm commented 1 year ago

@CodyLDA You can access JS object stage via this.stage in nglview