File: test_distance.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 (55 lines) | stat: -rw-r--r-- 1,599 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
# fmt: off
import itertools

import numpy as np

from ase import Atoms
from ase.geometry import distance


def test_distance():

    # artificial structure
    org = Atoms('COPNS',
                [[-1.75072, 0.62689, 0.00000],
                 [0.58357, 2.71652, 0.00000],
                 [-5.18268, 1.36522, 0.00000],
                 [-1.86663, -0.77867, 2.18917],
                 [-1.80586, 0.20783, -2.79331]])

    maxdist = 3.0e-13

    # translate
    for dx in range(3, 10, 2):
        new = org.copy()
        new.translate([dx / np.sqrt(2), -dx / np.sqrt(2), 0])
        dist = distance(org, new, True)
        dist2 = distance(org, new, False)
        print('translation', dx, '-> distance', dist)
        assert dist < maxdist
        assert dist == dist2

    # rotate
    for axis in ['x', '-y', 'z', np.array([1, 1, 1] / np.sqrt(3))]:
        for rot in [20, 200]:
            new = org.copy()
            new.translate(-new.get_center_of_mass())
            new.rotate(rot, axis)
            dist = distance(org, new, True)
            dist2 = distance(org, new, False)
            print('rotation', axis, ', angle', rot, '-> distance', dist)
            assert dist < maxdist
            assert dist == dist2

    # permute
    for i, a in enumerate(org):
        if i < 3:
            a.symbol = 'H'

    for indxs in itertools.permutations(range(3)):
        new = org.copy()
        for c in range(3):
            new[c].position = org[indxs[c]].position
        dist = distance(org, new)
        print('permutation', indxs, '-> distance', dist)
        assert dist < maxdist