Skip to content

Commit

Permalink
Improve handling of discontinues paths
Browse files Browse the repository at this point in the history
Combine kpoint labels when plotting the unfolded effective band
structure.
  • Loading branch information
zhubonan committed Aug 26, 2024
1 parent 016d0af commit fbb1e1e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion easyunfold/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Collection of code for band unfolding
"""

__version__ = '0.3.6'
__version__ = '0.3.7'
2 changes: 1 addition & 1 deletion easyunfold/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _plot_spectral_function_rgba(
def _add_kpoint_labels(self, ax: plt.Axes, x_is_kidx=False):
"""Add labels to the k-points for a given axes"""
# Label the kpoints
labels = self.unfold.kpoint_labels
labels = self.unfold.get_combined_kpoint_labels()
kdist = self.unfold.get_kpoint_distances()

# Explicit label indices
Expand Down
26 changes: 25 additions & 1 deletion easyunfold/unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,22 +615,46 @@ def as_dict(self) -> dict:
output[key] = getattr(self, key)
return output

def get_kpoint_distances(self):
def get_kpoint_distances(self, hide_discontinuities=True):
"""
Distances between the kpoints along the path in the reciprocal space.
This does not take account of the breaking of the path.
:::{note}
The reciprocal lattice vectors includes the $2\\pi$ factor, e.g. `np.linalg.inv(L).T * 2 * np.pi`.
:::
"""
# Check for
kpts = self.kpts_pc
pc_latt = self.pc_latt
kpts_path = kpts @ np.linalg.inv(pc_latt).T * np.pi * 2 # Kpoint path in the reciprocal space
dists = np.cumsum(np.linalg.norm(np.diff(kpts_path, axis=0), axis=-1))
dists = np.append([0], dists)

if hide_discontinuities:
last_idx = -2
for idx, _ in self.kpoint_labels:
if idx - last_idx == 1:
# This label is directly adjacent to the previous one - this is a discontinuity
shift = dists[idx] - dists[idx - 1]
# Shift the distances beyond
dists[idx:] -= shift
last_idx = idx

return dists

def get_combined_kpoint_labels(self):
"""Get kpoints label with discontinuities combined into a single label"""
last_entry = [-2, None]
comnbined_labels = []
for idx, name in self.kpoint_labels:
if idx - last_entry[0] == 1:
comnbined_labels.append([last_entry[0], last_entry[1] + '|' + name])
else:
comnbined_labels.append([idx, name])
last_entry = [idx, name]

return comnbined_labels


def LorentzSmearing(x, x0, sigma=0.02):
r"""
Expand Down

0 comments on commit fbb1e1e

Please sign in to comment.