jmbuhr / quarto-molstar

Shortcode to embed proteins and trajectories with Mol*
https://jmbuhr.de/quarto-molstar/
MIT License
42 stars 4 forks source link

Added Snapshot Loading #6

Closed BradyAJohnston closed 2 years ago

BradyAJohnston commented 2 years ago

This adds ability for loading of snapshot files for Mol either from URL or local file. Snapshots are useful for saving a particular setup or view between sessions of Mol.

jmbuhr commented 2 years ago

Looks good, thanks for the PR! Do you know if a snapshot can also work with loadStructureFromData? Because then we could make this work with the embed option as well and pack the snapshot into the html as a string on request. https://github.com/jmbuhr/quarto-molstar/blob/7192d5d1725bf84ec807dd13e1280d87854e7982/_extensions/molstar/molstar.lua#L145-L146

BradyAJohnston commented 2 years ago

From my testing it doesn't work with loadStructreFromData. The .molj snapshot (which you get from using the 'Save State' in Mol*) is just a .json with instructions for how to rebuild the scene, but still requires access to the original model sources as it doesn't actually store any model data. The .molx snapshot (from Save Session) is a binary file which actually contains the structure data as well as the instructions on how to rebuild the current scene.

I just played around with it and I wasn't able to get viewer.loadStructureFromSnapshot to read the .molx using the readFile(url) which you use in the mol-url case. You can get it work with the .molj snapshot, but that still requires the connections to the original data sources.

In theory you could use some combination of the snapshot reading an embedded .molj file which itself points to embedded structure files, but I'm not sure how one would do it.

jmbuhr commented 2 years ago

Ah, yes readFile reads plain text files, because loadStructureFromData expects a string. So getting embedding to work with molj files would require parsing them to find the original data source. Let's leave that for now.