File: test_standard_form.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 (24 lines) | stat: -rw-r--r-- 877 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
# fmt: off
import numpy as np
from numpy.testing import assert_allclose

from ase.cell import Cell
from ase.lattice import all_variants


def test_standard_form():
    TOL = 1E-10
    for lat in all_variants():
        cell0 = lat.tocell()
        for sign in [-1, 1]:
            cell = Cell(sign * cell0)
            # lower triangular form
            rcell, Q = cell.standard_form(form='lower')
            assert_allclose(rcell @ Q, cell, atol=TOL)
            assert_allclose(np.linalg.det(rcell), np.linalg.det(cell))
            assert_allclose(rcell.ravel()[[1, 2, 5]], 0, atol=TOL)
            # upper triangular form
            rcell, Q = cell.standard_form(form='upper')
            assert_allclose(rcell @ Q, cell, atol=TOL)
            assert_allclose(np.linalg.det(rcell), np.linalg.det(cell))
            assert_allclose(rcell.ravel()[[3, 6, 7]], 0, atol=TOL)