File: test_polarizability.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (25 lines) | stat: -rw-r--r-- 812 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
# fmt: off
import pytest

from ase.calculators.excitation_list import polarizability
from ase.calculators.h2morse import H2Morse, H2MorseExcitedStatesCalculator


def test_shapes():
    """Test evaluation of polarizabily and resulting shapes"""
    atoms = H2Morse()
    exl = H2MorseExcitedStatesCalculator().calculate(atoms)

    alphaf = polarizability(exl, range(2))
    assert alphaf.shape == (2, )
    assert alphaf.dtype == float
    alphat = polarizability(exl, 5 + 2j, tensor=True)
    assert alphat.shape == (3, 3)
    assert alphat.dtype == complex
    alphat = polarizability(exl, range(2), tensor=True)
    assert alphat.shape == (2, 3, 3)
    assert alphat.dtype == float

    # check tensor
    for af, at in zip(alphaf, alphat):
        assert at.diagonal().sum() / 3 == pytest.approx(af, 1.e-8)