--- license: cc0-1.0 task_categories: - other tags: - chemistry - scattering - molecular - hdf5 pretty_name: IQ Train Set (L=50) size_categories: - 1M//` Each `.xyz` file produces one HDF5 group nested two levels deep. ``` // .attrs['name'] str / I_q float32 (Q,) coords float64 (n, 3) angles float64 (n, 2) r float64 (n,) elms str (n,) ``` | Level | Key | Description | | --------- | -------------- | ------------------------------------------------------------------------------------------------------------------- | | group | `` | Arbitrary label supplied via the `groups` dict argument | | subgroup | `` | Filename without `.xyz` extension | | attribute | `name` | Molecule name string (from XYZ line 2) | | dataset | `I_q` | Orientationally-averaged scattering intensity, float32 `(Q,)`, ZFP lossless | | dataset | `coords` | Centroid-subtracted Cartesian coordinates, float64 `(n, 3)`, ZFP lossless | | dataset | `angles` | Spherical angles, float64 `(n, 2)`: col 0 = theta (polar, 0 to pi), col 1 = phi (azimuthal, 0 to 2pi), ZFP lossless | | dataset | `r` | Radial distances from centroid in angstroms, float64 `(n,)`, ZFP lossless | | dataset | `elms` | Element symbol per atom, variable-length UTF-8 string `(n,)`, uncompressed | `Q` is the number of points in `/q_grid` and is fixed for the whole file. `n` varies per molecule. Coordinates are centroid-subtracted (shifted to geometric centroid before storage). `angles` and `r` are stored pre-computed for fast loading; they are consistent with `coords` via: ``` r[i] = norm(coords[i]) theta[i] = arccos(z[i] / r[i]) (0 if r = 0) phi[i] = arctan2(y[i], x[i]) ``` Form factors are **not** stored -- they are recomputed from `xraydb`. ## Groups The `groups` argument maps each group name to a directory of `.xyz` files. Every group becomes a top-level HDF5 group containing one subgroup per molecule. | Group | Molecules | Atom range | Description | | ----- | --------: | ---------- | ----------- | | COD | 532,302 | 1-6,032 | Crystallography Open Database | | QM9 | 133,844 | 3-29 | Small organic molecules | | tmQM | 108,541 | 7-569 | Transition metal complexes | | rcsb_sml | 96,158 | 28-6,036 | PDB small structures | | viro3D | 60,488 | 173-6,046 | Viral protein structures | | hydration_shells | 48,571 | 3-147 | Water solvation shells | | rcsb_med | 31,749 | 2,996-6,046 | PDB medium structures | | mofs | 30,863 | 10-5,760 | Metal-organic frameworks | | (Na,Co,Ag,Pb,Mo,Fe)_monoatomic_clusters | 1,282 | 2-380 | Monoatomic clusters | | binary_clusters | 371 | 2-1,482 | Binary alloy clusters | | si_ge_clusters | 217 | 4-60 | Silicon/germanium clusters | | ar_ne_clusters | 127 | 2-55 | Noble gas clusters | | (NaCl)_nCl- | 70 | 3-71 | Sodium chloride clusters | | **TOTAL** | **1,044,583** | **1-6,046** | | ## Compression codecs | Codec | Used for | Notes | | -------------------------------- | ---------------------------------------- | -------------------------------- | | ZFP lossless (`reversible=True`) | `q_grid`, `I_q`, `coords`, `angles`, `r` | Floating-point; exact round-trip | | Bitshuffle + Zstd level 22 | `sources_tsv`, `makeup_tsv` | uint8 blobs; ZFP incompatible | `elms` is a variable-length UTF-8 string dataset and is stored uncompressed. ## B-tree corruption recovery (rcsb_med, June 2026) The `rcsb_med` group B-tree was corrupted mid-build (at roughly 40% completion, ~40k of 101,989 entries written). Standard h5py operations on it (`del`, `keys()`) raised checksum errors. Recovery procedure: ### Step 1 -- OHDR binary scan Scan the raw file with `mmap.find(b'OHDR')`, skip non-v2 headers (version byte != 2), then call `H5Oopen_by_addr` via ctypes on h5py's bundled libhdf5 to open each candidate object directly by byte offset, bypassing the corrupted B-tree. Each call is wrapped in a `signal.SIGALRM` timeout (1 s) to prevent infinite hangs on pathological corrupted objects. Valid molecule groups are written incrementally to a recovery file (checkpoint every 200 molecules for resume safety). Result: 37 GB file, 4.7 M OHDR signatures, ~26 min, 25 timeouts. **Warning -- zombie objects**: OHDR scan finds ALL HDF5 objects ever written to the file, including orphaned objects from previous build runs that were logically deleted but not physically zeroed. After recovery, cross-check every recovered key against the source XYZ directory and delete any key with no matching `.xyz`. In this run: 107,616 raw hits, 67,616 were garbage (old unprefixed hydration_shells orphans from a previous naming convention), leaving 40,000 legitimate rcsb_med entries. ### Step 2 -- Fresh file rebuild `del hf['rcsb_med']` also fails with checksum errors on a corrupted group. Solution: build a new file from scratch using `h5py.File.copy()` (H5Ocopy -- raw chunk copy, no decompression) to transfer all intact top-level groups/datasets from the original, then copy rcsb_med from the recovery file. Rename rebuilt file over original. Result: ~12 min to rebuild. ### Step 3 -- Resume build_db With the recovered 40,000 entries in place, `build_db.py` resumes normally: it opens the file in append mode, skips entries that already exist, and fills in the remaining 61,989 rcsb_med entries plus all subsequent groups (rcsb_sml, si_ge_clusters, tmQM, viro3D). ### Key tools - `h5clear -s `: reset write-open flags left by an interrupted write - `H5Oopen_by_addr` (ctypes): open HDF5 objects by raw byte offset, bypassing B-trees - `signal.SIGALRM`: bound hanging C-library calls to a fixed timeout ## Crash safety Entries are written under a temporary name `__tmp__` and atomically moved to `` only after shape assertions pass. Any `__tmp__*` keys found at startup are cleaned up before processing resumes.