File: test_xrdebye.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 (49 lines) | stat: -rw-r--r-- 1,554 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Tests for XrDebye class"""

from pathlib import Path

import numpy as np
import pytest

from ase.utils.xrdebye import XrDebye, wavelengths
from ase.cluster.cubic import FaceCenteredCubic

tolerance = 1E-5


@pytest.fixture
def xrd():
    # test system -- cluster of 587 silver atoms
    atoms = FaceCenteredCubic('Ag', [(1, 0, 0), (1, 1, 0), (1, 1, 1)],
                              [6, 8, 8], 4.09)
    return XrDebye(atoms=atoms, wavelength=wavelengths['CuKa1'], damping=0.04,
                   method='Iwasa', alpha=1.01, warn=True)


def test_get(xrd):
    expected = 116850.37344
    obtained = xrd.get(s=0.09)
    assert np.abs((obtained - expected) / expected) < tolerance


def test_xrd(testdir, xrd):
    expected = np.array([18549.274677, 52303.116995, 38502.372027])
    obtained = xrd.calc_pattern(x=np.array([15, 30, 50]), mode='XRD')
    assert np.allclose(obtained, expected, rtol=tolerance)
    xrd.write_pattern('tmp.txt')
    assert Path('tmp.txt').exists()


def test_saxs_and_files(testdir, figure, xrd):
    expected = np.array([372650934.006398, 280252013.563702,
                         488123.103628])
    obtained = xrd.calc_pattern(x=np.array([0.021, 0.09, 0.53]),
                                mode='SAXS')
    assert np.allclose(obtained, expected, rtol=tolerance)

    # (Admittedly these tests are a little bit toothless)
    xrd.write_pattern('tmp.txt')
    assert Path('tmp.txt').exists()
    ax = figure.add_subplot(111)
    xrd.plot_pattern(ax=ax, filename='pattern.png')
    assert Path('pattern.png').exists()