-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimulatedPeakDimension.py
56 lines (48 loc) · 2.12 KB
/
simulatedPeakDimension.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class SimulatedPeakDimension(object):
"""Dimension of an expected peak."""
def __init__(self, simulatedPeak, atom):
super(SimulatedPeakDimension, self).__init__()
self.simulatedPeak = simulatedPeak
self.atom = atom
self.shift = None
self.shift_is_assigned = False
self.update_shift()
def update_shift(self):
'''Update shift. Either gets the shift
from a shift list, if present. Otherwise
takes average shift in the reference
database.
'''
self.shift = self.get_shift_from_list()
if self.shift:
self.shift_is_assigned = True
return
self.shift_is_assigned = False
self.shift = self.get_average_reference_shift()
def get_shift_from_list(self):
'''Get the shift for the atom in this peak
dimension from a shift list.
'''
shiftList = self.simulatedPeak.simulated_partial_spectrum.shiftList
if not shiftList:
return
shifts = []
if self.atom.atomSet and self.atom.atomSet.resonanceSets:
for resonanceSet in self.atom.atomSet.resonanceSets:
for resonance in resonanceSet.resonances:
shift = resonance.findFirstShift(parentList=shiftList)
if shift:
shifts.append(shift.value)
if shifts:
return sum(shifts)/float(len(shifts))
def get_average_reference_shift(self):
'''Get shift from reference data base.'''
atomName = self.atom.chemAtom.name
project = self.atom.residue.chain.molSystem.parent
ccpCode = self.atom.residue.ccpCode
nmrRefStore = project.findFirstNmrReferenceStore(molType='protein',
ccpCode=ccpCode)
chemCompNmrRef = nmrRefStore.findFirstChemCompNmrRef(sourceName='RefDB')
chemCompVarNmrRef = chemCompNmrRef.findFirstChemCompVarNmrRef(linking='any',descriptor='any')
chemAtomNmrRef = chemCompVarNmrRef.findFirstChemAtomNmrRef(name=atomName)
return chemAtomNmrRef.meanValue