def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) orthorhombic = range(16, 75) tetragonal = range(75, 143) rhombohedral = range(143, 168) hexagonal = range(168, 195) cubic = range(195, 231) species = ["K", "La", "Ti"] coords = [[0.345, 5, 0.77298], [0.1345, 5.1, 0.77298], [0.7, 0.8, 0.9]] for i in range(230): sg_num = i + 1 if sg_num in triclinic: lattice = Lattice( [[3.0233057319441246, 1, 0], [0, 7.9850357844548681, 1], [0, 1.2, 8.1136762279561818]] ) elif sg_num in monoclinic: lattice = Lattice.monoclinic(2, 9, 1, 99) elif sg_num in orthorhombic: lattice = Lattice.orthorhombic(2, 9, 1) elif sg_num in tetragonal: lattice = Lattice.tetragonal(2, 9) elif sg_num in rhombohedral: lattice = Lattice.hexagonal(2, 95) elif sg_num in hexagonal: lattice = Lattice.hexagonal(2, 9) elif sg_num in cubic: lattice = Lattice.cubic(2) struct = Structure.from_spacegroup(sg_num, lattice, species, coords) kpath = KPathSeek(struct) # Throws error if something doesn't work, causing test to fail. kpoints = kpath.get_kpoints() # noqa: F841
def _get_hin_kpath(self, symprec, angle_tolerance, atol, tri): """ Returns: Hinuma et al. k-path with labels. """ bs = KPathSeek(self._structure, symprec, angle_tolerance, atol, tri) kpoints = bs.kpath["kpoints"] tmat = bs._tmat for key in kpoints: kpoints[key] = np.dot(np.transpose(np.linalg.inv(tmat)), kpoints[key]) bs.kpath["kpoints"] = kpoints self._rec_lattice = self._structure.lattice.reciprocal_lattice warn( "K-path from the Hinuma et al. convention has been transformed to the basis of the reciprocal lattice \ of the input structure. Use `KPathSeek` for the path in the original author-intended basis." ) return bs
def _get_hin_kpath(self, symprec, angle_tolerance, atol, tri): """ Returns: Hinuma et al. k-path with labels. """ bs = KPathSeek(self._structure, symprec, angle_tolerance, atol, tri) kpoints = bs.kpath["kpoints"] tmat = bs._tmat for key in kpoints: kpoints[key] = np.dot(np.transpose(np.linalg.inv(tmat)), kpoints[key]) return bs
def test_kpath_acentered(self): species = ["K", "La", "Ti"] coords = [[0.345, 5, 0.77298], [0.1345, 5.1, 0.77298], [0.7, 0.8, 0.9]] lattice = Lattice.orthorhombic(2, 9, 1) struct = Structure.from_spacegroup(38, lattice, species, coords) kpath = KPathSeek(struct) kpoints = kpath._kpath["kpoints"] labels = list(kpoints.keys()) self.assertEqual( sorted(labels), sorted( ["B_0", "B_2", "DELTA_0", "F_0", "GAMMA", "G_0", "G_2", "R", "R_2", "S", "T", "T_2", "Y", "Z", "Z_2"] ), ) self.assertAlmostEqual(kpoints["GAMMA"][0], 0.0) self.assertAlmostEqual(kpoints["GAMMA"][1], 0.0) self.assertAlmostEqual(kpoints["GAMMA"][2], 0.0) self.assertAlmostEqual(kpoints["Y"][0], 0.5) self.assertAlmostEqual(kpoints["Y"][1], 0.5) self.assertAlmostEqual(kpoints["Y"][2], 0.0) self.assertAlmostEqual(kpoints["T"][0], 0.5) self.assertAlmostEqual(kpoints["T"][1], 0.5) self.assertAlmostEqual(kpoints["T"][2], 0.5) self.assertAlmostEqual(kpoints["T_2"][0], 0.5) self.assertAlmostEqual(kpoints["T_2"][1], 0.5) self.assertAlmostEqual(kpoints["T_2"][2], -0.5) self.assertAlmostEqual(kpoints["Z"][0], 0.0) self.assertAlmostEqual(kpoints["Z"][1], 0.0) self.assertAlmostEqual(kpoints["Z"][2], 0.5) self.assertAlmostEqual(kpoints["Z_2"][0], 0.0) self.assertAlmostEqual(kpoints["Z_2"][1], 0.0) self.assertAlmostEqual(kpoints["Z_2"][2], -0.5) self.assertAlmostEqual(kpoints["S"][0], 0.0) self.assertAlmostEqual(kpoints["S"][1], 0.5) self.assertAlmostEqual(kpoints["S"][2], 0.0) self.assertAlmostEqual(kpoints["R"][0], 0.0) self.assertAlmostEqual(kpoints["R"][1], 0.5) self.assertAlmostEqual(kpoints["R"][2], 0.5) self.assertAlmostEqual(kpoints["R_2"][0], 0.0) self.assertAlmostEqual(kpoints["R_2"][1], 0.5) self.assertAlmostEqual(kpoints["R_2"][2], -0.5) self.assertAlmostEqual(kpoints["DELTA_0"][0], -0.25308641975308643) self.assertAlmostEqual(kpoints["DELTA_0"][1], 0.25308641975308643) self.assertAlmostEqual(kpoints["DELTA_0"][2], 0.0) self.assertAlmostEqual(kpoints["F_0"][0], 0.25308641975308643) self.assertAlmostEqual(kpoints["F_0"][1], 0.7469135802469136) self.assertAlmostEqual(kpoints["F_0"][2], 0.0) self.assertAlmostEqual(kpoints["B_0"][0], -0.25308641975308643) self.assertAlmostEqual(kpoints["B_0"][1], 0.25308641975308643) self.assertAlmostEqual(kpoints["B_0"][2], 0.5) self.assertAlmostEqual(kpoints["B_2"][0], -0.25308641975308643) self.assertAlmostEqual(kpoints["B_2"][1], 0.25308641975308643) self.assertAlmostEqual(kpoints["B_2"][2], -0.5) self.assertAlmostEqual(kpoints["G_0"][0], 0.25308641975308643) self.assertAlmostEqual(kpoints["G_0"][1], 0.7469135802469136) self.assertAlmostEqual(kpoints["G_0"][2], 0.5) self.assertAlmostEqual(kpoints["G_2"][0], 0.25308641975308643) self.assertAlmostEqual(kpoints["G_2"][1], 0.7469135802469136) self.assertAlmostEqual(kpoints["G_2"][2], -0.5)
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()