This issue is part of a Codex global repository code scan.
The ABACUS STRU writer has an operator-precedence bug when writing scalar spin-constraint (sc) flags. For False, the expression appends only "0" instead of appending " sc 0", so the 0 is concatenated directly to the preceding move flag.
Affected code:
|
if sc is not None: |
|
if isinstance(ndarray2list(sc[iatomtype]), (list, tuple)) and len( |
|
sc[iatomtype] |
|
) in [1, 3]: |
|
iout += " sc " + " ".join( |
|
["1" if ii else "0" for ii in sc[iatomtype]] |
|
) |
|
elif isinstance(ndarray2list(sc[iatomtype]), (int, float, bool)): |
|
iout += " sc " + "1" if sc[iatomtype] else "0" |
Minimal reproducer:
import dpdata
s = dpdata.System("tests/abacus.scf/STRU.ch4", fmt="stru")
s.to(
"stru",
"STRU_tmp",
mass=[12, 1],
pp_file=["C.upf", "H.upf"],
sc=[False] * s.get_natoms(),
)
print(open("STRU_tmp").read())
Current position lines include malformed endings like:
5.192682633809 4.557725978258 4.436846615358 1 1 10
5.416431453540 4.011298860305 3.511161492417 0 0 00
Expected output should include an explicit sc 0 token rather than concatenating 0 to the previous field.
This issue is part of a Codex global repository code scan.
The ABACUS STRU writer has an operator-precedence bug when writing scalar spin-constraint (
sc) flags. ForFalse, the expression appends only"0"instead of appending" sc 0", so the0is concatenated directly to the preceding move flag.Affected code:
dpdata/dpdata/formats/abacus/stru.py
Lines 797 to 805 in a7a50bf
Minimal reproducer:
Current position lines include malformed endings like:
Expected output should include an explicit
sc 0token rather than concatenating0to the previous field.