molstar / pdbe-molstar

Molstar PDBe implementation
Apache License 2.0
96 stars 33 forks source link

Get selection programatically #85

Open duerrsimon opened 1 year ago

duerrsimon commented 1 year ago

I'm looking for a way to programmatically access the currently selected residues. I checked the methods in viewerInstance.visual but there was no obvious way of getting a data object.

orangeSi commented 1 year ago

I also had the silimar question: get which one residues is hovered now? I am looking at https://rcsb.org/3d-view/ to get some clue.

midlik commented 2 months ago

PDBe Molstar does not provide helper functions for this. But it is achievable via core Molstar functionality.

You can add listeners for highlight (when the user hovers a residue) and select (when the user clicks a residue while in Selection Mode):

viewerInstance.plugin.managers.interactivity.lociHighlights.addProvider((loci, action) => console.log('mark', loci, action));
viewerInstance.plugin.managers.interactivity.lociSelects.addProvider((loci, action) => console.log('select', loci, action));

Getting useful info from loci and action won't be straightforward. I can just point you to the source code where these are declared: loci: https://github.com/molstar/molstar/blob/523dfe7928d3f8cad9b62b1c95667816f1ca9d2a/src/mol-model/structure/structure/element/loci.ts#L31 action: https://github.com/molstar/molstar/blob/523dfe7928d3f8cad9b62b1c95667816f1ca9d2a/src/mol-util/marker-action.ts#L11

midlik commented 2 months ago

If you meant getting residues that you have previously selected via viewerInstance.visual.select, just save the object that you passed to the function.