-
Notifications
You must be signed in to change notification settings - Fork 875
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
Fix bug in feff inputs.py #3256
Conversation
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #3256 +/- ##
==========================================
- Coverage 74.69% 74.12% -0.57%
==========================================
Files 230 230
Lines 69375 69374 -1
Branches 16154 16154
==========================================
- Hits 51818 51423 -395
- Misses 14490 14918 +428
+ Partials 3067 3033 -34
☔ View full report in Codecov by Sentry. |
This reverts commit 8112068.
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.
Thanks for the fix @kaifengZheng! Do we need a new CIF file? Maybe some of the existing ones could be used instead?
tests/io/feff/test_sets.py
Outdated
def test_cluster_index(self): | ||
cif_file = f"{TEST_FILES_DIR}/Fe3O4.cif" | ||
structure = CifParser(cif_file).get_structures()[0] | ||
for i in range(len(structure.species)): | ||
if structure.species[i] == Element("O"): | ||
assert Atoms(structure, i, 3).cluster |
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 don't see how this test is related to your change in pymatgen/io/feff/inputs.py
. The past passes with or without your change.
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.
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.
Try running the actual test with the old code
pytest tests/io/feff/test_sets.py
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.
This error happens when the absorbing atom index exceeds the number of atoms in the created cluster. Thus for any structure with many absorbers(same type of atom). We want to use the program to create a small particle surrounding the absorber, which has a big index. The program will fail.
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.
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.
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.
By the way, to show the error, we need the Oxygen block behind the Fe:
If the order is reversed, I think we need to change the absorber atom to Fe to fulfill this test:
def test_cluster_index(self):
cif_file = f"{TEST_FILES_DIR}/Fe3O4.cif"
structure = CifParser(cif_file).get_structures()[0]
for i in range(len(structure.species)):
if structure.species[i] == Element("Fe"):
assert Atoms(structure, i, 3).cluster
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.
Please try this time. I removed choosing Element part.
…checks initialize PymatgenTest.TEST_STRUCTURES as dict[Path, None]
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
Signed-off-by: KaifengZheng <[email protected]>
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.
Thanks for the new test. Just confirmed that it covers the fix. 👍
Thanks for the merge @janosh! |
Summary
I found a small bug inside the feff.inputs module. The absorbing_atom index is misused in the following sentence, which generated a bug.
When I created a cluster using
inputs.Atoms
,there is an error, sinceabsorbing_atom
in the argument is the index of the absorbing atom in the original structure, but the above sentence misused this index for the absorbing atom in the generated cluster, which should be 0. If we create a particle that has fewer atoms than the assigned index of the absorbing atom in the original structure, it can generate an IndexError.For example:
the original structure has 55 U atoms and assigns a U atom with index 54 as the absorber, but we generate a particle that only has 30 atoms, so the index is mismatched and will prompt the following error.
I resubmitted this PR, since the previous one shows too many conflicts.
Major changes:
Firstly, I changed this
absorbing_atom
argument to 0. However, after scrutinizing the codes, I found that this sentence was redundant, so I deleted it.test_set.py
with a test functionTodos
If this is work in progress, what else needs to be done?
Checklist
ruff
.mypy
.duecredit
@due.dcite
decorators to reference relevant papers by DOI (example)Tip: Install
pre-commit
hooks to auto-check types and linting before every commit: