From 5ae27b132459d17b34f64ac17938aca2ee4ffaaa Mon Sep 17 00:00:00 2001 From: t_oikawa Date: Wed, 10 Jul 2024 22:35:48 +0900 Subject: [PATCH 1/3] add vlines --- band_comp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/band_comp.py b/band_comp.py index 3be32cc..ba52652 100644 --- a/band_comp.py +++ b/band_comp.py @@ -84,7 +84,6 @@ def main(): wannier_band_gnu = "pwscf_band.gnu" pwscf_band = "./band/bands.out.gnu" - x, y = get_band_data(wannier_band) x_qe, y_qe = get_band_data(pwscf_band) @@ -102,7 +101,10 @@ def main(): plt.xlim([0, 1]) y_min = np.min(y-ef) y_max = np.max(y-ef) - plt.ylim([y_min - 0.05*(y_max-y_min), y_max + 0.05*(y_max-y_min)]) + py_min = y_min - 0.05*(y_max-y_min) + py_max = y_max + 0.05*(y_max-y_min) + plt.ylim([py_min, py_max]) + plt.vlines(klabel[0], py_min, py_max, colors='black', linewidth=1.0, zorder=3) plt.savefig("./band/band_compare.png", bbox_inches="tight") plt.savefig("./band/band_compare.eps", bbox_inches="tight") From e42eebbb824698ff2f5faee9f22a921ffb38cf01 Mon Sep 17 00:00:00 2001 From: t_oikawa Date: Wed, 10 Jul 2024 22:36:31 +0900 Subject: [PATCH 2/3] fix k-path --- cif2qewan.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/cif2qewan.py b/cif2qewan.py index 3c610ed..5a5604d 100644 --- a/cif2qewan.py +++ b/cif2qewan.py @@ -208,13 +208,12 @@ def convert2band(self): self.control_str = self.control_str.replace("'nscf'", "'bands'") self.kpoints_str = "K_POINTS {crystal_b}\n" self.kpoints_str += "{}\n".format(len(self.tick_labels) - self.tick_labels.count("")) + j = 0 for i in range(len(self.tick_labels)): - if(i != (len(self.tick_labels)-1) and self.tick_labels[i+1] == ""): - kstr = "{:15.10f} {:15.10f} {:15.10f} {} ! {}\n".format(self.tick_locs[i][0], self.tick_locs[i][1], self.tick_locs[i][2], 0, self.tick_labels[i]) - self.kpoints_str += kstr - elif(self.tick_labels[i] != ""): - kstr = "{:15.10f} {:15.10f} {:15.10f} {} ! {}\n".format(self.tick_locs[i][0], self.tick_locs[i][1], self.tick_locs[i][2], 20, self.tick_labels[i]) + if(self.tick_labels[i] != ""): + kstr = "{:15.10f} {:15.10f} {:15.10f} {:>4d} ! {}\n".format(self.tick_locs[i][0], self.tick_locs[i][1], self.tick_locs[i][2], self.band_nks[j], self.tick_labels[i]) self.kpoints_str += kstr + j += 1 def calc_bands_seekpath(self): try: @@ -229,17 +228,19 @@ def calc_bands_seekpath(self): cell = np.array([self.a1, self.a2, self.a3]) pos = self.atom_pos_list z = [Element(s).Z for s in self.atom_list] - kpath = seekpath.getpaths.get_explicit_k_path([cell, pos, z]) - - new_b = kpath["reciprocal_primitive_lattice"] - m = np.matmul(new_b,cell.T) / (2 * np.pi) - self.kpoints_rel = [ np.matmul(k, m) for k in kpath["explicit_kpoints_rel"] ] + #kpath = seekpath.getpaths.get_explicit_k_path([cell, pos, z]) + kpath = seekpath.getpaths.get_explicit_k_path_orig_cell([cell, pos, z]) + #new_b = kpath["reciprocal_primitive_lattice"] + #m = np.matmul(new_b,cell.T) / (2 * np.pi) + #self.kpoints_rel = [ np.matmul(k, m) for k in kpath["explicit_kpoints_rel"] ] + self.kpoints_rel = kpath["explicit_kpoints_rel"] kpoints_labels = kpath["explicit_kpoints_labels"] + hsp_indices = [] + discon_hsps = [] self.tick_locs = [] self.tick_labels = [] - for i, label in enumerate(kpoints_labels): if(label == ""): continue label = label.replace("GAMMA","G") @@ -247,9 +248,25 @@ def calc_bands_seekpath(self): if(i != 0 and kpoints_labels[i-1] != ""): self.tick_labels.extend(["", label]) self.tick_locs.extend([np.array([0.0, 0.0, 0.0]), self.kpoints_rel[i]]) + discon_hsps.append(i) else: self.tick_labels.append(label) self.tick_locs.append(self.kpoints_rel[i]) + hsp_indices.append(i) + + kdistances = [] + kpoints_abs = kpath["explicit_kpoints_abs"] + for i in range(len(hsp_indices)-1): + s = hsp_indices[i] + e = hsp_indices[i+1] + if e in discon_hsps: + kdistances.append(0) + else: + kdistances.append(np.linalg.norm(kpoints_abs[e] - kpoints_abs[s])) + kdistances = np.array(kdistances) + min_distance = np.min(kdistances[np.nonzero(kdistances)]) + band_nks = [int(10 * d / min_distance) for d in kdistances] + self.band_nks = np.append(band_nks, 10) def write_pwscf_in(self, pwscf_in): with open(pwscf_in, "w") as fp: From efede52d5c19bc6a16db08cc9ae8e702af462951 Mon Sep 17 00:00:00 2001 From: t_oikawa Date: Thu, 11 Jul 2024 11:47:16 +0900 Subject: [PATCH 3/3] add exception handling for seekpath version --- cif2qewan.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cif2qewan.py b/cif2qewan.py index 5a5604d..e6f3b42 100644 --- a/cif2qewan.py +++ b/cif2qewan.py @@ -218,11 +218,14 @@ def convert2band(self): def calc_bands_seekpath(self): try: import seekpath + if seekpath.__version__ < '2.1.0': + raise ImportError except ImportError: - print("Failed to import seek path. Simple kpath is used instead.") + print("Failed to import seekpath (>= 2.1.0). Simple kpath is used instead.") self.tick_labels = ["R", "G", "X", "M", "G"] self.tick_locs = [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.0], [0.0, 0.0, 0.0]] + self.band_nks = np.full(len(self.tick_labels), 20) return cell = np.array([self.a1, self.a2, self.a3])