|
5 | 5 | import warnings |
6 | 6 |
|
7 | 7 | import IsoSpecPy |
8 | | -from numpy import array, exp, isnan, nextafter, power |
| 8 | +from numpy import array, ceil, exp, floor, isnan, nextafter, power, rint |
9 | 9 |
|
10 | 10 | # this is to handle both versions of IsoSpecPy, 2.0.2 and 2.2.2 |
11 | 11 | # TODO in a future release remove support for legacy isospecpy |
@@ -711,13 +711,30 @@ def _calc_kmd(self, dict_base): |
711 | 711 | tuple |
712 | 712 | The tuple of the KMD, Kendrick mass, and nominal Kendrick mass. |
713 | 713 | """ |
| 714 | + if hasattr(self, "_mspeak_parent") and self._mspeak_parent: |
| 715 | + kendrick_rounding_method = ( |
| 716 | + self._mspeak_parent._ms_parent.mspeaks_settings.kendrick_rounding_method |
| 717 | + ) |
| 718 | + else: |
| 719 | + kendrick_rounding_method = MSParameters.ms_peak.kendrick_rounding_method |
| 720 | + |
714 | 721 | mass = 0 |
715 | 722 | for atom in dict_base.keys(): |
716 | 723 | mass = mass + Atoms.atomic_masses.get(atom) * dict_base.get(atom) |
717 | 724 |
|
718 | 725 | kendrick_mass = (int(mass) / mass) * self.mz_calc |
719 | 726 |
|
720 | | - nominal_km = int(kendrick_mass) |
| 727 | + if kendrick_rounding_method == "ceil": |
| 728 | + nominal_km = ceil(kendrick_mass) |
| 729 | + elif kendrick_rounding_method == "round": |
| 730 | + nominal_km = rint(kendrick_mass) |
| 731 | + elif kendrick_rounding_method == "floor": |
| 732 | + nominal_km = floor(kendrick_mass) |
| 733 | + else: |
| 734 | + raise Exception( |
| 735 | + "%s method was not implemented, please refer to corems.ms_peak.calc.MSPeakCalc Class" |
| 736 | + % kendrick_rounding_method |
| 737 | + ) |
721 | 738 |
|
722 | 739 | kmd = (nominal_km - kendrick_mass) * 100 |
723 | 740 |
|
|
0 commit comments