-
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 all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -62,6 +62,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
"""Convert ase.Atoms to a LabeledSystem. Energies and forces | ||||||||||||||||||||||||||||||||||||||||||||||||||
are calculated by the calculator. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Note that this method will try to load virials from the following sources: | ||||||||||||||||||||||||||||||||||||||||||||||||||
- atoms.info['virial'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
- atoms.info['virials'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
- converted from stress tensor | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+65
to
+68
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. It's not correctly rendered. All three items in the list are shown in one line. @coderabbitai Fix it. 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. @njzjz, I've adjusted the docstring to ensure the list items are rendered correctly. Here's the corrected version: def from_labeled_system(self, atoms: ase.Atoms, **kwargs) -> dict:
"""Convert ase.Atoms to a LabeledSystem. Energies and forces
are calculated by the calculator.
Note that this method will try to load virials from the following sources:
- atoms.info['virial']
- atoms.info['virials']
- converted from stress tensor
Parameters
----------
atoms : ase.Atoms
an ASE Atoms, containing a structure
**kwargs : dict
other parameters
Returns
-------
dict
data dict
Raises
------
RuntimeError
ASE will raise RuntimeError if the atoms does not
have a calculator
""" This should ensure that the list is displayed correctly in any markdown-rendering context. Please let me know if there are any more adjustments needed! 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. Yes, a blank line needs to be added. 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. @njzjz, I've added the requested blank line to the docstring. Here's the updated version: def from_labeled_system(self, atoms: ase.Atoms, **kwargs) -> dict:
"""Convert ase.Atoms to a LabeledSystem. Energies and forces
are calculated by the calculator.
Note that this method will try to load virials from the following sources:
- atoms.info['virial']
- atoms.info['virials']
- converted from stress tensor
Parameters
----------
atoms : ase.Atoms
an ASE Atoms, containing a structure
**kwargs : dict
other parameters
Returns
-------
dict
data dict
Raises
------
RuntimeError
ASE will raise RuntimeError if the atoms does not
have a calculator
""" This should ensure that the list is displayed correctly in any markdown-rendering context. Please let me know if this looks good or if any further adjustments are needed! |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||
---------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
atoms : ase.Atoms | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -93,13 +98,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") | ||||||||||||||||||||||||||||||||||||||||||||||||||
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. It's unclear why it has two different keys. 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. It's a fallback strategy as users may use either 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. Documentation is necessary if users are expected to do something 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. 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 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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||
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( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -165,7 +178,6 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
structures = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
species = [data["atom_names"][tt] for tt in data["atom_types"]] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
for ii in range(data["coords"].shape[0]): | ||||||||||||||||||||||||||||||||||||||||||||||||||
structure = Atoms( | ||||||||||||||||||||||||||||||||||||||||||||||||||
symbols=species, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
Update the method documentation to reflect the new virial retrieval logic.
Committable suggestion
Ensure the documentation accurately describes all sources for virials.
Committable suggestion