Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, key1, key2):
super(TempContactAccumulate, self).__init__()
self.fscore = 0 # score of current frame
self.contributingAtomContacts = [] # contrib. atoms, later appended to AccumulatedContact's contributingAtoms list
self.key1 = key1
self.key2 = key2
self.bb1score = 0
self.bb2score = 0
self.sc1score = 0
self.sc2score = 0
frame_contacts_accumulated.append(currentFrameAcc)
accumulatedContactsDict = {}
stop = time.time()
print(stop - start)
# accumulatedContactsDict (dict)
# ---> key vs. list of TempContactAccumulated
#
# loop fills gaps with zero-score TempContactAccumulate of key if key is not occuring in a frame
# provides clean data!
start = time.time()
for key in allkeys:
accumulatedContactsDict[key] = []
for frame_dict in frame_contacts_accumulated:
if not key in frame_dict: # puts empty score TempContactAccumulate in dict
key1, key2 = self.makeKeyArraysFromKey(key)
emptyCont = TempContactAccumulate(key1, key2)
emptyCont.fscore = 0
frame_dict[key] = emptyCont
accumulatedContactsDict[key].append(frame_dict[key])
# make a list of AccumulatedContacts from accumulatedContactsDict
# probably, there is a much easier way to do that, but I am too tired at the moment and it works, though... (M)
finalAccumulatedContacts = [] # list of AccumulatedContacts
for key in accumulatedContactsDict:
key1, key2 = self.makeKeyArraysFromKey(key)
acc = AccumulatedContact(key1, key2)
for tempContact in accumulatedContactsDict[key]:
acc.addScore(tempContact.fscore)
acc.addContributingAtoms(tempContact.contributingAtomContacts)
acc.bb1 += tempContact.bb1score
acc.bb2 += tempContact.bb2score
acc.sc1 += tempContact.sc1score
for cont in frame:
key1, key2 = self.makeKeyArraysFromMaps(map1, map2, cont)
key = self.makeKeyFromKeyArrays(key1, key2)
if key in currentFrameAcc:
currentFrameAcc[key].fscore += cont.weight
currentFrameAcc[key].contributingAtomContacts.append(cont)
if cont.idx1 in self.backbone:
currentFrameAcc[key].bb1score += cont.weight
else:
currentFrameAcc[key].sc1score += cont.weight
if cont.idx2 in self.backbone:
currentFrameAcc[key].bb2score += cont.weight
else:
currentFrameAcc[key].sc2score += cont.weight
else:
currentFrameAcc[key] = TempContactAccumulate(key1, key2)
currentFrameAcc[key].fscore += cont.weight
currentFrameAcc[key].contributingAtomContacts.append(cont)
if cont.idx1 in self.backbone:
currentFrameAcc[key].bb1score += cont.weight
else:
currentFrameAcc[key].sc1score += cont.weight
if cont.idx2 in self.backbone:
currentFrameAcc[key].bb2score += cont.weight
else:
currentFrameAcc[key].sc2score += cont.weight
if not key in allkeys:
allkeys.append(key)
frame_contacts_accumulated.append(currentFrameAcc)
accumulatedContactsDict = {}
stop = time.time()
print(stop - start)