Skip to content

Commit

Permalink
Merge pull request #266 from glotzerlab/add-flush
Browse files Browse the repository at this point in the history
Add HOOMDTrajectory.flush
  • Loading branch information
joaander committed Jul 28, 2023
2 parents c19d928 + 0feef0a commit efeb19b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Change Log
3.x
---

3.1.0 (2023-07-??)
^^^^^^^^^^^^^^^^^^

*Added:*

* ``HOOMDTrajectory.flush`` - flush buffered writes on an open ``HOOMDTrajectory``.

3.0.1 (2023-06-20)
^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions gsd/hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,10 @@ def __exit__(self, exc_type, exc_value, traceback):
"""Close the file when the context manager exits."""
self.file.close()

def flush(self):
"""Flush all buffered frames to the file."""
self._file.flush()


def open(name, mode='r'):
"""Open a hoomd schema GSD file.
Expand Down
17 changes: 17 additions & 0 deletions gsd/test/test_hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ def test_append(tmp_path, open_mode):
assert len(hf) == 5


def test_flush(tmp_path, open_mode):
"""Test that HOOMTrajectory objects flush buffered writes."""
frame = gsd.hoomd.Frame()
frame.particles.N = 10

hf = gsd.hoomd.open(name=tmp_path / "test_append.gsd", mode=open_mode.write)
for i in range(5):
frame.configuration.step = i + 1
hf.append(frame)

hf.flush()

with gsd.hoomd.open(name=tmp_path / "test_append.gsd",
mode=open_mode.read) as hf:
assert len(hf) == 5


def create_frame(i):
"""Helper function to create frame objects."""
frame = gsd.hoomd.Frame()
Expand Down

0 comments on commit efeb19b

Please sign in to comment.