root / ase / dft / dos.py @ 7
Historique | Voir | Annoter | Télécharger (2,11 ko)
| 1 |
from math import pi, sqrt |
|---|---|
| 2 |
|
| 3 |
import numpy as np |
| 4 |
|
| 5 |
|
| 6 |
class DOS: |
| 7 |
def __init__(self, calc, width=0.1, window=None, npts=201): |
| 8 |
"""Electronic Density Of States object.
|
| 9 |
|
| 10 |
calc: calculator object
|
| 11 |
Any ASE compliant calculator object.
|
| 12 |
width: float
|
| 13 |
Width of guassian smearing.
|
| 14 |
window: tuple of two float
|
| 15 |
Use ``window=(emin, emax)``. If not specified, a window
|
| 16 |
big enough to hold all the eigenvalues will be used.
|
| 17 |
npts: int
|
| 18 |
Number of points.
|
| 19 |
|
| 20 |
"""
|
| 21 |
|
| 22 |
self.npts = npts
|
| 23 |
self.width = width
|
| 24 |
self.w_k = calc.get_k_point_weights()
|
| 25 |
self.nspins = calc.get_number_of_spins()
|
| 26 |
self.e_skn = np.array([[calc.get_eigenvalues(kpt=k, spin=s)
|
| 27 |
for k in range(len(self.w_k))] |
| 28 |
for s in range(self.nspins)]) |
| 29 |
self.e_skn -= calc.get_fermi_level()
|
| 30 |
|
| 31 |
if window is None: |
| 32 |
emin = self.e_skn.min() - 5 * self.width |
| 33 |
emax = self.e_skn.max() + 5 * self.width |
| 34 |
else:
|
| 35 |
emin, emax = window |
| 36 |
|
| 37 |
self.energies = np.linspace(emin, emax, npts)
|
| 38 |
|
| 39 |
def get_energies(self): |
| 40 |
"""Return the array of energies used to sample the DOS."""
|
| 41 |
return self.energies |
| 42 |
|
| 43 |
def delta(self, energy): |
| 44 |
"""Return a delta-function centered at 'energy'."""
|
| 45 |
x = -((self.energies - energy) / self.width)**2 |
| 46 |
return np.exp(x) / (sqrt(pi) * self.width) |
| 47 |
|
| 48 |
def get_dos(self, spin=None): |
| 49 |
"""Get array of DOS values.
|
| 50 |
|
| 51 |
The *spin* argument can be 0 or 1 (spin up or down) - if not
|
| 52 |
specified, the total DOS is returned.
|
| 53 |
"""
|
| 54 |
|
| 55 |
if spin is None: |
| 56 |
if self.nspins == 2: |
| 57 |
# Spin-polarized calculation, but no spin specified -
|
| 58 |
# return the total DOS:
|
| 59 |
return self.get_dos(spin=0) + self.get_dos(spin=1) |
| 60 |
else:
|
| 61 |
spin = 0
|
| 62 |
|
| 63 |
dos = np.zeros(self.npts)
|
| 64 |
for w, e_n in zip(self.w_k, self.e_skn[spin]): |
| 65 |
for e in e_n: |
| 66 |
dos += w * self.delta(e)
|
| 67 |
return dos
|