|
4 | 4 | from dpdata.cp2k.output import Cp2kSystems
|
5 | 5 | from dpdata.format import Format
|
6 | 6 |
|
| 7 | +string_warning = """ |
| 8 | +Hi, you got an error from dpdata, |
| 9 | +please check if your cp2k files include full information, |
| 10 | +otherwise its version is not supported by dpdata. |
| 11 | +Try use dpdata plugin from cp2kdata package, |
| 12 | +for details, please refer to |
| 13 | +https://robinzyb.github.io/cp2kdata/ |
| 14 | +""" |
| 15 | + |
7 | 16 |
|
8 | 17 | @Format.register("cp2k/aimd_output")
|
9 | 18 | class CP2KAIMDOutputFormat(Format):
|
10 | 19 | def from_labeled_system(self, file_name, restart=False, **kwargs):
|
11 | 20 | xyz_file = sorted(glob.glob(f"{file_name}/*pos*.xyz"))[0]
|
12 | 21 | log_file = sorted(glob.glob(f"{file_name}/*.log"))[0]
|
13 |
| - return tuple(Cp2kSystems(log_file, xyz_file, restart)) |
| 22 | + try: |
| 23 | + return tuple(Cp2kSystems(log_file, xyz_file, restart)) |
| 24 | + except (StopIteration, RuntimeError) as e: |
| 25 | + # StopIteration is raised when pattern match is failed |
| 26 | + raise PendingDeprecationWarning(string_warning) from e |
14 | 27 |
|
15 | 28 |
|
16 | 29 | @Format.register("cp2k/output")
|
17 | 30 | class CP2KOutputFormat(Format):
|
18 | 31 | def from_labeled_system(self, file_name, restart=False, **kwargs):
|
19 |
| - data = {} |
20 |
| - ( |
21 |
| - data["atom_names"], |
22 |
| - data["atom_numbs"], |
23 |
| - data["atom_types"], |
24 |
| - data["cells"], |
25 |
| - data["coords"], |
26 |
| - data["energies"], |
27 |
| - data["forces"], |
28 |
| - tmp_virial, |
29 |
| - ) = dpdata.cp2k.output.get_frames(file_name) |
30 |
| - if tmp_virial is not None: |
31 |
| - data["virials"] = tmp_virial |
32 |
| - return data |
| 32 | + try: |
| 33 | + data = {} |
| 34 | + ( |
| 35 | + data["atom_names"], |
| 36 | + data["atom_numbs"], |
| 37 | + data["atom_types"], |
| 38 | + data["cells"], |
| 39 | + data["coords"], |
| 40 | + data["energies"], |
| 41 | + data["forces"], |
| 42 | + tmp_virial, |
| 43 | + ) = dpdata.cp2k.output.get_frames(file_name) |
| 44 | + if tmp_virial is not None: |
| 45 | + data["virials"] = tmp_virial |
| 46 | + return data |
| 47 | + # TODO: in the future, we should add exact error type here |
| 48 | + # TODO: when pattern match is failed |
| 49 | + # TODO: For now just use RuntimeError as a placeholder. |
| 50 | + except RuntimeError as e: |
| 51 | + raise PendingDeprecationWarning(string_warning) from e |
0 commit comments