-
Notifications
You must be signed in to change notification settings - Fork 661
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
Updating Serialization Functionality from PR #2140 #2704
Changes from 22 commits
a00840e
133072f
aa595f5
ba1a138
caa588d
e21361d
99bdd08
f1a7d5a
931d9b5
7126473
0c528c7
59f55e8
dce2dd4
c730e79
598a671
2c2883a
7f1f4a1
33bf888
90d8f78
31e08a4
5bbc9b2
e9121df
91b28f4
864d733
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
|
||
from . import base | ||
|
||
class GSDReader(base.ReaderBase): | ||
class GSDReader(base.ReaderBase, base._ExAsciiPickle): | ||
"""Reader for the GSD format. | ||
|
||
""" | ||
|
@@ -76,23 +76,27 @@ def __init__(self, filename, **kwargs): | |
super(GSDReader, self).__init__(filename, **kwargs) | ||
self.filename = filename | ||
self.open_trajectory() | ||
self.n_atoms = self._file[0].particles.N | ||
self.n_atoms = self._f[0].particles.N | ||
self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs) | ||
self._read_next_timestep() | ||
|
||
def open_trajectory(self) : | ||
def open_trajectory(self): | ||
"""opens the trajectory file using gsd.hoomd module""" | ||
self._frame = -1 | ||
self._file = gsd.hoomd.open(self.filename,mode='rb') | ||
self._f = gsd.hoomd.open(self.filename,mode='rb') | ||
|
||
def open_trajectory_for_pickle(self): | ||
"""opens the trajectory file while not reset frame""" | ||
self._f = gsd.hoomd.open(self.filename, mode='rb') | ||
|
||
def close(self): | ||
"""close reader""" | ||
self._file.file.close() | ||
self._f.file.close() | ||
|
||
@property | ||
def n_frames(self): | ||
"""number of frames in trajectory""" | ||
return len(self._file) | ||
return len(self._f) | ||
|
||
def _reopen(self): | ||
"""reopen trajectory""" | ||
|
@@ -101,7 +105,7 @@ def _reopen(self): | |
|
||
def _read_frame(self, frame): | ||
try : | ||
myframe = self._file[frame] | ||
myframe = self._f[frame] | ||
except IndexError: | ||
raise_from(IOError, None) | ||
|
||
|
@@ -131,3 +135,4 @@ def _read_frame(self, frame): | |
def _read_next_timestep(self) : | ||
"""read next frame in trajectory""" | ||
return self._read_frame(self._frame + 1) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8 don't need a blank line on the last line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IAlibay do we have a PEP8 checker running? If not, we should add one to the linter. @lilyminium does the user guide talk about PEP8-checking? I'm just asking I find myself writing a lot of "PEP8" comments on PRs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we do - I think there's already an ongoing discussion in #2450 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, the user guide highlights important points from PEP8, mentions tools like flake8 for linting, and autopep8/yapf for autoformatting. It doesn't mention stuff like spaces after commas and around comparison operators, or blank lines, though. |
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.
We'll probably want to document somewhere (in the AnalysisBase docstring at the very least?) that we expect files to be stored under self._f for the readers / writers.
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.
If it's important, make the attribute name more expressive, e.g.,
_file
or_stream
or_open_stream
. Readability is important!