root / ase / dft / __init__.py @ 7
Historique | Voir | Annoter | Télécharger (780 octet)
| 1 |
import numpy as np |
|---|---|
| 2 |
from ase.dft.stm import STM |
| 3 |
from ase.dft.dos import DOS |
| 4 |
from ase.dft.wannier import Wannier |
| 5 |
from ase.dft.kpoints import monkhorst_pack |
| 6 |
|
| 7 |
def get_distribution_moment(x, y, order=0): |
| 8 |
"""Return the moment of nth order of distribution.
|
| 9 |
|
| 10 |
1st and 2nd order moments of a band correspond to the band's
|
| 11 |
center and width respectively.
|
| 12 |
|
| 13 |
For integration, the trapezoid rule is used.
|
| 14 |
"""
|
| 15 |
|
| 16 |
x = np.asarray(x) |
| 17 |
y = np.asarray(y) |
| 18 |
|
| 19 |
if order==0: |
| 20 |
return np.trapz(y, x)
|
| 21 |
elif isinstance(order, int): |
| 22 |
return np.trapz(x**order * y, x) / np.trapz(y, x)
|
| 23 |
elif hasattr(order, '__iter__'): |
| 24 |
return [get_distribution_moment(x, y, n) for n in order] |
| 25 |
else:
|
| 26 |
raise ValueError('Illegal order: %s' % order) |
| 27 |
|