mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

AlignTraj doesn't accept writer kwargs

Open ljwoods2 opened this issue 1 year ago • 0 comments

Expected behavior

When creating an aligned trajectory which is written to a file rather than stored in memory, I want to be able to pass in kwargs to the writer like I normally would when creating a writer object, but AlignTraj doesn't allow this.

Actual behavior

AlignTraj's init method creates a writer for the provided filename like this:

self._writer = mda.Writer(self.filename, natoms)

Code to reproduce the behavior

Example use case, when writing to h5md and you want the output file to be compressed.

from MDAnalysisTests.datafiles import COORDINATES_TOPOLOGY, COORDINATES_H5MD
from MDAnalysis.analysis import rms, align
import h5py

aligner = align.AlignTraj(u, ref,
                          select='protein and name CA',
                          filename='aligned_traj.h5md',
                          compression='gzip', compression_opts=9,
                          in_memory=False).run()
with h5py.File('aligned_traj.h5md', 'r') as f:
    print(f"{f["particles"]["trajectory"]["position"]["value"].compression}")

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)") 2.8.0

ljwoods2 avatar Apr 12 '24 17:04 ljwoods2