-
Notifications
You must be signed in to change notification settings - Fork 3
Move MDGeomParser into castep_outputs
#218
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
base: main
Are you sure you want to change the base?
Conversation
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
01feeba to
2ef9b18
Compare
f63a3ff to
2945a7c
Compare
2945a7c to
4e49a54
Compare
7af8bf2 to
04f2946
Compare
ajjackson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems useful and nicely written!
I think I see a design issue, however, which can be solved with better separation of the "data container" and "generator" aspects of the object.
| """ | ||
|
|
||
| def __init__(self, md_geom_file: Path | str) -> None: | ||
| self._next_frame = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self._next_frame = 0 | |
| self._next_frame: int | None = 0 |
| pass | ||
| self._frame_len = self._handle.lineno - self._start_line - 1 | ||
|
|
||
| self._byte_len = self._handle.tell() - self._start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like _frame_bytes would be less confusing. byte_len is 8, surely 😎
| self._len = int(len_est) | ||
|
|
||
| @property | ||
| def next_frame(self) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def next_frame(self) -> int: | |
| def next_frame(self) -> int | None: |
|
|
||
| @property | ||
| def next_frame(self) -> int: | ||
| """Get index of next frame to be read.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Get index of next frame to be read.""" | |
| """Get index of next frame to be read, or None if at file end.""" |
| MDGeomTimestepInfo | ||
| Parsed frame. | ||
| """ | ||
| if -len(self) > frame > len(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will always fail for positive values of len and frame.
>>> -3 > 1 > 3
False
Bid odd that it only raises a warning. But I assume that is how the tests are passing?
| def __iter__(self) -> Generator[MDGeomTimestepInfo, int, None]: | ||
| """ | ||
| Get generator over all frames in system. | ||
|
|
||
| Jumps permitted through ``send``. | ||
|
|
||
| Yields | ||
| ------ | ||
| MDGeomTimestepInfo | ||
| Frames in file. | ||
| """ | ||
| self._handle.file.seek(self._start) | ||
| self._handle._lineno = self._start_line | ||
| self._next_frame = 0 | ||
| while self._next_frame is not None: | ||
| jump = yield next(self) | ||
| if jump is not None: | ||
| self._go_to_frame(jump) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some "fun" things (in Dwarf Fortress sense) can happen if multiple iterators are opened from the same instance, as each iterator mutates the same state.
There are some strong opinions on the topic at this StackOverflow: https://stackoverflow.com/questions/46941719/how-can-i-have-multiple-iterators-over-a-single-python-iterable-at-the-same-time
I think Python classes are not supposed to be used as both an Iterator and Iterable. Perhaps this class should choose to act like an Iterable collection (with get-item functionality), not providing a __next__ method. Then the __iter__ code (which acts as a Generator) should maintain its own position information, independent of the main object state, and be able to seek to the next position even if the underlying object is not in sync.
04f2946 to
ea31d62
Compare
a78c3a5 to
1358fed
Compare
No description provided.