Mercurial > repos > guerler > springsuite
comparison spring_package/Energy.py @ 37:0be0af9e695d draft
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
author | guerler |
---|---|
date | Wed, 25 Nov 2020 14:35:35 +0000 |
parents | |
children | 172398348efd |
comparison
equal
deleted
inserted
replaced
36:2fe8ffff530d | 37:0be0af9e695d |
---|---|
1 import math | |
2 | |
3 NTYPE = 21 | |
4 NDIST = 20 | |
5 NSCALE = 2.0 | |
6 | |
7 | |
8 class Energy: | |
9 def __init__(self): | |
10 self.dfire = list() | |
11 with open("spring_package/dfire/dfire.txt") as file: | |
12 for line in file: | |
13 self.dfire.append(float(line)) | |
14 | |
15 def get(self, moleculeA, moleculeB): | |
16 result = 0 | |
17 chainA = list(moleculeA.calpha.keys())[0] | |
18 chainB = list(moleculeB.calpha.keys())[0] | |
19 for i in moleculeA.calpha[chainA]: | |
20 atomA = moleculeA.calpha[chainA][i] | |
21 indexA = self.toResCode(atomA["residue"]) | |
22 for j in moleculeB.calpha[chainB]: | |
23 atomB = moleculeB.calpha[chainB][j] | |
24 indexB = self.toResCode(atomB["residue"]) | |
25 dist2 = (atomA["x"] - atomB["x"]) ** 2 + (atomA["y"] - atomB["y"]) ** 2 + (atomA["z"] - atomB["z"]) ** 2 | |
26 dist = int((math.sqrt(dist2) * NSCALE)) | |
27 if dist < NDIST: | |
28 index = indexA * NTYPE * NDIST + indexB * NDIST + dist | |
29 result = result + self.dfire[index] | |
30 return result | |
31 | |
32 def toResCode(self, seq): | |
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, | |
34 ASN=11, PRO=12, GLN=13, ARG=14, SER=15, THR=16, VAL=17, TRP=18, TYR=19) | |
35 return code[seq] if seq in code else 20 |