Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions corems/encapsulation/factory/processingSetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def __post_init__(self):
class MassSpecPeakSetting:

kendrick_base: Dict = dataclasses.field(default_factory=dict)

kendrick_rounding_method: str = 'floor' # 'floor', 'ceil' or 'round' are valid methods for calculating nominal kendrick mass

implemented_kendrick_rounding_methods : tuple = ('floor','ceil','round')

# kendrick_base : Dict = {'C': 1, 'H':2}

Expand Down
19 changes: 17 additions & 2 deletions corems/ms_peak/calc/MSPeakCalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@


from scipy.stats import norm, cauchy
from numpy import linspace, sqrt, log, trapz, pi, log, poly1d, polyfit,flip, square,exp, nan
from numpy import linspace, sqrt, log, trapz, pi, log, poly1d, polyfit,flip, square,exp, nan, ceil, rint, floor
from corems.encapsulation.constant import Atoms
from corems.encapsulation.factory.parameters import MSParameters
from lmfit import models
import pyswarm

Expand All @@ -19,14 +20,28 @@ class MSPeakCalculation(object):
def _calc_kdm(self, dict_base):
'''dict_base = {"C": 1, "H": 2}
'''
kendrick_rounding_method = MSParameters.ms_peak.kendrick_rounding_method # rounding method can be one of floor, ceil or round

mass = 0
for atom in dict_base.keys():
mass += Atoms.atomic_masses.get(atom) * dict_base.get(atom)

kendrick_mass = (int(mass) / mass) * self.mz_exp

nominal_km = int(kendrick_mass)
if kendrick_rounding_method == 'ceil':

nominal_km = ceil(kendrick_mass)

elif kendrick_rounding_method == 'round':

nominal_km = rint(kendrick_mass)

elif kendrick_rounding_method == 'floor':

nominal_km = floor(kendrick_mass)

else:
raise Exception("%s method was not implemented, please refer to corems.ms_peak.calc.MSPeakCalc Class" % kendrick_rounding_method)

kmd = (nominal_km - kendrick_mass)

Expand Down