"""Read the three-field worked endpoint; pip install numpy zstandard huggingface_hub. Scientific metadata and example code: CC BY 4.0, Project-14 (2026). Downloads only the small first raw shard and the metadata needed for this example. """ import hashlib import io import json import struct import tarfile from pathlib import Path import numpy as np import zstandard from huggingface_hub import hf_hub_download REPO = "project-14/soc-scf-trajectories" TRAJECTORY = "proto014-feal2-reference130-002" BOHR_A = 0.529177210903 RY_EV = 13.605693122994 def decode(payload, reference, context, role): if len(payload) != reference["bytes"]: raise ValueError("Field byte count differs") if hashlib.sha256(payload).hexdigest() != reference["sha256"]: raise ValueError("Field checksum differs") encoding = reference["encoding"] if encoding == "qe-grid1": if payload[:8] != b"GPOGRID1": raise ValueError("Unknown raw header") header = struct.unpack("<7q", payload[8:64]) if header != (*context["dims"], *context["padded"], 4): raise ValueError("Grid header/context mismatch") payload = payload[64:] elif encoding != "canonical-f64le": raise ValueError("Unknown encoding") shape = (4, *reversed(context["dims"])) if len(payload) != int(np.prod(shape)) * 8: raise ValueError("Unexpected field length") a = np.frombuffer(payload, dtype="