From da9918e0dd1995246ec85cd7ab40872c1fbf9070 Mon Sep 17 00:00:00 2001 From: YuLiu98 Date: Tue, 18 Jul 2023 10:16:24 +0800 Subject: [PATCH 1/3] Fix: bug in reading abacus md files --- dpdata/abacus/md.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 7726cafeb..92f4ecb4e 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -44,12 +44,17 @@ def get_coords_from_dump(dumplines, natoms): nlines = len(dumplines) total_natoms = sum(natoms) calc_stress = False + calc_force = False + check_line = 6 if "VIRIAL" in dumplines[6]: calc_stress = True - else: - assert ( - "POSITIONS" in dumplines[6] and "FORCE" in dumplines[6] - ), "keywords 'POSITIONS' and 'FORCE' cannot be found in the 6th line. Please check." + check_line = 10 + assert ( + "POSITION" in dumplines[check_line] + ), "keywords 'POSITION' cannot be found in the 6th line. Please check." + if "FORCE" in dumplines[check_line]: + calc_force = True + nframes_dump = -1 if calc_stress: nframes_dump = int(nlines / (total_natoms + 13)) @@ -104,9 +109,10 @@ def get_coords_from_dump(dumplines, natoms): if not newversion: coords[iframe, iat] *= celldm - forces[iframe, iat] = np.array( - [float(i) for i in dumplines[iline + skipline + iat].split()[5:8]] - ) + if calc_force: + forces[iframe, iat] = np.array( + [float(i) for i in dumplines[iline + skipline + iat].split()[5:8]] + ) iframe += 1 assert iframe == nframes_dump, ( "iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump." From 7e1e40fc11269abdbd772e08dd11d0f51a5fbb24 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jul 2023 02:20:45 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/abacus/md.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 92f4ecb4e..ca5d688ce 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -111,7 +111,10 @@ def get_coords_from_dump(dumplines, natoms): if calc_force: forces[iframe, iat] = np.array( - [float(i) for i in dumplines[iline + skipline + iat].split()[5:8]] + [ + float(i) + for i in dumplines[iline + skipline + iat].split()[5:8] + ] ) iframe += 1 assert iframe == nframes_dump, ( From 630a79970abd8b4ba366bf8b3759caa6f3d6dcd4 Mon Sep 17 00:00:00 2001 From: YuLiu98 Date: Tue, 18 Jul 2023 10:42:47 +0800 Subject: [PATCH 3/3] add annotations for reading abacus MD_dump --- dpdata/abacus/md.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 92f4ecb4e..b410af4b0 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -43,6 +43,8 @@ def get_coord_dump_freq(inlines): def get_coords_from_dump(dumplines, natoms): nlines = len(dumplines) total_natoms = sum(natoms) + # The output of VIRIAL, FORCE, and VELOCITY are controlled by INPUT parameters dump_virial, dump_force, and dump_vel, respectively. + # So the search of keywords can determine whether these datas are printed into MD_dump. calc_stress = False calc_force = False check_line = 6