You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Option to prevent in-place changes in rms.RMSD class #5532
rms.RMSD class makes in-place changes to the timestep positions when group selections exist as seen here:
# Transform each atom in the trajectory (use inplace ops to# avoid copying arrays) (Marginally (~3%) faster than# "ts.positions[:] = (ts.positions - x_com) * R + ref_com".)self._ts.positions[:] -=mobile_com# R acts to the left & is broadcasted N times.self._ts.positions[:] =np.dot(self._ts.positions, self._R)
self._ts.positions+=self._ref_com
The reason for this is already well documented in the code above. This is fine for normal trajectory iteration because the timestep object will get replaced as the the trajectory is iterated. However, in the streaming case, we only get one shot at reading in a given timestep instance and hence have to re-use this across different analyses. It is thus not ideal to have analyses classes modify values like positions etc of the timestep in-place.
Describe the solution you'd like
Maybe add an inplace option to this class, defaulting to True so as to not change any existing behavior, but allow this to be controlled?
Describe alternatives you've considered
Provide a copy of the timestep to sidestep this behavior.
Additional context
mdadash has a Group RMSD widget that uses rms.RMSD. It works around this problem by returning a copy of the timestep from it's buffer for this particular analysis so as to not impact other analyses that take place on the same data.
I am wondering we ought to be considering making ts immutability (or lack thereof) more explicit. Before doing a one-off hack for RMSD, we should be considering the broader picture.
@PardhavMaradani do you have a sense of what other analysis classes do? Are there others that change the ts?
Hi @orbeckst, I haven't checked all the other analysis classes in detail yet. I however ran this quick test / hack where I cleared the writeable flag (to make it read-only) for the ts._pos array in AnalysisBase before invoking self._single_frame() and reset it back right after - the goal was to get an overall sense of who all are modifying the ts positions in-place against our tests - as this would lead to a ValueError: assignment destination is read-only. Here are the findings for the tests in testsuite/MDAnalysisTests/analysis:
The only analysis class that was directly modifying this in-place was the rms.RMSD class
There were quite a few other failures in other analysis classes (align, dielectric, encore, lineardensity and pca), but they were all due to the indirect use of the transformation functions in GroupBase - wrap, unwrap, translate, rotate etc.
Among these, both wrap and unwrap have an inplace param, but it defaults to True
Changing this to False obviously cleared those tests
The others don't have this option and make the changes in-place
With the above info, I agree this is a more generic issue and requires a broader consideration if and how to proceed. Thanks
Activity
Hirujan-R commentedon Nov 5, 2026
Hi, can I work on this?
orbeckst commentedon Nov 13, 2026
@PardhavMaradani do you have a sense of what other analysis classes do? Are there others that change the ts?
At the moment, the AnalysisBase "API" https://docs.mdanalysis.org/stable/documentation_pages/analysis/base.html does not promise that ts is immutable.
I am wondering we ought to be considering making ts immutability (or lack thereof) more explicit. Before doing a one-off hack for RMSD, we should be considering the broader picture.
PardhavMaradani commentedon Nov 14, 2026
Hi @orbeckst, I haven't checked all the other analysis classes in detail yet. I however ran this quick test / hack where I cleared the writeable flag (to make it read-only) for the
ts._posarray inAnalysisBasebefore invokingself._single_frame()and reset it back right after - the goal was to get an overall sense of who all are modifying the ts positions in-place against our tests - as this would lead to aValueError: assignment destination is read-only. Here are the findings for the tests intestsuite/MDAnalysisTests/analysis:rms.RMSDclassGroupBase-wrap,unwrap,translate,rotateetc.wrapandunwraphave aninplaceparam, but it defaults toTrueFalseobviously cleared those testsWith the above info, I agree this is a more generic issue and requires a broader consideration if and how to proceed. Thanks