Skip to content

[Code scan] ABACUS STRU scalar sc=False writes malformed position lines #998

Description

@njzjz

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions