File: test_rotate.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 (33 lines) | stat: -rw-r--r-- 729 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
from math import sqrt

import numpy as np

from ase import Atoms
from ase.utils import irotate, rotate


def test_rotate():

    def test(xyz):
        a = rotate(xyz)
        ixyz = '%sx,%sy,%sz' % irotate(a)
        a2 = rotate(ixyz)
        print(xyz)
        print(ixyz)
        assert abs(a - a2).max() < 1e-10

    test('10z')
    test('155x,43y,190z')
    test('55x,90y,190z')
    test('180x,-90y,45z')
    test('-180y')
    test('40z,50x')

    norm = np.linalg.norm

    for eps in [1.e-6, 1.e-8]:
        struct = Atoms('H2',
                       [[0, 0, 0],
                        [0, sqrt(1 - eps**2), eps]])
        struct.rotate(struct[1].position, 'y')
        assert abs(norm(struct[1].position) - 1) < 1.e-12