[Code scan] Symmetrize ASE calculator stress after reshaping virial
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start in deepmd/calculator.py around lines 151-163, where the virial is reshaped and converted into ASE stress. Verify the conversion with a nonsymmetric virial, then ensure symmetrization happens on the 3x3 matrix before Voigt indexing; done means ASE receives the corrected stress values.
Written by the indexing model from the issue text.
Description
This issue comes from a Codex global scan of deepmodeling/deepmd-kit at commit 73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.
Problem
The ASE calculator stores the model virial as a 3x3 matrix:
but when converting virial to stress it operates on the original flat 9-vector v[0]:
For a one-dimensional NumPy array, .T is a no-op. Therefore 0.5 * (v[0] + v[0].T) does not symmetrize the virial tensor; it just returns the flat virial vector. The subsequent Voigt indexing then uses unsymmetrized off-diagonal entries.
Impact
ASE stress returned by the DeePMD calculator can be wrong for models/inputs whose virial tensor is not exactly symmetric. This affects workflows that consume ASE stress, including cell/lattice relaxation.
Suggested fix
Reshape before symmetrizing:
virial = v[0].reshape(3, 3)
stress = -0.5 * (virial + virial.T) / atoms.get_volume()
self.results["stress"] = stress.flat[[0, 4, 8, 5, 2, 1]]
Alternatively, reuse self.results["virial"] after assigning it.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 651
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from deepmodeling/deepmd-kit
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepmodeling/deepmd-kit#5991 ·
-
Docs enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
deepmodeling/deepmd-kit#5766 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepmodeling/deepmd-kit#5686 · 1 comment ·
-
branch: master lang: py todo comment type: todo
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
deepmodeling/deepmd-kit#5480 ·
-
branch: master lang: toml todo comment type: todo
Difficulty 1/5 Under an hour Newbie friendliness 72/100
deepmodeling/deepmd-kit#5462 ·
All issues in deepmodeling/deepmd-kit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100