-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccpn_isotope_shift.py
140 lines (111 loc) · 5.59 KB
/
ccpn_isotope_shift.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'''Can be used to calculate pairs of protonated - deuterated chemical
shifts for a resonance when the different protonated and deuterated
shifts are
'''
from isotope_shift import correct_for_isotope_shift as correct
from ccpnmr.analysis.core.AssignmentBasic import makeResonanceGuiName
class ShiftedResonce(object):
'''Contains all inforation about the protonated and deuterated
chemical shift.
'''
def __init__(self, resonance, protonatedShiftList=None,
deuteratedShiftList=None, isotope_correction=True):
'''Init.
args: resonance: resonance that is described.
protonatedShiftList: shift list of protonated shifts
deuteratedShiftList: shift list of deuterated shifts
correct: If False, no isotope correction will be
performed and the first shift that is found
is used. The object will only contain one
shiftedShift. If True, istope correction
will be carried out for CA and CB chemical
shifts.
'''
self.isotope_correction = isotope_correction
self.resonance = resonance
self.shiftedShifts = []
self.protonatedShiftList = protonatedShiftList
self.deuteratedShiftList = deuteratedShiftList
self.determine_shifts()
def determine_shifts(self):
'''Determine protonated and deuterated shift for the described
resonance. If the resonance is present in one or both of the
shift lists, the chemical shift value is taken directly from
there. If
'''
if self.isotope_correction and self.protonatedShiftList \
and self.deuteratedShiftList \
and self.resonance.assignNames[0] in ('CA', 'CB'):
protonated_shift = None
deuterated_shift = None
protonated_is_estimate = False
deuterated_is_estimate = False
shift_object = self.resonance.findFirstShift(parentList=self.protonatedShiftList)
if shift_object:
protonated_shift = shift_object.value
shift_object = self.resonance.findFirstShift(parentList=self.deuteratedShiftList)
if shift_object:
deuterated_shift = shift_object.value
# Find out amino acid type
aa_name = self.resonance.resonanceGroup.ccpCode
if not aa_name and self.resonance.resonanceGroup.residue:
aa_name = self.resonance.resonanceGroup.residue.ccpCode
if not aa_name:
aa_name = 'Avg'
if protonated_shift and not deuterated_shift:
deuterated_shift = correct(aa_name=aa_name,
atom_name=self.resonance.assignNames[0],
shift=protonated_shift,
deuterated=False)
deuterated_is_estimate = True
if deuterated_shift and not protonated_shift:
protonated_shift = correct(aa_name=aa_name,
atom_name=self.resonance.assignNames[0],
shift=deuterated_shift,
deuterated=True)
protonated_is_estimate = True
if not protonated_shift and not deuterated_shift:
text = '''Resonance {} does not have a shift in either
of the two shift lists {} and {}.'''
raise ValueError(text.format(self.resonance.serial,
self.protonatedShiftList,
self.deuteratedShiftList))
self.shiftedShifts = [ShiftedShift(resonance=self.resonance,
value=protonated_shift,
estimated=protonated_is_estimate,
deuterated=False),
ShiftedShift(resonance=self.resonance,
value=deuterated_shift,
estimated=deuterated_is_estimate,
deuterated=True)]
else:
shiftedShift = ShiftedShift(resonance=self.resonance,
value=self.resonance.findFirstShift().value)
self.shiftedShifts = [shiftedShift]
class ShiftedShift(object):
"""docstring for ShiftedShift"""
def __init__(self, resonance, value, estimated=False, deuterated=False):
super(ShiftedShift, self).__init__()
self.resonance = resonance
self.value = value
self.estimated = estimated
self.deuterated = deuterated
def create_name(self, full=True):
'''Returns a resonance name where deuterated and
protonated are distinguishable.
returns: str name description
'''
name = makeResonanceGuiName(self.resonance, fullName=full)
if not self.deuterated:
return name
else:
return '{} (D)'.format(name)
def create_shift_description(self):
'''Returns protonated or deuterated chemical shift with
a question mark if the value is estimated.
returns: str shift description
'''
if self.estimated:
return '{}?'.format(round(self.value, 3))
else:
return str(round(self.value, 3))