forked from duartegroup/autodE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_values.py
80 lines (50 loc) · 1.92 KB
/
test_values.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
from autode.units import ang, ha, ha_per_ang, ha_per_a0, ev
from autode.values import (ValueArray, Gradient, Coordinate, Coordinates,
MomentOfInertia)
class TmpValues(ValueArray):
implemented_units = [ha, ev]
def __repr__(self):
return ''
def test_base_arr():
tmp_values = TmpValues(np.arange(2))
assert tmp_values.units is None
tmp_values = TmpValues(np.arange(2), units=ha)
assert tmp_values.units == ha
for item in (None, 'a', 0, np.zeros(2)):
# These are not the same! != calls __ne__
assert not tmp_values == item
assert tmp_values != item
def test_unit_retention():
vals = TmpValues(np.array([0.1]), units=ev)
assert vals.units == ev
# Initialising an array from something with units should not default to the
# default unit type (Hartrees for energies)
vals1 = TmpValues(vals)
assert vals1.units == ev
def test_coordinate():
coord = Coordinate(0.0, 0.0, 0.0)
assert coord.units == ang
assert 'coord' in repr(coord).lower()
assert coord is not None
# Equality defaults to np.allclose
assert coord == np.zeros(3)
def test_coordinates():
arr = np.array([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.1]])
coords = Coordinates(arr)
assert coords.units == ang
# Coordinates should reshape into n_atoms x 3
coords = Coordinates(arr.flatten())
assert coords.shape == (2, 3)
def test_moi():
moi = MomentOfInertia(np.zeros(shape=(3, 3)))
assert 'i' in repr(moi).lower()
def test_gradients():
# Default gradient units are Ha Å^-1
gradients = Gradient(np.arange(2, dtype='f8'))
assert gradients.units == ha_per_ang
assert 'grad' in repr(gradients).lower()
gradients_ha_a0 = gradients.to(ha_per_a0)
# Energy per bohr is smaller than per angstrom..
assert all(g1 - g2 <= 0 for g1, g2 in zip(gradients_ha_a0, gradients))