-
Notifications
You must be signed in to change notification settings - Fork 844
timeseries() for all Readers #2271
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
Changes from all commits
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 | ||
|---|---|---|---|---|
|
|
@@ -1692,6 +1692,70 @@ def __repr__(self): | |||
| natoms=self.n_atoms | ||||
| )) | ||||
|
|
||||
| def timeseries(self, asel=None, start=None, stop=None, step=None, | ||||
| order='fac'): | ||||
| """Return a subset of coordinate data for an AtomGroup | ||||
|
|
||||
| Parameters | ||||
| ---------- | ||||
| asel : AtomGroup (optional) | ||||
| The :class:`~MDAnalysis.core.groups.AtomGroup` to read the | ||||
| coordinates from. Defaults to ``None``, in which case the full set of | ||||
| coordinate data is returned. | ||||
| start : int (optional) | ||||
| Begin reading the trajectory at frame index `start` (where 0 is the index | ||||
| of the first frame in the trajectory); the default ``None`` starts | ||||
| at the beginning. | ||||
| stop : int (optional) | ||||
| End reading the trajectory at frame index `stop`-1, i.e, `stop` is excluded. | ||||
| The trajectory is read to the end with the default ``None``. | ||||
| step : int (optional) | ||||
| Step size for reading; the default ``None`` is equivalent to 1 and means to | ||||
| read every frame. | ||||
| order : str (optional) | ||||
| the order/shape of the return data array, corresponding | ||||
| to (a)tom, (f)rame, (c)oordinates all six combinations | ||||
| of 'a', 'f', 'c' are allowed ie "fac" - return array | ||||
| where the shape is (frame, number of atoms, | ||||
| coordinates) | ||||
|
|
||||
| .. note:: Only `"fac"` implemented. | ||||
|
|
||||
|
|
||||
| See Also | ||||
| -------- | ||||
| MDAnalysis.coordinates.memory | ||||
|
|
||||
|
|
||||
| .. versionadded:: 0.20.0 | ||||
| """ | ||||
| start, stop, step = self.check_slice_indices(start, stop, step) | ||||
| nframes = len(range(start, stop, step)) | ||||
|
|
||||
| if asel is not None: | ||||
| if len(asel) == 0: | ||||
| raise NoDataError( | ||||
| "Timeseries requires at least one atom to analyze") | ||||
| atom_numbers = asel.indices | ||||
| natoms = len(atom_numbers) | ||||
| else: | ||||
| atom_numbers = None | ||||
| natoms = self.n_atoms | ||||
|
|
||||
| if not order in ('fac', None): | ||||
| # need to add swapping around axes etc | ||||
| # see MemoryReader.timeseries() and lib.formats.libdcd.DCDfile.readframe() | ||||
| raise NotImplementedError | ||||
|
|
||||
| # allocate output array | ||||
| coordinates = np.empty((nframes, natoms, 3), dtype=np.float32) | ||||
| for i, ts in enumerate(self[start:stop:step]): | ||||
| # if atom_number == None, this will cause view of array | ||||
| # do we need copy in this case? | ||||
| coordinates[i] = ts.positions[atom_numbers].copy() | ||||
|
Member
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 this might be double copying in the case of a non-memoryview. I think maybe either np.array or np.asarray lets you specify copy=True which will end up with one copy max.
Member
Author
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 you're right. But note that you gave the MemoryReader its own
Would be nice if we could do everything consistently in
Member
Author
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. Btw, I think I misunderstood your comment.... you were not referring to MemoryReader at all, were you?
Member
Author
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.
Do you want to do something like x = ts.positions[atom_numbers]
if is_copy(x):
coordinates[i] = x
else:
coordinates[i] = x.copy()(and where I don't know how to do |
||||
|
|
||||
| return coordinates | ||||
|
|
||||
| def add_auxiliary(self, auxname, auxdata, format=None, **kwargs): | ||||
| """Add auxiliary data to be read alongside trajectory. | ||||
|
|
||||
|
|
||||
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 is cool, but maybe it should be called
coordinates_timeseries? unless it's obvious that the only timeseries of interest is the coordinates? I also think maybe the function should be made more general to be a timeseries of all time data, so box info, velocities etc? This would make theReader -> MemoryReadertransformation trivial. So returning something like a numpy structured array? Not sure what a good container for this is 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.
I know, it's not general enough at the moment. However, it is consistent with the MemoryReader
mdanalysis/package/MDAnalysis/coordinates/memory.py
Lines 475 to 478 in f83498e