-
Notifications
You must be signed in to change notification settings - Fork 648
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
combine trajectory iterators with zip #747
Comments
Do you have the same issue with Somebody mentioned that it would be feasible to have a full TimeStep for each frame rather than updating the same TimeStep. I don't know what it would cost performance wise, but I like the idea. |
I think @kain88-de did that on the XDR rework (temporarily, it went back for uniformity) and apparently there wasn't a big performance hit. I'd want to check with a large (1M+) system to see what the memory usage is like for a quick iteration (just getting But I'd like it if it could work, it would make things like this work nicely. The other thing is I don't know if anywhere in the code we're using a pointer to |
Yes using |
I get this with the DCD Reader?
Is xdr making a new ts every step? |
As far as I can tell no. |
For me this works as expected from six.moves import zip
u = mda.Universe(PSF, DCD)
for ts_a, ts_b in zip(u.trajectory[:-2], u.trajectory[2:]):
print(ts_a.frame, ts_b.frame) |
Using old (Reopen if you disagree and make a suggestion what to do.) |
I might have been a little bit tired yesterday. This is the same I get with XTC using iterators. So this is broken without returning new copies of the timesteps. |
Yeah I get the same with xdr. So what's happening is when izip does the I don't mind moving to a new copy of ts for each frame so long as it doesn't kill performance. |
All of this used work, didn't it? If so what broke it? Oliver Beckstein Am Mar 1, 2016 um 4:38 schrieb Richard Gowers notifications@github.com:
|
https://youtu.be/WjJUPxKB164?t=1117 maybe we have a problem with the generators we returned? |
I think it's just how our Reader model works currently? # at Reader init
Reader.ts = Timestep()
u.trajectory[10]
# Reader goes to frame 10
# Reader fills .ts with frame 10 data
# Reader returns a **view** onto its .ts object So then when we do the izip # still only one ts object
Reader.ts = Timestep()
for ts1, ts2 in izip(u.trajectory[], u.trajectory[]):
# izip asks the reader for the first frame from the first generator, changing the state of .ts
# izip asks the reader for the first frame from the second generator, changing the state of .ts
# izip returns these two (identical) objects, which are at the state of ts2 as that happened afterwards So with the reference to the video, yeah we could make each iteration over the trajectory have its own |
I'd like this to work again. |
@orbeckst I'm not sure this will have ever worked. The izip defect is just a smaller version of the zip case - it uses the same object to generate ts, so it changes the state of ts. I think I like @kain88-de 's idea above to have one |
Yeah that would work. Then we would only need to update the |
Errr, we'd have to put in creating a Timestep to every generator, so for def __iter__(self):
self._reopen()
ts = self._Timestep() # need to remember args for this in __init__
ts = self.ts.copy() # or maybe this is better?
while True:
try:
yield self._read_next_timestep(ts) # need to pass in local version of ts to this method now
except (EOFError, IOError):
self.rewind()
raise StopIteration So the signature of I think that all Readers use most of the methods from the base class to do iteration, so it might not be too bad, just hacking their |
So for my XTC reader this would already work. I'm not sure about the others. |
Ok, so I just realised this doesn't really work for us ag = u.select_atoms('something')
for ts1, ts2 in izip(u.traj[10:20], u.traj[20:30]):
ag.positions = ??? So which ts does AtomGroup refer to? |
I have no idea how you would make this work but in the context if RMSD we always said that you need two universes. Oliver Beckstein Am Mar 3, 2016 um 4:11 schrieb Richard Gowers notifications@github.com:
|
alternatively, you can try itertools.tee to create independent iterators. https://docs.python.org/3/library/itertools.html#itertools.tee |
@hainm This will not solve the problem. When one of the iterator will move forward, it will change the Timestep for all the other iterators as they all share a view to the same object. I am not sure the issue can be solved as the dynamic aspect of the AtomGroups is based on the fact that ts is a view. I would be tempted to close the issue with a won't fix tag. I someone want to use |
ah, yeah. |
@kain88-de I'm thinking this is wont-fix, with the solution being use 2 Universes @jbarnoud moving forward I'd like to have 2 universes share a topology, so very light indeed :) |
I'm ok with wont-fix |
Yes, wont fix. (Btw, I am sorry, I didn't realize that the |
I recently had to iterate over pairs of frames in a trajectory. My first approach was this.
As you can see this doesn't work. In the mean time a fix for me is
That works but is not very nice. It would already help if I could copy an AtomGroup instead of just the coordinates.
The text was updated successfully, but these errors were encountered: