# Data Models

autostorage uses SQLModel/SQLAlchemy to define a relational schema for computational chemistry workflow data. The models form a graph structure where molecular geometries, calculations, stationary points, and chemical identities are linked through explicit relationship tables.


# Model Overview

The schema is organized into five functional groups:


## Link Tables

Association tables implementing many-to-many relationships between entities.

| Model | Description |
|----|----|
| [CalculationGeometryLink](../reference/CalculationGeometryLink.md#autostorage.CalculationGeometryLink) | Associates geometries with calculations, tracking whether each geometry is an input or output |
| [GeometryTrajectoryLink](../reference/GeometryTrajectoryLink.md#autostorage.GeometryTrajectoryLink) | Links geometries to trajectories with position indices and, optionally, the physical value along each dimension ([values](../reference/GeometryTrajectoryLink.md#autostorage.GeometryTrajectoryLink.values)) |
| [CalculationTrajectoryLink](../reference/CalculationTrajectoryLink.md#autostorage.CalculationTrajectoryLink) | Associates trajectories with calculations as inputs or outputs |
| [StageStationaryLink](../reference/StageStationaryLink.md#autostorage.StageStationaryLink) | Connects stationary points to reaction stages |
| [StepValidationLink](../reference/StepValidationLink.md#autostorage.StepValidationLink) | Links validation calculations to reaction steps |
| [IdentityStationaryLink](../reference/IdentityStationaryLink.md#autostorage.IdentityStationaryLink) | Associates chemical identities with stationary points; its [identity_cache](../reference/IdentityStationaryLink.md#autostorage.IdentityStationaryLink.identity_cache) holds data that makes generating identities cheaper |


## Core Data Models

The fundamental entities representing molecular structures, calculations, and their results.

| Model | Description |
|----|----|
| [GeometryRow](../reference/GeometryRow.md#autostorage.GeometryRow) | Molecular geometry with atomic symbols, coordinates, charge, and spin; extends `autogeom.Geometry` |
| [TrajectoryRow](../reference/TrajectoryRow.md#autostorage.TrajectoryRow) | Ordered sequence of geometries from a dynamic calculation; `view(axis, at)` animates the geometries along one dimension, and `values_along(axis, at)` gives their physical values |
| [TrajectoryAxisRow](../reference/TrajectoryAxisRow.md#autostorage.TrajectoryAxisRow) | The physical coordinate (distance, angle, dihedral, or other) that one dimension of a trajectory runs along, such as a scanned dihedral |
| [ModelRow](../reference/ModelRow.md#autostorage.ModelRow) | Calculation model specification (program, method, basis set, keywords) |
| [CalculationRow](../reference/CalculationRow.md#autostorage.CalculationRow) | Quantum chemistry calculation with provenance metadata |
| [PropertyKindRow](../reference/PropertyKindRow.md#autostorage.PropertyKindRow) | A kind of property (`energy`, `gradient`, `hessian`, …), mirroring [PropertyKindRegistry](../reference/PropertyKindRegistry.md#autostorage.PropertyKindRegistry) by name |
| [PropertyValueRow](../reference/PropertyValueRow.md#autostorage.PropertyValueRow) | A property value for a geometry/calculation pair, validated against its kind's expected shape |
| [ValidationRow](../reference/ValidationRow.md#autostorage.ValidationRow) | Validation result (e.g., IRC) for a reaction step |


## Stationary Points

Models representing critical points on potential energy surfaces.

| Model | Description |
|----|----|
| [StationaryPointRow](../reference/StationaryPointRow.md#autostorage.StationaryPointRow) | A stationary point with Hessian index and validation status |


## Reaction Network

Models defining elementary reaction steps and their constituent chemical states.

| Model | Description |
|----|----|
| [StageRow](../reference/StageRow.md#autostorage.StageRow) | A chemical state in a reaction (reactant, product, or transition state) |
| [StepRow](../reference/StepRow.md#autostorage.StepRow) | An elementary reaction step connecting two stages via a transition state (or barrierless) |


## Chemical Identities

Models for chemical identification and classification.

| Model | Description |
|----|----|
| [IdentityAlgorithmRow](../reference/IdentityAlgorithmRow.md#autostorage.IdentityAlgorithmRow) | An identity algorithm (name, kind, parent), mirroring an [IdentityAlgorithm](../reference/IdentityAlgorithm.md#autostorage.IdentityAlgorithm) |
| [IdentityRow](../reference/IdentityRow.md#autostorage.IdentityRow) | A chemical identifier value (InChI, SMILES, Hill formula, …) generated by an algorithm; attached to stationary points automatically |


# Scans and Other Trajectories

A trajectory's geometries are placed on a grid by their integer [index](../reference/GeometryTrajectoryLink.md#autostorage.GeometryTrajectoryLink.index). To record what a dimension means physically, such as the dihedral angle of a relaxed scan, give the trajectory a [TrajectoryAxisRow](../reference/TrajectoryAxisRow.md#autostorage.TrajectoryAxisRow) for that dimension:

``` python
from autostorage import AxisKind, GeometryTrajectoryLink, TrajectoryAxisRow, TrajectoryRow

scan = TrajectoryRow()
scan.axes.append(
    TrajectoryAxisRow(
        axis=0, kind=AxisKind.DIHEDRAL, keys=[0, 1, 2, 3], label="H-O-O-H torsion"
    )
)
for i, geo in enumerate(scan_geometries):
    scan.geometry_links.append(GeometryTrajectoryLink(geometry=geo, index=[i]))
session.add(scan)
session.commit()

scan.values_along(0)                  # dihedrals in degrees, in index order
scan.values_along(0, units="radian")
```

On flush, each link's [values](../reference/GeometryTrajectoryLink.md#autostorage.GeometryTrajectoryLink.values) (one per dimension, aligned with [index](../reference/GeometryTrajectoryLink.md#autostorage.GeometryTrajectoryLink.index)) are filled in:

- Missing values of distance, angle, and dihedral axes are measured from the geometry with autogeom. Distances default to Angstrom and angles to degrees; set [units](../reference/PropertyKindRow.md#autostorage.PropertyKindRow.units) on the axis to store them in other units. Measured dihedrals lie between -180° and 180°.
- Given values are kept, so you can store a scan's nominal (constrained) values instead. A `pint.Quantity` is converted to the axis's units.
- [AxisKind.OTHER](../reference/AxisKind.md#autostorage.AxisKind.OTHER) axes (e.g. an IRC arc length) are never measured, so their values must be given.
- Adding an axis to a stored trajectory fills in the values of its existing geometries.


# Design Principles

- **autogeom integration**: [GeometryRow](../reference/GeometryRow.md#autostorage.GeometryRow) extends `autogeom.Geometry` directly rather than wrapping it, delegating validation and format conversions to autogeom
- **Identities from a registry**: identities are generated by the algorithms in [IdentityAlgorithmRegistry](../reference/IdentityAlgorithmRegistry.md#autostorage.IdentityAlgorithmRegistry) (see [Identities](identities.md))
- **Registries mirrored by name**: [IdentityAlgorithmRow](../reference/IdentityAlgorithmRow.md#autostorage.IdentityAlgorithmRow) and [PropertyKindRow](../reference/PropertyKindRow.md#autostorage.PropertyKindRow) rows are seeded from their in-memory registries when a [Database](../reference/Database.md#autostorage.Database) is opened, and looked up by name
- **Explicit relationships**: Many-to-many relationships use dedicated link tables rather than implicit joins
- **Cascading deletes**: deleting a row deletes its link rows and the data that depends on it: a model's calculations, a geometry's or calculation's property values and stationary points, and a calculation's validations. Geometries, stages, steps, and identities are kept
- **Provenance tracking**: Calculations record both input and output provenance metadata
- **Native units**: each property kind declares its native units (`energy` in Hartree, `gradient` in Hartree/Bohr, `hessian` in Hartree/Bohr²). Values are always stored in them: a `pint.Quantity` (e.g. `autogeom.ureg.Quantity(-1.2, "kcal/mol")`) is converted on flush, and a value without units is assumed to be in the native units already. molar units such as kcal/mol are converted with Avogadro's constant. `PropertyKind.from_native(value, "kcal/mol")` converts a stored value back out, and [PropertyKind.quantity](../reference/PropertyKind.md#autostorage.PropertyKind.quantity) attaches the native units to it
- **Validated stationary points**: on flush, a stationary point is marked `is_validated` if every Hessian of its geometry has `order` negative eigenvalues after translations and rotations are projected out (`autogeom.vibrational_analysis` and `autogeom.stationary_point_order`). Otherwise, `is_validated` is reset to `False` and a [StationaryOrderWarning](../reference/StationaryOrderWarning.md#autostorage.StationaryOrderWarning) is issued. This check runs again when the point or one of its Hessians is added, changed, or deleted. Pseudo stationary points are skipped
- **Compressed storage**: NumPy arrays (coordinates and property values) are stored as zlib-compressed binary data via [CompressedArrayTypeDecorator](../reference/types.CompressedArrayTypeDecorator.md#autostorage.types.CompressedArrayTypeDecorator); property values are stored as float64, except Hessians (float32). Identity caches are stored as zlib-compressed JSON via [CompressedJSONTypeDecorator](../reference/types.CompressedJSONTypeDecorator.md#autostorage.types.CompressedJSONTypeDecorator)
- **Graph structure**: The schema forms a directed graph where calculations consume and produce geometries/trajectories, geometries carry results, stationary points reference geometries, and reaction steps connect stages
