getMolecularMass

PURPOSE ^

get mono-isotopic exact molecular mass for a single formula or a cell array of

SYNOPSIS ^

function M=getMolecularMass(formulae,isotopeAbundance)

DESCRIPTION ^

 get mono-isotopic exact molecular mass for a single formula or a cell array of
 formulae using the atomic weight for each element from NIST
 http://physics.nist.gov/PhysRefData/Compositions/

 An atomic weight of an element from a specified source is the ratio of
 the average mass per atom of the element to 1/12 of the mass of an
 atom of 12C.

 Note the term "relative atomic mass" is usually reserved for the mass of a
 specific nuclide (or isotope), while "atomic weight" is usually used for the
 weighted mean of the relative atomic mass over all the atoms in the
 sample (polyisotopic mass). 
 

 If the ratio of the different isotopes are known exactly, this may be
 provided in the m x 2 cell array of m isotopes, i.e. isotopeAbundance.

 By default, this script gives the molecular mass assuming monoisotopic
 exact mass.

 INPUT
 formula           single formula or a cell array of formulae

 OPTIONAL INPUT
 isotopeAbundance  {(1),0} 
                   1 = monoisotopic exact mass
                       i.e. only uses naturally predominant isotope
                       of each element.
                   0 = polyisotopic inexact mass
                       i.e. uses all isotopes of each element weighted
                       by natural abundance
                   
                   or
 
                   m x 2 cell arrray with user defined isotope abundance
                   isotopeAbundance{i,1}= 'Atomic_Symbol';
                   isotopeAbundance{i,2}= Mass_Number;
                   isotopeAbundance{i,3}= abundance;
                   (where sum of abundances of all isotopes of an element
                   must be one)

                   e.g. Carbon, all as C13
                   isotopeAbundance{i,1}= 'C'
                   isotopeAbundance{i,2}= 12;
                   isotopeAbundance{i,3}= 0;
                   isotopeAbundance{i+1,1}= 'C'
                   isotopeAbundance{i+1,2}= 13;
                   isotopeAbundance{i+1,3}= 1;
                   isotopeAbundance{i+2,1}= 'C'
                   isotopeAbundance{i+2,2}= 14;
                   isotopeAbundance{i+2,3}= 0;

 OUTPUT
 M         molecular mass(es) in (gram/Mol)

 Exact mass check:
 If you want to double check that the mass given by this script is correct
 then compare it to either
 (1) OpenBabel: echo "InChIstring"|babel -iinchi -  -oreport
 or
 (2) http://www.sisweb.com/referenc/tools/exactmass.htm
 Please report any errors as these are critical for use of this script
 with mass spec machines.
 
 Ronan Fleming 9 March 09  ronan.mt.fleming@gmail.com
               15 Sept 09  Support for non-natural isotope distributions

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function M=getMolecularMass(formulae,isotopeAbundance)
0002 % get mono-isotopic exact molecular mass for a single formula or a cell array of
0003 % formulae using the atomic weight for each element from NIST
0004 % http://physics.nist.gov/PhysRefData/Compositions/
0005 %
0006 % An atomic weight of an element from a specified source is the ratio of
0007 % the average mass per atom of the element to 1/12 of the mass of an
0008 % atom of 12C.
0009 %
0010 % Note the term "relative atomic mass" is usually reserved for the mass of a
0011 % specific nuclide (or isotope), while "atomic weight" is usually used for the
0012 % weighted mean of the relative atomic mass over all the atoms in the
0013 % sample (polyisotopic mass).
0014 %
0015 %
0016 % If the ratio of the different isotopes are known exactly, this may be
0017 % provided in the m x 2 cell array of m isotopes, i.e. isotopeAbundance.
0018 %
0019 % By default, this script gives the molecular mass assuming monoisotopic
0020 % exact mass.
0021 %
0022 % INPUT
0023 % formula           single formula or a cell array of formulae
0024 %
0025 % OPTIONAL INPUT
0026 % isotopeAbundance  {(1),0}
0027 %                   1 = monoisotopic exact mass
0028 %                       i.e. only uses naturally predominant isotope
0029 %                       of each element.
0030 %                   0 = polyisotopic inexact mass
0031 %                       i.e. uses all isotopes of each element weighted
0032 %                       by natural abundance
0033 %
0034 %                   or
0035 %
0036 %                   m x 2 cell arrray with user defined isotope abundance
0037 %                   isotopeAbundance{i,1}= 'Atomic_Symbol';
0038 %                   isotopeAbundance{i,2}= Mass_Number;
0039 %                   isotopeAbundance{i,3}= abundance;
0040 %                   (where sum of abundances of all isotopes of an element
0041 %                   must be one)
0042 %
0043 %                   e.g. Carbon, all as C13
0044 %                   isotopeAbundance{i,1}= 'C'
0045 %                   isotopeAbundance{i,2}= 12;
0046 %                   isotopeAbundance{i,3}= 0;
0047 %                   isotopeAbundance{i+1,1}= 'C'
0048 %                   isotopeAbundance{i+1,2}= 13;
0049 %                   isotopeAbundance{i+1,3}= 1;
0050 %                   isotopeAbundance{i+2,1}= 'C'
0051 %                   isotopeAbundance{i+2,2}= 14;
0052 %                   isotopeAbundance{i+2,3}= 0;
0053 %
0054 % OUTPUT
0055 % M         molecular mass(es) in (gram/Mol)
0056 %
0057 % Exact mass check:
0058 % If you want to double check that the mass given by this script is correct
0059 % then compare it to either
0060 % (1) OpenBabel: echo "InChIstring"|babel -iinchi -  -oreport
0061 % or
0062 % (2) http://www.sisweb.com/referenc/tools/exactmass.htm
0063 % Please report any errors as these are critical for use of this script
0064 % with mass spec machines.
0065 %
0066 % Ronan Fleming 9 March 09  ronan.mt.fleming@gmail.com
0067 %               15 Sept 09  Support for non-natural isotope distributions
0068 
0069 if ~exist('isotopeAbundance','var')
0070     isotopeAbundance =1;
0071 end
0072 
0073 if ischar(formulae)
0074     tmp=formulae;
0075     formulae=[];
0076     formulae{1}=tmp;
0077 end
0078 
0079 if exist('isotopeAbundance','var')
0080     isotopeSensitive=1;
0081     if isnumeric(isotopeAbundance) || islogical(isotopeAbundance)
0082         if isotopeAbundance
0083             clear isotopeAbundance
0084             %Uses only the most naturally predominant isotope of each
0085             %element
0086             isotopeSensitive=1;
0087             i=1;
0088             %e.g. Carbon, all as C12
0089             isotopeAbundance{i,1}= 'C';
0090             isotopeAbundance{i,2}= 12;
0091             isotopeAbundance{i,3}= 1;
0092             i=i+1;
0093             isotopeAbundance{i,1}= 'C';
0094             isotopeAbundance{i,2}= 13;
0095             isotopeAbundance{i,3}= 0;
0096             i=i+1;
0097             isotopeAbundance{i,1}= 'C';
0098             isotopeAbundance{i,2}= 14;
0099             isotopeAbundance{i,3}= 0;
0100             i=i+1;
0101             %e.g. Hydrogen, all as H1
0102             isotopeAbundance{i,1}= 'H';
0103             isotopeAbundance{i,2}= 1;
0104             isotopeAbundance{i,3}= 1;
0105             i=i+1;
0106             %e.g. Oxygen, all as O16
0107             isotopeAbundance{i,1}= 'O';
0108             isotopeAbundance{i,2}= 16;
0109             isotopeAbundance{i,3}= 1;
0110             i=i+1;
0111             isotopeAbundance{i,1}= 'O';
0112             isotopeAbundance{i,2}= 17;
0113             isotopeAbundance{i,3}= 0;
0114             i=i+1;
0115             isotopeAbundance{i,1}= 'O';
0116             isotopeAbundance{i,2}= 18;
0117             isotopeAbundance{i,3}= 0;
0118             i=i+1;
0119             %e.g. Nitrogen, all as N14
0120             isotopeAbundance{i,1}= 'N';
0121             isotopeAbundance{i,2}= 14;
0122             isotopeAbundance{i,3}= 1;
0123             i=i+1;
0124             isotopeAbundance{i,1}= 'N';
0125             isotopeAbundance{i,2}= 15;
0126             isotopeAbundance{i,3}= 0;
0127             i=i+1;
0128             %e.g. Sulphur, all as S32 (94% naturally S32)
0129             isotopeAbundance{i,1}= 'S';
0130             isotopeAbundance{i,2}= 32;
0131             isotopeAbundance{i,3}= 1;
0132             i=i+1;
0133             isotopeAbundance{i,1}= 'S';
0134             isotopeAbundance{i,2}= 33;
0135             isotopeAbundance{i,3}= 0;
0136             i=i+1;
0137             isotopeAbundance{i,1}= 'S';
0138             isotopeAbundance{i,2}= 34;
0139             isotopeAbundance{i,3}= 0;
0140             i=i+1;
0141             isotopeAbundance{i,1}= 'S';
0142             isotopeAbundance{i,2}= 35;
0143             isotopeAbundance{i,3}= 0;
0144             i=i+1;
0145             %e.g. Magnesium, all as Mg24, (79 % naturally Mg24)
0146             isotopeAbundance{i,1}= 'Mg';
0147             isotopeAbundance{i,2}= 24;
0148             isotopeAbundance{i,3}= 1;
0149             i=i+1;
0150             isotopeAbundance{i,1}= 'Mg';
0151             isotopeAbundance{i,2}= 25;
0152             isotopeAbundance{i,3}= 0;
0153             i=i+1;
0154             isotopeAbundance{i,1}= 'Mg';
0155             isotopeAbundance{i,2}= 26;
0156             isotopeAbundance{i,3}= 0;
0157             i=i+1;
0158             %e.g. Magnesium, all as Mg24, (93% naturally K39)
0159             isotopeAbundance{i,1}= 'K';
0160             isotopeAbundance{i,2}= 39;
0161             isotopeAbundance{i,3}= 1;
0162             i=i+1;
0163             isotopeAbundance{i,1}= 'K';
0164             isotopeAbundance{i,2}= 40;
0165             isotopeAbundance{i,3}= 0;
0166             i=i+1;
0167             isotopeAbundance{i,1}= 'K';
0168             isotopeAbundance{i,2}= 41;
0169             isotopeAbundance{i,3}= 0;
0170             i=i+1;
0171             %e.g. Chlorine, all as Cl35 (75.78 naturally Cl35)
0172             isotopeAbundance{i,1}= 'Cl';
0173             isotopeAbundance{i,2}= 35;
0174             isotopeAbundance{i,3}= 1;
0175             i=i+1;
0176             isotopeAbundance{i,1}= 'Cl';
0177             isotopeAbundance{i,2}= 37;
0178             isotopeAbundance{i,3}= 0;
0179             i=i+1;
0180             %e.g. Calcium, all as Ca40 (96% naturally Ca40)
0181             isotopeAbundance{i,1}= 'Ca';
0182             isotopeAbundance{i,2}= 40;
0183             isotopeAbundance{i,3}= 1;
0184             i=i+1;
0185             isotopeAbundance{i,1}= 'Ca';
0186             isotopeAbundance{i,2}= 42;
0187             isotopeAbundance{i,3}= 0;
0188             i=i+1;
0189             isotopeAbundance{i,1}= 'Ca';
0190             isotopeAbundance{i,2}= 43;
0191             isotopeAbundance{i,3}= 0;
0192             i=i+1;
0193             isotopeAbundance{i,1}= 'Ca';
0194             isotopeAbundance{i,2}= 44;
0195             isotopeAbundance{i,3}= 0;
0196             i=i+1;
0197             isotopeAbundance{i,1}= 'Ca';
0198             isotopeAbundance{i,2}= 46;
0199             isotopeAbundance{i,3}= 0;
0200             i=i+1;
0201             isotopeAbundance{i,1}= 'Ca';
0202             isotopeAbundance{i,2}= 48;
0203             isotopeAbundance{i,3}= 0;
0204             i=i+1;
0205             % Zinc, all as Zn64 (48% naturally Zn64)
0206             isotopeAbundance{i,1}= 'Zn';
0207             isotopeAbundance{i,2}= 64;
0208             isotopeAbundance{i,3}= 1;
0209             i=i+1;
0210             isotopeAbundance{i,1}= 'Zn';
0211             isotopeAbundance{i,2}= 66;
0212             isotopeAbundance{i,3}= 0;
0213             i=i+1;
0214             isotopeAbundance{i,1}= 'Zn';
0215             isotopeAbundance{i,2}= 67;
0216             isotopeAbundance{i,3}= 0;
0217             i=i+1;
0218             isotopeAbundance{i,1}= 'Zn';
0219             isotopeAbundance{i,2}= 68;
0220             isotopeAbundance{i,3}= 0;
0221             i=i+1;
0222             isotopeAbundance{i,1}= 'Zn';
0223             isotopeAbundance{i,2}= 70;
0224             isotopeAbundance{i,3}= 0;
0225             i=i+1;
0226             % Copper, all as Cu63 (69% naturally Cu63)
0227             isotopeAbundance{i,1}= 'Cu';
0228             isotopeAbundance{i,2}= 63;
0229             isotopeAbundance{i,3}= 0;
0230             i=i+1;
0231             isotopeAbundance{i,1}= 'Cu';
0232             isotopeAbundance{i,2}= 65;
0233             isotopeAbundance{i,3}= 0;
0234             i=i+1;
0235             % Molybdenum, all as Mo98 (24% naturally Mo98)
0236             isotopeAbundance{i,1}= 'Mo';
0237             isotopeAbundance{i,2}= 92;
0238             isotopeAbundance{i,3}= 0;
0239             i=i+1;
0240             isotopeAbundance{i,1}= 'Mo';
0241             isotopeAbundance{i,2}= 94;
0242             isotopeAbundance{i,3}= 0;
0243             i=i+1;
0244             isotopeAbundance{i,1}= 'Mo';
0245             isotopeAbundance{i,2}= 95;
0246             isotopeAbundance{i,3}= 0;
0247             i=i+1;
0248             isotopeAbundance{i,1}= 'Mo';
0249             isotopeAbundance{i,2}= 96;
0250             isotopeAbundance{i,3}= 0;
0251             i=i+1;
0252             isotopeAbundance{i,1}= 'Mo';
0253             isotopeAbundance{i,2}= 97;
0254             isotopeAbundance{i,3}= 0;
0255             i=i+1;
0256             isotopeAbundance{i,1}= 'Mo';
0257             isotopeAbundance{i,2}= 98;
0258             isotopeAbundance{i,3}= 1;
0259             i=i+1;
0260             isotopeAbundance{i,1}= 'Mo';
0261             isotopeAbundance{i,2}= 100;
0262             isotopeAbundance{i,3}= 0;
0263             i=i+1;
0264             % Phosphorus
0265             isotopeAbundance{i,1}= 'P';
0266             isotopeAbundance{i,2}= 31;
0267             isotopeAbundance{i,3}= 1;
0268             i=i+1;
0269             %Sodium
0270             isotopeAbundance{i,1}= 'Na';
0271             isotopeAbundance{i,2}= 23;
0272             isotopeAbundance{i,3}= 1;
0273             i=i+1;
0274             %Iron
0275             isotopeAbundance{i,1}= 'Fe';
0276             isotopeAbundance{i,2}= 54;
0277             isotopeAbundance{i,3}= 0;
0278             i=i+1;
0279             isotopeAbundance{i,1}= 'Fe';
0280             isotopeAbundance{i,2}= 56;
0281             isotopeAbundance{i,3}= 1;
0282             i=i+1;
0283             isotopeAbundance{i,1}= 'Fe';
0284             isotopeAbundance{i,2}= 57;
0285             isotopeAbundance{i,3}= 0;
0286             i=i+1;
0287             isotopeAbundance{i,1}= 'Fe';
0288             isotopeAbundance{i,2}= 58;
0289             isotopeAbundance{i,3}= 0;
0290             i=i+1;
0291             %Iodine
0292             isotopeAbundance{i,1}= 'I';
0293             isotopeAbundance{i,2}= 127;
0294             isotopeAbundance{i,3}= 1;
0295             i=i+1;
0296         end
0297     end
0298 else
0299     isotopeSensitive=0;
0300 end
0301 
0302 
0303 allBiologicalElements={'C','O','P','N','S','H','Mg','Na','K','Cl','Ca','Zn','Fe','Cu','Mo','I'};
0304 
0305 atomicWeights=parse_Atomic_Weights_and_Isotopic_Compositions_for_All_Elements;
0306 
0307 M=zeros(length(formulae),1);
0308 
0309 for n=1:length(formulae)
0310     %molecular formula
0311     formula=formulae{n};
0312     for a=1:length(allBiologicalElements)
0313         %number of atoms in element
0314         N=numAtomsOfElementInFormula(formula,allBiologicalElements{a});
0315         if N~=0
0316             %             fprintf('%d\t%s\n',N,allBiologicalElements{a})
0317             %index of element
0318             ind=strmatch(allBiologicalElements{a}, atomicWeights.AtomicSymbol, 'exact');
0319             if isotopeSensitive
0320                 indIso=strmatch(allBiologicalElements{a}, isotopeAbundance(:,1), 'exact');
0321                 if length(ind)~=length(indIso)
0322                     fprintf('%s\n',['Isotopic distribution for ' allBiologicalElements{a} ' is incomplete'])
0323                 end
0324                 weight=0;
0325                 for q = 1:length(ind)
0326                     weight = weight + isotopeAbundance{indIso(q),3}*atomicWeights.data(ind(q)).RelativeAtomicMass;
0327                 end
0328             else
0329                 if length(ind)>1
0330                     %uses the first isotope by default
0331                     weight=atomicWeights.data(ind(1)).StandardAtomicWeight;
0332                 else
0333                     weight=atomicWeights.data(ind).StandardAtomicWeight;
0334                 end
0335             end
0336             %mass contribution from this element
0337             M(n)=M(n)+N*weight;
0338         end
0339     end
0340 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003