chemfiles icon indicating copy to clipboard operation
chemfiles copied to clipboard

Add mechanism to flush trajectories

Open JordanPrograms opened this issue 1 year ago • 1 comments

As far as I can tell, the only way to force a trajectory to flush its buffer is to call its destructor. I believe it would be useful to add a function to flush a trajectory to disk manually.

When running a long molecular dynamics simulation using chemfiles to write a trajectory, I'm encountering an issue where if the simulation crashes (due to a bug/power outage/whatever), the resulting trajectory file is incomplete because its contents weren't written to disk. Being able to manually flush the trajectory at each step would help solve this problem.

I'd be happy to add this feature.

JordanPrograms avatar Jan 15 '25 20:01 JordanPrograms

I agree that being able to ensure complete files in case of a crash is good!

The implementation would mainly be the responsibility of the various File classes, and should be easy to do for text-based format, although I can see two issues for more complex file format:

  • for compressed text files, flushing would mean stopping the compression of the current block of data, and starting a new one. I'm not 100% sure all the compression format would support this.
  • some binary file formats also have a footer and while the current data can be flushed to disk, flushing alone is not enough to produce a valid file.

Luthaf avatar Jan 16 '25 13:01 Luthaf