Skip to content

Allow any iterator over Atoms objects to be written.

username-removed-265766 requested to merge schiotz/ase:write-iterator into master

The file formats that allowed writing more than one Atoms object handled it by testing explicitly for the argument being an instance of tuple or list. This patch changes the (reverse) test to check for the presence of the get_positions method; if that is not present it is not an Atoms object, and an iterator over such objects is assumed.

In particular, this allows to write an ase.io.iread object directly to a different file format, without first reading all configurations into memory.

Examples:

ase.io.write("output.xyz", ase.io.iread("input.traj"))  # Convert file format

ase.io.write("output.xyz", modifyer(ase.io.iread("input.traj")))

In the latter example, modifyer is a generator function that reads configurations one by one, and modifies the configurations somehow.

Merge request reports