chemiscope icon indicating copy to clipboard operation
chemiscope copied to clipboard

Changing active molecule from within API

Open joegilkes opened this issue 2 years ago • 5 comments

Hi all,

I'm just having a first play around with chemiscope so apologies if there is a very simple answer I'm missing. I've currently got the library running through Flask and I'm trying to find a way to use the API to change the selected molecule in the EnvironmentInfo, the PropertiesMap and the ViewersGrid simultaneously, such that the server can say "now show structure no. 24" and it can push that to the client.

I've got this working already for the EnvironmentInfo and ViewersGrid by directly firing the DefaultVisualizer.map.onselect() callback with the structure ID I want to change to, but this doesn't update the active point in PropertiesMap. From what I can tell, I want to be using DefaultVisualizer.map.activeChanged() to do this all in one, but that requires a GUID as well as a structure ID.

Is this the correct way to go about this? If so, how do I find the GUID of the point within the Plotly plot to change to? I've been combing through the source code but so far haven't figured out how GUIDs are mapped to their respective points.

Thanks in advance, Joe

joegilkes avatar Aug 31 '22 21:08 joegilkes

Hi Joe, I think @Luthaf is much more likely to be able to help. If you succeed in this, it would be really cool to also expose this functionality for the jupyter widget. There is already the possibility of changing the visualizer settings with a traitlet-style mechanism, I think that being able to set the active point would open up some interesting use cases.

ceriottm avatar Aug 31 '22 23:08 ceriottm

So activeChanged is used when there are multiple structure viewers, to change the active one (bigger marker on the map). Theoretically, calling DefaultVisualizer.map.onselect() and then DefaultVisualizer.map.select() with the same arguments should work, but looks like it fails to update the marker. I'll try to fix it!

Luthaf avatar Sep 01 '22 12:09 Luthaf

Ahh I see, yeah I've given the select() + onselect() combo a go on my end and it also fails to update the map. Thanks, looking forward to the fix!

joegilkes avatar Sep 02 '22 08:09 joegilkes

select() should work now! I'll leave this open to add a nicer API to do this kind of things.

Luthaf avatar Sep 02 '22 14:09 Luthaf

Excellent, thank you!

joegilkes avatar Sep 02 '22 15:09 joegilkes