File: test_dimensionality.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 (47 lines) | stat: -rw-r--r-- 1,062 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
import pytest

import ase.build
from ase.io import write


def build_layer():
    atoms = ase.build.mx2(formula='MoS2', kind='2H', a=3.18, thickness=3.19)
    atoms.cell[2, 2] = 7
    atoms.set_pbc((1, 1, 1))
    return atoms


@pytest.fixture(
    params=[
        (build_layer(), 'layer'),
        (ase.build.bulk('Ti'), 'bulk'),
    ],
    ids=['layer', 'bulk'],
)
def file(request, testdir):
    atoms, dimtype = request.param
    file = f'atoms.{dimtype}.cfg'
    write(file, atoms)
    return file


@pytest.mark.parametrize("display_all", [False, True])
def test_single(cli, file, display_all):
    if display_all:
        output = cli.ase('dimensionality', '--display-all', file)
    else:
        output = cli.ase('dimensionality', file)

    rows = output.split('\n')
    rows = [line for line in rows if len(line) > 1]
    assert len(rows) >= 3
    rows = rows[2:]

    row = rows[0].split()
    if 'layer' in file:
        assert row[1] == '2D'
    elif 'bulk' in file:
        assert row[1] == '3D'

    if display_all:
        assert len(rows) > 1