One Crystal, One Token? Testing Equivalent Unit Cells
Standardizing equivalent unit cells gave bit-identical stored environment channels in 96–100% of tested cases. Atomic positions had a 95th-percentile round-trip error of 0.00016 Å on 1,000 MP20 test crystals.
Scientists can describe the same crystal in several valid ways, and an AI model should give the same prediction for each one. In one test, changing only the description raised the model’s error in predicting the energy change when a crystal forms by 66–72%. We standardized how crystals are described before passing them to the model, and the saved numbers describing each atom’s surroundings matched exactly in 96–100% of the equivalent cases we tested.
We built Shodh's crystal token to improve consistency across equivalent descriptions and keep geometry precise. Each atom becomes a compact 192-number token. After standardization, the stored environment channels were bit-identical in 96–100% of tested equivalent cases across 512 crystals in 26 descriptions each. In a separate round-trip test on 1,000 MP20 crystals, atomic positions came back with a 95th-percentile error of 0.00016 Å.
- 96–100% of tested equivalent cases had bit-identical stored environment channels
- 13,312 equivalent descriptions tested across 512 MP20 crystals
- 0.00016 Å 95th-percentile position error, full round trip on 1,000 MP20 test crystals
- 0 retraining runs for the standardization step
Inside a Shodh crystal token
Each atom becomes a 192-number token with three parts, plus a header that stores the atomic numbers and the unit cell:
- A 32-channel carrier of deterministic values, including position and cell entries.
- 30 position-phase channels: sine and cosine functions of the atom's fractional coordinates.
- 130 environment channels, produced by an encoder from the atom's identity, its periodic neighbourhood and the cell shape.
We test the geometry and the environment features separately.
Precise geometry
The position decoder reads only the phase channels. In a full encode–decode round trip on 1,000 MP20 test crystals, every structure was recovered, with the atom types and order intact, a median position error of 0.00006 Å and a 95th percentile of 0.00016 Å. On a separate set of 1,200 larger crystals with 14 to 252 atoms each, every structure was again recovered, with a 95th percentile of 0.00024 Å. In the channel-zeroing tests, decoded positions remained bit-identical after zeroing all 130 environment channels. Zeroing the phase channels moved atoms by 4–5 Å.
The equivalent-cell problem
A crystal can be described with different, equally valid unit cells. Changing basis multiplies the cell matrix by an integer matrix with determinant one and adjusts the fractional coordinates to match; the physical crystal is unchanged. Supercells, Niggli-reduced cells, conventional and primitive cells all describe the same material.
Two valid unit cells for the same pattern
The periodic atomic pattern is unchanged.
Any encoder that reads the raw cell sees these descriptions differently. Across 512 MP20 crystals, the environment features of equivalent descriptions fell as low as a cosine similarity of 0.27, and predictions made from them drifted by 24–44% of the predictor's own error. We found the same pattern in encoders with random, untrained weights, which shows the effect comes from the raw input itself. That makes it a general problem for crystal representations, and it calls for a general fix.
The effect reaches all the way to property prediction. A transformer trained to predict formation energy from raw MP20 descriptions was tested on all 9,046 MP20 test crystals, each rewritten in an equivalent unit cell. Its error rose from 0.043 to about 0.071–0.073 eV/atom, and 86–87% of its predictions moved by more than 0.01 eV/atom. Band-gap error rose by 0.11 eV. The same model given only element identities was exactly unaffected by these basis changes, so the shift comes entirely from how the cell is written.
The fix: standardize before encoding
The tested pipeline uses spglib to reduce each crystal to a standard primitive cell before encoding. It chooses among the lattice's proper symmetry operations and atom origins, then orders the atoms deterministically. The standardization step leaves the encoder weights unchanged.
We first tested it on 15 crystals, 12 from MP20 and 3 synthetic, each under six equivalent changes plus a real physical change as a control:
| Equivalent description | Lowest similarity without standardization | Identical after standardization |
|---|---|---|
| Rotation | 1.000 | 15/15 |
| Translation | 1.000 | 15/15 |
| Atom reordering | 1.000 | 15/15 |
| Basis cycle | 0.601 | 15/15 |
| Basis shear | 0.948 | 15/15 |
| Doubled supercell | 0.965 | 15/15 |
| Real 10% scale change (control) | 0.996 | 0/15, as intended |
All 90 equivalent comparisons produced bit-identical environment channels, and the real physical change still changed them in every case. Standardization removes convention noise without hiding genuine differences between materials.
At scale: 13,312 descriptions
We then repeated the test on 512 MP20 crystals, each written in 26 equivalent descriptions: rotations, translations, atom reorderings, random basis changes, Niggli, conventional and primitive cells, and several supercells.
| Measure across equivalent descriptions | Without standardization | With standardization |
|---|---|---|
| Lowest environment-feature cosine similarity | 0.27 | — |
| Share of cases with bit-identical stored environment channels | — | 96–100% |
| Prediction drift, as share of predictor error | 24–44% | 1.3–1.7% |
At this scale, stored environment channels were bit-identical in 96–100% of tested cases. Prediction drift fell from 24–44% of the predictor's own error to 1.3–1.7%.
String representations such as Mat2Seq and SLICES also aim for consistent crystal descriptions. Our approach standardizes the input of a continuous per-atom tokenizer using established crystallographic tools.
Why it matters
- Unit-cell choice affects predictions. In the raw-input transformer test, rewriting a crystal's unit cell raised formation-energy error by 66–72%.
- More consistent environment features. Standardization made stored environment channels match bit for bit in most tested equivalent cases.
- Verifiable geometry. Both round-trip sets had sub-milliångström position error at the 95th percentile.
- A preprocessing change. Standardization runs before the encoder and leaves the tested weights unchanged.
How we measured
Representation: Shodh crystal codec release candidate rc.3, with BF16 storage.
Standardization: spglib 2.7.0 at symprec 10⁻⁵, designed for clean, database-quality structures such as MP20. Atomic noise of 10⁻⁴ Å or more can change the standardized cell, so noisy experimental or relaxed structures need a tolerance-aware variant.
Tests. We used 15 structures with six equivalent changes each, plus a scale control. The larger test used 512 MP20 training structures with 26 descriptions each (13,312 variants). In the equivalence tests, “identical” refers to the stored environment channels.
Prediction sensitivity: transformer regressors trained on raw MP20 descriptions, three seeds, all 9,046 MP20 test structures, prediction only, with two random equivalent basis changes; paired bootstrap confidence intervals with 10,000 resamples. A model trained on raw descriptions must be retrained on standardized inputs to benefit from standardization.
Prediction drift: ridge predictors with training-only normalization, fitted on composition-separated MP20 training structures; drift is the mean change in prediction between equivalent descriptions, divided by the predictor's error.
Geometry: full encode–decode round trip on 1,000 MP20 test structures and on 1,200 larger non-MP20 crystals (14–252 atoms), all matched by pymatgen StructureMatcher at default tolerances; position error is the Cartesian minimum-image RMSD per structure, with BF16 storage. Channel-zeroing tests on synthetic test crystals.
References
- spglib: spglib.readthedocs.io
- Mat2Seq, NeurIPS 2024: proceedings.neurips.cc
- SLICES, Nature Communications 2023: nature.com/articles/s41467-023-42870-7