File: __init__.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (28 lines) | stat: -rw-r--r-- 740 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np

from ase.dft.dos import DOS
from ase.dft.kpoints import monkhorst_pack

__all__ = ['DOS', 'monkhorst_pack']


def get_distribution_moment(x, y, order=0):
    """Return the moment of nth order of distribution.

    1st and 2nd order moments of a band correspond to the band's
    center and width respectively.

    For integration, the trapezoid rule is used.
    """

    x = np.asarray(x)
    y = np.asarray(y)

    if order == 0:
        return np.trapz(y, x)
    elif isinstance(order, int):
        return np.trapz(x**order * y, x) / np.trapz(y, x)
    elif hasattr(order, '__iter__'):
        return [get_distribution_moment(x, y, n) for n in order]
    else:
        raise ValueError('Illegal order: %s' % order)