forked from maddy-abrahams/Proteins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parse2
84 lines (73 loc) · 2.22 KB
/
Parse2
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
import math as math
import numpy as np
import time
#If distance is less than 4.5 angstroms returns True, else returns False
def distance(atom1,atom2):
if(np.sum((atom1-atom2)**2)<=.2025):
return True
else:
return False
#Makes list or residues by parsing file
def makeRes():
res = []
current = ' '
for line in open("/home/jstudent/Downloads/AB42.gro"):
list = line.split()
if list[0] != current:
res.append(list[0])
current = list[0]
return res[3:-2]
#makes a numpy array of the coordinates for all the atoms a certain residue
def makeCoords(id):
atoms = []
for line in open("/home/jstudent/Downloads/AB42.gro"):
list = line.split()
if list[0] == id and 'H' not in list[1]:
coords = (list[3],list[4],list[5])
coords = map(float,coords)
atoms.append(coords)
return np.array(atoms)
#Compares two residues to see if there is a contact, returns 0 for false, 1 for true
def compRes(res1,res2):
for i, x in enumerate(res1):
for j,y in enumerate(res2):
if(distance(x,y)):
return 1
return 0
def makeIdentity():
start = time.clock()
res = makeRes()
identity = [[0 for col in res] for row in res]
for a, x in enumerate(res):
r1 = makeCoords(x)
for b, y in enumerate(res[a+1:]):
r2 = makeCoords(y)
identity[a][res.index(y)] = compRes(r1,r2)
# identity[res.index(y)][a] = compRes(r1,r2)
end = time.clock()
print"%.2gs"%(end-start)
identity = np.array(identity)
identity = np.triu(identity, 4)
np.savetxt('identityfullDiag.txt',np.array(identity),fmt = '%i')
return identity
def makeIDFile():
identity = makeIdentity()
start = 4
file = open("idLine.txt","w")
for i in identity:
for j in i[start:]:
file.write("%i" %(j))
start += 1
'''
#Reads a PDB file and parses accordingly
def readPDB():
atoms = np.array([])
for line in open("1KNY.pdb"):
list = line.split()
id = list[0]
if id == 'ATOM' or id == 'HETATM':
coords = (list[6], list[7], list[8])
atoms.append(coords)
np.array(atoms)
#MAKE INTO NUMPY ARRAY
'''