File: __init__.py

package info (click to toggle)
python-ase 3.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 15,448 kB
  • sloc: python: 144,945; xml: 2,728; makefile: 113; javascript: 47
file content (29 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (2)
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
29
import numpy as np
from scipy.integrate import trapezoid

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 trapezoid(y, x)
    elif isinstance(order, int):
        return trapezoid(x**order * y, x) / trapezoid(y, x)
    elif hasattr(order, '__iter__'):
        return [get_distribution_moment(x, y, n) for n in order]
    else:
        raise ValueError(f'Illegal order: {order}')