Skip to content
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 min "thickness" check in CifParser to filter invalid structure which leads to infinite loop #4133

Merged

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 25, 2024

Summary

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Oct 25, 2024

@anyangml I hope this looks good to you, with this patch your example would terminate gracefully:

/Users/yang/developer/pymatgen/src/pymatgen/io/cif.py:1318: UserWarning: No structure parsed for section 1 in CIF.
lattice.volume=2.2009330203855426e-06 ų below threshold, double check your structure.
  warnings.warn(msg)
/Users/yang/developer/pymatgen/src/pymatgen/io/cif.py:1322: UserWarning: Issues encountered while parsing CIF: No structure parsed for section 1 in CIF.
lattice.volume=2.2009330203855426e-06 ų below threshold, double check your structure.
  warnings.warn("Issues encountered while parsing CIF: " + "\n".join(self.warnings))
Traceback (most recent call last):
  File "/Users/yang/developer/pymatgen/debug/recreate_cif.py", line 15, in <module>
    read_file("./example.cif")
  File "/Users/yang/developer/pymatgen/debug/recreate_cif.py", line 6, in read_file
    structure = cif.parse_structures(primitive=True)[0]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yang/developer/pymatgen/src/pymatgen/io/cif.py", line 1325, in parse_structures
    raise ValueError("Invalid CIF file with no structures!")
ValueError: Invalid CIF file with no structures!

@DanielYang59
Copy link
Contributor Author

@anyangml May I have your permission to include your cif file as a test file for pymatgen for such cases?

src/pymatgen/io/cif.py Outdated Show resolved Hide resolved
src/pymatgen/io/cif.py Outdated Show resolved Hide resolved
@anyangml
Copy link

@anyangml May I have your permission to include your cif file as a test file for pymatgen for such cases?

yes!

@DanielYang59
Copy link
Contributor Author

Cool thanks!

@DanielYang59 DanielYang59 marked this pull request as ready for review October 25, 2024 13:18
@DanielYang59 DanielYang59 marked this pull request as draft October 25, 2024 15:29
@DanielYang59 DanielYang59 changed the title Add min volume check in CifParser to filter invalid structure which leads to infinite loop Add min "thickness" check in CifParser to filter invalid structure which leads to infinite loop Oct 26, 2024
@DanielYang59 DanielYang59 marked this pull request as ready for review October 26, 2024 13:13
@@ -969,8 +969,22 @@ def _get_structure(
primitive: bool,
symmetrized: bool,
check_occu: bool = False,
min_thickness: float = 0.01,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this default minimal "thickness" of 0.01 Å would be a good default value (it's already "lower than it should be", but I just want to prevent false positive), is there any case that we might expect valid structure below this threshold?

@shyuep shyuep merged commit 65f52ea into materialsproject:master Nov 13, 2024
43 checks passed
@DanielYang59 DanielYang59 deleted the 4028-cif-parser-check-lattice branch November 14, 2024 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CifParser taking forever without throwing an error
3 participants