Skip to main content

ASE DB

This package provides a SQL Alchemy model to the ASE Atoms object.

For more information, see the documentation.

Basic Usage

The AtomsModel is the main model that translates an atoms object (and attached calculator info) into a SQL model.

from asedb import AtomsModel, Element, initialize_engine, make_sqlite_engine
import ase
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine


engine = make_sqlite_engine("foo.db")  # Helper function to create a SQL Alchemy engine for sqlite
initialize_engine(engine)  # Create necessary schema/tables

Session = sessionmaker(bind=engine)
session = Session()

atoms = ase.Atoms('H2',
           positions=[[0, 0, 0],
                      [0, 0, 0.7]])

model = AtomsModel.from_atoms(atoms)

session.add(model)
session.commit()

model_id = model.id

loaded = session.query(AtomsModel).where(AtomsModel.id == model_id).scalar()
atoms_loaded = loaded.to_atoms()  # The atoms object loaded from the database

print(atoms_loaded)  # Atoms(symbols='H2', pbc=False, tags=...)

Here, we used the make_sqlite_engine helper function to create the SQL Alchemy engine object for a sqlite database. You can also create your own engine, e.g. for postgres:

import urllib.parse
from sqlalchemy import create_engine

def make_engine():
    database = os.environ["PG_DATABASE"]
    user = os.environ["PG_USER"]
    password = urllib.parse.quote_plus(os.environ["PG_PASSWORD"])
    host = os.environ["PG_HOST"]
    port = os.environ["PG_PORT"]
    connection_string = (
        f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}"
    )
    return create_engine(connection_string)

where the parameters for the connection parameters have been stored in the environment variables.

Querying

We can construct queries using the SQL Alchemy models, e.g. looking for all atoms objects with at least 2 hydrogen atoms:

# Fetch all AtomsModel objects that fit the query
results = (session.query(AtomsModel)
                  .join(Element)
                  .where((Element.symbol == 'H') & (Element.count >= 2))
                  .all())
# Convert them into actual Atoms objects
all_atoms = [res.to_atoms() for res in results]

Schema

By default, the schema asedb is used - except for sqlite databases, which doesn't utilize schemas. In this case, the make_sqlite_engine helper function ensures the schema is remapped to None.

For any "real" database connections, such as Postgres, the schema asedb will be used.

Metadata

Release files for asedb 0.0.1

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

Source distribution (sdist)

Source distribution for asedb 0.0.1
File Size Uploaded Provenance Actions
asedb-0.0.1.tar.gz 25.3 kB Without provenance Details for asedb-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asedb 0.0.1
File Interpreter ABI Platform Actions
asedb-0.0.1-py3-none-any.whl Python 3 none any Details for asedb-0.0.1-py3-none-any.whl

Total release size: 36.8 kB

Release files / asedb-0.0.1.tar.gz

Download URL asedb-0.0.1.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e82dbc2b9467302d46655a7828a540f482b6b579d3269d7a88cec3b27f9855c9
BLAKE2b-256 checksum
How to use checksums
6ef784d54babf76e0715568a632c8804bd610badf2d4ab8421e5ff0ae0677efb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / asedb-0.0.1-py3-none-any.whl

Download URL asedb-0.0.1-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
810d978fcbfed67b230ff68be2c944492fc8cf1608ed34ddae475d7e021014a1
BLAKE2b-256 checksum
How to use checksums
a307da80014f93c993d4b28d74669e9adc3b779113e151a22eef4a760f2418ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Security for asedb 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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