Skip to content

Fix some Kpoints generated using wrong mesh types#3245

Merged
shyuep merged 6 commits into
materialsproject:masterfrom
matthewkuner:fix_auto_kpoints
Aug 18, 2023
Merged

Fix some Kpoints generated using wrong mesh types#3245
shyuep merged 6 commits into
materialsproject:masterfrom
matthewkuner:fix_auto_kpoints

Conversation

@matthewkuner

Copy link
Copy Markdown
Contributor

Addresses #3220. Also adds a lot of tests to (hopefully) make sure nothing like this happens again.

@matthewkuner

matthewkuner commented Aug 17, 2023

Copy link
Copy Markdown
Contributor Author

@janosh seems like the tests that are failing are unrelated? Not 100% sure. If they are indeed unrelated, this should be ready for merging

…float]]

>       self._space_group_data = _get_symmetry_dataset(self._cell, symprec, angle_tolerance)
@janosh

janosh commented Aug 17, 2023

Copy link
Copy Markdown
Member

Tests were fine on master. Looks like something you changed turned magmons from tuple to list. I pushed a fix.

self._cell
>>> (((...), (...), (...)), ((...),), (1,), ([...],))

if len(magmoms) > 0:
self._cell: tuple[Any, ...] = (
tuple(map(tuple, structure.lattice.matrix.tolist())),
tuple(map(tuple, structure.frac_coords.tolist())),
tuple(zs),
tuple(map(tuple, magmoms)),
)
else: # if no magmoms given do not add to cell
self._cell = (
tuple(map(tuple, structure.lattice.matrix.tolist())),
tuple(map(tuple, structure.frac_coords.tolist())),
tuple(zs),
)
self._space_group_data = _get_symmetry_dataset(self._cell, symprec, angle_tolerance)

@matthewkuner

matthewkuner commented Aug 17, 2023

Copy link
Copy Markdown
Contributor Author

@janosh This could possibly be discovering some other issue with the magmoms, because I don't think a single line from my new code has anything to do with magmoms? ¯_(ツ)_/¯ unsure

         if len(magmoms) > 0:
            self._cell: tuple[Any, ...] = (
                tuple(map(tuple, structure.lattice.matrix.tolist())),
                tuple(map(tuple, structure.frac_coords.tolist())),
                tuple(zs),
>               tuple(map(tuple, magmoms)),
            )
@janosh

janosh commented Aug 17, 2023

Copy link
Copy Markdown
Member

Not sure either why this is surfacing now. I think this is good to go except for one thing. Do we need to add 3 new POSCAR files? How about you pick some of 31 that we already have:

from collections import defaultdict
from glob import glob

from pymatgen.io.vasp.inputs import Poscar
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.util.testing import TEST_FILES_DIR

# glob all POSCARs in test files dir and count their crystal types
crys_sys_counts = defaultdict(int)
test_potcars = [*glob(f"{TEST_FILES_DIR}/*POSCAR*"), *glob(f"{TEST_FILES_DIR}/**/*POSCAR*")]
print(f"{len(test_potcars)=}")

for filepath in test_potcars:
    try:
        poscar = Poscar.from_file(filepath)
        crys_sys = SpacegroupAnalyzer(poscar.structure).get_crystal_system()
        crys_sys_counts[crys_sys] += 1
    except Exception:
        pass

crys_sys_counts = {'cubic': 15, 'trigonal': 3, 'hexagonal': 3, 'monoclinic': 3, 'orthorhombic': 2, 'triclinic': 2}

@janosh janosh changed the title [FIX] Fix major bug where some Kpoints are generated using wrong mesh types Fix some Kpoints generated using wrong mesh types Aug 17, 2023
@codecov-commenter

codecov-commenter commented Aug 18, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.08%. Comparing base (ccc1831) to head (2bf1d96).
⚠️ Report is 1565 commits behind head on master.

Files with missing lines Patch % Lines
pymatgen/analysis/chemenv/utils/scripts_utils.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3245      +/-   ##
==========================================
- Coverage   74.65%   74.08%   -0.57%     
==========================================
  Files         230      230              
  Lines       69384    69386       +2     
  Branches    16154    16155       +1     
==========================================
- Hits        51799    51408     -391     
- Misses      14513    14941     +428     
+ Partials     3072     3037      -35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shyuep shyuep merged commit b33bced into materialsproject:master Aug 18, 2023
@matthewkuner matthewkuner deleted the fix_auto_kpoints branch October 12, 2023 18:19
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.

4 participants