ProteoWizard
Ion.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2005 Louis Warschaw Prostate Cancer Center
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#ifndef _ION_HPP_
25#define _ION_HPP_
26
27
28#include "Chemistry.hpp"
29#include <stdexcept>
30
31
32namespace pwiz {
33namespace chemistry {
34
35
36namespace Ion
37{
38 /*!
39 * Converts the m/z of an ion to a neutral mass.
40 * @param[in] mz The m/z to convert.
41 * @param[in] protonDelta The number of extra protons attached to the ion.
42 * @param[in] electronDelta The number of extra electrons attached to the ion.
43 * @param[in] neutronDelta The number of extra neutrons attached to the ion.
44 * \pre protonDelta != electronDelta
45 */
46 inline double neutralMass(double mz, int protonDelta, int electronDelta = 0, int neutronDelta = 0)
47 {
48 int charge = protonDelta - electronDelta;
49 return charge == 0 ? throw std::invalid_argument("[Ion::neutralMass()] m/z with protonDelta=electronDelta is impossible")
50 : mz * charge - ((Proton * protonDelta) +
51 (Electron * electronDelta) +
52 (Neutron * neutronDelta));
53 }
54
55 /*!
56 * Converts a neutral mass to an ionized mass.
57 * @param[in] neutralMass The neutral mass to ionize.
58 * @param[in] protonDelta The number of extra protons to attach to the ion.
59 * @param[in] electronDelta The number of extra electrons to attach to the ion.
60 * @param[in] neutronDelta The number of extra neutrons to attach to the ion.
61 * \pre protonDelta != electronDelta
62 */
63 inline double ionMass(double neutralMass, int protonDelta, int electronDelta = 0, int neutronDelta = 0)
64 {
65 return neutralMass + (Proton * protonDelta) +
66 (Electron * electronDelta) +
67 (Neutron * neutronDelta);
68 }
69
70 /*!
71 * Converts a neutral mass to an m/z.
72 * @param[in] neutralMass The neutral mass to ionize.
73 * @param[in] protonDelta The number of extra protons to attach to the ion.
74 * @param[in] electronDelta The number of extra electrons to attach to the ion.
75 * @param[in] neutronDelta The number of extra neutrons to attach to the ion.
76 * \pre protonDelta != electronDelta
77 */
78 inline double mz(double neutralMass, int protonDelta, int electronDelta = 0, int neutronDelta = 0)
79 {
80 int z = protonDelta - electronDelta;
81 double m = ionMass(neutralMass, protonDelta, electronDelta, neutronDelta);
82 return z == 0 ? throw std::invalid_argument("[Ion::mz()] m/z with protonDelta=electronDelta is impossible")
83 : m / z;
84 }
85}
86
87
88} // namespace chemistry
89} // namespace pwiz
90
91
92#endif // _ION_HPP_
93
double ionMass(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition Ion.hpp:63
double neutralMass(double mz, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition Ion.hpp:46
double mz(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition Ion.hpp:78
const double Electron
the mass of an electron in unified atomic mass units
Definition Chemistry.hpp:47
const double Proton
the mass of a proton in unified atomic mass units
Definition Chemistry.hpp:41
const double Neutron
the mass of a neutron in unified atomic mass units
Definition Chemistry.hpp:44