Skip to main content

Reading and writing ASE trajectories to HDF5 files.

Project description

ase-hdf5

PyPI - Version GitHub License codecov

ase-hdf5 provides a simple I/O for converting list[ase.Atoms] <—> HDF5.

Quickstart

Install the package with pip install -q ase-hdf5.

Then, a simple example of writing a list of ase.Atoms to a file:

import ase
from ase_hdf5 import ASEH5Trajectory

atoms_list: list[ase.Atoms] = get_my_atoms_list() # with extra per-atom arrays.

traj_writer = ASEH5Trajectory(
    immutable=["numbers", "mol-id", "atom-type"],
    mutable=["positions"]
)

# write to file.
traj_writer.write(atoms_list, "atoms_list.h5")

We can run a simple check that the read-in version is equivalent:

def atoms_are_equal(atoms1: ase.Atoms, atoms2: ase.Atoms) -> bool:
    """ Check if two ase.Atoms objects are equal. """

    _basic_properties = ["cell", "positions", "numbers"]
    _extra_properties = ["mol-id", "atom-type"]

    # all close because default writing converts to float32.
    for prop in _basic_properties:
        if not np.allclose(getattr(atoms1, prop), getattr(atoms2, prop)):
            return False
        
    for prop in _extra_properties:
        if (
            prop in atoms1.arrays 
            and prop in atoms2.arrays 
            and not np.array_equal(atoms1.arrays[prop], atoms2.arrays[prop])
        ):
            return False
        
    return True


# read in result.
atoms_list_read = traj_writer.read("atoms_list.h5")

for atom1, atom2 in zip(atoms_list, atoms_list_read):
    assert atoms_are_equal(atom1, atom2)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ase_hdf5-0.1.6.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ase_hdf5-0.1.6-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file ase_hdf5-0.1.6.tar.gz.

File metadata

  • Download URL: ase_hdf5-0.1.6.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ase_hdf5-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6e25ab98fb871508666e9d5172ff795f0c7dfbd0277bf471a428d8a461877ccd
MD5 744352a9c3c53b8aefdd23fd45bb7934
BLAKE2b-256 b4bb55c414a395ad649bed31d7a6f2f3d6b2943f6a20d8675ced4e22890c0b95

See more details on using hashes here.

File details

Details for the file ase_hdf5-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: ase_hdf5-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ase_hdf5-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7c56ee8d6a6695becd5853aa00884c3ebc3086b6418068c91f5e50246f829b10
MD5 e12720b0ed1f62adfd2c331bdb9aa0e3
BLAKE2b-256 8a496e140ec5a09bf8cd3acaa68a3ff04947540723e9ec72868ac3b68d3e5d43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page