-
Notifications
You must be signed in to change notification settings - Fork 135
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
improve: ase try to get virials from different sources #660
base: devel
Are you sure you want to change the base?
Changes from 1 commit
aa8d22e
42e31bf
2867039
451bd0d
774fb7d
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -93,13 +93,21 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
"energies": np.array([energies]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
"forces": np.array([forces]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||
stress = atoms.get_stress(False) | ||||||||||||||||||||||||||||||||||||||||||||||||||
except PropertyNotImplementedError: | ||||||||||||||||||||||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||
virials = np.array([-atoms.get_volume() * stress]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
# try to get virials from different sources | ||||||||||||||||||||||||||||||||||||||||||||||||||
virials = atoms.info.get("virial") | ||||||||||||||||||||||||||||||||||||||||||||||||||
if virials is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
virials = atoms.info.get("virials") | ||||||||||||||||||||||||||||||||||||||||||||||||||
if virials is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||||||||
stress = atoms.get_stress(False) | ||||||||||||||||||||||||||||||||||||||||||||||||||
except PropertyNotImplementedError: | ||||||||||||||||||||||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+109
to
+110
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. Handle - except PropertyNotImplementedError:
- pass
+ except PropertyNotImplementedError as e:
+ logging.warning(f"Failed to compute stress due to: {str(e)}") Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||
virials = np.array([-atoms.get_volume() * stress]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if virials is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+102
to
+113
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. Consider handling the The current implementation passes silently if - except PropertyNotImplementedError:
- pass
+ except PropertyNotImplementedError as e:
+ logging.warning(f"Failed to compute stress due to: {str(e)}") Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
info_dict["virials"] = virials | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return info_dict | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
def from_multi_systems( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
It's unclear why it has two different keys.
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.
It's a fallback strategy as users may use either
virial
orvirials
.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.
Documentation is necessary if users are expected to do something
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.
I try to search in the code base but find no place to add comment for this.
I don't think we need add extra documents for this as
dpdata
is supposed to be able to findvirial
for user automatically. My patch doesn't introduce any compatibility issue, it just make the ase plugin more robust to findvirial
.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.
It finds data from non-standard keys, which needs documentation to avoid unexpected behaviors.
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.
I just add a comment in docstring.
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.
It's not rendered correctly.