-
Notifications
You must be signed in to change notification settings - Fork 27
Cluster materials lux schema #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bfoley12
merged 5 commits into
materialsproject:master
from
RajbanulAkhond:cluster-materials-lux-schema
Sep 8, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09828b4
Add Cluster Materials Lux schema
RajbanulAkhond 72afa1f
Use project name for Cluster Materials schema
RajbanulAkhond d481286
Relaxing the tolerance
RajbanulAkhond 90b6dc3
Address Cluster Materials schema review
RajbanulAkhond ddadb27
Simplify flat-band presence and validation
RajbanulAkhond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
mpcontribs-lux/mpcontribs/lux/projects/cluster_materials/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """Public models for the Cluster Materials Lux schema.""" | ||
|
|
||
| from .schema import ( | ||
| ClusterDescriptor, | ||
| ClusterMaterial, | ||
| ClusterPointGroup, | ||
| FlatBandProperties, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ClusterDescriptor", | ||
| "ClusterMaterial", | ||
| "ClusterPointGroup", | ||
| "FlatBandProperties", | ||
| ] |
275 changes: 275 additions & 0 deletions
275
mpcontribs-lux/mpcontribs/lux/projects/cluster_materials/schema.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,275 @@ | ||
| """Pydantic schemas for contributed cluster and cited flat-band results.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from math import isclose | ||
| from typing import Annotated, Literal | ||
|
|
||
| from emmet.core.mpid import MPID | ||
| from pydantic import ( | ||
| BaseModel, | ||
| BeforeValidator, | ||
| ConfigDict, | ||
| Field, | ||
| StringConstraints, | ||
| model_validator, | ||
| ) | ||
| from pymatgen.core import Element | ||
|
|
||
|
|
||
| def _validate_compound_system(value: object) -> str: | ||
| """Validate both element symbols while preserving the upload string.""" | ||
| if not isinstance(value, str): | ||
| raise ValueError("compoundSystem must be a string") | ||
|
|
||
| symbols = value.split("-") | ||
| if len(symbols) != 2: | ||
| raise ValueError("compoundSystem must contain exactly two element symbols") | ||
|
|
||
| try: | ||
| for symbol in symbols: | ||
| Element(symbol) | ||
| except ValueError as exc: | ||
| raise ValueError("compoundSystem contains an invalid element symbol") from exc | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| CompoundSystem = Annotated[ | ||
| str, | ||
| BeforeValidator(_validate_compound_system), | ||
| StringConstraints(max_length=5), | ||
| ] | ||
|
RajbanulAkhond marked this conversation as resolved.
Outdated
|
||
| ClusterLabel = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^X\d+$", max_length=16), | ||
| ] | ||
| FlatBandLatticeId = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^(?:LI|SK)-\d+$", max_length=16), | ||
| ] | ||
|
|
||
| _MODEL_CONFIG = ConfigDict(extra="forbid", allow_inf_nan=False) | ||
|
|
||
|
|
||
| class ClusterDescriptor(BaseModel): | ||
| """Properties of one cluster instance identified by Cluster Finder.""" | ||
|
|
||
| model_config = _MODEL_CONFIG | ||
|
|
||
| size: int = Field( | ||
| ge=2, | ||
| description="Number of atomic sites in this cluster instance.", | ||
| ) | ||
|
bfoley12 marked this conversation as resolved.
|
||
| averageDistance: float = Field( | ||
| gt=0, | ||
| description=( | ||
| "Mean Cartesian distance, in angstroms, over the connected site pairs " | ||
| "used by Cluster Finder for this cluster instance." | ||
| ), | ||
| ) | ||
|
bfoley12 marked this conversation as resolved.
|
||
| elements: list[Element] = Field( | ||
| min_length=2, | ||
| description="Element symbol at each site in this cluster instance.", | ||
| ) | ||
| isExtended: bool = Field( | ||
|
RajbanulAkhond marked this conversation as resolved.
|
||
| description=( | ||
| "Whether supercell analysis identifies the cluster as part of an " | ||
| "extended cluster network." | ||
| ) | ||
| ) | ||
| isShared: bool = Field( | ||
| description=( | ||
| "Whether supercell analysis identifies sharing between periodic " | ||
| "cluster images." | ||
| ) | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_cluster(self) -> ClusterDescriptor: | ||
| """Enforce invariants used when Cluster Finder created the CSV.""" | ||
| if len(self.elements) != self.size: | ||
| raise ValueError("elements must contain exactly size entries") | ||
|
RajbanulAkhond marked this conversation as resolved.
|
||
| if self.isExtended and self.isShared: | ||
| raise ValueError("isExtended and isShared cannot both be true") | ||
| return self | ||
|
|
||
|
|
||
| class ClusterPointGroup(BaseModel): | ||
| """Point-group assignment for one unique cluster type.""" | ||
|
|
||
| model_config = _MODEL_CONFIG | ||
|
|
||
| label: ClusterLabel = Field( | ||
| description="Cluster Finder label for the unique cluster type." | ||
| ) | ||
| symbol: str = Field( | ||
| min_length=1, | ||
| max_length=16, | ||
| description="Schoenflies point-group symbol of the unique cluster type.", | ||
| ) | ||
|
bfoley12 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class FlatBandProperties(BaseModel): | ||
| """Selected flat-band model annotation from Neves et al. (2024).""" | ||
|
|
||
| model_config = _MODEL_CONFIG | ||
|
|
||
| sublatticeElement: Element = Field( | ||
| description="Elemental sublattice hosting the selected flat-band model." | ||
| ) | ||
| numberOfFlatBands: int = Field( | ||
| ge=1, | ||
| description="Number of flat bands hosted by the selected sublattice model.", | ||
| ) | ||
| sitesInSublattice: int = Field( | ||
| ge=1, | ||
| description="Number of sites present in the selected flat-band model.", | ||
| ) | ||
| latticeDimensionalities: list[Literal[1, 2, 3]] = Field( | ||
| min_length=1, | ||
| description="Dimensionality of each classified flat-band lattice motif.", | ||
| ) | ||
| latticeIds: list[FlatBandLatticeId] = Field( | ||
| min_length=1, | ||
| description=( | ||
| "Flat-band lattice identifiers assigned by Neves et al.; LI denotes " | ||
| "lattice-invariant classification and SK denotes Systre-key " | ||
| "classification." | ||
| ), | ||
| ) | ||
| remainsFlatWithDecay: bool = Field( | ||
| description=( | ||
| "Whether the selected model contains a flat band when hopping " | ||
| "strength decays exponentially with bond length." | ||
| ) | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_lattice_annotations(self) -> FlatBandProperties: | ||
| """Require one dimensionality annotation for each lattice identifier.""" | ||
| if len(self.latticeDimensionalities) != len(self.latticeIds): | ||
| raise ValueError( | ||
| "latticeDimensionalities and latticeIds must have equal lengths" | ||
| ) | ||
| return self | ||
|
|
||
|
|
||
| class ClusterMaterial(BaseModel): | ||
| """Contributed cluster results for one Materials Project material.""" | ||
|
|
||
| model_config = _MODEL_CONFIG | ||
|
|
||
| materialId: MPID = Field( | ||
| description=( | ||
| "Materials Project identifier used only as the external linkage key " | ||
| "for this contribution." | ||
| ) | ||
| ) | ||
| compoundSystem: CompoundSystem = Field( | ||
| description=( | ||
| "Transition-metal and anion pair used for the Cluster Finder search, " | ||
| "formatted as <primary-transition-metal>-<anion>." | ||
| ) | ||
|
bfoley12 marked this conversation as resolved.
RajbanulAkhond marked this conversation as resolved.
|
||
| ) | ||
| numberOfClusters: int = Field( | ||
| ge=1, | ||
| description="Number of cluster instances reported for this material.", | ||
| ) | ||
| clusters: list[ClusterDescriptor] = Field( | ||
| min_length=1, | ||
| description="Cluster instances identified in the material.", | ||
| ) | ||
| clusterLatticeSpaceGroup: str = Field( | ||
| min_length=1, | ||
| max_length=32, | ||
| description=( | ||
| "Space-group symbol of the derived lattice whose sites are unique " | ||
| "cluster centroids; this is not the parent material space group." | ||
| ), | ||
| ) | ||
| clusterPointGroups: list[ClusterPointGroup] = Field( | ||
| min_length=1, | ||
| description=( | ||
| "Point groups of unique cluster types. Its length may be smaller than " | ||
| "numberOfClusters when instances are symmetry-equivalent." | ||
| ), | ||
| ) | ||
|
RajbanulAkhond marked this conversation as resolved.
|
||
| predictedDimensionality: Literal["0D", "1D", "2D", "3D"] = Field( | ||
| description=( | ||
| "Effective dimensionality assigned to the cluster-centroid lattice by " | ||
| "the Cluster Finder classification." | ||
| ) | ||
| ) | ||
| minimumAverageDistance: float = Field( | ||
| gt=0, | ||
| description=( | ||
| "Minimum, in angstroms, of averageDistance over all reported cluster " | ||
| "instances." | ||
| ), | ||
| ) | ||
| isPolar: bool = Field( | ||
|
bfoley12 marked this conversation as resolved.
|
||
| description="Whether the parent material belongs to a polar crystal class." | ||
| ) | ||
| isPiezoelectric: bool = Field( | ||
| description=( | ||
| "Whether the parent material's crystal class permits piezoelectricity." | ||
| ) | ||
| ) | ||
| isEnantiomorphic: bool = Field( | ||
| description=( | ||
| "Whether the parent material belongs to an enantiomorphic space-group " | ||
| "class." | ||
| ) | ||
| ) | ||
| hasFlatData: bool = Field( | ||
| description=( | ||
| "Whether this material has a cited flat-band record in the reviewed " | ||
| "flat-band source snapshot." | ||
| ) | ||
|
RajbanulAkhond marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
bfoley12 marked this conversation as resolved.
Outdated
|
||
| hasBatteryData: bool = Field( | ||
| description=( | ||
| "Whether this material appears in the reviewed Materials Project " | ||
| "Battery Explorer snapshot. No battery properties are duplicated in " | ||
| "this contribution." | ||
| ) | ||
| ) | ||
| flatBand: FlatBandProperties | None = Field( | ||
| default=None, | ||
| description=( | ||
| "Optional selected flat-band lattice annotation from Neves et al., " | ||
| "npj Computational Materials 10, 39 (2024), " | ||
| "doi:10.1038/s41524-024-01220-x." | ||
| ), | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_material(self) -> ClusterMaterial: | ||
| """Enforce cross-field invariants for the contributed cluster data.""" | ||
| if len(self.clusters) != self.numberOfClusters: | ||
| raise ValueError("numberOfClusters must equal len(clusters)") | ||
|
|
||
|
RajbanulAkhond marked this conversation as resolved.
|
||
| minimum = min(cluster.averageDistance for cluster in self.clusters) | ||
| if not isclose( | ||
| minimum, | ||
| self.minimumAverageDistance, | ||
| rel_tol=1e-9, | ||
| abs_tol=1e-6, | ||
| ): | ||
| raise ValueError( | ||
| "minimumAverageDistance must equal the minimum cluster distance" | ||
| ) | ||
|
RajbanulAkhond marked this conversation as resolved.
|
||
|
|
||
| if len(self.clusterPointGroups) > self.numberOfClusters: | ||
| raise ValueError( | ||
| "clusterPointGroups cannot contain more entries than clusters" | ||
| ) | ||
|
|
||
| labels = [point_group.label for point_group in self.clusterPointGroups] | ||
| if len(labels) != len(set(labels)): | ||
| raise ValueError("clusterPointGroups labels must be unique") | ||
|
|
||
| if self.hasFlatData != (self.flatBand is not None): | ||
|
bfoley12 marked this conversation as resolved.
Outdated
|
||
| raise ValueError("hasFlatData must agree with the presence of flatBand") | ||
| return self | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.