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