forked from charnley/rmsd
/
tests.py
executable file
·107 lines (85 loc) · 3.05 KB
/
tests.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
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
#!/usr/bin/env python
"""
Perform some test of the calculate_rmsd function
Needs to be expanded
by: Maximilian Peters (lastNameDotFirstNameATgmail)
project: https://github.com/charnley/rmsd
license: https://github.com/charnley/rmsd/blob/master/LICENSE
"""
from os import path
import rmsd
def test_all(example_path="examples", threshold=0.001):
"""
Some very basic functional tests
:return: True if all test passed
"""
print('Testing PDB RMSD')
if not test_pdb(example_path=example_path, threshold=threshold):
return False
else:
print('Passed')
print('Testing xyz RMSD')
if not test_xyz(example_path=example_path, threshold=threshold):
return False
else:
print('Passed')
print('\nPassed all tests')
return True
def test_xyz(example_path="examples", threshold=0.001):
"""
A simple test for the xyz functionality
:return: True if all test passed
"""
p_atoms, P = rmsd.get_coordinates(example_path+'/ethane.xyz', 'xyz')
q_atoms, Q = rmsd.get_coordinates(example_path+'/ethane.xyz', 'xyz')
n_rmsd = rmsd.rmsd(P, Q)
Pc = rmsd.centroid(P)
Qc = rmsd.centroid(Q)
P -= Pc
Q -= Qc
k_rmsd = rmsd.kabsch_rmsd(P, Q)
q_rmsd = rmsd.quaternion_rmsd(P, Q)
if abs(n_rmsd) > threshold:
print('Failed to calculate normal RMSD, result: {0}'.format(n_rmsd))
return False
if abs(k_rmsd) > threshold:
print('Failed to calculate Kabsch RMSD, result: {0}'.format(k_rmsd))
return False
if abs(q_rmsd) > threshold:
print('Failed to calculate quaternion RMSD, result: {0}'.format(q_rmsd))
return False
if abs(q_rmsd - k_rmsd) > threshold ** 2:
print('Failed to yield similar Kabsch and quaternion RMSD, result: {0} vs {1}'.format(k_rmsd, q_rmsd))
return False
return True
def test_pdb(example_path="examples", threshold=0.001):
"""
A simple test for the PDB functionality
:return: True if all test passed
"""
p_atoms, P = rmsd.get_coordinates(example_path+'/ci2_1.pdb', 'pdb')
q_atoms, Q = rmsd.get_coordinates(example_path+'/ci2_2.pdb', 'pdb')
n_rmsd = rmsd.rmsd(P, Q)
Pc = rmsd.centroid(P)
Qc = rmsd.centroid(Q)
P -= Pc
Q -= Qc
k_rmsd = rmsd.kabsch_rmsd(P, Q)
q_rmsd = rmsd.quaternion_rmsd(P, Q)
if abs(n_rmsd - 26.975) > threshold:
print('Failed to calculate normal RMSD, result: {0}'.format(n_rmsd))
return False
if abs(k_rmsd - 11.777) > threshold:
print('Failed to calculate Kabsch RMSD, result: {0}'.format(k_rmsd))
return False
if abs(q_rmsd - 11.777) > threshold:
print('Failed to calculate quaternion RMSD, result: {0}'.format(q_rmsd))
return False
if abs(q_rmsd - k_rmsd) > threshold ** 2:
print('Failed to yield similar Kabsch and quaternion RMSD, result: {0} vs {1}'.format(k_rmsd, q_rmsd))
return False
return True
if __name__ == '__main__':
# Find the absolute path
here = path.abspath(path.dirname(__file__))
test_all(example_path=here+"/examples")