-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicDeltaOperations.py
More file actions
238 lines (173 loc) · 8.35 KB
/
basicDeltaOperations.py
File metadata and controls
238 lines (173 loc) · 8.35 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import numpy as np
import pandas as pd
'''
This code takes care of basic manipulations between delta, ratio, and concentration space. Currently, it works for H, C, N, O, and S.
'''
#DEFINE STANDARDS
#Doubly isotopic atoms are given as standard ratios. The standards are: VPDB for carbon, AIR for nitrogen, VSMOW for H/O, and CDT for sulfur.
STD_Rs = {"H": 0.00015576, "C": 0.011180, "N": 0.003676, "17O": 0.0003799, "18O": 0.0020052,
"33S":0.007877,"34S":0.0441626,"36S":0.000105274}
def deltaToConcentration(atomIdentity,delta):
'''
Converts an input delta value for a given type of atom in some reference frame to a 4-tuple containing the concentration of the unsubstituted, M+1, M+2, and all other versions of the atom. For atoms with multiple rare isotopes, sets the additional isotopes following a mass-scaling law.
Inputs:
atomIdentity: A string giving the isotope of interest. Note "S" gives 33S.
delta: The input delta value. See STD_Rs, above, for the standard ratios.
Outputs:
A 4-tuple giving the concentration vector for this delta value. The first entry gives the unsubstituted; successive entries give higher mass substitutions. E.g. for S the entries are (32S, 33S, 34S, 36S).
'''
if type(delta) == tuple:
return twoDeltasToConcentration(atomIdentity, delta)
if atomIdentity == 'C' or atomIdentity == '13C':
ratio = (delta/1000+1)*STD_Rs['C']
concentrationSub = ratio/(1+ratio)
return (1-concentrationSub,concentrationSub,0,0)
if atomIdentity == 'H' or atomIdentity == 'D':
ratio = (delta/1000+1)*STD_Rs['H']
concentrationSub = ratio/(1+ratio)
return (1-concentrationSub,concentrationSub,0,0)
if atomIdentity == 'N' or atomIdentity == '15N':
ratio = (delta/1000+1)*STD_Rs['N']
concentrationSub = ratio/(1+ratio)
return (1-concentrationSub,concentrationSub,0,0)
elif atomIdentity == '17O' or atomIdentity == 'O':
r17 = (delta/1000+1)*STD_Rs['17O']
delta18 = 1/0.52 * delta
r18 = (delta18/1000+1)*STD_Rs['18O']
o17 = r17/(1+r17+r18)
o18 = r18/(1+r17+r18)
o16 = 1-(o17+o18)
return (o16,o17,o18,0)
elif atomIdentity == '33S' or atomIdentity == 'S':
r33 = (delta/1000+1)*STD_Rs['33S']
delta34 = delta/0.515
r34 = (delta34/1000+1)*STD_Rs['34S']
delta36 = delta34*1.9
r36 = (delta36/1000+1)*STD_Rs['36S']
s33 = r33/(1+r33 + r34 + r36)
s34 = r34/(1+r33+r34+r36)
s36 = r36/(1+r33+r34+r36)
s32 = 1-(s33+s34+s36)
return (s32,s33,s34,s36)
elif atomIdentity == '34S':
r34 = (delta/1000+1)*STD_Rs['34S']
delta33 = delta * 0.515
r33 = (delta/1000+1)*STD_Rs['33S']
delta36 = delta*1.9
r36 = (delta36/1000+1)*STD_Rs['36S']
s33 = r33/(1+r33 + r34 + r36)
s34 = r34/(1+r33+r34+r36)
s36 = r36/(1+r33+r34+r36)
s32 = 1-(s33+s34+s36)
return (s32,s33,s34,s36)
else:
raise Exception('Sorry, I do not know how to deal with ' + atomIdentity)
def twoDeltasToConcentration(atomIdentity, deltaTuple):
'''
A special version of the deltaToConcentration function, for 17/18O or 33/34S, when both are constrained via experiment. In this case, we do not set the additional isotopes via a mass scaling law, and instead calculate explicitly.
Inputs:
atomIdentity: "O" or "S", for oxygen or sulfur.
deltaTuple: A 2-tuple. The first entry is 17O or 33S, the second is 18O or 34S.
Outputs:
A 4-tuple giving the concentration vector for this delta value. The first entry gives the unsubstituted; successive entries give higher mass substitutions. E.g. for S the entries are (32S, 33S, 34S, 36S).
'''
if atomIdentity == 'O':
delta17 = deltaTuple[0]
delta18 = deltaTuple[1]
r17 = (delta17/1000+1)*STD_Rs['17O']
r18 = (delta18/1000+1)*STD_Rs['18O']
o17 = r17/(1+r17+r18)
o18 = r18/(1+r17+r18)
o16 = 1-(o17+o18)
return (o16,o17,o18,0)
elif atomIdentity == 'S':
delta33 = deltaTuple[0]
delta34 = deltaTuple[1]
r33 = (delta33/1000+1)*STD_Rs['33S']
r34 = (delta34/1000+1)*STD_Rs['34S']
delta36 = delta34*1.9
r36 = (delta36/1000+1)*STD_Rs['36S']
s33 = r33/(1+r33 + r34 + r36)
s34 = r34/(1+r33+r34+r36)
s36 = r36/(1+r33+r34+r36)
s32 = 1-(s33+s34+s36)
return (s32,s33,s34,s36)
def concentrationToM1Ratio(concentrationTuple):
'''
Gives the ratio for the mass 1 rare isotope of an atom.
Inputs:
concentrationTuple: A 4-tuple giving the concentration vector for this delta value. The first entry gives the unsubstituted; successive entries give higher mass substitutions. E.g. for S the entries are (32S, 33S, 34S, 36S).
Outputs:
A float, giving the ratio between the mass 1 isotope and the unsubstituted isotope.
'''
return concentrationTuple[1]/concentrationTuple[0]
def ratioToDelta(atomIdentity, ratio):
'''
Converts an input ratio for a given atom to a delta value.
Inputs:
atomIdentity: A string giving the isotope of interest
ratio: The isotope ratio.
outputs:
delta: The delta value for that isotope and ratio.
'''
delta = 0
if atomIdentity == 'D':
atomIdentity = 'H'
if atomIdentity in 'HCN' or atomIdentity in ['13C','15N']:
#in case atomIdentity is 2H, 13C, 15N, take last character only
delta = (ratio/STD_Rs[atomIdentity[-1]]-1)*1000
elif atomIdentity == 'O' or atomIdentity == '17O':
delta = (ratio/STD_Rs['17O']-1)*1000
elif atomIdentity == '18O':
delta = (ratio/STD_Rs['18O']-1)*1000
elif atomIdentity == 'S' or atomIdentity == '33S':
delta = (ratio/STD_Rs['33S']-1)*1000
elif atomIdentity == '34S':
delta = (ratio/STD_Rs['34S']-1)*1000
elif atomIdentity == '36S':
delta = (ratio/STD_Rs['36S']-1)*1000
else:
raise Exception('Sorry, I do not know how to deal with ' + atomIdentity)
return delta
def deltaToRatio(atomIdentity, delta):
'''
Converts an input delta value into the corresponding isotope ratio
Inputs:
atomID: A string, the atom of interest
delta: The delta value
Outputs:
ratio: The corresponding isotope ratio
'''
ratio = 0
if atomIdentity == 'D':
atomIdentity = 'H'
if atomIdentity in 'HCN' or atomIdentity in ['13C','15N']:
#in case atomIdentity is 2H, 13C, 15N, take last character only
ratio = STD_Rs[atomIdentity[-1]]* (delta / 1000 + 1)
elif atomIdentity == 'O' or atomIdentity == '17O':
ratio = STD_Rs['17O']* (delta / 1000 + 1)
elif atomIdentity == '18O':
ratio = STD_Rs['18O']* (delta / 1000 + 1)
elif atomIdentity == 'S' or atomIdentity == '33S':
ratio = STD_Rs['33S']* (delta / 1000 + 1)
elif atomIdentity == '34S':
ratio = STD_Rs['34S']* (delta / 1000 + 1)
elif atomIdentity == '36S':
ratio = STD_Rs['36S']* (delta / 1000 + 1)
else:
raise Exception('Sorry, I do not know how to deal with ' + atomIdentity)
return ratio
def compareRelDelta(atomID, deltaStd, deltaSmp):
'''
Given at atom ID and two deltas in VPDB etc. space, finds their relative difference (not in VPDB etc. space). This is useful for making sample standard comparisons.
Inputs:
atomID: A string, to be fed to deltaToConcentration
deltaStd: The delta value of the "standard" (denominator)
deltaSmp: The delta value of the "sample" (numerator)
Outputs:
relDelta: The delta value of the sample relative to the standard.
'''
rStd = concentrationToM1Ratio(deltaToConcentration(atomID,deltaStd))
rSmp = concentrationToM1Ratio(deltaToConcentration(atomID,deltaSmp))
relDelta = 1000*(rSmp/rStd-1)
return relDelta