molstar / mol-view-spec

https://molstar.org/mol-view-spec/
MIT License
8 stars 1 forks source link

Support for topology and trajectory #21

Open papillot opened 2 months ago

papillot commented 2 months ago

I would like to know it the specification allows to export a scene that contains topology and trajectory from two different resources?

JonStargaryen commented 2 months ago

Not sure I understand. Data from multiple sources is supported by invoking the .download() method multiple times. See e.g. the 4th example on this page: https://molstar.org/mol-view-spec/. You can combine data from different resources by pointing to their respective URLs.

papillot commented 2 months ago

Thanks for the explanation. I think that what I was referring to is a different scenario. For example in a Molecular Dynamics simulation, one structure is defined by its topology (let's say it's downloaded as a PDB file) but the coordinates of this structure change through time, which is described in a distinct trajectory file (for example in netCDF format). The representations and colorings remain the same though and in that sense are associated with the topology entity.

It's true that each frame could be extracted to its own distinct PDB file, each having a complete specification for its rendering, but this would be very inefficient (i.e. parsing + memory + representations) especially for long trajectories.

JonStargaryen commented 2 months ago

I see. I'm not familiar with netCDF but this seems comparable to NMR trajectories.

Right now, it would be possible to download some NMR structure and select different frames/models before creating representations. These would appear as separate/duplicate items in the MolViewSpec JSON representation but Mol* will cache e.g. the download of resources to avoid downloading the same content multiple times. It seems more elegant to trust the viewer with optimizing (potentially in some viewer-specific fashion) than moving this responsibility to the MolViewSpec specification itself. But we are open to revisit if performance becomes an issue.

Glucksistemi commented 1 month ago

@papillot, As I found, Mol* supports multi-model PDB file as an option of trajectory showcase. It becomes heavy (got 58mb .pdb from <2MB .gro+.xtc) but it works.

For me easiest way to combine such file was using PyMol with something like this:

load topology.gro
load_traj trajectory.xtc
save md_output.pdb, state=0

What I haven't found was option to autoplay trajectory right from load, but I think it's not absolutely necessary and can be done with custom Mol* installation

papillot commented 1 month ago

Thanks @Glucksistemi for sharing! The multiple model PDB file approach leads to information duplication as all the columns for the atom names, chains, residues, etc remain the same across the Models, while the only columns that change between models are the coordinates. But it is amenable to gz compression (although not up to the 30x ratio you have measured). For my purposes, I will try to leverage Mol* sessions directly instead of mol-view-specs as I initially thought I could.

Glucksistemi commented 1 month ago

For my purposes, I will try to leverage Mol* sessions directly instead of mol-view-specs as I initially thought I could.

@papillot yes, I considered this approach earlier. If you need to build scenes manually, it should work fine. My problem is that I need to prepare MD results showcase automatically and session file is harder to prepare without handiwork in Mol* itself