def test_init(self): filepath = os.path.join(test_dir, 'PROCAR.simple') p = Procar(filepath) self.assertAlmostEqual(p.get_occupation(0, 'd')[Spin.up], 0) self.assertAlmostEqual( p.get_occupation(0, 's')[Spin.up], 0.35381249999999997) self.assertAlmostEqual(p.get_occupation(0, 'p')[Spin.up], 1.19540625) self.assertRaises(ValueError, p.get_occupation, 1, 'm') self.assertEqual(p.nbands, 10) self.assertEqual(p.nkpoints, 10) self.assertEqual(p.nions, 3) lat = Lattice.cubic(3.) s = Structure(lat, ["Li", "Na", "K"], [[0., 0., 0.], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]]) d = p.get_projection_on_elements(s) self.assertAlmostEqual(d[Spin.up][2][2], { 'Na': 0.042, 'K': 0.646, 'Li': 0.042 }) filepath = os.path.join(test_dir, 'PROCAR') p = Procar(filepath) self.assertAlmostEqual( p.get_occupation(0, 'dxy')[Spin.up], 0.96214813853000025) self.assertAlmostEqual( p.get_occupation(0, 'dxy')[Spin.down], 0.85796295426000124)
def process_PROCAR(self, procar_path=None, poscar_path=None, dir_to_save=None): """ This function process PROCAR file obtained by VASP using pymatgen.io.vasp.outputs.Procar class and saves ion_names, orbital_names and data array data array contains projections in the following form: data[kpoint][band][ion_number][orbital_number] All numberings start from 0 :param procar_path: path to PROCAR file :param poscar_path: path to POSCAR file :param dir_to_save: directory to save data :return: """ if procar_path == None: procar_path = self.procar_path if poscar_path == None: poscar_path = self.poscar_path if dir_to_save == None: dir_to_save = self.dir_to_save procar = Procar(procar_path) for key in procar.data.keys(): self.procar_data = procar.data[key] self.orbital_names = procar.orbitals self.ion_names = self._get_atom_types(poscar_path=poscar_path) for var in ['procar_data', 'orbital_names', 'ion_names']: self.save(var, dir_to_save)
def test_phase_factors(self): filepath = os.path.join(test_dir, 'PROCAR.phase') p = Procar(filepath) self.assertAlmostEqual(p.phase_factors[Spin.up][0, 0, 0, 0], -0.746+0.099j) self.assertAlmostEqual(p.phase_factors[Spin.down][0, 0, 0, 0], 0.372-0.654j) # Two Li should have same phase factor. self.assertAlmostEqual(p.phase_factors[Spin.up][0, 0, 0, 0], p.phase_factors[Spin.up][0, 0, 1, 0]) self.assertAlmostEqual(p.phase_factors[Spin.up][0, 0, 2, 0], -0.053+0.007j) self.assertAlmostEqual(p.phase_factors[Spin.down][0, 0, 2, 0], 0.027-0.047j)
def test_init(self): filepath = os.path.join(test_dir, "PROCAR.simple") p = Procar(filepath) self.assertAlmostEqual(p.get_occupation(0, "d")[Spin.up], 0) self.assertAlmostEqual(p.get_occupation(0, "s")[Spin.up], 0.35381249999999997) self.assertAlmostEqual(p.get_occupation(0, "p")[Spin.up], 1.19540625) self.assertRaises(ValueError, p.get_occupation, 1, "m") self.assertEqual(p.nbands, 10) self.assertEqual(p.nkpoints, 10) self.assertEqual(p.nions, 3) lat = Lattice.cubic(3.0) s = Structure(lat, ["Li", "Na", "K"], [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]]) d = p.get_projection_on_elements(s) self.assertAlmostEqual(d[Spin.up][2][2], {"Na": 0.042, "K": 0.646, "Li": 0.042}) filepath = os.path.join(test_dir, "PROCAR") p = Procar(filepath) self.assertAlmostEqual(p.get_occupation(0, "dxy")[Spin.up], 0.96214813853000025) self.assertAlmostEqual(p.get_occupation(0, "dxy")[Spin.down], 0.85796295426000124)
def test_init(self): filepath = os.path.join(test_dir, 'PROCAR.simple') p = Procar(filepath) self.assertAlmostEqual(p.get_occupation(1, 'd'), 0) self.assertAlmostEqual(p.get_occupation(1, 's'), 0.3538125) self.assertAlmostEqual(p.get_occupation(1, 'p'), 1.19540625) self.assertRaises(ValueError, p.get_occupation, 1, 'm') self.assertEqual(p.nb_bands, 10) self.assertEqual(p.nb_kpoints, 10) lat = Lattice.cubic(3.) s = Structure(lat, ["Li", "Na", "K"], [[0., 0., 0.], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]]) d = p.get_projection_on_elements(s) self.assertAlmostEqual(d[1][2][2], {'Na': 0.042, 'K': 0.646, 'Li': 0.042}) filepath = os.path.join(test_dir, 'PROCAR') p = Procar(filepath) self.assertAlmostEqual(p.get_occupation(0, 'd'), 4.3698147704200059) self.assertAlmostEqual(p.get_occupation(0, 'dxy'), 0.85796295426000124)
#%% import os from pymatgen.io.vasp import Vasprun from pymatgen.electronic_structure.plotter import BSDOSPlotter from pymatgen.io.vasp.outputs import Procar os.chdir('/home/jinho93/oxides/perobskite/strontium-vanadate') os.chdir('/home/jinho93/oxides/perobskite/strontium-Molybdate') plt = BSDOSPlotter() bands = Vasprun("./band/vasprun.xml").get_band_structure("./band/KPOINTS", line_mode=True) data = Procar("./band/PROCAR").data # density of states dosrun = Vasprun("./loptics/dos/prj/vasprun.xml") plt.get_plot(bands, dosrun.complete_dos).show() # %%
# --------- # kpoints labels can be read from the built-in functions. Right now, set manually. # path = HighSymmKpath(mg.Structure.from_file("./CONTCAR")).kpath["path"] path = [["X", "\Gamma", "R", "A", "Z", "\Gamma"]] labels = [ "X", r"$\boldsymbol{\Gamma}$", "R", "A", "Z", r"$\boldsymbol{\Gamma}$" ] #[r"$%s$" % lab for lab in path[0][0:6]] # bands object prepared using pymatgen library. contains eigenvalue information bands = Vasprun("./vasprun.xml").get_band_structure("./KPOINTS", line_mode=True) # projected bands read from procar files data = Procar("./PROCAR").data # set up matplotlib plot # ---------------------- # general options for plot font = {'family': 'serif', 'size': 20, 'weight': 'bold'} plt.rc('font', **font) markers = ("o", "^", "h", "*", "s", "D") colorlist = ("r", "g", "b", "m", "c", "y") # set ylim for the plot # --------------------- ax = plt.axes()
vasprun_file = 'vasprun_a_-4%.xml' kpoints_file = 'KPOINTS' procar_file = 'PROCAR_a_-4%' saving_dictory = '/mnt/c/Users/a/OneDrive/Calculation_Data/Mg2C_Graphene/Picture/Band/' saving_file = '{}'.format('Atom_' + Plot_Atom + '_Bands' + vasprun_file.strip('vasprun' + '.xml')) # vasprun.xml位置 vasprun = Vasprun("{}".format(vasprun_dirctory + vasprun_file), parse_projected_eigen=True) # 生成独立的band数据 bands = vasprun.get_band_structure("{}".format(vasprun_dirctory + kpoints_file), line_mode=True, efermi=vasprun.efermi) # 读取投影数据 procar = Procar("{}".format(vasprun_dirctory + procar_file)) Atom_symbol = vasprun.atomic_symbols dot_size = np.zeros(((3, bands.nb_bands, len(bands.kpoints)))) for n in range(bands.nb_bands): for k in range(len(bands.kpoints)): # 挑选出投影原子的点大小数据 for atom_nb in range(len(Atom_symbol)): if Atom_symbol[atom_nb] == Plot_Atom: dot_size[0][n][k] += procar.data[ Spin.up][k][n][atom_nb][3] * 300 dot_size[1][n][k] += procar.data[ Spin.up][k][n][atom_nb][1] * 300 dot_size[2][n][k] += procar.data[ Spin.up][k][n][atom_nb][2] * 300 for nb_p in range(3): # 选定能量区间
if __name__ == "__main__": os.chdir('/home/jinho93/interface/pzt-bso/loose/opti/') # Load Structure structure = Structure.from_file("./band/dense/POSCAR") # Load Band Structure Calculations bands_K = Vasprun("./band/dense/vasprun.xml") # Load Band Structure Calculations bands = bands_K.get_band_structure("./band/dense/KPOINTS", line_mode=True) # projected bands data = Procar("./band/dense/PROCAR").data # density of states dosrun = Vasprun("./dos/vasprun.xml") # labels # general options for plot # set up 2 graph with aspec ration 2/1 # plot 1: bands diagram # plot 2: Density of States gs = GridSpec(1, 2, width_ratios=[1, 1]) fig = plt.figure(figsize=(11.69, 8.27)) # fig.suptitle("$BN_2 Monolayer$") ax1 = plt.subplot(gs[0]) ax2 = plt.subplot(gs[1]) # , sharey=ax1)