mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

Edit transformations on a Universe

Open BradyAJohnston opened this issue 8 months ago • 3 comments

Is your feature request related to a problem?

If a universe has some transformations applied to it's positions, I'd like to be able to either remove them individually or cleanly create a copy of that universe without the transformations applied.

Describe the solution you'd like

Remove the transformation via removing it from the list of transformations, or creating a copy of the universe.

del u.transformations[1]
u_copy = u.copy(transformations=False)
# keep the first but drop all other transforms in the new universe
u_copy.add_transformations(u.transformations[0])

These would be problematic for in-memory trajectories, and the simplest would be to continue to not allow the changing of transformations for in-memory trajectories.

Describe alternatives you've considered

Discussed in #4477 with the potential solutions being keeping a copy of the un-transformed universe and then keep copying from that and adding new transforms when needed. Reloading a universe from file information from the Universe when needing a 'clean' copy.

Additional context

It was raised in that discussion that this isn't allowed because in-memory trajectories alter the coordinates when an transformation is applied, rather than altering them as reading. Removing a transformation won't undo the transformed coordinates.

The first approach would require limiting the removal of transformations to only trajectories that aren't in-memory, but that might be too much of a disconnect for usage that we might want to avoid.

The second strategy of a universe.copy() that allows you to not copy across transforms would also have a similar problem with in-memory coordinates, likley requiring re-reading of coordinates from disk to get a 'clean' version of the universe.

This is primarily for usage inside of Molecular Nodes, when visualising a trajecotry playback a user can add / remove different transformations to smothe out the playback of their trajectory. From a GUI perspective, it's expected that the user would 'tinker' and add / remove the number of frames that they might be averaging to get the desired look. Because of this, I've currently got my own frame averaging implemented to handle easily adding & removing.

I would like to however unify with the MDAnalysis averaging, and also potentially offer the other transformations that MDA offers. This could be done with the strategy if keeping a 'backup' clean universe to copy from & add new transformations, but it would be simpler (on the MN side) to just edit the existing transformations.

At least for my usecase in MN, all trajectories would be streamed from disk, so I wouldn't have to worry about in-memory problems.

Would appreciate thoughts from others about whether allowing modifications of transformations when not in-memory would be feasible (I would work on implementing it if agreed upon).

BradyAJohnston avatar Mar 18 '25 03:03 BradyAJohnston

u_copy = u.copy(transformations=False) with an appropriate failure for in-memory (ValueError ??) seems like a clean solution to me.

orbeckst avatar Jun 11 '25 22:06 orbeckst

I'd say just assign yourself to the issue and work on it.

orbeckst avatar Jun 11 '25 22:06 orbeckst

Won't be able to think about it for a few weeks, but I'll revisit this sometime soon.

BradyAJohnston avatar Jun 12 '25 07:06 BradyAJohnston