Skip to content

RandomRotation: stale ase.constraints stress import breaks on ASE 3.29 (+ in-place mutation of input atoms) #5

Description

@sirmarcel

RandomRotation.random_map in marathon/grain/transforms/transforms.py has two issues, found while using rotational augmentation with a magnetic model (ASE 3.29.0).

1. Stale ASE import (breaks augmentation with Voigt-6 stress)

Line ~134:

from ase.constraints import (
    full_3x3_to_voigt_6_stress,
    voigt_6_to_full_3x3_stress,
)

These were moved to ase.stress in recent ASE (3.29). This raises ImportError: cannot import name 'full_3x3_to_voigt_6_stress' from 'ase.constraints' whenever a sample carries stress in Voigt-6 shape (6,) (the stress.shape == (6,) branch).

Note: marathon/grain/data_source/properties.py::convert_stress already imports these correctly from ase.stress — so the fix is just to match that here.

2. In-place mutation of the input atoms' calculator (minor)

Line ~126:

results = atoms.calc.results
if "forces" in self.keys and "forces" in results:
    results["forces"] = np.einsum("ab,ib->ia", R, F)

results aliases the input atoms' calc.results, so the rotation is written back onto the source atoms before atoms.copy(). Harmless in a grain pipeline (fresh atoms per read), but surprising and a footgun. Suggest results = dict(atoms.calc.results) first.

Repro

from marathon.grain import RandomRotation
import numpy as np
# atoms with a Voigt-6 stress in its SinglePointCalculator
RandomRotation().random_map(atoms, np.random.default_rng(0))  # ImportError under ASE 3.29

Fix: import full_3x3_to_voigt_6_stress, voigt_6_to_full_3x3_stress from ase.stress, and copy results before mutating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions