def get_phonon_band(structure, supercell_matrix, force_constants, band_paths=None, npoints=51, labels=None, save_data=False, save_fig=False): ''' Return the phonon bandstructure Parameters ---------- structure : pymatgen.Structure Unitcell (not supercell) of interest. supercell_matrix : numpy.ndarray 3x3 matrix of the supercell deformation, e.g. [[3, 0, 0], [0, 3, 0], [0, 0, 3]]. force_constants: list force constants band_paths : list, multi dimention Sets of end points of paths, e.g. [[[0, 0, 0], [0.5, 0.5, 0], [0.5, 0.5, 0.5]], [[0.5, 0.25, 0.75], [0, 0, 0]]] If it equals None, it will determine the path automatically by phononpy npoints: int Number of q-points in each path including end points. labels: list of str The label of high symmetry points, if None, it will determine it automatically by phononpy save_data/save_fig: bool Determine if save the data/figure or not ''' volume = structure.volume formula = structure.composition.reduced_formula filename = "{}-phonon-Vol{:.2f}".format(formula, volume) unitcell = get_phonopy_structure(structure) ph_band_obj = Phonopy(unitcell, supercell_matrix) ph_band_obj.set_force_constants(force_constants) if band_paths: qpoints, connections = get_band_qpoints_and_path_connections( band_paths, npoints=npoints) ph_band_obj.run_band_structure(qpoints, path_connections=connections, labels=labels) else: ph_band_obj.auto_band_structure() if save_fig: fig_band = ph_band_obj.plot_band_structure() fig_band.savefig(fname='{}-band.png'.format(filename)) fig_band.close() if save_data: ph_band_obj.write_yaml_band_structure( filename='{}-band.yaml'.format(filename)) return ph_band_obj
def get_phonon(self, phonon, **kwargs): flag_savefig = kwargs.get('savefig', False) flag_savedata = kwargs.get('savedata', False) flag_band = kwargs.get('band', False) flag_dos = kwargs.get('phonon_dos', False) flag_pdos = kwargs.get('phonon_pdos', False) mesh = kwargs.get('mesh', [50, 50, 50]) labels = kwargs.get('labels', None) if 'unitcell' not in phonon: raise FileNotFoundError( 'There is no phonon result. Please run phonon first.') self.head = ['Temperature', 'F_vib', 'CV_vib', 'S_vib'] self.unit = ['K', 'eV', 'eV/K', 'eV/K'] self.data = np.vstack((phonon.pop('temperatures'), phonon.pop('F_vib'), phonon.pop('CV_vib'), phonon.pop('S_vib'))).T filename = '{}-phonon-Vol{:.2f}'.format(self.formula, self.volume) unitcell = get_phonopy_structure(self.structure) supercell_matrix = phonon['supercell_matrix'] force_constants = phonon['force_constants'] ph = Phonopy(unitcell, supercell_matrix) ph.set_force_constants(force_constants) #for band structure if flag_band: if 'path' in kwargs: qpoints, connections = get_band_qpoints_and_path_connections( path, npoints=51) ph.run_band_structure(qpoints, path_connections=connections, labels=labels) else: ph.auto_band_structure() if flag_savefig: fig_band = ph.plot_band_structure() fig_band.savefig(fname='{}-band.png'.format(filename)) fig_band.close() if flag_savedata: ph.write_yaml_band_structure( filename='{}-band.yaml'.format(filename)) #for dos if flag_dos: ph.run_mesh(mesh) ph.run_total_dos() #phonon_dos_tmp = np.vstack((ph._total_dos._frequency_points, ph._total_dos._dos)) #print(phonon_dos_tmp) #print(type(phonon_dos_tmp)) if flag_savefig: fig_dos = ph.plot_total_dos() fig_dos.savefig(fname='{}-dos.png'.format(filename)) fig_dos.close() if flag_savedata: ph.write_total_dos(filename='{}-dos.dat'.format(filename)) #for pdos. if flag_pdos: ph.run_mesh(mesh, with_eigenvectors=True, is_mesh_symmetry=False) ph.run_projected_dos() if flag_savefig: ph.plot_projected_dos().savefig( fname='{}-pdos.png'.format(filename)) if flag_savedata: ph.write_projected_dos(filename='{}-pdos.dat'.format(filename)) phonon.pop('_id') self.parameter = phonon
def MVibrationauto(self, maxx=4500): import os import numpy as np from pymatgen.io.phonopy import get_phonopy_structure import pymatgen as pmg from pymatgen.io.vasp.outputs import Vasprun from pymatgen.io.vasp import Poscar from pymatgen.symmetry.kpath import KPathSeek, KPathBase from phonopy.phonon.band_structure import get_band_qpoints_and_path_connections from phonopy import Phonopy from phonopy.structure.atoms import Atoms as PhonopyAtoms from pymatgen.phonon.plotter import PhononBSPlotter from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine import csv import pandas as pd import matplotlib.pyplot as plt os.chdir(self.dire) print(os.getcwd()) poscar = Poscar.from_file("POSCAR") structure = poscar.structure scell = [[2, 0, 0], [0, 2, 0], [0, 0, 2]] vrun = Vasprun("vasprun.xml") phonopyAtoms = get_phonopy_structure(structure) phonon = Phonopy(phonopyAtoms, scell) phonon.set_force_constants(-vrun.force_constants) # labels = ["$\\Gamma$", "X", "U", "K", "L"] labels = ['K', "$\\Gamma$", 'L', 'W', 'X'] # bands = [] cd = KPathSeek(structure) cds = cd.kpath # print(cds) for k, v in cds.items(): if "kpoints" in k: dics = v else: dicss = v print(dics) print(dicss) # bands=[] # for k,v in dics.items(): # if k in dicss[0]: # bands.append(v) path = [] # # bandd1=[] # for k,v in dics.items(): # for i in dicss[0]: # if k in i: # bandd1.append(v) # path.append(bandd1) bandd1 = [] for i in dicss[1]: for k, v in dics.items(): if k in i: bandd1.append(v) path.append(bandd1) print(dicss[1]) qpoints, connections = get_band_qpoints_and_path_connections( path, npoints=51) phonon.run_band_structure(qpoints, path_connections=connections, labels=labels) print(path) # kpoints=cd.get_kpoints # print(kpoints) # phonon.set_band_structure(bands,labels=labels) phonon.plot_band_structure().show() phonon.plot_band_structure().savefig("BAND.png", bbox_inches='tight', transparent=True, dpi=300, format='png') # phonon.write_band_structure() mesh = [31, 31, 31] phonon.set_mesh(mesh) phonon.set_total_DOS() phonon.write_total_DOS() phonon.plot_total_DOS().show() phonon.plot_total_DOS().savefig("DOS.png") # c = np.fromfile('total_dos.dat', dtype=float) datContent = [ i.strip().split() for i in open("./total_dos.dat").readlines() ] del datContent[0] x_ax = [] y_ax = [] for i in datContent: x_ax.append(1 / ((3 * (10**8) / (float(i[0]) * (10**12))) * 100)) y_ax.append(float(i[1])) da = {'Density of states': x_ax, 'Frequency': y_ax} df = pd.DataFrame(da) #构造原始数据文件 df.to_excel("Wave number.xlsx") #生成Excel文件,并存到指定文件路径下 fig, ax = plt.subplots() line1 = ax.plot(x_ax, y_ax, c='grey') ax.set_xlim([maxx, 0]) # 以下是XRD图片的格式设置 #设置横纵坐标的名称以及对应字体格式 font2 = { 'family': 'Times New Roman', 'weight': 'bold', } plt.xlabel('Wavenumber ($\mathregular{cm^-}$$\mathregular{^1}$)', font2) plt.ylabel('Density of states', font2) #不显示Y轴的刻度 plt.yticks([]) #设置图例对应格式和字体 font1 = { 'family': 'Times New Roman', 'weight': 'bold', } # ax.legend(edgecolor='none', prop=font1) # plt.legend(edgecolor='none', prop=font1) # plt.set_facecolor('none') ax.set_facecolor('none') #存储为 fig.savefig('FTIR.png', bbox_inches='tight', transparent=True, dpi=300, format='png') #指定分辨率,边界紧,背景透明 plt.show()
# freq, eigvec = phonon.get_frequencies_with_eigenvectors([0.00000333,0.00000333,0.]) # freq, eigvec = phonon.get_frequencies_with_eigenvectors([0.,0.000001,0.]) freq, eigvec = phonon.get_frequencies_with_eigenvectors(G) eigvec = eigvec.T np.savez('freqNeigvec', freq=freq, eigvec=eigvec) ########## Plot ################ from subprocess import call #### Band plot if run_mode == 'phonon': # N_q = 100 bands = ssp.make_band(path, N_q) phonon.run_band_structure( bands, with_eigenvectors=True, ) phonon.run_total_dos() # eu1 = eigvec[3] # eu2 = eigvec[4] yaml_name = 'gnuplot_phonon.yaml' phonon.write_yaml_band_structure(filename=yaml_name) call([ 'phonopy-bandplot --gnuplot ' + yaml_name + ' > band-' + calc + '.in' ], shell=True) ssp.plot_band_and_dos( phonon, labels=labels,