|
50 | 50 |
|
51 | 51 | from pymatgen.core.lattice import Lattice
|
52 | 52 | from pymatgen.core.structure import Molecule, Structure
|
| 53 | + from pymatgen.util.typing import Kpoint |
53 | 54 |
|
54 | 55 | __author__ = "Nicholas Winner"
|
55 | 56 | __version__ = "2.0"
|
@@ -2031,37 +2032,44 @@ def from_kpoints(cls, kpoints: VaspKpoints, structure=None) -> Self:
|
2031 | 2032 | weights = kpoints.kpts_weights
|
2032 | 2033 |
|
2033 | 2034 | if kpoints.style == KpointsSupportedModes.Monkhorst:
|
2034 |
| - k = kpts[0] |
2035 |
| - x, y, z = (k, k, k) if isinstance(k, (int, float)) else k |
| 2035 | + kpt: Kpoint = kpts[0] # type: ignore[assignment] |
| 2036 | + x, y, z = (kpt, kpt, kpt) if isinstance(kpt, (int, float)) else kpt # type: ignore[misc] |
2036 | 2037 | scheme = f"MONKHORST-PACK {x} {y} {z}"
|
2037 | 2038 | units = "B_VECTOR"
|
| 2039 | + |
2038 | 2040 | elif kpoints.style == KpointsSupportedModes.Reciprocal:
|
2039 | 2041 | units = "B_VECTOR"
|
2040 | 2042 | scheme = "GENERAL"
|
| 2043 | + |
2041 | 2044 | elif kpoints.style == KpointsSupportedModes.Cartesian:
|
2042 | 2045 | units = "CART_ANGSTROM"
|
2043 | 2046 | scheme = "GENERAL"
|
| 2047 | + |
2044 | 2048 | elif kpoints.style == KpointsSupportedModes.Gamma:
|
| 2049 | + if not structure: |
| 2050 | + raise ValueError( |
| 2051 | + "No cp2k automatic gamma constructor. A structure is required to construct from spglib" |
| 2052 | + ) |
| 2053 | + |
2045 | 2054 | if (isinstance(kpts[0], Iterable) and tuple(kpts[0]) == (1, 1, 1)) or (
|
2046 | 2055 | isinstance(kpts[0], (float, int)) and int(kpts[0]) == 1
|
2047 | 2056 | ):
|
2048 | 2057 | scheme = "GAMMA"
|
2049 |
| - units = "B_VECTOR" |
2050 |
| - elif not structure: |
2051 |
| - raise ValueError( |
2052 |
| - "No cp2k automatic gamma constructor. A structure is required to construct from spglib" |
2053 |
| - ) |
2054 | 2058 | else:
|
2055 | 2059 | sga = SpacegroupAnalyzer(structure)
|
2056 |
| - _kpts, weights = zip(*sga.get_ir_reciprocal_mesh(mesh=kpts)) |
2057 |
| - kpts = list(itertools.chain.from_iterable(_kpts)) |
| 2060 | + _kpts, weights = zip(*sga.get_ir_reciprocal_mesh(mesh=kpts)) # type: ignore[assignment] |
| 2061 | + kpts = tuple(itertools.chain.from_iterable(_kpts)) |
2058 | 2062 | scheme = "GENERAL"
|
2059 |
| - units = "B_VECTOR" |
| 2063 | + |
| 2064 | + units = "B_VECTOR" |
| 2065 | + |
2060 | 2066 | elif kpoints.style == KpointsSupportedModes.Line_mode:
|
2061 | 2067 | scheme = "GENERAL"
|
2062 | 2068 | units = "B_VECTOR"
|
| 2069 | + |
2063 | 2070 | else:
|
2064 | 2071 | raise ValueError("Unrecognized k-point style")
|
| 2072 | + |
2065 | 2073 | return Kpoints(kpts=kpts, weights=weights, scheme=scheme, units=units)
|
2066 | 2074 |
|
2067 | 2075 |
|
|
0 commit comments