def read_vasprun_pdos(filename='vasprun.xml'): """Read a vasprun.xml containing projected density-of-states (PDOS) data Pymatgen must be present on the system to use this method Args: filename (str): Path to vasprun.xml file Returns: pdos_data (np.ndarray): PDOS data formatted as nestled OrderedDict of: {element: {'energy': energies, 's': densities, 'p' ... } """ dos = read_vasprun(filename) from pymatgen.electronic_structure.core import Spin, OrbitalType pdos_data = OrderedDict() for element in dos.structure.symbol_set: pdos_data[element] = OrderedDict([('energy', dos.energies)]) pdos = dos.get_element_spd_dos(element) for orb in sorted([orb.value for orb in pdos.keys()]): # this way we can ensure the orbitals remain in the correct order orbital = OrbitalType(orb) # sum spin up and spin down channels densities = pdos[orbital].densities[Spin.up] if len(dos.densities) > 1: densities += pdos[orbital].densities[Spin.down] pdos_data[element][orbital.name] = densities return pdos_data
def get_cdos(): for n in range(1, 74): pdos = defaultdict(dict) atom = '' orb = '' for a in atoms: if os.path.exists(f'pwscf.pdos_atm#{n}({a})_wfc#{1}(s)'): atom = Element(a) if atom == '': continue for l, o in enumerate(orbital): if os.path.exists(f'pwscf.pdos_atm#{n}({str(atom)})_wfc#{l + 1}({o})'): orb = OrbitalType(l) data = np.genfromtxt(f'pwscf.pdos_atm#{n}({str(atom)})_wfc#{l + 1}({orb.name})') pdos[orb][Spin.up] = data[:, 1] pdos[orb][Spin.down] = data[:, 2] energies = data[:,0] pdoss.append(pdos) efermi = fermi_fromfile('report.scf') total_density= six.moves.reduce(add_densities, [six.moves.reduce(add_densities, p.values()) for p in pdoss]) total_dos = Dos(efermi, energies, total_density) s = Structure.from_file('123.cif') return CompleteDos(s, total_dos, pdoss)
def test_get_element_spd_dos(self): # with spin polarization energies_spin = [ -11.25000, -7.50000, -3.75000, 0.00000, 3.75000, 7.50000 ] fermi = 0.0 PDOS_F_2s_up = [0.00000, 0.00159, 0.00000, 0.00011, 0.00000, 0.00069] PDOS_F_2s_down = [0.00000, 0.00159, 0.00000, 0.00011, 0.00000, 0.00069] PDOS_F_2py_up = [0.00000, 0.00160, 0.00000, 0.25801, 0.00000, 0.00029] PDOS_F_2py_down = [ 0.00000, 0.00161, 0.00000, 0.25819, 0.00000, 0.00029 ] PDOS_F_2pz_up = [0.00000, 0.00161, 0.00000, 0.25823, 0.00000, 0.00029] PDOS_F_2pz_down = [ 0.00000, 0.00160, 0.00000, 0.25795, 0.00000, 0.00029 ] PDOS_F_2px_up = [0.00000, 0.00160, 0.00000, 0.25805, 0.00000, 0.00029] PDOS_F_2px_down = [ 0.00000, 0.00161, 0.00000, 0.25814, 0.00000, 0.00029 ] self.assertListEqual( self.LobsterCompleteDOS_spin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].energies.tolist(), energies_spin, ) self.assertListEqual( self.LobsterCompleteDOS_spin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].densities[Spin.up].tolist(), PDOS_F_2s_up, ) self.assertListEqual( self.LobsterCompleteDOS_spin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].densities[Spin.down].tolist(), PDOS_F_2s_down, ) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_element_spd_dos(el=Element( "F"))[OrbitalType(1)].densities[Spin.up].tolist()): self.assertAlmostEqual( listel, (np.array(PDOS_F_2px_up) + np.array(PDOS_F_2py_up) + np.array(PDOS_F_2pz_up)).tolist()[ilistel], ) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_element_spd_dos(el=Element( "F"))[OrbitalType(1)].densities[Spin.down].tolist()): self.assertAlmostEqual( listel, (np.array(PDOS_F_2px_down) + np.array(PDOS_F_2py_down) + np.array(PDOS_F_2pz_down)).tolist()[ilistel], ) self.assertAlmostEqual( self.LobsterCompleteDOS_spin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].efermi, fermi, ) # without spin polarization energies_nonspin = [ -11.25000, -7.50000, -3.75000, 0.00000, 3.75000, 7.50000 ] efermi = 0.0 PDOS_F_2s = [0.00000, 0.00320, 0.00000, 0.00017, 0.00000, 0.00060] PDOS_F_2py = [0.00000, 0.00322, 0.00000, 0.51635, 0.00000, 0.00037] PDOS_F_2pz = [0.00000, 0.00322, 0.00000, 0.51636, 0.00000, 0.00037] PDOS_F_2px = [0.00000, 0.00322, 0.00000, 0.51634, 0.00000, 0.00037] self.assertListEqual( self.LobsterCompleteDOS_nonspin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].energies.tolist(), energies_nonspin, ) self.assertListEqual( self.LobsterCompleteDOS_nonspin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].densities[Spin.up].tolist(), PDOS_F_2s, ) for ilistel, listel in enumerate( self.LobsterCompleteDOS_nonspin.get_element_spd_dos(el=Element( "F"))[OrbitalType(1)].densities[Spin.up].tolist()): self.assertAlmostEqual( listel, (np.array(PDOS_F_2px) + np.array(PDOS_F_2py) + np.array(PDOS_F_2pz)).tolist()[ilistel], ) self.assertAlmostEqual( self.LobsterCompleteDOS_nonspin.get_element_spd_dos( el=Element("F"))[OrbitalType(0)].efermi, efermi, )
def test_get_spd_dos(self): # with spin polarization energies_spin = [ -11.25000, -7.50000, -3.75000, 0.00000, 3.75000, 7.50000 ] fermi = 0.0 PDOS_F_2s_up = [0.00000, 0.00159, 0.00000, 0.00011, 0.00000, 0.00069] PDOS_F_2s_down = [0.00000, 0.00159, 0.00000, 0.00011, 0.00000, 0.00069] PDOS_F_2py_up = [0.00000, 0.00160, 0.00000, 0.25801, 0.00000, 0.00029] PDOS_F_2py_down = [ 0.00000, 0.00161, 0.00000, 0.25819, 0.00000, 0.00029 ] PDOS_F_2pz_up = [0.00000, 0.00161, 0.00000, 0.25823, 0.00000, 0.00029] PDOS_F_2pz_down = [ 0.00000, 0.00160, 0.00000, 0.25795, 0.00000, 0.00029 ] PDOS_F_2px_up = [0.00000, 0.00160, 0.00000, 0.25805, 0.00000, 0.00029] PDOS_F_2px_down = [ 0.00000, 0.00161, 0.00000, 0.25814, 0.00000, 0.00029 ] PDOS_K_3s_up = [0.00000, 0.00000, 0.00000, 0.00008, 0.00000, 0.00007] PDOS_K_3s_down = [0.00000, 0.00000, 0.00000, 0.00008, 0.00000, 0.00007] PDOS_K_4s_up = [0.00000, 0.00018, 0.00000, 0.02035, 0.00000, 0.02411] PDOS_K_4s_down = [0.00000, 0.00018, 0.00000, 0.02036, 0.00000, 0.02420] PDOS_K_3py_up = [0.00000, 0.26447, 0.00000, 0.00172, 0.00000, 0.00000] PDOS_K_3py_down = [ 0.00000, 0.26446, 0.00000, 0.00172, 0.00000, 0.00000 ] PDOS_K_3pz_up = [0.00000, 0.26446, 0.00000, 0.00172, 0.00000, 0.00000] PDOS_K_3pz_down = [ 0.00000, 0.26447, 0.00000, 0.00172, 0.00000, 0.00000 ] PDOS_K_3px_up = [0.00000, 0.26447, 0.00000, 0.00172, 0.00000, 0.00000] PDOS_K_3px_down = [ 0.00000, 0.26446, 0.00000, 0.00172, 0.00000, 0.00000 ] PDOS_s_up = (np.array(PDOS_F_2s_up) + np.array(PDOS_K_3s_up) + np.array(PDOS_K_4s_up)).tolist() PDOS_s_down = (np.array(PDOS_F_2s_down) + np.array(PDOS_K_3s_down) + np.array(PDOS_K_4s_down)).tolist() PDOS_p_up = (np.array(PDOS_F_2py_up) + np.array(PDOS_F_2pz_up) + np.array(PDOS_F_2px_up) + np.array(PDOS_K_3py_up) + np.array(PDOS_K_3pz_up) + np.array(PDOS_K_3px_up)).tolist() PDOS_p_down = (np.array(PDOS_F_2py_down) + np.array(PDOS_F_2pz_down) + np.array(PDOS_F_2px_down) + np.array(PDOS_K_3py_down) + np.array(PDOS_K_3pz_down) + np.array(PDOS_K_3px_down)).tolist() self.assertListEqual( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType( 0)].energies.tolist(), energies_spin, ) self.assertEqual( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType(0)].efermi, fermi) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType( 0)].densities[Spin.up].tolist()): self.assertAlmostEqual(listel, PDOS_s_up[ilistel]) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType( 0)].densities[Spin.down].tolist()): self.assertAlmostEqual(listel, PDOS_s_down[ilistel]) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType( 1)].densities[Spin.up].tolist()): self.assertAlmostEqual(listel, PDOS_p_up[ilistel]) for ilistel, listel in enumerate( self.LobsterCompleteDOS_spin.get_spd_dos()[OrbitalType( 1)].densities[Spin.down].tolist()): self.assertAlmostEqual(listel, PDOS_p_down[ilistel]) # without spin polarization energies_nonspin = [ -11.25000, -7.50000, -3.75000, 0.00000, 3.75000, 7.50000 ] PDOS_F_2s = [0.00000, 0.00320, 0.00000, 0.00017, 0.00000, 0.00060] PDOS_F_2py = [0.00000, 0.00322, 0.00000, 0.51635, 0.00000, 0.00037] PDOS_F_2pz = [0.00000, 0.00322, 0.00000, 0.51636, 0.00000, 0.00037] PDOS_F_2px = [0.00000, 0.00322, 0.00000, 0.51634, 0.00000, 0.00037] PDOS_K_3s = [0.00000, 0.00000, 0.00000, 0.00005, 0.00000, 0.00004] PDOS_K_4s = [0.00000, 0.00040, 0.00000, 0.04039, 0.00000, 0.02241] PDOS_K_3py = [0.00000, 0.52891, 0.00000, 0.00345, 0.00000, 0.00000] PDOS_K_3pz = [0.00000, 0.52891, 0.00000, 0.00345, 0.00000, 0.00000] PDOS_K_3px = [0.00000, 0.52891, 0.00000, 0.00345, 0.00000, 0.00000] PDOS_s = (np.array(PDOS_F_2s) + np.array(PDOS_K_3s) + np.array(PDOS_K_4s)).tolist() PDOS_p = (np.array(PDOS_F_2py) + np.array(PDOS_F_2pz) + np.array(PDOS_F_2px) + np.array(PDOS_K_3py) + np.array(PDOS_K_3pz) + np.array(PDOS_K_3px)).tolist() self.assertListEqual( self.LobsterCompleteDOS_nonspin.get_spd_dos()[OrbitalType( 0)].energies.tolist(), energies_nonspin, ) for ilistel, listel in enumerate( self.LobsterCompleteDOS_nonspin.get_spd_dos()[OrbitalType( 0)].densities[Spin.up].tolist()): self.assertAlmostEqual(listel, PDOS_s[ilistel]) for ilistel, listel in enumerate( self.LobsterCompleteDOS_nonspin.get_spd_dos()[OrbitalType( 1)].densities[Spin.up].tolist()): self.assertAlmostEqual(listel, PDOS_p[ilistel])