-
Notifications
You must be signed in to change notification settings - Fork 1
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
Recreate structure fresh during get_primitive_cell #144
base: main
Are you sure you want to change the base?
Conversation
This avoids a problem, when you pass standardize=True and the resulting cell would be larger than the original.
I mark this pull request as draft until the tests pass. |
I made tests pass by passing |
The trouble is that when spglib returns the symmetrized cell, it may permute, add or remove atoms so that we cannot tell anymore which values from the original arrays we would need to copy or remove.
# Conflicts: # structuretoolkit/analyse/symmetry.py
for more information, see https://pre-commit.ci
WalkthroughThe recent changes to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
structuretoolkit/analyse/symmetry.py (1)
388-390
: Add a period at the end of the warning message.The warning message should end with a period for consistency.
- Custom arrays defined in the base structures - :attr:`ase.atoms.Atoms.arrays` are not copied to the new structure! + Custom arrays defined in the base structures + :attr:`ase.atoms.Atoms.arrays` are not copied to the new structure!.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- structuretoolkit/analyse/symmetry.py (1 hunks)
- tests/test_symmetry.py (2 hunks)
Additional context used
Ruff
structuretoolkit/analyse/symmetry.py
421-421: Undefined name
warning
(F821)
Additional comments not posted (3)
tests/test_symmetry.py (2)
176-178
: LGTM! The addition ofpbc=True
is correct.The change ensures that the structure is treated as periodic, which is necessary for the
get_primitive_cell
function to work correctly.
204-204
: LGTM! The addition ofpbc=True
is correct.The change ensures that the structure is treated as periodic, which is necessary for the
get_primitive_cell
function to work correctly.structuretoolkit/analyse/symmetry.py (1)
392-393
: Good check for periodic structures.The check ensures that the function only operates on periodic structures, which is necessary for symmetrization.
symbols = [indices_dict[i] for i in indices] | ||
arrays = { | ||
k: self._structure.arrays[k] | ||
for k in self._structure.arrays | ||
if k not in ("numbers", "positions") | ||
} | ||
new_structure = type(self._structure)( | ||
symbols=symbols, | ||
scaled_positions=scaled_positions, | ||
cell=cell, | ||
pbc=[True, True, True], | ||
) | ||
keys = set(arrays) - {"numbers", "positions"} | ||
if len(keys) > 0: | ||
warning(f"Custom arrays {keys} do not carry over to new structure!") |
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.
Fix the undefined name warning
.
The warning
function is not defined. Use the warnings.warn
function instead.
- if len(keys) > 0:
- warning(f"Custom arrays {keys} do not carry over to new structure!")
+ if len(keys) > 0:
+ import warnings
+ warnings.warn(f"Custom arrays {keys} do not carry over to new structure!")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
symbols = [indices_dict[i] for i in indices] | |
arrays = { | |
k: self._structure.arrays[k] | |
for k in self._structure.arrays | |
if k not in ("numbers", "positions") | |
} | |
new_structure = type(self._structure)( | |
symbols=symbols, | |
scaled_positions=scaled_positions, | |
cell=cell, | |
pbc=[True, True, True], | |
) | |
keys = set(arrays) - {"numbers", "positions"} | |
if len(keys) > 0: | |
warning(f"Custom arrays {keys} do not carry over to new structure!") | |
symbols = [indices_dict[i] for i in indices] | |
arrays = { | |
k: self._structure.arrays[k] | |
for k in self._structure.arrays | |
if k not in ("numbers", "positions") | |
} | |
new_structure = type(self._structure)( | |
symbols=symbols, | |
scaled_positions=scaled_positions, | |
cell=cell, | |
pbc=[True, True, True], | |
) | |
keys = set(arrays) - {"numbers", "positions"} | |
if len(keys) > 0: | |
import warnings | |
warnings.warn(f"Custom arrays {keys} do not carry over to new structure!") |
Tools
Ruff
421-421: Undefined name
warning
(F821)
This avoids a problem, when you pass standardize=True and the resulting cell would be larger than the original.
Summary by CodeRabbit
New Features
Bug Fixes
Tests