Dumping FilesΒΆ

IOData can also be used to write different file formats:

1from iodata import dump_one, load_one
2
3mol = load_one("water.fchk")
4# Here you may put some code to manipulate mol before writing it the data
5# to a different file.
6dump_one(mol, "water.molden", allow_changes=True)

One could also convert (and manipulate) an entire trajectory. The following example converts a geometry optimization trajectory from a Gaussian FCHK file to an XYZ file:

1from iodata import dump_many, load_many
2
3# Load all optimization steps and write as XYZ.
4dump_many(load_many("peroxide_opt.fchk"), "peroxide_opt.xyz")

If you wish to perform some manipulations before writing the trajectory, the simplest way is to load the entire trajectory in a list of IOData objects and dump it later:

1from iodata import dump_many, load_many
2
3# Read the trajectory
4trj = list(load_many("peroxide_opt.fchk"))
5# Manipulate if desired
6for i, data in enumerate(trj):
7    data.title = f"Frame {i}"
8# Write the trajectory
9dump_many(trj, "peroxide_opt.xyz")

For very large trajectories, you may want to avoid loading it as a whole in memory. For this, one should avoid making the list object in the above example. The following approach would be more memory efficient.

 1from iodata import dump_many, load_many
 2
 3
 4def iter_data():
 5    """Read and modify the trajectory."""
 6    for i, data in enumerate(load_many("peroxide_opt.fchk")):
 7        data.title = f"Frame {i}"
 8        yield data
 9
10
11# Write the trajectory
12dump_many(iter_data(), "peroxide_opt.xyz")

More details can be found in the API documentation of iodata.api.dump_one() and iodata.api.dump_many().