httk.core.property_definitions¶
First-class OPTIMADE property and entry-type definitions.
An OPTIMADE property definition is a self-describing JSON document giving a
property’s canonical identifier, type, unit, requirements, and human-readable
description. An entry-type definition bundles the property definitions of one
entry type (structures, references, …) together with the entry type’s
own description.
This module models both as immutable Python objects:
PropertyDefinitionwraps one full property-definition document. It can be built from a vendored OPTIMADE definition (PropertyDefinition.from_optimade()) or generated from a compact description (PropertyDefinition.from_simple()).EntryTypeDefinitionwraps an entry type’s description and the ordered mapping of its property definitions, and can beextended()with database-specific custom properties.
The vendored OPTIMADE standard definitions shipped with httk-core (the
references, files, and calculations entry types) are loaded through
the IRI schema registry by standard_entry_type() and
load_entry_type_definition().
On the “1.2” definition-format stamp: PropertyDefinition.from_simple()
generates only property-definition features that already exist in format
"1.2" of the OPTIMADE property-definition schema, so every generated
definition is stamped x-optimade-definition.format == "1.2". The definition
format is versioned in lockstep with the OPTIMADE specification and is only
bumped when a definition actually uses features introduced by a newer format;
custom generated definitions therefore keep the "1.2" stamp even for
entry types (such as calculations) whose specification version is newer.
Attributes¶
Classes¶
An immutable wrapper around one full OPTIMADE property definition. |
|
An immutable OPTIMADE entry-type definition. |
Functions¶
|
Register a database-specific OPTIMADE property-name |
Return the registered database-specific property-name prefixes. |
|
|
Return one of httk-core's vendored standard OPTIMADE entry types. |
Module Contents¶
- httk.core.property_definitions.PROPERTY_DEFINITION_META_SCHEMA = 'https://schemas.optimade.org/meta/v1.2/optimade/property_definition.json'[source]¶
- httk.core.property_definitions.register_definition_prefix(prefix, id_base)[source]¶
Register a database-specific OPTIMADE property-name
prefix.A custom property served by a database MUST use such a prefix (see the OPTIMADE specification, “Database-Specific Properties”). Once registered, a property name carrying
prefixgets its$idsynthesized underid_basebyPropertyDefinition.from_simple(), andEntryTypeDefinition.extended()accepts it as a custom property.prefixmust be a lower-case alphanumeric token wrapped in single underscores (matching_[a-z0-9]+_); anything else raises a clearValueError. Re-registering an existing prefix overwrites its base.- Parameters:
- Raises:
ValueError – If
prefixdoes not match_[a-z0-9]+_.
- httk.core.property_definitions.known_definition_prefixes()[source]¶
Return the registered database-specific property-name prefixes.
The tuple reflects the current state of the prefix registry (see
register_definition_prefix());_httk_is pre-registered.
- class httk.core.property_definitions.PropertyDefinition(name, payload)[source]¶
An immutable wrapper around one full OPTIMADE property definition.
Instances are constructed from a vendored definition document (
from_optimade()) or generated from a compact description (from_simple()). The wrapped document is always deep-copied on the way in and out, so an instance never shares mutable state with its inputs or its callers.- Parameters:
name (str) – The canonical property name.
payload (collections.abc.Mapping[str, Any]) – The complete property-definition document.
- classmethod from_optimade(name, definition)[source]¶
Wrap a full vendored OPTIMADE property definition.
definitionmust at least carry$id,description,x-optimade-type, andtype; a clearValueErroris raised otherwise. The document is deep-copied.- Parameters:
name (str) – The canonical property name.
definition (collections.abc.Mapping[str, Any]) – The full property-definition document to wrap.
- Returns:
A validated property definition.
- Raises:
ValueError – If a required property-definition field is missing.
- Return type:
Self
- classmethod from_simple(name, *, description, fulltype='string', unit=None, dimensions=None, dict_properties=None, metadata_definition=None, required_response=False, definition_id=None)[source]¶
Generate a property definition from a compact description.
This mirrors the OPTIMADE property-definition generator: it emits the
$schemameta-schema reference, a synthesized$id(under the base registered for a matching prefix viaregister_definition_prefix()— e.g.httk.orgfor_httk_— underschemas.optimade.orgotherwise, unlessdefinition_idoverrides it), a title, thedescription, the OPTIMADE type derived fromfulltype("string","integer","float","boolean","timestamp","dict", or"list of ..."), thex-optimade-unit(with an ångström unit definition whenunit == "angstrom"), thex-optimade-definitionstamp (format"1.2"; see the module docstring), the JSONtypewith nullability derived fromrequired_response,itemsfor lists, adate-timeformat for timestamps, innerpropertiesfor dicts (fromdict_properties),x-optimade-dimensionsfromdimensions, and anx-optimade-metadata-definition(explicit, or a generatedlist_axesdefinition whendimensionsis given).The result is implementation-neutral: per-deployment
sortableandresponse-defaultflags are layered on later viawith_implementation().- Parameters:
name (str) – The canonical property name.
description (str) – The human-readable property description.
fulltype (str) – The OPTIMADE property type description.
unit (str | None) – The unit associated with numeric or list values.
dimensions (collections.abc.Mapping[str, Any] | None) – Dimension names and sizes for list values.
dict_properties (collections.abc.Mapping[str, str] | None) – Inner property names and type descriptions for dictionaries.
metadata_definition (collections.abc.Mapping[str, Any] | None) – An explicit metadata definition for the property.
required_response (bool) – Whether responses must contain a non-null value.
definition_id (str | None) – An explicit property-definition IRI.
- Returns:
A generated property definition.
- Return type:
Self
- property format_version: str | None[source]¶
Return the property’s definition-format version, if declared.
- property requirements: collections.abc.Mapping[str, Any][source]¶
Return the property’s OPTIMADE requirements mapping.
- property dimensions: collections.abc.Mapping[str, Any] | None[source]¶
Return the property’s dimensions declaration, if any.
- property metadata_definition: collections.abc.Mapping[str, Any] | None[source]¶
Return the property’s metadata definition, if any.
- with_implementation(*, sortable=None, response_default=None)[source]¶
Return a copy carrying this deployment’s implementation flags.
Adds an
x-optimade-implementationobject with thesortableandresponse-defaultkeys that are provided (aNoneargument leaves that key unset), and — whensortableis given — mirrors it in a top-levelsortablefield. The original instance is untouched. The original$idandx-optimade-definitionare retained because the vendored v1.2Property Definitionsmeta-schema says definitions “SHOULD be regarded as the same if they only differ by” changes tox-optimade-implementation; the specification says a redefinition “MUST change the $id”. Top-levelsortableis the additional field required by theEntry Listing Info Endpointssection.
- class httk.core.property_definitions.EntryTypeDefinition(name, description, properties, definition_id=None, extends_id=None)[source]¶
An immutable OPTIMADE entry-type definition.
Bundles the entry type’s
nameanddescriptionwith an insertion-ordered mapping ofPropertyDefinitionobjects (one per described property). A standard definition typically describes more properties than any given deployment serves; the served subset is chosen separately (anEntryProvidernames it through itsproperty_keys()).definition_ididentifies the source document when present. An extended definition is a new document, so it clears that identity and retains the original standard IRI inextends_idinstead.- Parameters:
name (str) – The entry type name.
description (str) – The human-readable entry type description.
properties (collections.abc.Mapping[str, PropertyDefinition]) – Property definitions keyed by property name.
definition_id (str | None) – The source document IRI, if one exists.
extends_id (str | None) – The standard document IRI extended by this definition, if any.
- classmethod from_optimade(name, entrytype)[source]¶
Build an entry-type definition from a vendored OPTIMADE entry type.
entrytypeis the vendored document shape: adescriptionstring, an optional top-level$id, and apropertiesmapping of property name to full property definition. A clearValueErroris raised when either required field is missing. The optional ID identifies the source document; ad-hoc definitions remain valid without one.- Parameters:
name (str) – The entry type name.
entrytype (collections.abc.Mapping[str, Any]) – The vendored entry-type definition document.
- Returns:
An entry-type definition built from the document.
- Raises:
ValueError – If
descriptionorpropertiesis missing.- Return type:
Self
- property definition_id: str | None[source]¶
Return this definition’s document IRI, if it has a standard one.
- property extends_id: str | None[source]¶
Return the original standard IRI extended to make this definition, if any.
- property properties: collections.abc.Mapping[str, PropertyDefinition][source]¶
Return a copy of the property definitions keyed by name.
- extended(extra, *, allow_unprefixed=False)[source]¶
Return a copy with
extracustom property definitions merged in.Each name in
extraMUST be new (a collision with an existing property raisesValueErrornaming it) and, unlessallow_unprefixedis set, MUST carry a registered database-specific prefix (seeregister_definition_prefix()/known_definition_prefixes()); a custom property that does not is rejected with aValueErrorexplaining the OPTIMADE prefix rule. The result deliberately has nodefinition_id: it is a new document, not the standard resource. Itsextends_idrecords the original standard ID so repeated extensions retain that provenance.- Parameters:
extra (collections.abc.Mapping[str, PropertyDefinition]) – New custom property definitions to add.
allow_unprefixed (bool) – Whether to allow custom names without a registered prefix.
- Returns:
A new definition containing the original and extra properties.
- Raises:
ValueError – If a property collides or violates the prefix rule.
- Return type:
Self
- httk.core.property_definitions.standard_entry_type(name)[source]¶
Return one of httk-core’s vendored standard OPTIMADE entry types.
Supported names are
"references","files", and"calculations"; an unknown name raises aValueErrorlisting the known ones. Thestructuresstandard is vendored by httk-atomistic, not httk-core.- Parameters:
name (str) – The standard entry type name to load.
- Returns:
The vendored entry-type definition.
- Raises:
ValueError – If
nameis not vendored by httk-core.- Return type: