File: test_cell_completion.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 (26 lines) | stat: -rw-r--r-- 669 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
def test_cell_completion():
    import numpy as np
    from ase.geometry.cell import complete_cell

    eps = 1E-10
    rng = np.random.RandomState(0)


    def random_unit_vector():
        while 1:
            v = rng.uniform(-1, 1, 3)
            norm = np.linalg.norm(v)
            if norm > eps:
                return v / norm


    for it in range(100):

        cell = np.zeros((3, 3))
        index = rng.randint(0, 3)
        cell[index] = random_unit_vector()
        complete = complete_cell(cell)

        assert abs(np.linalg.norm(complete[index]) - 1) < eps
        assert np.linalg.det(complete) > 0
        assert np.linalg.matrix_rank(complete) == 3