-
Notifications
You must be signed in to change notification settings - Fork 0
/
cumulative_overlap.py
151 lines (112 loc) · 3.99 KB
/
cumulative_overlap.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
def main():
import Numeric,LinearAlgebra
import sys
sys.path.append('/home/people/tc/svn/tc_sandbox/misc/rmsf_nmr.py')
import rmsf_nmr
pdb = '1e8l'
chain = 'A'
model1 = 1
model2 = 2
d_coordinates = rmsf_nmr.parse_coordinates(pdb,chain,)
vector_difference = calculate_difference_vector(d_coordinates,model1,model2,)
l_coordinates = d_coordinates[1]
matrix_hessian = rmsf_nmr.calculate_hessian_matrix(l_coordinates)
l_eigenvectors = rmsf_nmr.calculate_eigenvectors(matrix_hessian)
l_eigenvectors_transposed = transpose_rows_and_columns(l_eigenvectors)
vector_difference = Numeric.array(vector_difference)
l_contributions = LinearAlgebra.solve_linear_equations(l_eigenvectors_transposed,vector_difference)
fd = open('contrib_%s_%s.tmp' %(model1,model2),'w')
fd.close()
for i in range(len(l_contributions)):
## print i, vector[i]
fd = open('contrib_%s_%s.tmp' %(model1,model2),'a')
fd.write('%s %s\n' %(i+1,l_contributions[i]))
fd.close()
fo = 'cumoverlap_%s_%s.tmp' %(model1,model2)
mode_min = 6
calculate_cumulated_overlap(fo,l_contributions,vector_difference,l_eigenvectors,mode_min)
return
def calculate_cumulated_overlap(fo,l_contributions,vector_difference,l_eigenvectors,mode_min,):
fd = open(fo,'w')
fd.close()
vector_cumulated = []
for i in range(len(l_contributions)):
vector_cumulated += [0]
## loop over mode
for i in range(len(l_contributions)):
if i < mode_min:
overlap = 0
else:
## loop over coordinate
for j in range(len(vector_cumulated)):
vector_cumulated[j] += l_contributions[i]*l_eigenvectors[i][j]
overlap = cosangle(vector_cumulated,vector_difference)
print i,overlap
fd = open(fo,'a')
fd.write('%s %s\n' %(i+1,overlap))
fd.close()
return
def cosangle(v1,v2):
import math
if len(v1) != len(v2):
print len(v1), len(v2)
stop
numerator = 0
for i in range(len(v1)):
numerator += v1[i]*v2[i]
denominator1 = 0
denominator2 = 0
for i in range(len(v1)):
denominator1 += v1[i]*v1[i]
denominator2 += v2[i]*v2[i]
denominator = math.sqrt(denominator1*denominator2)
cosang = numerator / denominator
return cosang
def transpose_rows_and_columns(l_eigenvectors):
import Numeric
n = len(l_eigenvectors)
l_eigenvectors2 = Numeric.zeros((n,n),typecode='d')
for i in range(n):
for j in range(n):
l_eigenvectors2[i][j] = l_eigenvectors[j][i]
return l_eigenvectors2
def calculate_difference_vector(d_coordinates,model1,model2):
l_vectors = []
n_coordinates = len(d_coordinates[1])
for i in range(n_coordinates):
c2 = d_coordinates[model2][i]
c1 = d_coordinates[model1][i]
l_vectors += [c2[0]-c1[0],c2[1]-c1[1],c2[2]-c1[2],]
return l_vectors
##def gauss_elimination(matrix,vector):
##
## n = len(matrix)
##
## for col in range(n):
## if col % 10 == 0:
## print 'col', col
## for row in range(col+1,n):
## ## addition
## multiple = float(matrix[row][col])/float(matrix[col][col])
## for i in range(col,n):
## matrix[row][i] -= multiple*matrix[col][i]
## vector[row] -= multiple*vector[col]
## ## multiplication
## multiple = float(matrix[row][col+1])
## if multiple != 0:
## for i in range(col,n):
## matrix[row][i] /= multiple
## vector[row] /= multiple
##
## for row in range(n-1-1,-1,-1):
#### print 'row', row
## for col in range(row+1,n):
## ## addition
## multiple = float(matrix[row][col])
#### for i in range(col,col-1,-1):
#### matrix[row][i] -= multiple*
## vector[row] -= multiple*vector[col]
##
## return vector
if __name__ == '__main__':
main()