Mercurial > repos > guerler > springsuite
annotate spring_package/Energy.py @ 40:06337927c198 draft
"planemo upload commit 68723d88e81923739538c34722bc9be164dd4646"
author | guerler |
---|---|
date | Sat, 23 Jan 2021 14:42:46 +0000 |
parents | 172398348efd |
children |
rev | line source |
---|---|
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
1 import math |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
2 from os.path import dirname, realpath |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
3 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
4 NTYPE = 21 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
5 NDIST = 20 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
6 NSCALE = 2.0 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
7 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
8 |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
9 class Energy: |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
10 def __init__(self): |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
11 self.dfire = list() |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
12 dirPath = dirname(realpath(__file__)) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
13 with open("%s/Energy.data" % dirPath) as file: |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
14 for line in file: |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
15 self.dfire.append(float(line)) |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
16 |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
17 def get(self, residuesA, residuesB): |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
18 result = 0 |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
19 for atomA in residuesA: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
20 indexA = self.toResCode(atomA["alignedResidue"]) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
21 for atomB in residuesB: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
22 indexB = self.toResCode(atomB["alignedResidue"]) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
23 dist2 = ((atomA["x"] - atomB["x"]) ** 2 + |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
24 (atomA["y"] - atomB["y"]) ** 2 + |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
25 (atomA["z"] - atomB["z"]) ** 2) |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
26 dist = int((math.sqrt(dist2) * NSCALE)) |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
27 if dist < NDIST: |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
28 index = indexA * NTYPE * NDIST + indexB * NDIST + dist |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
29 result = result + self.dfire[index] |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
30 return result |
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
31 |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
32 def getClashes(self, moleculeA, moleculeB, minDist=5.0): |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
33 minDist = minDist ** 2 |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
34 clashes = 0 |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
35 chainA = list(moleculeA.calpha.keys())[0] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
36 chainB = list(moleculeB.calpha.keys())[0] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
37 calphaA = moleculeA.calpha[chainA] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
38 calphaB = moleculeB.calpha[chainB] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
39 lenA = len(calphaA.keys()) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
40 lenB = len(calphaB.keys()) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
41 if lenA > lenB: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
42 temp = calphaB |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
43 calphaB = calphaA |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
44 calphaA = temp |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
45 lenA = len(calphaA.keys()) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
46 lenB = len(calphaB.keys()) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
47 for i in calphaA: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
48 atomA = calphaA[i] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
49 for j in calphaB: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
50 atomB = calphaB[j] |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
51 dist2 = ((atomA["x"] - atomB["x"]) ** 2 + |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
52 (atomA["y"] - atomB["y"]) ** 2 + |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
53 (atomA["z"] - atomB["z"]) ** 2) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
54 if dist2 < minDist: |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
55 clashes = clashes + 1 |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
56 break |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
57 return clashes / float(lenA) |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
58 |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
59 def toResCode(self, seq): |
39
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
60 code = dict(A=0, C=1, D=2, E=3, F=4, G=5, H=6, I=7, K=8, L=9, M=10, |
172398348efd
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents:
37
diff
changeset
|
61 N=11, P=12, Q=13, R=14, S=15, T=16, V=17, W=18, Y=19) |
37
0be0af9e695d
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff
changeset
|
62 return code[seq] if seq in code else 20 |