nglviewer / ngl

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

Feature request: use atomSets to set selections #269

Open ppillot opened 7 years ago

ppillot commented 7 years ago

Hi, I am implementing a routine to display only a unique representation for each atom (eg some are displayed as spheres, other as cartoon but none could be at the same time ribbon and cartoon). I use atomSets to keep track of each atom currently displayed in each representation. When I have to update the representation, I compute unions and intersections of atomSets for each representation and update their respective selections with a reprList[i].setSelection(atomSet.toSeleString()) This works.

My concern is performance. The sele string can be very long (each atom is listed in it) and from the debug messages I've seen that for a medium size molecule file (hemoglobin ~5000 atoms) some Structure.getAtomSet calls can take about 4ms (Chrome latest version, MacOSX), instead of less than 0.1 ms for shorter strings. As the corresponding atomSet are already memoized in my program, this process (converting to seleString and back to atomSet) could be shortcut if it were possible to select by directly sending the atom set instead of the selection object.

How do you think this could be done? Would it be better to add another method akin to setSelection() (for example setAtomSet()) and refactor the refresh() method to account for this other way of selecting, or to refactor each setSelection( string ) so that they could accept either a string or a BitSet ?

arose commented 7 years ago

Yes, yes, yes. That is the direction I want to go with selections. My plan is to have Selection object constructor accept atomSets as well. I would not want to add another method besides setSelection.