From dd098074432e0f0f0892f3249002e700172b71c7 Mon Sep 17 00:00:00 2001 From: Dale Gaines Date: Tue, 26 Nov 2024 22:57:16 -0600 Subject: [PATCH 1/3] Avoid connecting phonon bands at discontinuous q-points For some crystal symmetries, conventions specify a q-path that is discontinuous in the Brillouin zone. E.g. BCC (Spacegroup #229) q-paths have X|R (SeekPath) or H|P (pymatgen) The current plotting joins phonon bands across this discontinuity, although it is mostly only visible if the linewdith of the band is thicker than the linewidth of the vlines at these q-points. These discontinuities can be found by checking for two adjacent x values in the q-path that have the same value. You can then fix this issue by splitting the x and frequency arrays across each discontinuity and making separate ax.plot calls. --- tp/plot/phonons.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tp/plot/phonons.py b/tp/plot/phonons.py index 4033a5f..316d383 100644 --- a/tp/plot/phonons.py +++ b/tp/plot/phonons.py @@ -186,9 +186,17 @@ def add_dispersion(ax, data, sdata=None, bandmin=None, bandmax=None, main=True, # plotting + # avoid connecting bands at disconnected q-points + split_indices = [0, *np.where(np.diff(x) == 0)[0] + 1, len(x)] for n in range(len(f[0])): - ax.plot(x, f[:,n], color=colour[n], linestyle=linestyle[n], - marker=marker[n], label=label[n], **kwargs) + for i in range(len(split_indices)-1): + starting_index = split_indices[i] + ending_index = split_indices[i+1] + x_i = x[starting_index:ending_index] + f_ni = f[starting_index:ending_index, n] + label_ni = label[n] if i == 0 else None + ax.plot(x_i, f_ni, color=colour[n], linestyle=linestyle[n], + label=label_ni, marker=marker[n], **kwargs) # axes formatting From 93bc6555782e73ca6413d06d8bc4ffb742b89963 Mon Sep 17 00:00:00 2001 From: Dale Gaines Date: Tue, 26 Nov 2024 23:34:41 -0600 Subject: [PATCH 2/3] Update add_alt_dispersion for discontinuous q-points --- tp/plot/phonons.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tp/plot/phonons.py b/tp/plot/phonons.py index 316d383..a98ce8d 100644 --- a/tp/plot/phonons.py +++ b/tp/plot/phonons.py @@ -585,13 +585,21 @@ def add_alt_dispersion(ax, data, pdata, quantity, bandmin=None, bandmax=None, # plotting + # avoid connecting bands at disconnected q-points + split_indices = [0, *np.where(np.diff(x2) == 0)[0] + 1, len(x2)] for n in range(len(y2[0])): if scatter: ax.scatter(x2, y2[:,n], color=colour[n], linestyle=linestyle[n], label=label[n], marker=marker[n], **kwargs) else: - ax.plot(x2, y2[:,n], color=colour[n], linestyle=linestyle[n], - label=label[n], marker=marker[n], **kwargs) + for i in range(len(split_indices)-1): + starting_index = split_indices[i] + ending_index = split_indices[i+1] + x2_i = x2[starting_index:ending_index] + y2_ni = y2[starting_index:ending_index, n] + label_ni = label[n] if i == 0 else None + ax.plot(x2_i, y2_ni, color=colour[n], linestyle=linestyle[n], + label=label_ni, marker=marker[n], **kwargs) # axes formatting From 0b5b3571cb6273c2dd2ecf318637538501af1a58 Mon Sep 17 00:00:00 2001 From: "Kieran B. Spooner" Date: Fri, 20 Dec 2024 11:18:29 +0000 Subject: [PATCH 3/3] CLI phonons colour options Made changing of individual phonon mode colours at the command line possible to make it consistent with the python interface. --- tp/cli/cli.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tp/cli/cli.py b/tp/cli/cli.py index 898e00b..8570145 100644 --- a/tp/cli/cli.py +++ b/tp/cli/cli.py @@ -1595,11 +1595,23 @@ def converge_phonons(band_yaml, bandmin, bandmax, colour, alpha, linestyle, dosax = ax[1] ax = ax[0] - tp.plot.phonons.add_multi(ax, data, colour=colour, linestyle=linestyle, - marker=marker, label=label, bandmin=bandmin, - bandmax=bandmax, alpha=alpha, - xmarkkwargs={'color': xmarkcolour, - 'linestyle': xmarklinestyle}) + if len(band_yaml) == 1: + try: + colour = mpl.cm.get_cmap(colour)([0]) + except ValueError: + pass + tp.plot.phonons.add_dispersion(ax, data[0], colour=colour, + linestyle=linestyle[0], marker=marker[0], + label=label, bandmin=bandmin, + bandmax=bandmax, alpha=alpha, + xmarkkwargs={'color': xmarkcolour, + 'linestyle': xmarklinestyle}) + else: + tp.plot.phonons.add_multi(ax, data, colour=colour, linestyle=linestyle, + marker=marker, label=label, bandmin=bandmin, + bandmax=bandmax, alpha=alpha, + xmarkkwargs={'color': xmarkcolour, + 'linestyle': xmarklinestyle}) if dos is not None: dosdata = tp.data.load.phonopy_dos(dos, poscar, atoms) tp.plot.frequency.add_dos(dosax, dosdata, projected=projected,