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

Convert kpts in Kpoints to Sequence[tuple] and set it as property #3758

Merged
merged 42 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9dda81d
convert some types
DanielYang59 Apr 14, 2024
e31939e
Merge branch 'materialsproject:master' into kpoints-tuple-type
DanielYang59 Apr 14, 2024
42ac77b
make real tuple
DanielYang59 Apr 14, 2024
f8f43a2
remove unnecessary `int` before `math.floor/ceil`
DanielYang59 Apr 14, 2024
9d5d67a
Revert remove unnecessary int to avoid diff pollute
DanielYang59 Apr 14, 2024
511488a
fix some tests
DanielYang59 Apr 14, 2024
2ea2980
fix more tests
DanielYang59 Apr 14, 2024
53afb05
relocate type Vector3D Matrix3D SitePropsType
DanielYang59 Apr 15, 2024
04567b6
Merge branch master into kpoints-tuple-type
DanielYang59 Apr 15, 2024
7fad598
fix some Kpoint types
DanielYang59 Apr 15, 2024
cd0222a
Merge branch 'master' into kpoints-tuple-type
DanielYang59 Apr 20, 2024
4de7605
Merge branch 'master' into kpoints-tuple-type
DanielYang59 Apr 21, 2024
6dedfcb
Merge branch 'master' into kpoints-tuple-type
DanielYang59 Apr 23, 2024
3a1f290
fix some type
DanielYang59 Apr 28, 2024
530c3ac
relocate dunder methods to the head
DanielYang59 Apr 28, 2024
d60294a
fix some type errors
DanielYang59 Apr 28, 2024
3b7d545
revert unneeded cast to tuple
DanielYang59 Apr 28, 2024
8a31dfd
pre-commit auto-fixes
pre-commit-ci[bot] Apr 28, 2024
7778f12
revert unneeded cast to tuple
DanielYang59 Apr 28, 2024
219bf74
Merge branch 'master' into kpoints-tuple-type
DanielYang59 Apr 28, 2024
6a40a27
Merge branch 'kpoints-tuple-type' of github.com:DanielYang59/pymatgen…
DanielYang59 Apr 28, 2024
b728a21
revert unneeded cast to tuple
DanielYang59 Apr 28, 2024
a9e2ca2
pre-commit auto-fixes
pre-commit-ci[bot] Apr 28, 2024
986d0ec
use Union over |
DanielYang59 Apr 28, 2024
ee955ea
Merge branch 'kpoints-tuple-type' of github.com:DanielYang59/pymatgen…
DanielYang59 Apr 28, 2024
c412015
remove unnecessary wrapping
DanielYang59 Apr 28, 2024
7777047
fix some types
DanielYang59 Apr 28, 2024
c36e103
fix direct float str to int conversion
DanielYang59 Apr 28, 2024
3f88ae8
use float for Kpoint
DanielYang59 Apr 28, 2024
f9bbd1d
fix type
DanielYang59 Apr 28, 2024
b5c7918
increase msg verbosity
DanielYang59 Apr 28, 2024
b35a7f6
fix types
DanielYang59 Apr 28, 2024
b4ee6df
remove debug print
DanielYang59 Apr 28, 2024
ce91651
add missing types
DanielYang59 Apr 28, 2024
83b7eba
handle nparray
DanielYang59 Apr 28, 2024
b275971
fix/suppress mypy error
DanielYang59 Apr 28, 2024
9d7b883
change kpt weight to float in doc
DanielYang59 Apr 28, 2024
26404d1
add type for typealias
DanielYang59 Apr 28, 2024
118076a
fix typealias import
DanielYang59 Apr 28, 2024
9cc2cb8
remove type annotation for types
DanielYang59 Apr 28, 2024
596d256
add unit test for property kpts
DanielYang59 Apr 28, 2024
879530c
Merge branch 'master' into kpoints-tuple-type
DanielYang59 Apr 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pymatgen/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
from numpy.typing import ArrayLike
from typing_extensions import Self

from pymatgen.core.trajectory import Vector3D
from pymatgen.util.typing import CompositionLike
from pymatgen.util.typing import CompositionLike, Vector3D

# This module implements representations of grain boundaries, as well as
# algorithms for generating them.
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/core/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from numpy.typing import ArrayLike
from typing_extensions import Self

from pymatgen.core.trajectory import Vector3D
from pymatgen.util.typing import PbcLike
from pymatgen.util.typing import PbcLike, Vector3D

__author__ = "Shyue Ping Ong, Michael Kocher"
__copyright__ = "Copyright 2011, The Materials Project"
Expand Down
11 changes: 5 additions & 6 deletions pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import itertools
import warnings
from collections.abc import Iterator, Sequence
from fnmatch import fnmatch
from pathlib import Path
from typing import TYPE_CHECKING, Any, Union
from typing import TYPE_CHECKING

import numpy as np
from monty.io import zopen
Expand All @@ -20,17 +19,17 @@
from pymatgen.io.vasp.outputs import Vasprun, Xdatcar

if TYPE_CHECKING:
from collections.abc import Iterator

from typing_extensions import Self

from pymatgen.util.typing import Matrix3D, SitePropsType, Vector3D


__author__ = "Eric Sivonxay, Shyam Dwaraknath, Mingjian Wen, Evan Spotte-Smith"
__version__ = "0.1"
__date__ = "Jun 29, 2022"

Vector3D = tuple[float, float, float]
Matrix3D = tuple[Vector3D, Vector3D, Vector3D]
SitePropsType = Union[list[dict[Any, Sequence[Any]]], dict[Any, Sequence[Any]]]


class Trajectory(MSONable):
"""Trajectory of a geometry optimization or molecular dynamics simulation.
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/aims/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from collections.abc import Sequence
from pathlib import Path

from emmet.core.math import Matrix3D, Vector3D
from typing_extensions import Self

from pymatgen.core import Molecule, Structure
from pymatgen.util.typing import Matrix3D, Vector3D

__author__ = "Andrey Sobolev and Thomas A. R. Purcell"
__version__ = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/io/aims/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gzip
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, cast

import numpy as np

Expand All @@ -16,7 +16,7 @@
from collections.abc import Generator, Sequence
from io import TextIOWrapper

from emmet.core.math import Matrix3D, Vector3D
from pymatgen.util.typing import Matrix3D, Vector3D

__author__ = "Thomas A. R. Purcell and Andrey Sobolev"
__version__ = "1.0"
Expand Down Expand Up @@ -566,9 +566,9 @@ def _parse_lattice_atom_pos(
elif "atom " in line:
line_split = line.split()
species.append(line_split[4])
coords.append([float(inp) for inp in line_split[1:4]])
coords.append(cast(tuple[float, float, float], tuple(float(inp) for inp in line_split[1:4])))
elif "velocity " in line:
velocities.append([float(inp) for inp in line.split()[1:]])
velocities.append(cast(tuple[float, float, float], tuple(float(inp) for inp in line.split()[1:4])))

lattice = Lattice(lattice_vectors) if len(lattice_vectors) == 3 else None
return species, coords, velocities, lattice
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
if TYPE_CHECKING:
from typing_extensions import Self

from pymatgen.core.trajectory import Vector3D
from pymatgen.util.typing import Vector3D

__author__ = "Shyue Ping Ong, Will Richards, Matthew Horton"

Expand Down
28 changes: 18 additions & 10 deletions pymatgen/io/cp2k/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

from pymatgen.core.lattice import Lattice
from pymatgen.core.structure import Molecule, Structure
from pymatgen.util.typing import Kpoint

__author__ = "Nicholas Winner"
__version__ = "2.0"
Expand Down Expand Up @@ -2031,37 +2032,44 @@ def from_kpoints(cls, kpoints: VaspKpoints, structure=None) -> Self:
weights = kpoints.kpts_weights

if kpoints.style == KpointsSupportedModes.Monkhorst:
k = kpts[0]
x, y, z = (k, k, k) if isinstance(k, (int, float)) else k
kpt: Kpoint = kpts[0] # type: ignore[assignment]
x, y, z = (kpt, kpt, kpt) if isinstance(kpt, (int, float)) else kpt # type: ignore[misc]
scheme = f"MONKHORST-PACK {x} {y} {z}"
units = "B_VECTOR"

elif kpoints.style == KpointsSupportedModes.Reciprocal:
units = "B_VECTOR"
scheme = "GENERAL"

elif kpoints.style == KpointsSupportedModes.Cartesian:
units = "CART_ANGSTROM"
scheme = "GENERAL"

elif kpoints.style == KpointsSupportedModes.Gamma:
if not structure:
raise ValueError(
"No cp2k automatic gamma constructor. A structure is required to construct from spglib"
)

if (isinstance(kpts[0], Iterable) and tuple(kpts[0]) == (1, 1, 1)) or (
isinstance(kpts[0], (float, int)) and int(kpts[0]) == 1
):
scheme = "GAMMA"
units = "B_VECTOR"
elif not structure:
raise ValueError(
"No cp2k automatic gamma constructor. A structure is required to construct from spglib"
)
else:
sga = SpacegroupAnalyzer(structure)
_kpts, weights = zip(*sga.get_ir_reciprocal_mesh(mesh=kpts))
kpts = list(itertools.chain.from_iterable(_kpts))
_kpts, weights = zip(*sga.get_ir_reciprocal_mesh(mesh=kpts)) # type: ignore[assignment]
kpts = tuple(itertools.chain.from_iterable(_kpts))
scheme = "GENERAL"
units = "B_VECTOR"

units = "B_VECTOR"

DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
elif kpoints.style == KpointsSupportedModes.Line_mode:
scheme = "GENERAL"
units = "B_VECTOR"

else:
raise ValueError("Unrecognized k-point style")

return Kpoints(kpts=kpts, weights=weights, scheme=scheme, units=units)


Expand Down
8 changes: 3 additions & 5 deletions pymatgen/io/lobster/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from pymatgen.util.due import Doi, due

if TYPE_CHECKING:
from collections.abc import Sequence

from typing_extensions import Self

from pymatgen.core.composition import Composition
Expand Down Expand Up @@ -431,7 +429,7 @@ def write_KPOINTS(
reciprocal_density: int = 100,
isym: int = -1,
from_grid: bool = False,
input_grid: Sequence[int] = (5, 5, 5),
input_grid: tuple[int, int, int] = (5, 5, 5),
line_mode: bool = True,
kpoints_line_density: int = 20,
symprec: float = 0.01,
Expand All @@ -446,7 +444,7 @@ def write_KPOINTS(
isym (int): either -1 or 0. Current Lobster versions only allow -1.
from_grid (bool): If True KPOINTS will be generated with the help of a grid given in input_grid.
Otherwise, they will be generated from the reciprocal_density
input_grid (list): grid to generate the KPOINTS file
input_grid (tuple): grid to generate the KPOINTS file
line_mode (bool): If True, band structure will be generated
kpoints_line_density (int): density of the lines in the band structure
symprec (float): precision to determine symmetry
Expand Down Expand Up @@ -543,7 +541,7 @@ def write_KPOINTS(
comment=comment,
style=Kpoints.supported_modes.Reciprocal,
num_kpts=len(kpts),
kpts=kpts,
kpts=tuple(kpts),
kpts_weights=weights,
labels=all_labels,
)
Expand Down
7 changes: 4 additions & 3 deletions pymatgen/io/lobster/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,10 @@ def __init__(
self.p_eigenvals = p_eigenvals

label_dict = {}
for idx, label in enumerate(kpoints_object.labels[-self.number_kpts :], start=0):
if label is not None:
label_dict[label] = kpoints_array[idx]
if kpoints_object.labels is not None:
for idx, label in enumerate(kpoints_object.labels[-self.number_kpts :], start=0):
if label is not None:
label_dict[label] = kpoints_array[idx]

self.label_dict = label_dict

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/res.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from typing_extensions import Self

from pymatgen.core.trajectory import Vector3D
from pymatgen.util.typing import Vector3D


@dataclass(frozen=True)
Expand Down
Loading