forked from maddy-abrahams/Proteins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateWD
122 lines (106 loc) · 2.76 KB
/
CreateWD
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
import numpy as np
import math
import time
from scipy.linalg import eigh as eighsci
import copy
#Makes 2-d array of all conforms
#Access conform 1, contact 0 by conform = getConforms conform[1][0]
def getConforms():
with open("idLineAlltest_200.txt","r") as file:
conforms = [0] * 200
indexcount = 0
for line in file:
shape = list(line)
if '\n' in shape:
shape.remove('\n')
shape = [int(i) for i in shape]
conforms[indexcount] = shape
indexcount += 1
return conforms
def get1Conform(conform):
with open("idLineAlltest_200.txt","r") as file:
i = 0
for line in file:
if i == conform:
shape = list(line)
if '\n' in shape:
shape.remove('\n')
shape = [int(i) for i in shape]
return shape
i+=1
def getSums(i):
return sum(get1Conform(i))
#def writeSums(conforms):
#sums = open("sumlinestest5.txt","a")
#for i in conforms:
#sums.write('%i\n' %(sum(i)))
##Reads file of sums of all contacts
#def getSums(i):
#with open("sumlinestest4.txt","r") as file:
#sums = file.read()
#sums = sums.splitlines()
#return int(sums[i])
def getNij(i,j):
conform1 = get1Conform(i)
conform2 = get1Conform(j)
counter = 0
for i in range(len(conform1)):
if conform1[i] == 1 and conform2[i] == 1:
counter += 1
return counter
def getnegd(i,j):
nij = getNij(i,j)
ni = getSums(i)
nj = getSums(j)
num = float(nij)/(ni+nj)
num *=2.0
num = 1.0 - num
return num * -1
#START -->INPUT
def makeW():
start = time.time()
conforms = getConforms()
size = len(conforms)
w = np.empty([size,size])
for (i,j), value in np.ndenumerate(w):
w[i][j] = np.exp(getnegd(i,j))
# w[j][i] = np.exp(getnegd(i,j))
np.savetxt('WMatrix.txt',d, fmt ='%f')
def makeD(w):
d = np.zeros((len(w[0]),len(w[0])))
for i in range(len(w[0])):
d[i][i] = np.sum(w[i])
return d
def makeLaplacian(d,w):
return d - w
def makeDwd(d,w):
temparr = copy.deepcopy(d)
for i in range(len(temparr)):
temp = temparr[i][i]
temparr[i][i] = 1/(temp**.5)
return np.dot(temparr,w).dot(temparr)
#WRITE TO FILE --> np.savetxt('DMatrix.txt',d, fmt ='%f')
def makeDhalf(d):
temparr = copy.deepcopy(d)
for i in range(len(temparr)):
temp = temparr[i][i]
temparr[i][i] = 1/(temp**.5)
return temparr
def makeY(W):
D = makeD(W)
Dhalf = makeDhalf(D)
DWD = makeDwd(D,W)
eval2,evec2 = eighsci(DWD,eigvals =(198,198))
eval3, evec3 = eighsci(DWD, eigvals = (197,197))
eval4, evec4 = eighsci(DWD, eigvals=(196,196))
Y2 = Dhalf*evec2
Y3 = Dhalf*evec3
Y4 = Dhalf*evec4
Y = np.vstack((Y2,Y3,Y4))
return Y
def makeGoodW(w):
start = time.time()
for (i,j), value in np.ndenumerate(w):
if(w[i][j]) < .5:
w[i][j] = 0
np.savetxt('GoodWMatrix500.txt',w, fmt = "%f")