Skip to main content

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)

Metadata

Release files for ase-hdf5 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ase-hdf5 0.1.6
File Size Uploaded
ase_hdf5-0.1.6.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ase-hdf5 0.1.6
File Interpreter ABI Platform
ase_hdf5-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / ase_hdf5-0.1.6.tar.gz

Download URL ase_hdf5-0.1.6.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6e25ab98fb871508666e9d5172ff795f0c7dfbd0277bf471a428d8a461877ccd
BLAKE2b-256 checksum
How to use checksums
b4bb55c414a395ad649bed31d7a6f2f3d6b2943f6a20d8675ced4e22890c0b95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / ase_hdf5-0.1.6-py3-none-any.whl

Download URL ase_hdf5-0.1.6-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c56ee8d6a6695becd5853aa00884c3ebc3086b6418068c91f5e50246f829b10
BLAKE2b-256 checksum
How to use checksums
8a496e140ec5a09bf8cd3acaa68a3ff04947540723e9ec72868ac3b68d3e5d43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page