This issue is part of a Codex global repository code scan.
The DFTB+ parser only reads coordinate rows while flag in (3, 4, 5, 6) and force rows while flag in (8, 9, 10, 11). That limits parsing to four atoms regardless of the actual system size.
Affected code:
|
with open_file(fn_1) as f: |
|
flag = 0 |
|
for line in f: |
|
if flag == 1: |
|
flag += 1 |
|
elif flag == 2: |
|
components = line.split() |
|
flag += 1 |
|
elif line.startswith("Geometry"): |
|
flag = 1 |
|
coord = [] |
|
symbols = [] |
|
elif flag in (3, 4, 5, 6): |
|
s = line.split() |
|
components_num = int(s[1]) |
|
symbols.append(components[components_num - 1]) |
|
coord.append([float(s[2]), float(s[3]), float(s[4])]) |
|
flag += 1 |
|
if flag == 7: |
|
flag = 0 |
|
with open_file(fn_2) as f: |
|
flag = 0 |
|
for line in f: |
|
if line.startswith("Total Forces"): |
|
flag = 8 |
|
forces = [] |
|
elif flag in (8, 9, 10, 11): |
|
s = line.split() |
|
forces.append([float(s[1]), float(s[2]), float(s[3])]) |
|
flag += 1 |
|
if flag == 12: |
|
flag = 0 |
Current tests only cover ammonia, which has four atoms:
|
self.system_1 = dpdata.LabeledSystem( |
|
("dftbplus/dftb_pin.hsd", "dftbplus/detailed.out"), fmt="dftbplus" |
|
) |
|
|
|
self.system_2 = dpdata.LabeledSystem( |
|
data={ |
|
"atom_types": np.array([0, 1, 1, 1]), |
|
"atom_names": ["N", "H"], |
|
"atom_numbs": [1, 3], |
|
"coords": np.array( |
|
[ |
|
[ |
|
[1.014150, 0.112320, 0.047370], |
|
[3.909390, 0.037985, -0.101159], |
|
[0.702550, -0.851820, -0.060860], |
|
[0.702550, 0.603740, -0.789160], |
|
] |
|
] |
|
), |
|
"energies": np.array([-3.2963983884]) * energy_convert, |
|
"forces": np.array( |
|
[ |
|
[ |
|
[0.016567056203, 0.002817951422, 0.005634574270], |
|
[-0.018803818530, -0.000002880649, -0.000006015442], |
|
[0.001118562874, -0.005291070259, -0.000870711110], |
|
[0.001118199454, 0.002475999486, -0.004757847718], |
|
] |
|
] |
|
) |
|
* force_convert, |
Why this is a bug:
- A 5-atom or larger DFTB+ input can only contribute the first four coordinate rows.
- A 5-atom or larger DFTB+ output can only contribute the first four force rows.
- The parser then returns truncated arrays or trips the coordinate/force shape assertion instead of reading all atoms.
The parser should determine the number of geometry/force rows from the file content instead of using fixed flag values for a 4-atom fixture.
This issue is part of a Codex global repository code scan.
The DFTB+ parser only reads coordinate rows while
flag in (3, 4, 5, 6)and force rows whileflag in (8, 9, 10, 11). That limits parsing to four atoms regardless of the actual system size.Affected code:
dpdata/dpdata/formats/dftbplus/output.py
Lines 41 to 60 in a7a50bf
dpdata/dpdata/formats/dftbplus/output.py
Lines 61 to 72 in a7a50bf
Current tests only cover ammonia, which has four atoms:
dpdata/tests/test_dftbplus.py
Lines 17 to 47 in a7a50bf
Why this is a bug:
The parser should determine the number of geometry/force rows from the file content instead of using fixed flag values for a 4-atom fixture.