ASE-DB Backends

0.11.0 · active · verified Fri Apr 17

ASE-DB Backends (version 0.11.0) provides alternative database backends for ASE, focusing on more performant storage of large datasets than the default SQLite. It offers MongoDB, HDF5, and ZODB/JSON backends, allowing users to choose storage solutions optimized for their specific needs, such as distributed access or very large datasets. The library maintains an active development pace with releases tied to features and bug fixes, typically requiring recent ASE versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an HDF5 database backend, store an `ase.Atoms` object with key-value pairs and additional data, and then retrieve it. This pattern is similar for other backends like MongoDB or JSON/ZODB.

import os
from ase.atoms import Atoms
from ase.build import molecule
from ase_db_backends.hdf5 import HDF5Database

# Clean up previous run for repeatability
if os.path.exists('test_ase_backend.hdf5'):
    os.remove('test_ase_backend.hdf5')

# 1. Create an Atoms object
h2o = molecule('H2O')
h2o.info['user_note'] = 'A test molecule'

# 2. Instantiate the HDF5 backend
# Replace 'test_ase_backend.hdf5' with your desired filename
db = HDF5Database('test_ase_backend.hdf5')

# 3. Write the Atoms object to the database
# You can also add key-value pairs for searching
row_id = db.write(h2o,
                  key_value_pairs={'formula': 'H2O', 'source': 'ase_example'},
                  data={'energy_dft': -10.0}) # Arbitrary data can be stored

print(f"Stored H2O molecule with row_id: {row_id}")

# 4. Read back from the database (example for iterating)
# Note: Iterating returns (id, atoms, kvp, data)
print("\nRetrieving stored data:")
for r_id, atoms_read, kvp_read, data_read in db.select():
    print(f"  Read row_id: {r_id}")
    print(f"  Formula: {atoms_read.get_chemical_formula()}")
    print(f"  Label from KVP: {kvp_read.get('formula')}")
    print(f"  Energy from data: {data_read.get('energy_dft')}")

# Clean up
if os.path.exists('test_ase_backend.hdf5'):
    os.remove('test_ase_backend.hdf5')

view raw JSON →