This issue is part of a Codex global repository code scan.
In VASP POSCAR files, a negative scale factor represents the target cell volume, not a direct negative multiplier for lattice vectors and Cartesian coordinates. The current parser multiplies the cell by scale unconditionally, so negative scales produce negative lattice vectors and the wrong volume.
Affected code:
|
scale = float(lines[1]) |
|
cell = [] |
|
move_flags = [] |
|
for ii in range(2, 5): |
|
boxv = [float(jj) for jj in lines[ii].split()] |
|
boxv = np.array(boxv) * scale |
|
cell.append(boxv) |
|
system["cells"] = [np.array(cell)] |
|
natoms = sum(system["atom_numbs"]) |
|
coord = [] |
|
for ii in range(8, 8 + natoms): |
|
tmp = lines[ii].split() |
|
tmpv = [float(jj) for jj in tmp[:3]] |
|
if cartesian: |
|
tmpv = np.array(tmpv) * scale |
|
else: |
|
tmpv = np.matmul(np.array(tmpv), system["cells"][0]) |
Minimal reproducer:
import numpy as np
from dpdata.formats.vasp.poscar import to_system_data
lines = """test
-8
1 0 0
0 1 0
0 0 1
H
1
Direct
0 0 0
""".splitlines()
data = to_system_data(lines)
print(data["cells"][0])
print(np.linalg.det(data["cells"][0]))
Current behavior computes a cell with determinant -512. The expected cell volume is 8 for this input.
The parser should handle negative scale factors as target volumes, while preserving the current direct multiplier behavior for positive scale factors.
This issue is part of a Codex global repository code scan.
In VASP POSCAR files, a negative scale factor represents the target cell volume, not a direct negative multiplier for lattice vectors and Cartesian coordinates. The current parser multiplies the cell by
scaleunconditionally, so negative scales produce negative lattice vectors and the wrong volume.Affected code:
dpdata/dpdata/formats/vasp/poscar.py
Lines 20 to 36 in a7a50bf
Minimal reproducer:
Current behavior computes a cell with determinant
-512. The expected cell volume is8for this input.The parser should handle negative scale factors as target volumes, while preserving the current direct multiplier behavior for positive scale factors.