-
Notifications
You must be signed in to change notification settings - Fork 825
MemoryReader. #976
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
MemoryReader. #976
Changes from all commits
d5090ac
5710477
2637a20
2b30138
b503176
f4e3b65
7a999e4
4201b42
1c7fe34
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 |
|---|---|---|
|
|
@@ -183,6 +183,7 @@ | |
| import MDAnalysis.lib.qcprot as qcp | ||
| from MDAnalysis.exceptions import SelectionError, SelectionWarning | ||
| import MDAnalysis.analysis.rms as rms | ||
| from MDAnalysis.coordinates.memory import MemoryReader | ||
| # remove after rms_fit_trj deprecation over | ||
| from MDAnalysis.lib.log import ProgressMeter | ||
|
|
||
|
|
@@ -600,6 +601,7 @@ def rms_fit_trj( | |
| strict=False, | ||
| force=True, | ||
| quiet=False, | ||
| in_memory=False, | ||
| **kwargs): | ||
| """RMS-fit trajectory to a reference structure using a selection. | ||
|
|
||
|
|
@@ -652,15 +654,19 @@ def rms_fit_trj( | |
| - ``True``: suppress progress and logging for levels INFO and below. | ||
| - ``False``: show all status messages and do not change the the logging | ||
| level (default) | ||
|
|
||
| *in_memory* | ||
| Default: ``False`` | ||
| - ``True``: Switch to an in-memory trajectory so that alignment can | ||
| be done in-place, which can improve performance substantially in | ||
| some cases. | ||
|
|
||
| *kwargs* | ||
| All other keyword arguments are passed on the trajectory | ||
| :class:`~MDAnalysis.coordinates.base.Writer`; this allows manipulating/fixing | ||
| trajectories on the fly (e.g. change the output format by changing the extension of *filename* | ||
| and setting different parameters as described for the corresponding writer). | ||
|
|
||
| :Returns: *filename* (either provided or auto-generated) | ||
| :Returns: *filename* (either provided or auto-generated), or None if in_memory=True | ||
|
|
||
| .. _ClustalW: http://www.clustal.org/ | ||
| .. _STAMP: http://www.compbio.dundee.ac.uk/manuals/stamp.4.2/ | ||
|
|
@@ -682,19 +688,24 @@ def rms_fit_trj( | |
| logging.disable(logging.WARN) | ||
|
|
||
| kwargs.setdefault('remarks', 'RMS fitted trajectory to reference') | ||
| if filename is None: | ||
| path, fn = os.path.split(frames.filename) | ||
| filename = os.path.join(path, prefix + fn) | ||
| _Writer = frames.Writer | ||
| writer = None | ||
| if in_memory or isinstance(traj.trajectory, MemoryReader): | ||
| traj.transfer_to_memory() | ||
| frames = traj.trajectory | ||
|
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. You can just move the above
Contributor
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 mean moving the
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. Ah my mistake, didn't see that |
||
| filename = None | ||
| logger.info("Moved trajectory to in-memory representation") | ||
| else: | ||
| _Writer = frames.OtherWriter | ||
| if os.path.exists(filename) and not force: | ||
| logger.warn( | ||
| "{0} already exists and will NOT be overwritten; use force=True if you want this".format(filename)) | ||
| return filename | ||
| writer = _Writer(filename, **kwargs) | ||
| del _Writer | ||
|
|
||
| if filename is None: | ||
| path, fn = os.path.split(frames.filename) | ||
| filename = os.path.join(path, prefix + fn) | ||
| _Writer = frames.Writer | ||
| else: | ||
| _Writer = frames.OtherWriter | ||
| if os.path.exists(filename) and not force: | ||
| logger.warn("{0} already exists and will NOT be overwritten; use force=True if you want this".format(filename)) | ||
| return filename | ||
| writer = _Writer(filename, **kwargs) | ||
| del _Writer | ||
| select = rms.process_selection(select) | ||
| ref_atoms = reference.select_atoms(*select['reference']) | ||
| traj_atoms = traj.select_atoms(*select['mobile']) | ||
|
|
@@ -756,10 +767,11 @@ def rms_fit_trj( | |
| ts.positions[:] = ts.positions * R | ||
| ts.positions += ref_com | ||
|
|
||
| writer.write(traj.atoms) # write whole input trajectory system | ||
| percentage.echo(ts.frame) | ||
| if writer is not None: | ||
| writer.write(traj.atoms) # write whole input trajectory system | ||
| percentage.echo(ts.frame) | ||
| logger.info("Wrote %d RMS-fitted coordinate frames to file %r", | ||
| frames.n_frames, filename) | ||
| frames.n_frames, filename) | ||
|
|
||
| if rmsdfile is not None: | ||
| np.savetxt(rmsdfile, rmsd) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,13 +500,15 @@ def _read_frame(self, frame): | |
| ts.frame = frame | ||
| return ts | ||
|
|
||
| def timeseries(self, asel, start=None, stop=None, step=None, skip=None, | ||
| def timeseries(self, asel=None, start=None, stop=None, step=None, skip=None, | ||
|
Contributor
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.
Contributor
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. Good point. Fixed in 5710477. |
||
| format='afc'): | ||
| """Return a subset of coordinate data for an AtomGroup | ||
|
|
||
| :Arguments: | ||
| *asel* | ||
| :class:`~MDAnalysis.core.AtomGroup.AtomGroup` object | ||
| Defaults to None, in which case the full set of coordinate data | ||
| is returned. | ||
| *start, stop, step* | ||
| A range of the trajectory to access, with start being inclusive | ||
| and stop being exclusive. | ||
|
|
@@ -527,12 +529,17 @@ def timeseries(self, asel, start=None, stop=None, step=None, skip=None, | |
| category=DeprecationWarning) | ||
|
|
||
| start, stop, step = self.check_slice_indices(start, stop, step) | ||
| if len(asel) == 0: | ||
| raise NoDataError("Timeseries requires at least one atom to analyze") | ||
|
|
||
| if asel is not None: | ||
| if len(asel) == 0: | ||
| raise NoDataError("Timeseries requires at least one atom to analyze") | ||
| atom_numbers = list(asel.indices) | ||
| else: | ||
| atom_numbers = range(self.n_atoms) | ||
|
|
||
| if len(format) != 3 and format not in ['afc', 'acf', 'caf', 'cfa', 'fac', 'fca']: | ||
| raise ValueError("Invalid timeseries format") | ||
| atom_numbers = list(asel.indices) | ||
| # Check if the atom numbers can be grouped for efficiency, then we can read partial buffers | ||
| # Check if the atom numbers can be grouped for efficiency, then we can read partial buffers | ||
| # from trajectory file instead of an entire timestep | ||
| # XXX needs to be implemented | ||
| return self._read_timeseries(atom_numbers, start, stop, step, format) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -709,6 +709,7 @@ | |
| from . import TRZ | ||
| from . import XTC | ||
| from . import XYZ | ||
| from . import memory | ||
|
|
||
| try: | ||
| from . import DCD | ||
|
|
||
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.
Maybe mention that this is faster?
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 haven't tested the speed very systematically for the alignment, so I've just added ", which can improve performance substantially in some cases".