Skip to content

Conversation

@lohedges
Copy link
Contributor

@lohedges lohedges commented Oct 31, 2025

This PR closes #375 by implementing the missing SireIO::Gro87::getFrame() method. Previously, a null Frame() object would be returned whenever a frame loaded from a Gro87 file was accessed, e.g. via a TrajectoryIterator.

The PR also adds support for writing trajectory frames to user-defined filenames, rather than writing the output to a frame directory. This uses a frame_name map option, which then modifies the filename passed through to SireIO::MoleculeParser::writeToFile. This is mangling is required, since writeToFile is a static method. I've then wrapped the functionality in the new Sire API, allowing a user to pass a list of filenames to sire.save when the input (object to write) is a TrajectoryIterator. This allows the user to do things like:

import sire as sr

# Load a trajectory.
mols = sr.load_test_files("ala.top", "ala.traj")

# Write the first two trajectory frames to named files.
sr.save(mols.trajectory()[:2], ["cat/cat.gro", "dog/dog.gro"])
['/home/lester/Code/openbiosim/sire/trajectory_debug/cat/cat.gro',
 '/home/lester/Code/openbiosim/sire/trajectory_debug/dog/dog.gro']

A unit test validates that the correct output is generated, and that appropriate exceptions are thrown when the input is malformed, i.e. the number of filenames not matching the number of frames in the TrajectoryIterator, or there being a mismatch in the file extension between filenames.

Just to note the diff looks a bit weird owing to the removal of Gro87::operator[](int i), which now just returns an exception when used.

  • I confirm that I have merged the latest version of devel into this branch before issuing this pull request (e.g. by running git pull origin devel): [y]
  • I confirm that I have added a test for any new functionality in this pull request: [y]
  • I confirm that I have added documentation (e.g. a new tutorial page or detailed guide) for any new functionality in this pull request: [y]
  • I confirm that I have added a changelog entry to the changelog (we will add a link to this PR as part of the review): [y]
  • I confirm that I have permission to release this code under the GPL3 license: [y]

@lohedges lohedges added bug Something isn't working enhancement New feature or request recursion Related to work with Recursion labels Oct 31, 2025
@lohedges lohedges requested a review from chryswoods October 31, 2025 10:41
Copy link
Contributor

@chryswoods chryswoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Sorry not to have implemented it - the migration to the frame-based way of working required stubbed implementations on all the older IO classes. The Gro87 class never got the stub implemented...

@lohedges
Copy link
Contributor Author

No problem, it was very easy to add. I just wish I had thought to look there first, since it took me a while to backtrack my way via the trajectory code itself :-)

@lohedges lohedges merged commit 84b7ddd into devel Oct 31, 2025
3 of 5 checks passed
@lohedges lohedges deleted the fix_375 branch October 31, 2025 13:23
lohedges added a commit that referenced this pull request Oct 31, 2025
lohedges added a commit that referenced this pull request Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request recursion Related to work with Recursion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Trajectory reloading from Gro87 files leads to indexing errors

3 participants