File: test_dimensionality.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (102 lines) | stat: -rw-r--r-- 3,360 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pytest
import ase.build
from ase import Atoms
from ase.lattice.cubic import FaceCenteredCubic
from ase.geometry.dimensionality import (analyze_dimensionality,
                                         isolate_components)


@pytest.mark.parametrize("method", ['TSA', 'RDA'])
def test_mx2(method):
    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))
    atoms *= 2

    intervals = analyze_dimensionality(atoms, method=method)
    m = intervals[0]
    assert m.dimtype == '2D'

    assert intervals[0].dimtype == '2D'
    assert intervals[0].h == (0, 0, 2, 0)

    assert intervals[1].dimtype == '3D'
    assert intervals[1].h == (0, 0, 0, 1)

    assert intervals[2].dimtype == '0D'
    assert intervals[2].h == (24, 0, 0, 0)


@pytest.mark.parametrize("method", ['TSA', 'RDA'])
def test_fcc(method):
    atoms = FaceCenteredCubic(size=(2, 2, 2), symbol='Cu', pbc=(1, 1, 1))

    intervals = analyze_dimensionality(atoms, method=method)
    m = intervals[0]
    assert m.dimtype == '3D'


@pytest.mark.parametrize("kcutoff", [None, 1.1])
def test_isolation_0D(kcutoff):
    atoms = ase.build.molecule('H2O', vacuum=3.0)

    result = isolate_components(atoms, kcutoff=kcutoff)
    assert len(result) == 1
    key, components = list(result.items())[0]
    assert key == '0D'
    assert len(components) == 1
    molecule = components[0]
    assert molecule.get_chemical_formula() == atoms.get_chemical_formula()


def test_isolation_1D():
    atoms = Atoms(symbols='Cl6Ti2', pbc=True,
                  cell=[[6.27, 0, 0],
                        [-3.135, 5.43, 0],
                        [0, 0, 5.82]],
                  positions=[[1.97505, 0, 1.455],
                             [0.987525, 1.71044347, 4.365],
                             [-0.987525, 1.71044347, 1.455],
                             [4.29495, 0, 4.365],
                             [2.147475, 3.71953581, 1.455],
                             [-2.147475, 3.71953581, 4.365],
                             [0, 0, 0],
                             [0, 0, 2.91]])

    result = isolate_components(atoms)
    assert len(result) == 1
    key, components = list(result.items())[0]
    assert key == '1D'
    assert len(components) == 1
    chain = components[0]
    assert (chain.pbc == [False, False, True]).all()
    assert chain.get_chemical_formula() == atoms.get_chemical_formula()


def test_isolation_2D():
    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))
    atoms *= 2

    result = isolate_components(atoms)
    assert len(result) == 1
    key, components = list(result.items())[0]
    assert key == '2D'
    assert len(components) == 2
    for layer in components:
        empirical = atoms.get_chemical_formula(empirical=True)
        assert empirical == layer.get_chemical_formula(empirical=True)
        assert (layer.pbc == [True, True, False]).all()


def test_isolation_3D():
    atoms = FaceCenteredCubic(size=(2, 2, 2), symbol='Cu', pbc=(1, 1, 1))

    result = isolate_components(atoms)
    assert len(result) == 1
    key, components = list(result.items())[0]
    assert key == '3D'
    assert len(components) == 1
    bulk = components[0]
    assert bulk.get_chemical_formula() == atoms.get_chemical_formula()