Skip to content

Commit a091a59

Browse files
YuLiu98pre-commit-ci[bot]wanghan-iapcm
authored
Fix: bug in reading abacus md files (#496)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com>
1 parent 7bb6392 commit a091a59

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

dpdata/abacus/md.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ def get_coord_dump_freq(inlines):
4343
def get_coords_from_dump(dumplines, natoms):
4444
nlines = len(dumplines)
4545
total_natoms = sum(natoms)
46+
# The output of VIRIAL, FORCE, and VELOCITY are controlled by INPUT parameters dump_virial, dump_force, and dump_vel, respectively.
47+
# So the search of keywords can determine whether these datas are printed into MD_dump.
4648
calc_stress = False
49+
calc_force = False
50+
check_line = 6
4751
if "VIRIAL" in dumplines[6]:
4852
calc_stress = True
49-
else:
50-
assert (
51-
"POSITIONS" in dumplines[6] and "FORCE" in dumplines[6]
52-
), "keywords 'POSITIONS' and 'FORCE' cannot be found in the 6th line. Please check."
53+
check_line = 10
54+
assert (
55+
"POSITION" in dumplines[check_line]
56+
), "keywords 'POSITION' cannot be found in the 6th line. Please check."
57+
if "FORCE" in dumplines[check_line]:
58+
calc_force = True
59+
5360
nframes_dump = -1
5461
if calc_stress:
5562
nframes_dump = int(nlines / (total_natoms + 13))
@@ -104,9 +111,13 @@ def get_coords_from_dump(dumplines, natoms):
104111
if not newversion:
105112
coords[iframe, iat] *= celldm
106113

107-
forces[iframe, iat] = np.array(
108-
[float(i) for i in dumplines[iline + skipline + iat].split()[5:8]]
109-
)
114+
if calc_force:
115+
forces[iframe, iat] = np.array(
116+
[
117+
float(i)
118+
for i in dumplines[iline + skipline + iat].split()[5:8]
119+
]
120+
)
110121
iframe += 1
111122
assert iframe == nframes_dump, (
112123
"iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."

0 commit comments

Comments
 (0)