-
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
Changes from 2 commits
09828b4
72afa1f
d481286
90b6dc3
ddadb27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| """Pydantic schemas for contributed cluster and cited flat-band results.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field, StringConstraints, model_validator | ||
|
|
||
|
|
||
| ElementSymbol = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^[A-Z][a-z]?$"), | ||
| ] | ||
| MaterialId = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^mp-\d+$"), | ||
| ] | ||
|
RajbanulAkhond marked this conversation as resolved.
Outdated
|
||
| CompoundSystem = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^[A-Z][a-z]?-[A-Z][a-z]?$"), | ||
| ] | ||
|
bfoley12 marked this conversation as resolved.
|
||
| ClusterLabel = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^X\d+$"), | ||
| ] | ||
| FlatBandLatticeId = Annotated[ | ||
| str, | ||
| StringConstraints(pattern=r"^(?:LI|SK)-\d+$"), | ||
| ] | ||
|
|
||
| _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 angstrom, over the connected site pairs " | ||
| "used by Cluster Finder for this cluster instance." | ||
| ), | ||
| ) | ||
|
bfoley12 marked this conversation as resolved.
|
||
| elements: list[ElementSymbol] = 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, | ||
| 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: ElementSymbol = Field( | ||
| description="Elemental sublattice hosting the selected flat-band model." | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comments about pymatgen.Element type |
||
| 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: MaterialId = Field( | ||
| description=( | ||
| "Materials Project identifier used only as the external linkage key " | ||
| "for this contribution." | ||
| ) | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should replace |
||
| 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, | ||
| 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 angstrom, 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 abs(minimum - self.minimumAverageDistance) > 1e-9: | ||
| raise ValueError( | ||
| "minimumAverageDistance must equal the minimum cluster distance" | ||
| ) | ||
|
RajbanulAkhond marked this conversation as resolved.
|
||
|
|
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.