Coverage for /builds/kinetik161/ase/ase/dft/__init__.py: 92.86%
14 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1import numpy as np
3from ase.dft.dos import DOS
4from ase.dft.kpoints import monkhorst_pack
6__all__ = ['DOS', 'monkhorst_pack']
9def get_distribution_moment(x, y, order=0):
10 """Return the moment of nth order of distribution.
12 1st and 2nd order moments of a band correspond to the band's
13 center and width respectively.
15 For integration, the trapezoid rule is used.
16 """
18 x = np.asarray(x)
19 y = np.asarray(y)
21 if order == 0:
22 return np.trapz(y, x)
23 elif isinstance(order, int):
24 return np.trapz(x**order * y, x) / np.trapz(y, x)
25 elif hasattr(order, '__iter__'):
26 return [get_distribution_moment(x, y, n) for n in order]
27 else:
28 raise ValueError(f'Illegal order: {order}')