def test_plot_dis(): spp = kpath.SpecialPointsPath(ks=np.array([[0,0,0], [.5,0,0], [.7,0,0]]), ks_frac=np.array([[0,0,0], [.55,0,0], [.77,0,0]]), symbols=['A','B', 'C']) path_norm = np.linspace(0,1,100) nfreq = 5 freqs = np.random.rand(100, nfreq) try: print os.environ['DISPLAY'] fig1,ax1,axdos1 = kpath.plot_dis(path_norm, freqs, spp, show_coords='cart') assert axdos1 is None fig2,ax2 = mpl.fig_ax() kpath.plot_dis(path_norm, freqs, spp, ax=ax2, show_coords='frac') lines1 = ax1.get_lines() lines2 = ax2.get_lines() for idx in range(nfreq): x1 = lines1[idx].get_xdata() x2 = lines2[idx].get_xdata() y1 = lines1[idx].get_ydata() y2 = lines2[idx].get_ydata() assert (x1 == x2).all() assert (y1 == y2).all() faxis = np.linspace(freqs.min(), freqs.max(), 30) dos = np.array([faxis, np.random.rand(len(faxis))]).T fig3,ax3,ax3dos = kpath.plot_dis(path_norm, freqs, spp, dos=dos, show_coords=None) # plot 90 rotated -> x and y swapped assert (ax3dos.get_lines()[0].get_xdata() == dos[:,1]).all() assert (ax3dos.get_lines()[0].get_ydata() == dos[:,0]).all() except KeyError: tools.skip("no DISPLAY environment variable, skipping test")
def test_plot_dis(): spp = kpath.SpecialPointsPath(ks=np.array([[0, 0, 0], [.5, 0, 0], [.7, 0, 0]]), ks_frac=np.array([[0, 0, 0], [.55, 0, 0], [.77, 0, 0]]), symbols=['A', 'B', 'C']) path_norm = np.linspace(0, 1, 100) nfreq = 5 freqs = np.random.rand(100, nfreq) try: print(os.environ['DISPLAY']) fig1, ax1, axdos1 = kpath.plot_dis(path_norm, freqs, spp, show_coords='cart') assert axdos1 is None fig2, ax2 = mpl.fig_ax() kpath.plot_dis(path_norm, freqs, spp, ax=ax2, show_coords='frac') lines1 = ax1.get_lines() lines2 = ax2.get_lines() for idx in range(nfreq): x1 = lines1[idx].get_xdata() x2 = lines2[idx].get_xdata() y1 = lines1[idx].get_ydata() y2 = lines2[idx].get_ydata() assert (x1 == x2).all() assert (y1 == y2).all() faxis = np.linspace(freqs.min(), freqs.max(), 30) dos = np.array([faxis, np.random.rand(len(faxis))]).T fig3, ax3, ax3dos = kpath.plot_dis(path_norm, freqs, spp, dos=dos, show_coords=None) # plot 90 rotated -> x and y swapped assert (ax3dos.get_lines()[0].get_xdata() == dos[:, 1]).all() assert (ax3dos.get_lines()[0].get_ydata() == dos[:, 0]).all() except KeyError: tools.skip("no DISPLAY environment variable, skipping test")
rules, conv=True, mode='txt') common.file_write(matdyn_in_fn, txt) common.system("gunzip q2r.fc.gz; matdyn.x < %s; gzip q2r.fc" %matdyn_in_fn) # parse matdyn output and plot # define special points path, used in plot_dis() to plot lines at special # points and make x-labels sp = kpath.SpecialPointsPath(ks=sp_points, ks_frac=sp_points_frac, symbols=sp_symbols) # QE 4.x, 5.x ks, freqs = pwscf.read_matdyn_freq(matdyn_freq_fn) fig,ax = kpath.plot_dis(kpath.get_path_norm(ks_path), freqs, sp, marker='', ls='-', color='k') # QE 5.x ##d = np.loadtxt(matdyn_freq_fn + '.gp') ##fig,ax = kpath.plot_dis(d[:,0], d[:,1:], sp, marker='', ls='-', color='k') # if needed #ax.set_ylim(...) #mpl.plt.show() mpl.plt.savefig('1.pdf') # Band jumps at Gamma # ------------------- # Either use many points in kpath() or split sp_points in two sets: sp_points_1 # = something--Gamma and sp_points_2=Gamma--something_else. Do the whole
common.file_write(matdyn_in_fn, txt) common.system("gunzip q2r.fc.gz; matdyn.x < %s; gzip q2r.fc" % matdyn_in_fn) # parse matdyn output and plot # define special points path, used in plot_dis() to plot lines at special # points and make x-labels sp = kpath.SpecialPointsPath(ks=sp_points, ks_frac=sp_points_frac, symbols=sp_symbols) # QE 4.x, 5.x ks, freqs = pwscf.read_matdyn_freq(matdyn_freq_fn) fig, ax = kpath.plot_dis(kpath.get_path_norm(ks_path), freqs, sp, marker='', ls='-', color='k') # QE 5.x ##d = np.loadtxt(matdyn_freq_fn + '.gp') ##fig,ax = kpath.plot_dis(d[:,0], d[:,1:], sp, marker='', ls='-', color='k') # if needed #ax.set_ylim(...) #mpl.plt.show() mpl.plt.savefig('1.pdf') # Band jumps at Gamma # -------------------
ks_frac=sp_points_frac, symbols=sp_symbols) # QE 4.x, 5.x # ks is the coordinates of kpoints and the freqs is the frequencies for each band ks, freqs = pwscf.read_matdyn_freq(matdyn_freq_fn) print(type(sp)) print(dir(sp)) print(sp.path_norm) ylim = (-10, 1000) #print(dir(sp_points)) fig, ax, t = kpath.plot_dis(kpath.get_path_norm(ks_path), freqs, sp, marker='', ls='-', color='blue', ylim=ylim) #t after 'ax,' was added by ywfang nrm = sp.path_norm print('nrm is', nrm) print(type(nrm)) ax.vlines(nrm, ylim[0], ylim[1], color='k', linestyle='--') ax.hlines(y=0, xmin=nrm[0], xmax=nrm[-1], color='red') ax.set_ylim(list(ylim)) # QE 5.x ##d = np.loadtxt(matdyn_freq_fn + '.gp') ##fig,ax = kpath.plot_dis(d[:,0], d[:,1:], sp, marker='', ls='-', color='k') # if needed #ax.set_ylim(...)