Skip to content

Commit

Permalink
add decrecaption warning when dpdata throws errors while parsing cp2k (
Browse files Browse the repository at this point in the history
…deepmodeling#558)

Squashed commit of the following:

commit dfb6191
Merge: 1b55e6c 5028af6
Author: Yongbin Zhuang <[email protected]>
Date:   Mon Oct 30 22:02:15 2023 +0100

    add decrecaption warning when dpdata throws errors while parsing cp2k (deepmodeling#558)

commit 5028af6
Author: robinzyb <[email protected]>
Date:   Mon Oct 30 21:28:21 2023 +0100

    raise PendingDeprecationWarning

commit 3ee373d
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Oct 30 19:51:57 2023 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit cec3fc2
Author: robinzyb <[email protected]>
Date:   Mon Oct 30 20:51:26 2023 +0100

    add exact except for the cp2k plugin.

commit 7a09854
Author: robinzyb <[email protected]>
Date:   Mon Oct 30 20:38:23 2023 +0100

    fixed typo in checking cp2k pattern match.

commit 1a4b985
Author: robinzyb <[email protected]>
Date:   Mon Oct 30 14:34:50 2023 +0100

    update error for cp2k aimdoutput if none pattern is matched

commit a1a171a
Merge: 621d686 1b55e6c
Author: Yongbin Zhuang <[email protected]>
Date:   Mon Oct 30 13:59:10 2023 +0100

    Merge branch 'deepmodeling:devel' into devel

commit 621d686
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Fri Oct 20 22:53:54 2023 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit 03cc010
Author: robinzyb <[email protected]>
Date:   Sat Oct 21 00:50:51 2023 +0200

    add decrecaption warning when dpdata throws errors while parsing cp2k

commit 0576449
Merge: 4840bbc dbe2bc9
Author: Yongbin Zhuang <[email protected]>
Date:   Sat Oct 21 00:30:18 2023 +0200

    Merge branch 'deepmodeling:devel' into devel

commit 4840bbc
Author: robinzyb <[email protected]>
Date:   Thu Sep 7 14:12:19 2023 +0200

    Update README.md for recommendation of using cp2kdata
  • Loading branch information
robinzyb authored and njzjz committed Oct 30, 2023
1 parent 1b55e6c commit 7fb45d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
8 changes: 8 additions & 0 deletions dpdata/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ def __next__(self):
def get_log_block_generator(self):
lines = []
delimiter_flag = False
yield_flag = False
while True:
line = self.log_file_object.readline()
if line:
lines.append(line)
if any(p.match(line) for p in delimiter_patterns):
if delimiter_flag is True:
yield_flag = True
yield lines
lines = []
delimiter_flag = False
Expand All @@ -91,17 +93,23 @@ def get_log_block_generator(self):
if any(p.match(line) for p in avail_patterns):
delimiter_flag = True
else:
if not yield_flag:
raise StopIteration("None of the delimiter patterns are matched")
break
if delimiter_flag is True:
raise RuntimeError("This file lacks some content, please check")

def get_xyz_block_generator(self):
p3 = re.compile(r"^\s*(\d+)\s*")
yield_flag = False
while True:
line = self.xyz_file_object.readline()
if not line:
if not yield_flag:
raise StopIteration("None of the xyz patterns are matched")
break
if p3.match(line):
yield_flag = True
atom_num = int(p3.match(line).group(1))
lines = []
lines.append(line)
Expand Down
49 changes: 34 additions & 15 deletions dpdata/plugins/cp2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,48 @@
from dpdata.cp2k.output import Cp2kSystems
from dpdata.format import Format

string_warning = """
Hi, you got an error from dpdata,
please check if your cp2k files include full information,
otherwise its version is not supported by dpdata.
Try use dpdata plugin from cp2kdata package,
for details, please refer to
https://robinzyb.github.io/cp2kdata/
"""


@Format.register("cp2k/aimd_output")
class CP2KAIMDOutputFormat(Format):
def from_labeled_system(self, file_name, restart=False, **kwargs):
xyz_file = sorted(glob.glob(f"{file_name}/*pos*.xyz"))[0]
log_file = sorted(glob.glob(f"{file_name}/*.log"))[0]
return tuple(Cp2kSystems(log_file, xyz_file, restart))
try:
return tuple(Cp2kSystems(log_file, xyz_file, restart))
except (StopIteration, RuntimeError) as e:
# StopIteration is raised when pattern match is failed
raise PendingDeprecationWarning(string_warning) from e


@Format.register("cp2k/output")
class CP2KOutputFormat(Format):
def from_labeled_system(self, file_name, restart=False, **kwargs):
data = {}
(
data["atom_names"],
data["atom_numbs"],
data["atom_types"],
data["cells"],
data["coords"],
data["energies"],
data["forces"],
tmp_virial,
) = dpdata.cp2k.output.get_frames(file_name)
if tmp_virial is not None:
data["virials"] = tmp_virial
return data
try:
data = {}
(
data["atom_names"],
data["atom_numbs"],
data["atom_types"],
data["cells"],
data["coords"],
data["energies"],
data["forces"],
tmp_virial,
) = dpdata.cp2k.output.get_frames(file_name)
if tmp_virial is not None:
data["virials"] = tmp_virial
return data
# TODO: in the future, we should add exact error type here
# TODO: when pattern match is failed
# TODO: For now just use RuntimeError as a placeholder.
except RuntimeError as e:
raise PendingDeprecationWarning(string_warning) from e

0 comments on commit 7fb45d8

Please sign in to comment.