Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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('Illegal order: %s' % order)