def phonon_dos(fcp_file): if 'fcc2x2x2' in fcp_file: prim = read(ref_fcc_conv2x2x2) else: prim = read(ref_fcc) fcp = ForceConstantPotential.read(fcp_file) mesh = [33, 33, 33] atoms_phonopy = PhonopyAtoms(symbols=prim.get_chemical_symbols(), scaled_positions=prim.get_scaled_positions(), cell=prim.cell) phonopy = Phonopy(atoms_phonopy, supercell_matrix=5 * np.eye(3), primitive_matrix=None) supercell = phonopy.get_supercell() supercell = Atoms(cell=supercell.cell, numbers=supercell.numbers, pbc=True, scaled_positions=supercell.get_scaled_positions()) fcs = fcp.get_force_constants(supercell) phonopy.set_force_constants(fcs.get_fc_array(order=2)) phonopy.set_mesh(mesh, is_eigenvectors=True, is_mesh_symmetry=False) phonopy.run_total_dos() phonopy.plot_total_DOS() plt.savefig("phononDOS.png", dpi=200) Nq = 51 G2X = get_band(np.array([0, 0, 0]), np.array([0.5, 0.5, 0]), Nq) X2K2G = get_band(np.array([0.5, 0.5, 1.0]), np.array([0, 0, 0]), Nq) G2L = get_band(np.array([0, 0, 0]), np.array([0.5, 0.5, 0.5]), Nq) bands = [G2X, X2K2G, G2L] phonopy.set_band_structure(bands) phonopy.plot_band_structure() xticks = plt.gca().get_xticks() xticks = [x * hbar * 1e15 for x in xticks] # Convert THz to meV # plt.gca().set_xticks(xticks) plt.gca().set_xlabel("Frequency (THz)") plt.savefig("phononBand.png", dpi=200) phonopy.run_thermal_properties(t_step=10, t_max=800, t_min=100) tp_dict = phonopy.get_thermal_properties_dict() temperatures = tp_dict['temperatures'] free_energy = tp_dict['free_energy'] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(temperatures, free_energy) plt.show()
# Integration with phonopy from phonolammps import Phonolammps from phonopy import Phonopy phlammps = Phonolammps('in.lammps', supercell_matrix=[[3, 0, 0], [0, 3, 0], [0, 0, 3]]) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() phonon = Phonopy(unitcell, supercell_matrix) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) phonon.set_total_DOS() phonon.plot_total_DOS().show() phonon.set_thermal_properties() phonon.plot_thermal_properties().show()
q_points, distances, frequencies, eigvecs = phonon.get_band_structure() for q, d, freq in zip(q_points, distances, frequencies): print q, d, freq phonon.plot_band_structure().show() # Mesh sampling 20x20x20 phonon.set_mesh([20, 20, 20]) phonon.set_thermal_properties(t_step=10, t_max=1000, t_min=0) # DOS phonon.set_total_DOS(sigma=0.1) for omega, dos in np.array(phonon.get_total_DOS()).T: print "%15.7f%15.7f" % (omega, dos) phonon.plot_total_DOS().show() # Thermal properties for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T: print ("%12.3f " + "%15.7f" * 3) % ( t, free_energy, entropy, cv ) phonon.plot_thermal_properties().show() # PDOS phonon.set_mesh([10, 10, 10], is_mesh_symmetry=False, is_eigenvectors=True) phonon.set_partial_DOS(tetrahedron_method=True) omegas, pdos = phonon.get_partial_DOS() pdos_indices = [[0], [1]] phonon.plot_partial_DOS(pdos_indices=pdos_indices, legend=pdos_indices).show()
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()
def Vibration(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 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 = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] 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", "$\\Gamma$", "L", "W"] bands = [] # path 1 q_start = np.array([0.0, 0.0, 0.0]) q_end = np.array([0.5, 0.0, 0.0]) band = [] for i in range(51): band.append(q_start + (q_end - q_start) / 50 * i) bands.append(band) # path 2 q_start = np.array([0.5, 0.0, 0.0]) q_end = np.array([0.5, 0.5, 0.0]) band = [] for i in range(51): band.append(q_start + (q_end - q_start) / 50 * i) bands.append(band) # # path 3 # q_start = np.array([0.5, 0.5, 0.0]) # q_end = np.array([-0.0, -0.0, 0.0]) # band = [] # for i in range(51): # band.append(q_start + (q_end - q_start) / 50 * i) # bands.append(band) # # path 4 # q_start = np.array([0.0, 0.0, 0.0]) # q_end = np.array([0.5, 0.5, 0.5]) # band = [] # for i in range(51): # band.append(q_start + (q_end - q_start) / 50 * i) # bands.append(band) print(bands) phonon.set_band_structure(bands) phonon.plot_band_structure().show() phonon.plot_band_structure().savefig("BAND.png") 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()
def test_phonolammps(): os.chdir('data') with open('data.si', 'w') as f: f.write('''Generated using dynaphopy 8 atoms 1 atom types 0.0000000000 5.4500000000 xlo xhi 0.0000000000 5.4500000000 ylo yhi 0.0000000000 5.4500000000 zlo zhi 0.0000000000 0.0000000000 0.0000000000 xy xz yz Masses 1 28.0855000000 Atoms 1 1 4.7687500000 4.7687500000 4.7687500000 2 1 4.7687500000 2.0437500000 2.0437500000 3 1 2.0437500000 4.7687500000 2.0437500000 4 1 2.0437500000 2.0437500000 4.7687500000 5 1 0.6812500000 0.6812500000 0.6812500000 6 1 0.6812500000 3.4062500000 3.4062500000 7 1 3.4062500000 0.6812500000 3.4062500000 8 1 3.4062500000 3.4062500000 0.6812500000 ''') with open('si.in', 'w') as f: f.write(''' units metal boundary p p p box tilt large atom_style atomic read_data data.si pair_style tersoff pair_coeff * * SiCGe.tersoff Si(C) neighbor 0.3 bin ''') supercell = [[2, 0, 0], [0, 2, 0], [0, 0, 2]] print(supercell) phlammps = Phonolammps('si.in', supercell_matrix=supercell) print(phlammps) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() print(unitcell) print(force_constants) print(supercell_matrix) os.chdir('..') return phonon = Phonopy(unitcell, supercell_matrix) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) phonon.set_total_DOS() phonon.plot_total_DOS().show() phonon.set_thermal_properties() phonon.plot_thermal_properties().show()