Safe IO in Optimizer/MD
Let's solve the IO problems perpetuated by Optimizers/MD once and for all. Suppose we do BFGS(trajectory='opt.traj', logfile='opt.log'). Then:
- When we start, we might truncate the file, but we don't keep it open
- Whenever we want to write, we open the file, write, then close
- No obligation to remember to close the file "later"
- We still support actual open file handles, too
This might affect performance of very fast MD runs that log every step, but we should really get rid of the ongoing resource warnings and (rare, depending on usage patterns) file corruptions.
Checklist
-
The issue remains in the development version of ASE. -
An minimal example is provided to reproduce the issue.