Skip to content

Commit

Permalink
Add Kpoint.__eq__ method
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Feb 23, 2024
1 parent 2231ec5 commit 7c47053
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pymatgen/electronic_structure/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ def __str__(self) -> str:
"""Returns a string with fractional, Cartesian coordinates and label."""
return f"{self.frac_coords} {self.cart_coords} {self.label}"

def __eq__(self, other: object) -> bool:
"""Check if two kpoints are equal."""
if not isinstance(other, Kpoint):
return NotImplemented
return (
np.allclose(self.frac_coords, other.frac_coords)
and self.lattice == other.lattice
and self.label == other.label
)

def as_dict(self) -> dict[str, Any]:
"""JSON-serializable dict representation of a kpoint."""
return {
Expand Down

0 comments on commit 7c47053

Please sign in to comment.