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
Timestep API interface discussion (was: should Timestep.time start with 0.0?) #252
Comments
I think this makes sense. The obvious exception should be that if a Timestep has its own record of time (eg the simulation didn't start at t=0) then this should override everything. The only thing I can think of is that this is technically something that should "belong" to the Timestep, a Reader doesn't have an inherent time, but a Timestep does. So all the handling should be done there... so probably all Reader should do is access Timestep.time... ie as a Timestep, I try and return my record of time, but failing that I fudge one for the Reader. So something like: class Reader
@property
def time(self):
return self.ts.time
class Timestep
@property
def time(self):
try:
return self.ts.time
except AttributeError:
return self.ts.frame * self.ts.dt I'd consider the current implementation of Reader.time a bug worth changing. |
I agree that In short, are there trajectory formats that don't include time information? If so, how to handle them cleanly? |
Yeah I think I was half asleep when I wrote that, if .time is missing then I'm not sure how .dt would be populated... I think it'd just be single frame stuff that doesn't have time. |
I'm sure we'll run into exceptional cases. For instance, one can load multiple single-frame .pdb's or .gro's using the Chain Reader. Also, with the Chain Reader, will we reset the time back to 0 when multiple trajectories are loaded and the iteration goes from one to the next? |
IIRC, the original idea for having There are a bunch of formats like XYZ or multi-PDB, which are common lowest common denominator — and in fact not even DCD stores the time in a frame. You have to compute it from the header pretty much as frame_number * dt. |
It sounds like a good idea to me to make We could get rid of |
I propose to
The original question ("should trajectory time start at 0?") really boils down to "should frame numbering be 0 or 1 based". Currently it is supposed to be 1-based but this always creates confusion with the trajectory indexing and slicing notation so I would be in favor of harmonizing frame numbers and slicing/indexing and making it 0-based. I am not really sure, though, if there are deeper/annoying consequences to that decision. Comments? Once we have a sensible plan, we should open a few separate issues on sub-tasks. For instance, something like |
I think all the above sounds good. Changing frame numbering to 0 based makes sense in that trajectory[0] gives frame 0. So if we're moving time into Timestep, then ChainReader will likely need to pass some sort of time_offset to Timestep.. (another reason why having a better constructor would be useful #250) class Timestep
def __init__():
self.time_offset = kwargs.pop('time_offset', 0)
@property
def time(self):
return self.frame * self.dt + self.time_offset Then it's confusing if you need a frame offset or a time offset (ie are all the dts constants across your trajectories?).. but that's a headache for another Issue. I'm putting this into 0.11 (the big API break). |
Are there trajectory formats that do this? That is, that assume a constant |
Dcd I think
|
Yes, DCD does not store time stamps and instead you need to calculate As I haven't heard more on this, I have summarized the conclusions and we should go ahead with the following changes: Frame numbersFrame numbers will start at 0 (i.e. zero-based instead of the current 0.9.2 practice of being 1-based). This will harmonize slice notation with the frame numbering. We'll need to be sure to have the tests working properly and go through the code with a fine comb because there might be various places where 1 is substracted/added.... Handling of time in
|
@dotsdl – can I please leave it to you to follow-up on this issue (raise new ones and monitor implementation)? I suggest that you copy the API proposal from my last comment to the wiki, raise the sub-issues as needed and reference the new wiki page. Once the issues are raised, close this one. Thanks, |
Yes. Setting aside tomorrow (Memorial Day) to hammer on this, and probably the related issue #250. |
The
coordinates.Reader.time
property gives the frame number (1-based) multiplied by the timestep (dt
) between frames of the trajectory (determined from the first two frames of the trajectory for xdrfiles). However, the result of this is that the time of the first frame is shifted bydt
from what is commonly found in trajectory files, where the first frame (t = 0) is usually written.In other words, where
universe.trajectory.time
would be more accurate to give0.0
, with a dt = 1000.0 ps it would instead give1000.0
for the time of the first frame.It might be a bit disruptive to existing code, but should this be changed? It becomes less relevant if
time
becomes a common attribute for all Readers (#250), but then again, it also offers a point for confusion.The text was updated successfully, but these errors were encountered: