Skip to content

Commit 1e54cb6

Browse files
authored
fix(abacus): preserve scalar spin-constraint separators (deepmodeling#1022)
Fixes deepmodeling#998. Emit an explicit `sc 0` token for scalar false constraints and update the golden fixture that encoded the malformed output. Tests: `cd tests && python -m unittest test_abacus_stru_dump` Why existing tests missed it: The golden file was generated from the buggy output, so the old test institutionalized the defect. Coding agent: Codex Codex version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning effort: xhigh Co-authored-by: njzjz-bot <njzjz.bot@gmail.com>
1 parent 27c7a52 commit 1e54cb6

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

dpdata/formats/abacus/stru.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ def process_file_input(file_input, atom_names, input_name):
802802
["1" if ii else "0" for ii in sc[iatomtype]]
803803
)
804804
elif isinstance(ndarray2list(sc[iatomtype]), (int, float, bool)):
805-
iout += " sc " + "1" if sc[iatomtype] else "0"
805+
# Parenthesize the conditional expression so both True
806+
# and False values retain the ``sc`` field separator.
807+
iout += " sc " + ("1" if sc[iatomtype] else "0")
806808

807809
if lambda_ is not None:
808810
if isinstance(ndarray2list(lambda_[iatomtype]), (list, tuple)) and len(

tests/abacus.scf/stru.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ H
2525
4
2626
5.416431453540 4.011298860305 3.511161492417 1 1 1 mag 1.000000000000 1.000000000000 1.000000000000 angle2 90.000000000000 sc 1 lambda 0.400000000000 0.500000000000 0.600000000000
2727
4.131588222365 4.706745191323 4.431136645083 1 1 1 mag 1.000000000000 angle1 100.000000000000 angle2 80.000000000000 sc 1 0 1 lambda 0.700000000000 0.800000000000 0.900000000000
28-
5.630930319126 5.521640894956 4.450356541303 0 0 0 mag 1.000000000000 angle1 90.000000000000 angle2 70.0000000000000
28+
5.630930319126 5.521640894956 4.450356541303 0 0 0 mag 1.000000000000 angle1 90.000000000000 angle2 70.000000000000 sc 0
2929
5.499851012568 4.003388899277 5.342621842622 0 0 0 mag 1.000000000000 angle1 80.000000000000 sc 1

0 commit comments

Comments
 (0)