lab-cosmo / chemiscope

An interactive structure/property explorer for materials and molecules
http://chemiscope.org
BSD 3-Clause "New" or "Revised" License
118 stars 29 forks source link

Changing active molecule from within API #244

Open joegilkes opened 1 year ago

joegilkes commented 1 year ago

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

ceriottm commented 1 year ago

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.

Luthaf commented 1 year ago

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!

joegilkes commented 1 year ago

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!

Luthaf commented 1 year ago

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

joegilkes commented 1 year ago

Excellent, thank you!