pdbe-molstar icon indicating copy to clipboard operation
pdbe-molstar copied to clipboard

Get selection programatically

Open duerrsimon opened this issue 2 years ago • 3 comments

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.

duerrsimon avatar Apr 19 '23 16:04 duerrsimon

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.

orangeSi avatar Nov 07 '23 15:11 orangeSi

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 avatar Aug 28 '24 14:08 midlik

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

midlik avatar Aug 28 '24 14:08 midlik