Closed n-elie closed 1 year ago
Excuse my ignorance. What is H++
and why is the mass 0.5034? Why is the adjusted mass divided by abs(self.charge)
?
You are right, an H2+ does not make any sense. This was a very bad example. I edited the tests for this attribute.
The idea behind this PR is to use it for mass spectrometry applications. The adjusted mass is divided by abs(self.charge)
because this is a mass-to-charge ratio, noted m/z where m
is the mass and z
is the number of charge.
I renamed the ion_mass
attribute to mz
to make this clearer. I also added a charge
attribute and an mz
property to the Isotope
class to make sure the mass
attribute still return the same value than before. Maybe the monoisotopic mass should also be corrected by the electron mass. This would make sense (does not really matter for mean mass but it could be done).
I also added an mz_spectrum
attribute to the Formula
object. This will return an m/z spectrum with mz ratios and percentage of maximum intensity instead of masses and fractions, as this the common way to describe an m/z spectrum.
Would you be interested by these modifications if I can make things cleaner and backward compatible?
Thank you, and sorry for taking so long. This functionality has been integrated in v2022.10.18 .
>>> from molmass import Formula
>>> Formula("C5H14NO+")
Formula('[C5H14NO]+')
>>> Formula("C5H14NO+").charge
1
>>> print(Formula("C5H14NO+").spectrum())
A Relative mass Fraction % Intensity %
105 105.11004 5.616198 5.972305
106 106.11199 0.332810 0.353913
107 107.11451 0.013325 0.014170
108 108.11733 0.000297 0.000315
109 109.12017 0.000004 0.000004
110 110.12294 0.000000 0.000000
111 111.12567 0.000000 0.000000
112 112.12866 0.000000 0.000000
113 113.13330 0.000000 0.000000
>>> Formula("SO4_2-")
Formula('[SO4]2-')
>>> Formula('[SO4]2-').charge
-2
>>> print(Formula("SO4_2-").spectrum())
A Relative mass Fraction % Intensity % m/z
96 95.952827 94.070057 100.000000 47.976413
97 96.952996 0.886071 0.941927 48.476498
98 97.949936 4.983307 5.297443 48.974968
99 98.955046 0.013403 0.014247 49.477523
100 99.952236 0.046894 0.049850 49.976118
101 100.957185 0.000075 0.000080 50.478593
102 101.955117 0.000191 0.000203 50.977559
103 102.959521 0.000000 0.000000 51.479760
104 103.958227 0.000000 0.000000 51.979114
105 104.962061 0.000000 0.000000 52.481030
106 105.961473 0.000000 0.000000 52.980737
107 106.964788 0.000000 0.000000 53.482394
108 107.964816 0.000000 0.000000 53.982408
Good to hear, I will have a look to this soon Thanks for your work
This PR adds the possibility to add charges to formula objects, like this: