-
Notifications
You must be signed in to change notification settings - Fork 664
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
WIP Issue 2043 deprecate ts write #2110
Changes from 14 commits
5c6f4b3
926212e
2e7e164
937c215
5590b9a
7173865
0377dfc
cf4e3a8
d19fbd8
2b034a4
fac4510
cbc8a0a
8f1be73
2d1f27b
15e5374
b39aa24
288b2ec
3a96141
0d35fc6
cd0c209
205c402
e3ffe4c
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 |
---|---|---|
|
@@ -113,15 +113,19 @@ def __init__(self, filename, n_atoms=None, **kwargs): | |
""" | ||
self.filename = util.filename(filename) | ||
|
||
def write(self, obj): | ||
def _write_next_frame(self, obj): | ||
"""Write obj at current trajectory frame to file. | ||
richardjgowers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Parameters | ||
---------- | ||
obj : :class:`~MDAnalysis.core.groups.AtomGroup` or :class:`~MDAnalysis.core.universe.Universe` or a :class:`Timestep` | ||
obj : :class:`~MDAnalysis.core.groups.AtomGroup` or :class:`~MDAnalysis.core.universe.Universe` | ||
write coordinate information associate with `obj` | ||
richardjgowers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
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. need a deprecation warning here when using a
|
||
|
||
.. deprecated:: 1.0.0 | ||
Passing a Timestep is deprecated for removal in version 2.0 | ||
""" | ||
# TODO 2.0: Remove Timestep logic | ||
if isinstance(obj, base.Timestep): | ||
IAlibay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
n_atoms = obj.n_atoms | ||
coor = obj.positions.reshape(n_atoms*3) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -825,7 +825,7 @@ def _update_frame(self, obj): | |
* :attr:`PDBWriter.timestep` (the underlying trajectory | ||
:class:`~MDAnalysis.coordinates.base.Timestep`) | ||
|
||
Before calling :meth:`write_next_timestep` this method **must** be | ||
Before calling :meth:`_write_next_frame` this method **must** be | ||
called at least once to enable extracting topology information from the | ||
current frame. | ||
""" | ||
|
@@ -864,7 +864,7 @@ def write(self, obj): | |
# Issue 105: with write() ONLY write a single frame; use | ||
# write_all_timesteps() to dump everything in one go, or do the | ||
# traditional loop over frames | ||
self.write_next_timestep(self.ts, multiframe=self._multiframe) | ||
self._write_next_frame(self.ts, multiframe=self._multiframe) | ||
self._write_pdb_bonds() | ||
# END record is written when file is being close()d | ||
|
||
|
@@ -907,15 +907,15 @@ def write_all_timesteps(self, obj): | |
|
||
for framenumber in range(start, len(traj), step): | ||
traj[framenumber] | ||
self.write_next_timestep(self.ts, multiframe=True) | ||
self._write_next_frame(self.ts, multiframe=True) | ||
|
||
self._write_pdb_bonds() | ||
self.close() | ||
|
||
# Set the trajectory to the starting position | ||
traj[start] | ||
|
||
def write_next_timestep(self, ts=None, **kwargs): | ||
def _write_next_frame(self, ts=None, **kwargs): | ||
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. Is this the only 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 think so yes, it's because PDB also defines its own |
||
'''write a new timestep to the PDB file | ||
|
||
:Keywords: | ||
|
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 feel that it might be useful to leave one entry point open for handing over custom-timesteps. Perhaps not deprecate here?
Or are there better alternative ways to do non-standard things (such as writing a "trajectory" of principal components... someone did this a while ago), e.g., using Universe.empty() and friends?
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.
are the low-level functions in
lib.formats
good for that?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.
why is this changed in the first place? This is an internal API method to me. The write method in our base class used to handle this just fine. It also allowed us to have the code for unpacking the atomgroup into a timestep just once. I would rather vote for making this a private method and leaving childclasses as they are otherwise.
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.
The problem was
Writer.write(obj)
then callsWriter.write_next_timestep(ts)
(which is what is implemented in child classes). But really the argument forW.write_next_timestep()
should still be anAtomGroup
(else you end up with car crash code like this)So basically more of #206 where it's not really clear what a
Writer
is meant to implementI guess we could make it so that:
write_next_timestep()
which must accept AG/UniverseTimestep
in the above method?Currently the (very loose) default is that
Timestep
is accepted, andAG
is optional. (But there are a few dissenters to this)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 accept consistency as reasoning. I would still like that this code of unpacking an atomgroup exists only once as a helper function. We can properly test it.