Skip to content

Commit 5aa7a8f

Browse files
authored
fix(ase): aviod duplicate stress calculation for ase calculator (#4633)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 89ab2d3 commit 5aa7a8f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

deepmd/calculator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ def calculate(
138138
self.results["virial"] = v[0].reshape(3, 3)
139139

140140
# convert virial into stress for lattice relaxation
141-
if "stress" in properties:
142-
if sum(atoms.get_pbc()) > 0:
143-
# the usual convention (tensile stress is positive)
144-
# stress = -virial / volume
145-
stress = -0.5 * (v[0].copy() + v[0].copy().T) / atoms.get_volume()
146-
# Voigt notation
147-
self.results["stress"] = stress.flat[[0, 4, 8, 5, 2, 1]]
148-
else:
149-
raise PropertyNotImplementedError
141+
if cell is not None:
142+
# the usual convention (tensile stress is positive)
143+
# stress = -virial / volume
144+
stress = -0.5 * (v[0].copy() + v[0].copy().T) / atoms.get_volume()
145+
# Voigt notation
146+
self.results["stress"] = stress.flat[[0, 4, 8, 5, 2, 1]]
147+
elif "stress" in properties:
148+
raise PropertyNotImplementedError
149+
else:
150+
pass

0 commit comments

Comments
 (0)