-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add decrecaption warning when dpdata throws errors while parsing cp2k #558
Changes from 9 commits
4840bbc
0576449
03cc010
621d686
a1a171a
1a4b985
7a09854
cec3fc2
3ee373d
5028af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
xyz_file = sorted(glob.glob(f"{file_name}/*pos*.xyz"))[0] | ||
log_file = sorted(glob.glob(f"{file_name}/*.log"))[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines do not need to be inside the |
||
return tuple(Cp2kSystems(log_file, xyz_file, restart)) | ||
except (StopIteration, RuntimeError): | ||
# StopIteration is raised when pattern match is failed | ||
print(string_warning) | ||
|
||
|
||
@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: | ||
print(string_warning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ignores the error and does not exit the program. Is it expected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may be two codes acceptable: except RuntimeError from e:
raise PendingDeprecationWarning(string_warning) from e or except RuntimeError from e:
warnings.warn(string_warning)
raise e There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not exactly. I was trying to find a decent way that raises errors without showing too much trace back. In that case, users are often distracted by the trace back. But |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.