From 0166c97de566be76fa0464c24a4f50ab534f1cdf Mon Sep 17 00:00:00 2001 From: "weihong.xu" Date: Mon, 4 Sep 2023 15:52:51 +0800 Subject: [PATCH 1/6] fix cp2k 2023 output --- dpdata/cp2k/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index f7b94f25..361f40fd 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -409,7 +409,7 @@ def get_frames(fname): cell.append(ii.split()[4:7]) if "Atomic kind:" in ii: atom_symbol_list.append(ii.split()[3]) - if "Atom Kind Element" in ii: + if "Atom Kind Element" in ii or "Atom Kind Element" in ii: coord_flag = True coord_idx = idx From a083f17e3879bf46624b84b800fba4e9c9cf3409 Mon Sep 17 00:00:00 2001 From: "weihong.xu" Date: Mon, 4 Sep 2023 16:21:19 +0800 Subject: [PATCH 2/6] adapt cp2k 2023 format --- dpdata/cp2k/output.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index 361f40fd..2799651d 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -409,13 +409,16 @@ def get_frames(fname): cell.append(ii.split()[4:7]) if "Atomic kind:" in ii: atom_symbol_list.append(ii.split()[3]) - if "Atom Kind Element" in ii or "Atom Kind Element" in ii: + if "Atom Kind Element" in ii: + coord_flag = True + coord_idx = idx + 1 + if "Atom Kind Element" in ii: # cp2k 2023 format coord_flag = True coord_idx = idx # get the coord block info if coord_flag: - if idx > coord_idx + 1: + if idx > coord_idx: if ii == "\n": coord_flag = False else: From b1d834b09a9bce2bc2f8d12677974816486a8414 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:22:50 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/cp2k/output.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index e8f4bf37..3ae73503 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -409,9 +409,9 @@ def get_frames(fname): cell.append(ii.split()[4:7]) if "Atomic kind:" in ii: atom_symbol_list.append(ii.split()[3]) - - # parse coords - if "Atom Kind Element" in ii: # ver. < 2023 + + # parse coords + if "Atom Kind Element" in ii: # ver. < 2023 coord_flag = True coord_idx = idx + 1 # skip empty line elif "Atom Kind Element" in ii: # ver. >= 2023 @@ -424,7 +424,7 @@ def get_frames(fname): else: coord.append(ii.split()[4:7]) atom_symbol_idx_list.append(ii.split()[1]) - + if "ENERGY|" in ii: energy = ii.split()[8] if " Atom Kind " in ii: From edaa946f97928deb750b662c51961f73e4f3becc Mon Sep 17 00:00:00 2001 From: link89 Date: Tue, 5 Sep 2023 00:42:31 +0800 Subject: [PATCH 4/6] cp2k output: handle empty line properly Signed-off-by: link89 --- dpdata/cp2k/output.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index 3ae73503..364593d5 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -410,17 +410,14 @@ def get_frames(fname): if "Atomic kind:" in ii: atom_symbol_list.append(ii.split()[3]) - # parse coords - if "Atom Kind Element" in ii: # ver. < 2023 + # start to parse coords block + if "Atom Kind Element" in ii or "Atom Kind Element" in ii: coord_flag = True - coord_idx = idx + 1 # skip empty line - elif "Atom Kind Element" in ii: # ver. >= 2023 - coord_flag = True - coord_idx = idx - # get the coord block info + coord_idx = idx # save start line of coord block + # parse coords lines if coord_flag and idx > coord_idx: if ii == "\n": - coord_flag = False + coord_flag = len(coord) == 0 # skip empty line at the beginning else: coord.append(ii.split()[4:7]) atom_symbol_idx_list.append(ii.split()[1]) From 3b3d7202ea723f515ece6ce133103f3323572dc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:42:46 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/cp2k/output.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index 364593d5..135dd194 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -411,10 +411,10 @@ def get_frames(fname): atom_symbol_list.append(ii.split()[3]) # start to parse coords block - if "Atom Kind Element" in ii or "Atom Kind Element" in ii: + if "Atom Kind Element" in ii or "Atom Kind Element" in ii: coord_flag = True - coord_idx = idx # save start line of coord block - # parse coords lines + coord_idx = idx # save start line of coord block + # parse coords lines if coord_flag and idx > coord_idx: if ii == "\n": coord_flag = len(coord) == 0 # skip empty line at the beginning From ed22ca69de922b6ae48b4d5631cf9e1fd5ce7d74 Mon Sep 17 00:00:00 2001 From: link89 Date: Tue, 5 Sep 2023 00:49:58 +0800 Subject: [PATCH 6/6] cp2k output: remove unnecessary state Signed-off-by: link89 --- dpdata/cp2k/output.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index 135dd194..0b08c51e 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -410,12 +410,11 @@ def get_frames(fname): if "Atomic kind:" in ii: atom_symbol_list.append(ii.split()[3]) - # start to parse coords block + # beginning of coords block if "Atom Kind Element" in ii or "Atom Kind Element" in ii: coord_flag = True - coord_idx = idx # save start line of coord block # parse coords lines - if coord_flag and idx > coord_idx: + elif coord_flag: if ii == "\n": coord_flag = len(coord) == 0 # skip empty line at the beginning else: