-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_interpolators.py
167 lines (134 loc) · 5.41 KB
/
test_interpolators.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import sys, os, numpy
from math import pi
from time import time
import timeit
sys.path.insert(0, os.curdir)
#### RAMACHANDRAN
print ('TESTING RAMACHANDRAN INTERPOLATOR')
print ('Importing Ramachandran interpolator')
from ramachandran import Rama_Mgr
t = timeit.timeit(
"rmgr = Rama_Mgr()",
setup="from ramachandran import Rama_Mgr",
number=100000
)
print ("Importing Rama_Mgr 100k times took {} seconds".format(t))
rmgr = Rama_Mgr()
num_interpolations = 10000
angles = ((numpy.random.rand(num_interpolations,2)-1)*pi)
print ('Ramachandran case names: {}'.format(rmgr.keys()))
t = timeit.timeit(
"rmgr.interpolate_single('GENERAL', 1., 1.)",
setup='''
from ramachandran import Rama_Mgr
rmgr = Rama_Mgr()
''',
number=100000
)
print("Performing 100,000 single Rama evaluations took {} seconds".format(t))
# Check against some known values. Tolerances are relatively loose since
# known values were calculated in double precision but current implementation is
# float
abs_tol=1e-4
from numpy import isclose
known_rama_scores = (
[['GENERAL', -1.30604503, 2.68515261], 0.38533466754824536],
[['TRANSPRO', -1.02151863, -0.69621326], 0.7914812407411016],
[['CISPRO', -1.20270843, 2.79918665], 0.8549866164172167],
[['ILEVAL', -2.44296282, -0.35592498], 0.0036246624729488735],
[['GLY', 1.1895601 , 0.61036634], 0.823064915185082]
)
for r in known_rama_scores:
rama_details, known_score = r
try:
assert isclose(rmgr.interpolate_single(*rama_details), known_score, atol=abs_tol)
except AssertionError:
calc_score = rmgr.interpolate_single(*rama_details)
print('WARNING: Calculated score of {} for {} case phi={}, psi={} does not match stored value of {}.'
.format(calc_score, rama_details[0], rama_details[1], known_score))
t = timeit.timeit(
"rmgr.interpolate('GENERAL', angles)",
setup='''
from ramachandran import Rama_Mgr
rmgr = Rama_Mgr()
from __main__ import angles
''',
number=10
)
print('Performing 10x{} concerted Rama evaluations on random (phi, psi) double-precision pairs took {} seconds'.format(num_interpolations, t))
angles_float = angles.astype(numpy.float32)
t = timeit.timeit(
"rmgr.interpolate('GENERAL', angles)",
setup='''
from ramachandran import Rama_Mgr
rmgr = Rama_Mgr()
from __main__ import angles
''',
number=10
)
print('Performing 10x{} concerted Rama evaluations on random (phi, psi) single-precision pairs took {} seconds'.format(num_interpolations, t))
dp_results = rmgr.interpolate('GENERAL', angles)
sp_results = rmgr.interpolate('GENERAL', angles_float)
assert numpy.allclose(dp_results, sp_results)
#### ROTAMERS
print('\n\nTESTING ROTAMER INTERPOLATION')
print('Importing rotamer interpolator')
from rotamer import Rota_Mgr
rota_mgr = Rota_Mgr()
print ('Rotamer names: {}'.format(rota_mgr.keys()))
known_rota_scores = (
[['THR', [-1.18680692]], 0.27169472688690244],
[['LYS', [-0.97795798, -3.01192304, 2.85388646, 1.4183923]], 0.2325102334891604],
[['LEU', [-2.70087757, -2.41489383]], 8.858258998e-06],
[['ILE', [-0.93842671, -1.05547921]], 0.42725676541200613],
[['TYR', [2.94456112, 1.56040726]], 0.3246952257152924],
[['PHE', [2.94456112, 1.56040726]], 0.3246952257152924],
[['SER', [1.14593017]], 0.9879297437362637],
[['PRO', [-0.49725932]], 0.9593997327648075],
[['ASN', [1.32791294, -0.29426418]], 0.23133084762617592],
[['ASP', [-1.33717312, 2.77402037]], 0.7552585586278451],
[['VAL', [3.02299915]], 0.8141136782245025],
[['HIS', [-0.93634878, 1.79943171]], 0.33809833158450403],
[['ARG', [-2.50029818, 0.86957468, -2.81427486, 2.00635224]], 0.003460325535481471],
[['GLN', [-1.31204367, 1.53333072, -0.27079344]], 0.2286698477020941],
[['GLU', [-1.30131147, 1.43252533, 3.11070798]], 0.5837979452557274],
[['CYS', [3.12039768]], 0.4830497003515302],
[['MET', [-2.51420927, 2.69937058, 2.71132163]], 0.006540101745710986],
[['TRP', [-1.14757094, 1.75275024]], 0.9677868018396398],
)
for r in known_rota_scores:
rota_details, known_score = r
try:
assert isclose(rota_mgr.interpolate_single(*rota_details), known_score, atol=abs_tol)
except AssertionError:
calc_score = rota_mgr.interpolate_single(*rota_details)
print('WARNING: Calculated rotamer score of {} for {} with chi angles {} does not match stored value of {}.'
.format(calc_score, rota_details[0], ','.join((str(c) for c in rota_details[1])), known_score))
lys_angles = ((numpy.random.rand(num_interpolations,4)-1)*pi)
t = timeit.timeit(
"rota_mgr.interpolate('LYS', lys_angles)",
setup='''
from rotamer import Rota_Mgr
rota_mgr = Rota_Mgr()
from __main__ import lys_angles
''',
number=10
)
print('Performing 10x{} concerted lysine rotamer evaluations on random chi angles took {} seconds'.format(num_interpolations, t))
### CABLAM
print('\n\nTESTING CABLAM INTERPOLATION')
from cablam import CaBLAM_Mgr
cmgr = CaBLAM_Mgr()
for cablam_name in cmgr.keys():
dim = cmgr.dim(cablam_name)
angles = ((numpy.random.rand(num_interpolations,dim)*0.5)*pi)
t = timeit.timeit(
"cmgr.interpolate(cablam_name, angles)",
setup='''
from __main__ import cmgr
from __main__ import angles
from __main__ import cablam_name
''',
number=10
)
print('Performing 10x{} concerted {}-dimensional {} CaBLAM evaluations on random dihedral angles took {} seconds'.format(num_interpolations, dim, cablam_name, t))