diff --git a/python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py b/python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py index d6da4f7d8..9ed1f9599 100644 --- a/python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py +++ b/python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py @@ -349,16 +349,16 @@ def calculate( if do_backward: with record_function("ASECalculator::run_backward"): - energy.backward(-torch.ones_like(energy)) + energy.backward() with record_function("ASECalculator::convert_outputs"): if "forces" in properties: - forces_values = system.positions.grad.reshape(-1, 3) + forces_values = -system.positions.grad.reshape(-1, 3) forces_values = forces_values.to(device="cpu").to(dtype=torch.float64) self.results["forces"] = forces_values.numpy() if "stress" in properties: - stress_values = -strain.grad.reshape(3, 3) / atoms.cell.volume + stress_values = strain.grad.reshape(3, 3) / atoms.cell.volume stress_values = stress_values.to(device="cpu").to(dtype=torch.float64) self.results["stress"] = _full_3x3_to_voigt_6_stress( stress_values.numpy()