-
Notifications
You must be signed in to change notification settings - Fork 823
Description
Is your feature request related to a problem? Please describe.
The "make whole" (unwrap) on the fly transformation PR #2038 needs the fragments at every time step. Apparently, the fragments are recalculated every time (EDIT: They are not – see discussion below)
>>> u = mda.Universe(data.TPR, data.XTC)
>>> %timeit u.atoms.fragments
556 ms ± 71.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)Recalculating fragments takes 0.5 seconds per step.
Describe the solution you'd like
There is no need to recalculate fragments as they are based on bonds. Fragments can be created when the topology is created.
Or only recalculate if the bonds change, or just tell users that if they change bonds then they also need to recalculate fragments.
EDIT: Recalculating fragments is not the problem but building the actual data structure appears to be slow.
Describe alternatives you've considered
Recalculating fragments every time the managed attribute is accessed guards against stale data, which is good. However, user expectation is that attributes behave as instantaneous value stores (and the fact that we use managed attributes should not concern users). Furthermore, I contend that the case of accessing fragments for different time steps is more common than the case of changing the topology.
Additional context
Doing the unwrap is slow no matter what, ca 4s/iteration
In [81]: u = mda.Universe(TPR, XTC)
In [82]: u.trajectory.add_transformations(MDAnalysis.transformations.wrap.unwrap(u.atoms))
In [83]: with mda.Writer("unwrap.xtc", n_atoms=u.atoms.n_atoms) as W:
...: for ts in tqdm.tqdm(u.trajectory):
...: W.write(u.atoms)
...:
100%|██████████████████████████████████████████████████████████| 10/10 [00:39<00:00, 3.90s/it]but at least shaving off 0.5 s is a start.