nglviewer / ngl

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

How to control in with defaultRepresentation ? #927

Closed neriaaa46 closed 1 year ago

neriaaa46 commented 2 years ago

HI, in default when I display structure I use - defaultRepresentation: true. but when I add vector I want to control on the representation that I could change the defaultRepresentation to true or false without to load the file again.

can I do that ?! thank for help

neriaaa46 commented 2 years ago

When i load structure, i can add represantation like cartoon trace and more and control if to display it by checkbox or select.

My question is - can i control on the default represantation with checkbox ?

fredludlow commented 2 years ago

The default representations can be controlled just like any other, they're available through the components "reprList" attribute:

stage.loadFile( "rcsb://2vta", { defaultRepresentation: true } ).then(o => {
  const cartoon = o.reprList[0]       // Default reprs for proteins are [cartoon, base, ball+stick]
  cartoon.setVisibility(false)            // Turn it off...

Binding to a checkbox is best done with whatever UI framework you're using. If you're not using any UI framework then you can manually add an event listener to the checkbox (and hook up the visibilityChanged signal). The simple viewer example should give some idea: https://codepen.io/fludlow/pen/mdXPzoZ?editors=001&layout=left (it's creating controls programatically, for the most basic system with fixed files/components/representations you can just hard-code the checkboxes in the HTML.