-
Notifications
You must be signed in to change notification settings - Fork 0
/
chemical.py
158 lines (150 loc) · 9.19 KB
/
chemical.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def _get():
str_dict = {}
str_dict['X']='1,2;0.9,0.1'
str_dict['H']='1.0078246,2.0141021;0.99985,0.00015'
str_dict['He']='3.01603,4.00260;0.00000138,0.99999862'
str_dict['Li']='6.015121,7.016003;0.075,0.925'
str_dict['Be']='9.012182;1.0'
str_dict['B']='10.012937,11.009305;0.199,0.801'
str_dict['C']='12.0000000,13.0033554;0.988930,0.011070'
str_dict['N']='14.0030732,15.0001088;0.996337,0.003663'
str_dict['O']='15.9949141,16.9991322,17.9991616;0.997590,0.000374,0.002036'
str_dict['F']='18.9984032;1.0'
str_dict['Ne']='19.992435,20.993843,21.991383;0.9048,0.0027,0.0925'
str_dict['Na']='22.989767;1.0'
str_dict['Mg']='23.985042,24.985837,25.982593;0.7899,0.1000,0.1101'
str_dict['Al']='26.981539;1.0'
str_dict['Si']='27.976927,28.976495,29.973770;0.9223,0.0467,0.0310'
str_dict['P']='30.973762;1.0'
str_dict['S']='31.972070,32.971456,33.967866,35.967080;0.9502,0.0075,0.0421,0.0002'
str_dict['Cl']='34.9688531,36.9659034;0.755290,0.244710'
str_dict['Ar']='35.967545,37.962732,39.962384;0.00337,0.00063,0.99600'
str_dict['K']='38.963707,39.963999,40.961825;0.932581,0.000117,0.067302'
str_dict['Ca']='39.962591,41.958618,42.958766,43.955480,45.953689,47.952533;0.96941,0.00647,0.00135,0.02086,0.00004,0.00187'
str_dict['Sc']='44.955910;1.0'
str_dict['Ti']='45.952629,46.951764,47.947947,48.947871,49.944792;0.080,0.073,0.738,0.055,0.054'
str_dict['V']='49.947161,50.943962;0.00250,0.99750'
str_dict['Cr']='49.946046,51.940509,52.940651,53.938882;0.04345,0.83790,0.09500,0.02365'
str_dict['Mn']='54.938047;1.0'
str_dict['Fe']='53.939612,55.934939,56.935396,57.933277;0.0590,0.9172,0.0210,0.0028'
str_dict['Co']='58.933198;1.0'
str_dict['Ni']='57.935346,59.930788,60.931058,61.928346,63.927968;0.6827,0.2610,0.0113,0.0359,0.0091'
str_dict['Cu']='62.939598,64.927793;0.6917,0.3083'
str_dict['Zn']='63.929145,65.926034,66.927129,67.924846,69.925325;0.486,0.279,0.041,0.188,0.006'
str_dict['Ga']='68.925580,70.924700;0.60108,0.39892'
str_dict['Ge']='69.924250,71.922079,72.923463,73.921177,75.921401;0.205,0.274,0.078,0.365,0.078'
str_dict['As']='74.921594;1.0'
str_dict['Se']='73.922475,75.919212,76.919912,77.9190,79.916520,81.916698;0.009,0.091,0.076,0.236,0.499,0.089'
str_dict['Br']='78.918336,80.916289;0.5069,0.4931'
str_dict['Kr']='77.914,79.916380,81.913482,82.914135,83.911507,85.910616;0.0035,0.0225,0.116,0.115,0.570,0.173'
str_dict['Rb']='84.911794,86.909187;0.7217,0.2783'
str_dict['Sr']='83.913430,85.909267,86.908884,87.905619;0.0056,0.0986,0.0700,0.8258'
str_dict['Y']='88.905849;1.0'
str_dict['Zr']='89.904703,90.905644,91.905039,93.906314,95.908275;0.5145,0.1122,0.1715,0.1738,0.0280'
str_dict['Nb']='92.906377;1.0'
str_dict['Mo']='91.906808,93.905085,94.905840,95.904678,96.906020,97.905406,99.907477;0.1484,0.0925,0.1592,0.1668,0.0955,0.2413,0.0963'
str_dict['Tc']='98.0;1.0'
str_dict['Ru']='95.907599,97.905287,98.905939,99.904219,100.905582,101.904348,103.905424;0.0554,0.0186,0.127,0.126,0.171,0.316,0.186'
str_dict['Rh']='102.905500;1.0'
str_dict['Pd']='101.905634,103.904029,104.905079,105.903478,107.903895,109.905167;0.0102,0.1114,0.2233,0.2733,0.2646,0.1172'
str_dict['Ag']='106.905092,108.904757;0.51839,0.48161'
str_dict['Cd']='105.906461,107.904176,109.903005,110.904182,111.902758,112.904400,113.903357,115.904754;0.0125,0.0089,0.1249,0.1280,0.2413,0.1222,0.2873,0.0749'
str_dict['In']='112.904061,114.903880;0.043,0.957'
str_dict['Sn']='111.904826,113.902784,114.903348,115.901747,116.902956,117.901609,118.903310,119.902200,121.903440,123.905274;0.0097,0.0065,0.0036,0.1453,0.0768,0.2422,0.0858,0.3259,0.0463,0.0579'
str_dict['Sb']='120.903821,122.904216;0.574,0.426'
str_dict['Te']='119.904048,121.903054,122.904271,123.902823,124.904433,125.903314,127.904463,129.906229;0.00095,0.0259,0.00905,0.0479,0.0712,0.1893,0.3170,0.3387'
str_dict['I']='126.904473;1.0'
str_dict['Xe']='123.905894,125.904281,127.903531,128.904780,129.903509,130.905072,131.904144,133.905395,135.907214;0.0010,0.0009,0.0191,0.264,0.041,0.212,0.269,0.104,0.089'
str_dict['Cs']='132.905429;1.0'
str_dict['Ba']='129.906282,131.905042,133.904486,134.905665,135.904553,136.905812,137.905232;0.00106,0.00101,0.0242,0.06593,0.0785,0.1123,0.7170'
str_dict['La']='137.90711,138.906347;0.00090,0.99910'
str_dict['Ce']='135.907140,137.905985,139.905433,141.909241;0.0019,0.0025,0.8843,0.1113'
str_dict['Pr']='140.907647;1.0'
str_dict['Nd']='141.907719,142.909810,143.910083,144.912570,145.913113,147.916889,149.920887;0.2713,0.1218,0.2380,0.0830,0.1719,0.0576,0.0564'
str_dict['Pm']='145.0;1.0'
str_dict['Sm']='143.911998,146.914895,147.914820,148.917181,149.917273,151.919729,153.922206;0.031,0.150,0.113,0.138,0.074,0.267,0.227'
str_dict['Eu']='150.919847,152.921225;0.478,0.522'
str_dict['Gd']='151.919786,153.920861,154.922618,155.922118,156.923956,157.924099,159.927049;0.0020,0.0218,0.1480,0.2047,0.1565,0.2484,0.2186'
str_dict['Tb']='158.925342;1.0'
str_dict['Dy']='155.925277,157.924403,159.925193,160.926930,161.926795,162.928728,163.929171;0.0006,0.0010,0.0234,0.189,0.255,0.249,0.282'
str_dict['Ho']='164.930319;1.0'
str_dict['Er']='161.928775,163.929198,165.930290,166.932046,167.932368,169.935461;0.0014,0.0161,0.336,0.2295,0.268,0.149'
str_dict['Tm']='168.934212;1.0'
str_dict['Yb']='167.933894,169.934759,170.936323,171.936378,172.938208,173.938859,175.942564;0.0013,0.0305,0.143,0.219,0.1612,0.318,0.127'
str_dict['Lu']='174.940770,175.942679;0.9741,0.0259'
str_dict['Hf']='173.940044,175.941406,176.943217,177.943696,178.945812,179.946545;0.00162,0.05206,0.18606,0.27297,0.13629,0.35100'
str_dict['Ta']='179.947462,180.947992;0.00012,0.99988'
str_dict['W']='179.946701,181.948202,182.950220,183.950928,185.954357;0.0012,0.263,0.1428,0.307,0.286'
str_dict['Re']='184.952951,186.955744;0.3740,0.6260'
str_dict['Os']='183.952488,185.953830,186.955741,187.955860,188.958137,189.958436,191.961467;0.0002,0.0158,0.016,0.133,0.161,0.264,0.410'
str_dict['Ir']='190.960584,192.962917;0.373,0.627'
str_dict['Pt']='189.959917,191.961019,193.962655,194.964766,195.964926,197.967869;0.0001,0.0079,0.329,0.338,0.253,0.072'
str_dict['Au']='196.966543;1.0'
str_dict['Hg']='195.965807,197.966743,198.968254,199.968300,200.970277,201.970617,203.973467;0.0015,0.100,0.169,0.231,0.132,0.298,0.0685'
str_dict['Tl']='202.972320,204.974401;0.29524,0.70476'
str_dict['Pb']='203.973020,205.974440,206.975872,207.976627;0.014,0.241,0.221,0.524'
str_dict['Bi']='208.980374;1.0'
str_dict['Po']='209.0;1.0'
str_dict['At']='210.0;1.0'
str_dict['Rn']='222.0;1.0'
str_dict['Fr']='223.0;1.0'
str_dict['Ra']='226.025;1.0'
str_dict['Ac']='227.028;1.0'
str_dict['Th']='232.038054;1.0'
str_dict['Pa']='231.0359;1.0'
str_dict['U']='234.040946,235.043924,238.050784;0.000055,0.00720,0.992745'
str_dict['Np']='237.048;1.0'
str_dict['Pu']='244.0;1.0'
str_dict['Am']='243.0;1.0'
str_dict['Cm']='247.0;1.0'
str_dict['Bk']='247.0;1.0'
str_dict['Cf']='251.0;1.0'
str_dict['Es']='252.0;1.0'
str_dict['Fm']='257.0;1.0'
str_dict['Md']='258.0;1.0'
str_dict['No']='259.0;1.0'
str_dict['Lr']='260.0;1.0'
str_dict['15N']='14.0030732,15.0001088;0.01,0.99'
str_dict['14N']='14.0030732,15.0001088;0.996337,0.003663'
str_dict['18O']='15.9949141,16.9991322,17.9991616;0.005,0.005,0.99'
str_dict['2H']='1.0078246,2.0141021;0.01,0.99'
str_dict['13C']='12.0000000,13.0033554;0.01,0.99'
str_dict['Hex']='0;1'
str_dict['HexNAc']='0;1'
str_dict['NeuAc']='0;1'
str_dict['Pent']='0;1'
str_dict['dHex']='0;1'
str_dict['NeuGc']='0;1'
str_dict['Hep']='0;1'
chemical_dict = {}
for elem, value in str_dict.items():
items = value.split(";")
items = [item.split(',') for item in items]
items = [(float(items[0][i]), float(items[1][i])) for i in range(len(items[0]))]
chemical_dict[elem] = items
return chemical_dict
chem_dict = _get()
def _get_mono(chem_dict):
chem_mono_mass = {}
for elem, items in chem_dict.items():
mono_mass, mono_inten = items[0]
for i in range(1, len(items)):
if mono_inten < items[i][1]:
mono_mass, mono_inten = items[i]
chem_mono_mass[elem] = mono_mass
return chem_mono_mass
chem_mono_mass = _get_mono(chem_dict)
def calc_formula_mass(formula):
def _chem_tuples(formula):
items = formula.strip(')').split(')')
items = [item.split('(') for item in items]
return [(elem, int(n)) for elem, n in items]
chem_tuples = _chem_tuples(formula)
return sum([chem_mono_mass[elem]*n for elem, n in chem_tuples])
def replace_element_and_calc_mass(formula, replacement):
for from_elem, to_elem in replacement:
if formula[:len(from_elem)+1] == from_elem + "(":
formula = to_elem + formula[len(from_elem):]
else:
formula = formula.replace(')%s('%from_elem, ')%s('%to_elem)
return formula, calc_formula_mass(formula)