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