annotate spring_package/Energy.py @ 38:80a4b98121b6 draft

"planemo upload commit 22cd6b0fa88ce0ddc4052beab306f5ba10754f12"
author guerler
date Wed, 25 Nov 2020 17:38:24 +0000
parents 0be0af9e695d
children 172398348efd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
1 import math
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
2
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
3 NTYPE = 21
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
4 NDIST = 20
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
5 NSCALE = 2.0
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
6
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
7
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
8 class Energy:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
9 def __init__(self):
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
10 self.dfire = list()
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
11 with open("spring_package/dfire/dfire.txt") as file:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
12 for line in file:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
13 self.dfire.append(float(line))
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
14
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
15 def get(self, moleculeA, moleculeB):
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
16 result = 0
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
17 chainA = list(moleculeA.calpha.keys())[0]
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
18 chainB = list(moleculeB.calpha.keys())[0]
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
19 for i in moleculeA.calpha[chainA]:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
20 atomA = moleculeA.calpha[chainA][i]
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
21 indexA = self.toResCode(atomA["residue"])
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
22 for j in moleculeB.calpha[chainB]:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
23 atomB = moleculeB.calpha[chainB][j]
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
24 indexB = self.toResCode(atomB["residue"])
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
25 dist2 = (atomA["x"] - atomB["x"]) ** 2 + (atomA["y"] - atomB["y"]) ** 2 + (atomA["z"] - atomB["z"]) ** 2
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
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
32 def toResCode(self, seq):
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
33 code = dict(ALA=0, CYS=1, ASP=2, GLU=3, PHE=4, GLY=5, HIS=6, ILE=7, LYS=8, LEU=9, MET=10,
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
34 ASN=11, PRO=12, GLN=13, ARG=14, SER=15, THR=16, VAL=17, TRP=18, TYR=19)
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
35 return code[seq] if seq in code else 20