예제 #1
0
vdos._set_efermi(efermi)

e = vdos.energy
dos_up = vdos.dos[0]
dos_down = vdos.dos[1]
dos_total = dos_up + dos_down

dos_s_up = np.zeros(len(e))
dos_p_up = np.zeros(len(e))
dos_d_up = np.zeros(len(e))
dos_s_down = np.zeros(len(e))
dos_p_down = np.zeros(len(e))
dos_d_down = np.zeros(len(e))

for i in range(len(atoms)):
    dos_s_up += vdos.site_dos(i, 's-up')
    dos_p_up += vdos.site_dos(i, 'px-up') + vdos.site_dos(
        i, 'py-up') + vdos.site_dos(i, 'pz-up')
    dos_d_up += vdos.site_dos(i, 'dxy-up') + vdos.site_dos(
        i, 'dyz-up') + vdos.site_dos(i, 'dz2-up') + vdos.site_dos(
            i, 'dxz-up') + vdos.site_dos(i, 'dx2-up')
    dos_s_down += vdos.site_dos(i, 's-down')
    dos_p_down += vdos.site_dos(i, 'px-down') + vdos.site_dos(
        i, 'py-down') + vdos.site_dos(i, 'pz-down')
    dos_d_down += vdos.site_dos(i, 'dxy-down') + vdos.site_dos(
        i, 'dyz-down') + vdos.site_dos(i, 'dz2-down') + vdos.site_dos(
            i, 'dxz-down') + vdos.site_dos(i, 'dx2-down')

#dos_s_up = vdos.site_dos(4,'s-up')
#dos_p_up = vdos.site_dos(4,'px-up') + vdos.site_dos(4,'py-up') + vdos.site_dos(4, 'pz-up')
예제 #2
0
bulk = Atoms([Atom('Pd', (0.0, 0.0, 0.0))],
             cell=[(0, b, b), (b, 0, b), (b, b, 0)])
with jasp(
        'bulk/pd-ados',
        encut=300,
        xc='PBE',
        lreal=False,
        rwigs=[1.5],  # wigner-seitz radii for ados
        kpts=(8, 8, 8),
        atoms=bulk) as calc:
    # this runs the calculation
    bulk.get_potential_energy()
    # now get results
    ados = VaspDos(efermi=calc.get_fermi_level())
    energies = ados.energy  # energy is an attribute, not a function
    dos = ados.site_dos(0, 'd')  # this is a function, get d-orbitals on atom 0
    # we will select energies in the range of -10, 5
    ind = (energies < 5) & (energies > -10)
    energies = energies[ind]
    dos = dos[ind]
    Nstates = np.trapz(dos, energies)
    occupied = energies <= 0.0
    N_occupied_states = np.trapz(dos[occupied], energies[occupied])
    # first moment
    ed = np.trapz(energies * dos, energies) / Nstates
    # second moment
    wd2 = np.trapz(energies**2 * dos, energies) / Nstates
    print 'Total # states = {0:1.2f}'.format(Nstates)
    print 'number of occupied states = {0:1.2f}'.format(N_occupied_states)
    print 'd-band center = {0:1.2f} eV'.format(ed)
    print 'd-band width  = {0:1.2f} eV'.format(np.sqrt(wd2))
예제 #3
0
             cell=[(0, b, b),
                   (b, 0, b),
                   (b, b, 0)])
with jasp('bulk/pd-ados',
          encut=300,
          xc='PBE',
          lreal=False,
          rwigs=[1.5],  # wigner-seitz radii for ados
          kpts=(8, 8, 8),
          atoms=bulk) as calc:
    # this runs the calculation
    bulk.get_potential_energy()
    # now get results
    ados = VaspDos(efermi=calc.get_fermi_level())
    energies = ados.energy       # energy is an attribute, not a function
    dos = ados.site_dos(0, 'd')  # this is a function, get d-orbitals on atom 0
    # we will select energies in the range of -10, 5
    ind = (energies < 5) & (energies > -10)
    energies = energies[ind]
    dos = dos[ind]
    Nstates = np.trapz(dos, energies)
    occupied = energies <= 0.0
    N_occupied_states = np.trapz(dos[occupied], energies[occupied])
    # first moment
    ed = np.trapz(energies * dos, energies) / Nstates
    # second moment
    wd2 = np.trapz(energies**2 * dos, energies) / Nstates
    print 'Total # states = {0:1.2f}'.format(Nstates)
    print 'number of occupied states = {0:1.2f}'.format(N_occupied_states)
    print 'd-band center = {0:1.2f} eV'.format(ed)
    print 'd-band width  = {0:1.2f} eV'.format(np.sqrt(wd2))
예제 #4
0
파일: dos.py 프로젝트: impurity80/ase
vdos._set_efermi(efermi)

e = vdos.energy
dos_up = vdos.dos[0]
dos_down = vdos.dos[1]
dos_total = dos_up + dos_down

dos_s_up = np.zeros(len(e))
dos_p_up = np.zeros(len(e))
dos_d_up = np.zeros(len(e))
dos_s_down = np.zeros(len(e))
dos_p_down = np.zeros(len(e))
dos_d_down = np.zeros(len(e))

for i in range(len(atoms)):
    dos_s_up += vdos.site_dos(i,'s-up')
    dos_p_up += vdos.site_dos(i,'px-up') + vdos.site_dos(i,'py-up') + vdos.site_dos(i,'pz-up')
    dos_d_up += vdos.site_dos(i,'dxy-up') + vdos.site_dos(i,'dyz-up') + vdos.site_dos(i,'dz2-up') + vdos.site_dos(i,'dxz-up') + vdos.site_dos(i,'dx2-up')
    dos_s_down += vdos.site_dos(i, 's-down')
    dos_p_down += vdos.site_dos(i, 'px-down') + vdos.site_dos(i, 'py-down') + vdos.site_dos(i, 'pz-down')
    dos_d_down += vdos.site_dos(i, 'dxy-down') + vdos.site_dos(i, 'dyz-down') + vdos.site_dos(i, 'dz2-down') + vdos.site_dos(i,'dxz-down') + vdos.site_dos(i,'dx2-down')

#dos_s_up = vdos.site_dos(4,'s-up')
#dos_p_up = vdos.site_dos(4,'px-up') + vdos.site_dos(4,'py-up') + vdos.site_dos(4, 'pz-up')

#dos_s_down = vdos.site_dos(0,'s-down')
#dos_p_down = vdos.site_dos(0,'px-down') + vdos.site_dos(0,'py-down') + vdos.site_dos(0,'pz-down')
#dos_d_down = vdos.site_dos(0,'dxy-down') + vdos.site_dos(0,'dyz-down') + vdos.site_dos(0,'dz2-down') + vdos.site_dos(0,'dxz-down') + vdos.site_dos(0,'dx2-down')

plt.plot([-10,10],[0,0],color='black')
plt.plot(e, dos_total, label='total', color='b')
예제 #5
0
파일: serialize.py 프로젝트: jkshenton/jasp
def calc_to_dict(calc, **kwargs):
    d = {'doc': '''JSON representation of a VASP calculation.

energy is in eV
forces are in eV/\AA
stress is in GPa (sxx, syy, szz,  syz, sxz, sxy)
magnetic moments are in Bohr-magneton
The density of states is reported with E_f at 0 eV.
Volume is reported in \AA^3
Coordinates and cell parameters are reported in \AA

If atom-projected dos are included they are in the form:
{ados:{energy:data, {atom index: {orbital : dos}}}
'''}
    d['incar'] = {'doc': 'INCAR parameters'}
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.float_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.exp_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.string_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.int_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.bool_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.list_params.items())))
    d['incar'].update(dict(filter(lambda item: item[1] is not None,
                                  calc.dict_params.items())))
    d['input'] = calc.input_params
    d['potcar'] = calc.get_pseudopotentials()
    d['atoms'] = atoms_to_dict(calc.get_atoms())
    d['data'] = {'doc': 'Data from the output of the calculation'}
    atoms = calc.get_atoms()
    d['data']['total_energy'] = atoms.get_potential_energy()
    d['data']['forces'] = atoms.get_forces().tolist()

    # There are times when no stress is calculated
    try:
        stress = atoms.get_stress()
    except NotImplementedError:
        stress = None
    except AssertionError:
        stress = None

    if stress is not None:
        d['data']['stress'] = atoms.get_stress().tolist()
    else:
        d['data']['stress'] = None
    d['data']['fermi_level'] = calc.get_fermi_level()
    d['data']['volume'] = atoms.get_volume()
    if calc.spinpol:
        d['data']['magmom'] = atoms.get_magnetic_moment()

    if (calc.int_params.get('lorbit', 0) >= 10
        or calc.list_params.get('rwigs', None)):
        try:
            d['data']['magmoms'] = atoms.get_magnetic_moments().tolist()
        except AttributeError:
            d['data']['magmoms'] = None
    # store the metadata
    if hasattr(calc, 'metadata'):
        d['metadata'] = calc.metadata

    if kwargs.get('dos', None):
        from ase.dft.dos import DOS
        dos = DOS(calc, width=kwargs.get('width', 0.2))
        e = dos.get_energies()

        d['data']['dos'] = {'doc': 'Total density of states'}
        d['data']['dos']['e'] = e.tolist()

        if calc.spinpol:
            d['data']['dos']['dos-up'] = dos.get_dos(spin=0).tolist()
            d['data']['dos']['dos-down'] = dos.get_dos(spin=1).tolist()
        else:
            d['data']['dos']['dos'] = dos.get_dos().tolist()

    if kwargs.get('ados', None):
        from ase.calculators.vasp import VaspDos
        ados = VaspDos(efermi=calc.get_fermi_level())
        d['data']['ados'] = {'doc': 'Atom projected DOS'}
        nonspin_orbitals_no_phase = ['s', 'p', 'd']
        nonspin_orbitals_phase = ['s', 'py', 'pz', 'px',
                                  'dxy', 'dyz', 'dz2', 'dxz', 'dx2']
        spin_orbitals_no_phase = []
        for x in nonspin_orbitals_no_phase:
            spin_orbitals_no_phase += ['{0}-up'.format(x)]
            spin_orbitals_no_phase += ['{0}-down'.format(x)]

        spin_orbitals_phase = []
        for x in nonspin_orbitals_phase:
            spin_orbitals_phase += ['{0}-up'.format(x)]
            spin_orbitals_phase += ['{0}-down'.format(x)]

        if calc.spinpol and calc.int_params['lorbit'] != 11:
            orbitals = spin_orbitals_no_phase
        elif calc.spinpol and calc.int_params['lorbit'] == 11:
            orbitals = spin_orbitals_phase
        elif calc.int_params['lorbit'] != 11:
            orbitals = nonspin_orbitals_no_phase
        else:
            orbitals = nonspin_orbitals_phase

        for i, atom in enumerate(atoms):
            d['data']['ados']['energy'] = ados.energy.tolist()
            d['data']['ados'][i] = {}
            for orbital in orbitals:
                d['data']['ados'][i][orbital] = ados.site_dos(0, orbital).tolist()

    # convert all numpy arrays to lists
    for key in d:
        try:
            d[key] = d[key].tolist()
        except:
            pass
    for key in d['input']:
        try:
            d['input'][key] = d['input'][key].tolist()
        except:
            pass
    return d
예제 #6
0
                   (b, b, 0)])
RWIGS = [1.0, 1.1, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0 ]
ED, WD, N = [], [], []
for rwigs in RWIGS:
    with jasp('bulk/pd-ados') as calc:
        calc.clone('bulk/pd-ados-rwigs-{0}'.format(rwigs))
    with jasp('bulk/pd-ados-rwigs-{0}'.format(rwigs)) as calc:
        calc.set(rwigs=[rwigs])
        try:
            calc.calculate()
        except (VaspSubmitted, VaspQueued):
            continue
        # now get results
        ados = VaspDos(efermi=calc.get_fermi_level())
        energies = ados.energy
        dos = ados.site_dos(0, 'd')
        #we will select energies in the range of -10, 5
        ind = (energies < 5) & (energies > -10)
        energies = energies[ind]
        dos = dos[ind]
        Nstates = np.trapz(dos, energies)
        occupied = energies <= 0.0
        N_occupied_states = np.trapz(dos[occupied], energies[occupied])
        ed = np.trapz(energies * dos, energies) / np.trapz(dos, energies)
        wd2 = np.trapz(energies**2 * dos, energies) / np.trapz(dos, energies)
        N.append(N_occupied_states)
        ED.append(ed)
        WD.append(wd2**0.5)
plt.plot(RWIGS, N, 'bo', label='N. occupied states')
plt.legend(loc='best')
plt.xlabel('RWIGS ($\AA$)')
예제 #7
0
def calc_to_dict(calc, **kwargs):
    """Convert calc to a dictionary."""
    d = {
        'doc':
        '''JSON representation of a VASP calculation.

energy is in eV
forces are in eV/\AA
stress is in GPa (sxx, syy, szz,  syz, sxz, sxy)
magnetic moments are in Bohr-magneton
The density of states is reported with E_f at 0 eV.
Volume is reported in \AA^3
Coordinates and cell parameters are reported in \AA

If atom-projected dos are included they are in the form:
{ados:{energy:data, {atom index: {orbital : dos}}}
'''
    }
    d['incar'] = {'doc': 'INCAR parameters'}
    d['incar'].update(
        dict(
            filter(lambda item: item[1] is not None,
                   calc.float_params.items())))
    d['incar'].update(
        dict(filter(lambda item: item[1] is not None,
                    calc.exp_params.items())))
    d['incar'].update(
        dict(
            filter(lambda item: item[1] is not None,
                   calc.string_params.items())))
    d['incar'].update(
        dict(filter(lambda item: item[1] is not None,
                    calc.int_params.items())))
    d['incar'].update(
        dict(filter(lambda item: item[1] is not None,
                    calc.bool_params.items())))
    d['incar'].update(
        dict(filter(lambda item: item[1] is not None,
                    calc.list_params.items())))
    d['incar'].update(
        dict(filter(lambda item: item[1] is not None,
                    calc.dict_params.items())))
    d['input'] = calc.input_params
    d['potcar'] = calc.get_pseudopotentials()
    d['atoms'] = atoms_to_dict(calc.get_atoms())
    d['data'] = {'doc': 'Data from the output of the calculation'}
    atoms = calc.get_atoms()
    d['data']['total_energy'] = atoms.get_potential_energy()
    d['data']['forces'] = atoms.get_forces().tolist()

    # There are times when no stress is calculated
    try:
        stress = atoms.get_stress()
    except NotImplementedError:
        stress = None
    except AssertionError:
        stress = None

    if stress is not None:
        d['data']['stress'] = atoms.get_stress().tolist()
    else:
        d['data']['stress'] = None
    d['data']['fermi_level'] = calc.get_fermi_level()
    d['data']['volume'] = atoms.get_volume()
    if calc.spinpol:
        d['data']['magmom'] = atoms.get_magnetic_moment()

    if (calc.int_params.get('lorbit', 0) >= 10
            or calc.list_params.get('rwigs', None)):
        try:
            d['data']['magmoms'] = atoms.get_magnetic_moments().tolist()
        except AttributeError:
            d['data']['magmoms'] = None
    # store the metadata
    if hasattr(calc, 'metadata'):
        d['metadata'] = calc.metadata

    if kwargs.get('dos', None):
        from ase.dft.dos import DOS
        dos = DOS(calc, width=kwargs.get('width', 0.2))
        e = dos.get_energies()

        d['data']['dos'] = {'doc': 'Total density of states'}
        d['data']['dos']['e'] = e.tolist()

        if calc.spinpol:
            d['data']['dos']['dos-up'] = dos.get_dos(spin=0).tolist()
            d['data']['dos']['dos-down'] = dos.get_dos(spin=1).tolist()
        else:
            d['data']['dos']['dos'] = dos.get_dos().tolist()

    if kwargs.get('ados', None):
        from ase.calculators.vasp import VaspDos
        ados = VaspDos(efermi=calc.get_fermi_level())
        d['data']['ados'] = {'doc': 'Atom projected DOS'}
        nonspin_orbitals_no_phase = ['s', 'p', 'd']
        nonspin_orbitals_phase = [
            's', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'dx2'
        ]
        spin_orbitals_no_phase = []
        for x in nonspin_orbitals_no_phase:
            spin_orbitals_no_phase += ['{0}-up'.format(x)]
            spin_orbitals_no_phase += ['{0}-down'.format(x)]

        spin_orbitals_phase = []
        for x in nonspin_orbitals_phase:
            spin_orbitals_phase += ['{0}-up'.format(x)]
            spin_orbitals_phase += ['{0}-down'.format(x)]

        if calc.spinpol and calc.int_params['lorbit'] != 11:
            orbitals = spin_orbitals_no_phase
        elif calc.spinpol and calc.int_params['lorbit'] == 11:
            orbitals = spin_orbitals_phase
        elif calc.int_params['lorbit'] != 11:
            orbitals = nonspin_orbitals_no_phase
        else:
            orbitals = nonspin_orbitals_phase

        for i, atom in enumerate(atoms):
            d['data']['ados']['energy'] = ados.energy.tolist()
            d['data']['ados'][i] = {}
            for orbital in orbitals:
                d['data']['ados'][i][orbital] = ados.site_dos(
                    0, orbital).tolist()

    # convert all numpy arrays to lists
    for key in d:
        try:
            d[key] = d[key].tolist()
        except:
            pass
    for key in d['input']:
        try:
            d['input'][key] = d['input'][key].tolist()
        except:
            pass
    return d
예제 #8
0
save(result_file, 'forces \n {0}'.format(atoms.get_forces()))

calc.set(ismear=-5, lorbit=11, nedos=3001)
p = atoms.get_potential_energy()
save(result_file, '4th calculation \n total energy : {0} eV, {1} eV/atom'.format(p, p/len(atoms)))

tm = atoms.get_magnetic_moment()
m = atoms.get_magnetic_moments()
save(result_file, 'total magnetic moment : {0} mB {1} mB/atom '.format(tm, tm/len(atoms)))
save(result_file, 'magnetic moment: {0}'.format(m))


vdos = VaspDos()
vdos.read_doscar('DOSCAR')
print vdos.efermi
print vdos.site_dos(0,0)


dos = DOS(calc, width=0.05)

d = dos.get_dos()
up = dos.get_dos(0)
down = dos.get_dos(1)

e = dos.get_energies()

plt.plot(e,d, label='total')
plt.plot(e,up, label='spin-up')
plt.plot(e,-1.0*down, label='spin-down')

plt.grid(True)
예제 #9
0
파일: dos.py 프로젝트: impurity80/ase
emax, emin, ngrid, efermi = dos_info('DOSCAR')

vdos = VaspDos()
vdos.read_doscar('DOSCAR')

vdos._set_efermi(efermi)

e = vdos.energy
dos_total = vdos.dos

dos_s = np.zeros(len(e))
dos_p = np.zeros(len(e))
dos_d = np.zeros(len(e))

for i in range(len(atoms)): # atomic type number
    dos_s += vdos.site_dos(i,'s')
    dos_p += vdos.site_dos(i,'px') + vdos.site_dos(i,'py') + vdos.site_dos(i,'pz')
    dos_d += vdos.site_dos(i,'dxy') + vdos.site_dos(i,'dyz') + vdos.site_dos(i,'dz2') + vdos.site_dos(i,'dxz') + vdos.site_dos(i,'dx2')

# dos_s_up = vdos.site_dos(4,'s-up')
# dos_p_up = vdos.site_dos(4,'px-up') + vdos.site_dos(4,'py-up') + vdos.site_dos(4, 'pz-up')

# dos_s_down = vdos.site_dos(0,'s-down')
#dos_p_down = vdos.site_dos(0,'px-down') + vdos.site_dos(0,'py-down') + vdos.site_dos(0,'pz-down')
#dos_d_down = vdos.site_dos(0,'dxy-down') + vdos.site_dos(0,'dyz-down') + vdos.site_dos(0,'dz2-down') + vdos.site_dos(0,'dxz-down') + vdos.site_dos(0,'dx2-down')

plt.plot([-10,10],[0,0],color='black')
plt.plot(e, dos_total, label='total', color='b')
#plt.plot(e, dos_up, label='up', color='r')
#plt.plot(e, -1*dos_down, label='down', color='r')
예제 #10
0
#
f = open(doscar, "r")
line1 = f.readline()
natom = int(line1.split()[0])
f.close()

dos = VaspDos(doscar=doscar)

ene = dos.energy
tdos = dos.dos
tdos = smear_dos(ene, tdos, sigma=sigma)

if draw_pdos:
    pdos = np.zeros(len(tdos))
    for i in range(0, natom):
        pdos = pdos + dos.site_dos(i, orbital)
    pdos = smear_dos(ene, pdos, sigma=sigma)

sb.set(context='notebook',
       style='darkgrid',
       palette='deep',
       font='sans-serif',
       font_scale=1,
       color_codes=False,
       rc=None)

#plt.plot(ene, tdos,"r-",linewidth=2)
plt.plot(ene, tdos)
filename = "DOS_" + system + ".png"
plt.ylabel("Density of state (-)")
plt.xlabel("Energy (eV)")
예제 #11
0
lattice = obj.lattice
data = obj.data
#
# limit analysis only for occupied part
#
margin = 0.0
ene = list(filter(lambda x: x <= efermi + margin, ene))

for orbital in orbitals:
    #
    # get pdos for total system
    #
    pdos_tot = np.zeros(len(ene))
    tmpdos = np.zeros(len(ene))
    for i in range(0, natom):
        tmpdos = tmpdos + dos.site_dos(i, orbital)[:len(ene)]
    tmpdos = tmpdos[:len(ene)]
    tmpdos = tmpdos / np.max(tmpdos) if normalize_height else tmpdos
    pdos_tot = smear_dos(ene, tmpdos, sigma=sigma)
    integ = get_distribution_moment(ene, tmpdos, order=0)
    center = get_distribution_moment(ene, tmpdos, order=1)
    second = get_distribution_moment(ene, tmpdos, order=2)
    third = get_distribution_moment(ene, tmpdos, order=3)
    fourth = get_distribution_moment(ene, tmpdos, order=4)
    #
    # get pdos for surface layer
    #
    pdos_surf = np.zeros(len(ene))
    tmpdos = np.zeros(len(ene))
    for i in range(48, 64):
        tmpdos = tmpdos + dos.site_dos(i, orbital)[:len(ene)]
예제 #12
0
            elif o == 'd': orbitals = d_up + d_down
            elif o == 'f': orbitals = f_up + f_down
            elif o == 'all': orbitals = all_up + all_down
            else: orbitals = [o]
        elif options.spin == "+":
            if o == 's': orbitals = s_up
            elif o == 'p': orbitals = p_up
            elif o == 'd': orbitals = d_up
            elif o == 'f': orbitals = f_up
            elif o == 'all': orbitals = all_up
            else: orbitals = [o]
        elif options.spin == "-":
            if o == 's': orbitals = s_down
            elif o == 'p': orbitals = p_down
            elif o == 'd': orbitals = d_down
            elif o == 'f': orbitals = f_down
            elif o == 'all': orbitals = all_down
            else: orbitals = [o]
#        print range(a[0], a[1]+1)
        for orbit in orbitals:
            for i in range(a[0] - 1, a[1]):
                dos = dos + doscar.site_dos(i, orbit)

    for i in range(len(energy)):
        l_en = energy[i] - options.ferm
        l_dos = dos[i]
        if (options.per_atom == "True"):
            l_dos = l_dos / float(a[1] - a[0] + 1)
#        print l_en,l_dos
        print l_en, sign * dos[i]