BradyAJohnston / MolecularNodes

Toolbox for molecular animations in Blender, powered by Geometry Nodes.
https://bradyajohnston.github.io/MolecularNodes/
MIT License
833 stars 81 forks source link

Add trajectory smoothing when importing via MDAnalysis #440

Open BradyAJohnston opened 4 months ago

BradyAJohnston commented 4 months ago

Support potentially trajectory smoothing when importing an MD trajectory via MDAnalysis. (https://docs.mdanalysis.org/stable/documentation_pages/transformations/positionaveraging.html)

Potential for in theory to add enable / disable support for a variety of transformations. Some of these will be best implemented through Geometry Nodes node groups, but when streaming the trajectory from disk, transformations like averaging will be best done via MDAnalysis as Geometry Nodes won't have access to any frames other than the one that is currently loaded.

BradyAJohnston commented 4 months ago

Seems that it might be a bit more complex, as we can't directly alter a transformation after it has been applied (https://github.com/MDAnalysis/mdanalysis/discussions/4477#discussioncomment-8669043). Potential for us to have a panel for the trajectory to add or alter a transformation, but that it would require a bit of load time as the universe is re-loaded.

EDIT:

using Universe.copy() keeps transformations, but you can access filenames of the universe.

u1 = Universe(TOPOL, TRAJ)
u2 = Universe(u1.filename, u1.trajectory.filename)

It may even be better to keep the original universe with no transformations, then create copies of that universe when wanting to add a transformation.

u = Universe(TOPOL, TRAJ)

u_smoothed = u.copy()
u_smoothed.trajectory.add_transformation()

Then the transformed universe can be discarded and a new copy worked with, when wanting to change the transformation.

Dan-Burns commented 3 months ago

Smoothing frames would be great. I don't know the blender python API well enough but it's easy to take the coordinates from two frames you want to interpolate between and make the intermediate coordinate arrays.

BradyAJohnston commented 3 months ago

Subframes that interpolate between frames of a trajectory are already implemented and can be accessed via the 'Object' tab of the 'Molecular Nodes' panel after importing a trajectory. As you increase the number of subframes, the number of interpolated frames in between are increase.

image

This enhancement is more about utilising the trasnformations inside of MDAnalysis, which can load several frame (say 5 at a time) and then average their coordinates to create a smoother overall trajectory, rather than just interpolating between existing frames of a trajectory

Dan-Burns commented 3 months ago

That's great - glad I know that now!