"""Minimal reader for ORCA 6 .gbw files (reverse-engineered, validated against orca.out on OMol25 data). Layout: 64-byte header of little-endian int64 words; word 3 (byte 24) points to the MO block: int32 n_operators (1 = RHF/RKS, 2 = UHF/UKS), int32 dim, then for each operator dim*dim float64 coefficients stored so that reshape(dim, dim) gives C[ao, mo], dim float64 occupations, dim float64 orbital energies (Eh), dim int32 irreps, dim int32 core flags. Returns C[ao, mo] (columns = MOs) in ORCA AO ordering; C^T S C = I verified to 1e-7 against pyscf S. """ import struct, numpy as np, zstandard as zstd def read_gbw(path): b = open(path, "rb").read() if path.endswith(".zstd0") or b[:4] == b"\x28\xb5\x2f\xfd": b = zstd.ZstdDecompressor().decompressobj().decompress(b) hdr = struct.unpack_from("<8q", b, 0) ptr = hdr[3] nop, dim = struct.unpack_from("