File: test_2d_cell_pbc.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 (64 lines) | stat: -rw-r--r-- 1,777 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# fmt: off
import numpy as np
import pytest

from ase.cell import Cell


@pytest.fixture()
def cell():
    return Cell([[1., 0., 0.],
                 [.1, 1., 0.],
                 [0., 0., 0.]])


def test_obl(cell):
    """Verify 2D Bravais lattice and band path versus pbc information."""
    lat = cell.get_bravais_lattice()
    print(cell.cellpar())
    print(lat)
    assert lat.name == 'OBL'


def test_mcl_obl(cell):
    cell[2, 2] = 7
    lat3d = cell.get_bravais_lattice()
    print(lat3d)
    assert lat3d.name == 'MCL'
    lat2d_pbc = cell.get_bravais_lattice(pbc=[1, 1, 0])
    print(lat2d_pbc)
    assert lat2d_pbc.name == 'OBL'

    path = cell.bandpath()
    print(path)

    path2d = cell.bandpath(pbc=[1, 1, 0])
    print(path2d)
    assert path2d.cell.rank == 2
    assert path2d.cell.get_bravais_lattice().name == 'OBL'


@pytest.mark.parametrize('angle', [60, 120])
def test_2d_bandpath_handedness(angle):
    """Test that the x/y part is right-handed in 2D lattice.

    During lattice determination, the whole 3x3 matrix is right-handed
    including "dummy" z axis in 2D cells.  However this did not
    guarantee that the x/y part itself was right-handed, and this
    test would fail for angle=60."""

    cell = Cell.new([1, 1, 0, 90, 90, angle])
    assert cell.get_bravais_lattice().name == 'HEX2D'
    bandpath = cell.bandpath()

    assert bandpath.cell.rank == 2
    assert np.linalg.det(bandpath.cell[:2, :2]) > 0


def test_2d_handedness_obl():
    # Previous code had a bug where left-handed cell would pick the lattice
    # object corresponding to the wrong back-transformation.
    dalpha = 5.1234
    cell = Cell.new([2, 1, 0, 90, 90, 90 + dalpha])
    lat = cell.get_bravais_lattice()
    assert lat.alpha == pytest.approx(90 - dalpha)