Skip to content
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

AlignTraj Writer kwargs fix #4565

Merged
merged 9 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The rules for this file:
* 2.8.0

Fixes
* Fix `MDAnalysis.analysis.align.AlignTraj` not accepting writer kwargs
(Issue #4564, PR #4565)
* Fix doctest errors of analysis/pca.py related to rounding issues
(Issue #3925, PR #4377)
* Convert openmm Quantity to raw value for KE and PE in OpenMMSimulationReader.
Expand Down
7 changes: 6 additions & 1 deletion package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ class AlignTraj(AnalysisBase):
def __init__(self, mobile, reference, select='all', filename=None,
prefix='rmsfit_', weights=None,
tol_mass=0.1, match_atoms=True, strict=False, force=True, in_memory=False,
writer_kwargs=None,
**kwargs):
"""Parameters
----------
Expand Down Expand Up @@ -720,6 +721,8 @@ def __init__(self, mobile, reference, select='all', filename=None,
verbose : bool (optional)
Set logger to show more information and show detailed progress of
the calculation if set to ``True``; the default is ``False``.
writer_kwargs : dict (optional)
kwarg dict to be passed to the constructed writer
yuxuanzhuang marked this conversation as resolved.
Show resolved Hide resolved


Attributes
Expand Down Expand Up @@ -816,10 +819,12 @@ def __init__(self, mobile, reference, select='all', filename=None,
self.ref_atoms, self.mobile_atoms, tol_mass=tol_mass,
strict=strict, match_atoms=match_atoms)

if writer_kwargs is None:
writer_kwargs = {}
# with self.filename == None (in_memory), the NullWriter is chosen
# (which just ignores input) and so only the in_memory trajectory is
# retained
self._writer = mda.Writer(self.filename, natoms)
self._writer = mda.Writer(self.filename, natoms, **writer_kwargs)

self._weights = get_weights(self.ref_atoms, weights)

Expand Down
11 changes: 11 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ def test_AlignTraj_in_memory(self, universe, reference, tmpdir):
self._assert_rmsd(reference, universe, 0, 6.929083044751061)
self._assert_rmsd(reference, universe, -1, 0.0)

def test_AlignTraj_writer_kwargs(self, universe, reference, tmpdir):
# Issue 4564
writer_kwargs = dict(precision=2)
with tmpdir.as_cwd():
aligner = align.AlignTraj(universe, reference,
select='protein and name CA',
filename='aligned_traj.xtc',
writer_kwargs=writer_kwargs,
in_memory=False).run()
assert_equal(aligner._writer.precision, 2)

def _assert_rmsd(self, reference, fitted, frame, desired, weights=None):
fitted.trajectory[frame]
rmsd = rms.rmsd(reference.atoms.positions, fitted.atoms.positions,
Expand Down
Loading