Implement augmentation routines in metatomic#264
Open
ppegolo wants to merge 5 commits into
Open
Conversation
Luthaf
reviewed
Jun 26, 2026
Member
There was a problem hiding this comment.
this is a bit hard to follow, would be nice to make it clearer/better documented
Contributor
Author
There was a problem hiding this comment.
hopefully clearer now
5e6bae5 to
adfce14
Compare
Real Wigner-D matrices for O(3), used to rotate spherical (o3_mu) tensors. `compute_wigner_batch` builds a batch of real D matrices up to a given angular momentum from ZYZ Euler angles via the standard recursion. A small TorchScript-compatibility `jit` helper (`_jit_compat`) lets the recursion be scripted.
`apply_transformations` applies a batch of per-system O(3) matrices (proper or improper rotations) to a list of Systems and their target/extra-data TensorMaps simultaneously, deriving the needed Wigner-D matrices from the matrices themselves; `random_rotations` samples a uniform O(3) batch. Each component axis is transformed by tensor type inferred from its name: Cartesian axes (xyz/xyz_1/xyz_2) are contracted with R directly (so improper rotations flip them), and spherical axes (o3_mu/_1/_2) with the Wigner-D matrix of their o3_lambda, plus a (-1)^l * sigma parity per spherical axis when R is improper. A single TensorMap may mix scalar, Cartesian and spherical blocks, and gradients are transformed as blocks with extra axes. Value rows are routed to systems by their "system" label (remapping arbitrary dataset indices onto the provided systems); gradients are routed by the parent block's "system" label via the gradient "sample" column. System geometry, registered per-atom data and neighbor-list vectors are rotated too. The public entry point validates that the transformations are 3x3 and orthogonal and that transformations, systems and TensorMaps share a dtype and device.
Cross-checks the spherical (Wigner-D) path against the trivially-correct Cartesian path for general rotations, including both gimbal-lock branches of the ZYZ decomposition (beta = 0 and beta = pi) and improper rotations. Covers gradient rotation and per-system routing (including unsorted parent "system" labels and the arbitrary-dataset-index remap), System geometry, registered scalar/Cartesian/spherical data, neighbor-list vectors, `random_rotations` (orthogonality, inversions, reproducible generator) and the public-API validation errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Augmentation is currently implemented in metatrain, and it depends on
sphericalfor augmentation of spherical targets.In prepraration for the
SymmetrizedModelPR (currently #119, that would depend on metatrain just for the augmentation routines) I re-implemented the relevant parts of spherical (MIT license) here, getting rid of unnecessary stuff and most dependencies, and all the necessary functions that handle augmentation.Contributor (creator of pull-request) checklist
Reviewer checklist
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)