Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating SingleFrame readers does not call rewind() #3423

Closed
IAlibay opened this issue Sep 23, 2021 · 4 comments · Fixed by #3642
Closed

Iterating SingleFrame readers does not call rewind() #3423

IAlibay opened this issue Sep 23, 2021 · 4 comments · Fixed by #3642

Comments

@IAlibay
Copy link
Member

IAlibay commented Sep 23, 2021

Indirectly related to #3416

Expected behavior

All readers should behave similarly.

Actual behavior

See: #3415 (comment)

Iterating a SingleFrame reader does not rewind the reader, which means that any modified coordinates remain the same. This differs in behaviour from the trajectory readers which do rewind (and therefore update positions).

Code to reproduce the behavior

import MDAnalysis as mda
from MDAnalysisTests.datafiles import two_water_gro, GRO, XTC

# single frame
u = mda.Universe(two_water_gro)

assert u.atoms[0].position[2] != 0

for at in u.atoms:
    at.position = at.position[0], at.position[1], 0

assert u.atoms[0].position[2] == 0

for ts in u.trajectory:
    pass

assert u.atoms[0].position[2] == 0

# trajectory
u = mda.Universe(GRO, XTC)

assert u.atoms[0].position[2] != 0

for at in u.atoms:
    at.position = at.position[0], at.position[1], 0

assert u.atoms[0].position[2] == 0

for ts in u.trajectory:
    pass

assert u.atoms[0].position[2] != 0

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)") develop
  • Which version of Python (python -V)? 3.8
  • Which operating system? All under CI
@orbeckst
Copy link
Member

I would like to label this issue a defect. I don't think that a fix is a API change because the behavior was never intended or documented as such. I would consider a fix a fix for the API that makes the SingleFrameReaders behave consistent with the existing API.

@orbeckst
Copy link
Member

orbeckst commented Sep 23, 2021

If anyone disagrees please chime in.

(Note that if it's not a defect then we can only change it in 3.0 because under semantic versioning it would be a breaking API change.)

@IAlibay
Copy link
Member Author

IAlibay commented Sep 23, 2021

I'm on board with calling this a defect. There is however a possibility that folks may have unknowingly been relying on this behaviour, so we should make sure we advertise the change well.

@orbeckst
Copy link
Member

orbeckst commented May 1, 2022

Note that PR #3642 fixes the undefined behavior to rewind before iteration.

IAlibay added a commit that referenced this issue May 13, 2022
Fixes #3423 

## Work done in this PR
* Rewind singleframe before on iter call
* add documentation on rewinding after iteration
- Trajectory API
- FrameIterators
* fix failing RDF test
- use in-memory trajectory to make local coordinate patches
  permanent for tests (after rewind)
- use function-scoped fixtures instead of module-scoped
  to safely be able to patch coordinates
* fixed missing copy of convert_units=False in Reader.copy()
- update SingleFrameReaderBase.copy()
- update ReaderBase.copy()
- bug was uncovered after tests for
  TestGROReaderNoConversion::test_transformations_copy failed: with
  the fix, the original tests pass again TOGETHER with the other
  changes in PR #3642

Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants