-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
111 lines (76 loc) · 2.32 KB
/
test.py
File metadata and controls
111 lines (76 loc) · 2.32 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import amino
import numpy as np
# Load the test data
dat = np.loadtxt("data/BOUND_COLVAR").T
# Initialize the list of OPs
ops = [amino.OrderParameter(f"test_OP_{i}", d) for i, d in enumerate(dat)]
# Intialize the distance matrix
memo = amino.DistanceMatrix(50, 0.02, "epanechnikov")
memo.initialize_distances(ops)
# convenience variables
OP_1 = ops[0]
OP_2 = ops[1]
dist_1_2 = 0.5353485087893664
def test_load_data():
'''
Test the data loading
'''
assert dat.shape == (429, 1001)
def test_distance_1():
'''
Test the distance between an order parameter and itself
'''
self_dist = memo.distance(OP_1, OP_1)
assert np.isclose(self_dist, 0)
def test_distance_2():
'''
Test the distance between two order parameters to known value
'''
dist = memo.distance(OP_1, OP_2)
assert np.isclose(dist, dist_1_2)
def test_distance_3():
'''
Test the distance cache mechanism
'''
dist = memo.distance(OP_1, OP_2)
dist_same_order = memo.distance(OP_1, OP_2)
dist_reverse_order = memo.distance(OP_1, OP_2)
assert np.isclose(dist, dist_same_order)
assert np.isclose(dist, dist_reverse_order)
def test_add_op_1():
'''
Test adding OPs
'''
mat = amino.DissimilarityMatrix(2, memo)
mat.add_OP(OP_1)
assert np.isclose(mat.matrix[0][0], 0)
def test_add_op_2():
'''
Test adding OPs, basic symmetry
'''
mat = amino.DissimilarityMatrix(2, memo)
mat.add_OP(OP_1)
mat.add_OP(OP_2)
dis_matrix = np.array(mat.matrix)
assert np.isclose(dis_matrix[1,0], dis_matrix[0,1])
assert np.isclose(dis_matrix[1,0], dist_1_2)
assert np.isclose(dis_matrix[0,0], 0)
assert np.isclose(dis_matrix[1,1], 0)
def test_add_op_3():
'''
Test adding OPs to 2x2 matrix, adding the same coordinate twice
'''
mat = amino.DissimilarityMatrix(2, memo)
mat.add_OP(OP_1)
mat.add_OP(OP_1)
assert np.allclose(mat.matrix, [[0, 0], [0, 0]])
def test_add_op_4():
mat = amino.DissimilarityMatrix(2, memo)
mat.add_OP(OP_1)
mat.add_OP(OP_1)
mat.add_OP(OP_2)
dis_matrix = np.array(mat.matrix)
assert np.allclose(dis_matrix, [[0, dist_1_2], [dist_1_2, 0]])
def test_initialization():
assert np.isclose(memo._distance_kernel(0, 1), dist_1_2)
assert np.isclose(memo.distance(ops[0], ops[1]), dist_1_2)