Skip to content

Commit

Permalink
Merge branch 'materialsproject:master' into clean-up-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 authored Feb 24, 2024
2 parents c68d5c3 + 40afffb commit 1fff2d4
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 131 deletions.
61 changes: 35 additions & 26 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 Expand Up @@ -142,14 +152,14 @@ class BandStructure:
lattice_rec (Lattice): The reciprocal lattice of the band structure.
efermi (float): The Fermi energy.
is_spin_polarized (bool): True if the band structure is spin-polarized.
bands (dict): The energy eigenvalues as a {spin: ndarray}. Note that the use of an
ndarray is necessary for computational as well as memory efficiency due to the large
amount of numerical data. The indices of the ndarray are [band_index, kpoint_index].
bands (dict): The energy eigenvalues as a {spin: array}. Note that the use of an
array is necessary for computational as well as memory efficiency due to the large
amount of numerical data. The indices of the array are [band_index, kpoint_index].
nb_bands (int): Returns the number of bands in the band structure.
structure (Structure): Returns the structure.
projections (dict): The projections as a {spin: ndarray}. Note that the use of an
ndarray is necessary for computational as well as memory efficiency due to the large
amount of numerical data. The indices of the ndarray are [band_index, kpoint_index,
projections (dict): The projections as a {spin: array}. Note that the use of an
array is necessary for computational as well as memory efficiency due to the large
amount of numerical data. The indices of the array are [band_index, kpoint_index,
orbital_index, ion_index].
"""

Expand Down Expand Up @@ -184,8 +194,8 @@ def __init__(
structure: The crystal structure (as a pymatgen Structure object)
associated with the band structure. This is needed if we
provide projections to the band structure
projections: dict of orbital projections as {spin: ndarray}. The
indices of the ndarrayare [band_index, kpoint_index, orbital_index,
projections: dict of orbital projections as {spin: array}. The
indices of the array are [band_index, kpoint_index, orbital_index,
ion_index].If the band structure is not spin polarized, we only
store one data set under Spin.up.
"""
Expand Down Expand Up @@ -363,22 +373,21 @@ def get_cbm(self):
"""Returns data about the CBM.
Returns:
{"band_index","kpoint_index","kpoint","energy"}
- "band_index": A dict with spin keys pointing to a list of the
indices of the band containing the CBM (please note that you
can have several bands sharing the CBM) {Spin.up:[],
Spin.down:[]}
- "kpoint_index": The list of indices in self.kpoints for the
kpoint CBM. Please note that there can be several
kpoint_indices relating to the same kpoint (e.g., Gamma can
occur at different spots in the band structure line plot)
- "kpoint": The kpoint (as a kpoint object)
- "energy": The energy of the CBM
- "projections": The projections along sites and orbitals of the
CBM if any projection data is available (else it is an empty
dictionary). The format is similar to the projections field in
BandStructure: {spin:{'Orbital': [proj]}} where the array
[proj] is ordered according to the sites in structure
dict[str, Any]: with keys band_index, kpoint_index, kpoint, energy.
- "band_index": A dict with spin keys pointing to a list of the
indices of the band containing the CBM (please note that you
can have several bands sharing the CBM) {Spin.up:[], Spin.down:[]}
- "kpoint_index": The list of indices in self.kpoints for the
kpoint CBM. Please note that there can be several
kpoint_indices relating to the same kpoint (e.g., Gamma can
occur at different spots in the band structure line plot)
- "kpoint": The kpoint (as a kpoint object)
- "energy": The energy of the CBM
- "projections": The projections along sites and orbitals of the
CBM if any projection data is available (else it is an empty
dictionary). The format is similar to the projections field in
BandStructure: {spin:{'Orbital': [proj]}} where the array
[proj] is ordered according to the sites in structure
"""
if self.is_metal():
return {
Expand Down Expand Up @@ -710,8 +719,8 @@ def __init__(
structure: The crystal structure (as a pymatgen Structure object)
associated with the band structure. This is needed if we
provide projections to the band structure.
projections: dict of orbital projections as {spin: ndarray}. The
indices of the ndarray are [band_index, kpoint_index, orbital_index,
projections: dict of orbital projections as {spin: array}. The
indices of the array are [band_index, kpoint_index, orbital_index,
ion_index].If the band structure is not spin polarized, we only
store one data set under Spin.up.
"""
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/electronic_structure/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def _Orbitals_SumOrbitals(cls, dictio, sum_morbs):
)
if orb not in all_orbitals:
raise ValueError(f"The invalid name of orbital in 'sum_morbs[{elt}]' is given.")
if orb in individual_orbs and len(set(sum_morbs[elt]) & individual_orbs[orb]) != 0:
if orb in individual_orbs and len(set(sum_morbs[elt]) & set(individual_orbs[orb])) != 0:
raise ValueError(f"The 'sum_morbs[{elt}]' contains orbitals repeated.")
nelems = Counter(sum_morbs[elt]).values()
if sum(nelems) > len(nelems):
Expand Down
Loading

0 comments on commit 1fff2d4

Please sign in to comment.