mscore/chemistry/
formulas.rs

1use crate::chemistry::constants::MASS_PROTON;
2
3/// convert 1 over reduced ion mobility (1/k0) to CCS
4///
5/// Arguments:
6///
7/// * `one_over_k0` - 1 over reduced ion mobility (1/k0)
8/// * `charge` - charge state of the ion
9/// * `mz` - mass-over-charge of the ion
10/// * `mass_gas` - mass of drift gas (N2)
11/// * `temp` - temperature of the drift gas in C°
12/// * `t_diff` - factor to translate from C° to K
13///
14/// Returns:
15///
16/// * `ccs` - collision cross-section
17///
18/// # Examples
19///
20/// ```
21/// use mscore::chemistry::formulas::one_over_reduced_mobility_to_ccs;
22///
23/// let ccs = one_over_reduced_mobility_to_ccs(0.5, 1000.0, 2, 28.013, 31.85, 273.15);
24/// assert_eq!(ccs, 201.64796734428452);
25/// ```
26pub fn one_over_reduced_mobility_to_ccs(
27    one_over_k0: f64,
28    mz: f64,
29    charge: u32,
30    mass_gas: f64,
31    temp: f64,
32    t_diff: f64,
33) -> f64 {
34    let summary_constant = 18509.8632163405;
35    let reduced_mobility = 1.0 / one_over_k0;
36    let reduced_mass = (mz * charge as f64 * mass_gas) / (mz * charge as f64 + mass_gas);
37    summary_constant * charge as f64 / (reduced_mass * (temp + t_diff)).sqrt() / reduced_mobility
38}
39
40
41/// convert CCS to 1 over reduced ion mobility (1/k0)
42///
43/// Arguments:
44///
45/// * `ccs` - collision cross-section
46/// * `charge` - charge state of the ion
47/// * `mz` - mass-over-charge of the ion
48/// * `mass_gas` - mass of drift gas (N2)
49/// * `temp` - temperature of the drift gas in C°
50/// * `t_diff` - factor to translate from C° to K
51///
52/// Returns:
53///
54/// * `one_over_k0` - 1 over reduced ion mobility (1/k0)
55///
56/// # Examples
57///
58/// ```
59/// use mscore::chemistry::formulas::ccs_to_one_over_reduced_mobility;
60///
61/// let k0 = ccs_to_one_over_reduced_mobility(806.5918693771381, 1000.0, 2, 28.013, 31.85, 273.15);
62/// assert_eq!(k0, 2.0);
63/// ```
64pub fn ccs_to_one_over_reduced_mobility(
65    ccs: f64,
66    mz: f64,
67    charge: u32,
68    mass_gas: f64,
69    temp: f64,
70    t_diff: f64,
71) -> f64 {
72    let summary_constant = 18509.8632163405;
73    let reduced_mass = (mz * charge as f64 * mass_gas) / (mz * charge as f64 + mass_gas);
74    ((reduced_mass * (temp + t_diff)).sqrt() * ccs) / (summary_constant * charge as f64)
75}
76
77/// calculate the m/z of an ion
78///
79/// Arguments:
80///
81/// * `mono_mass` - monoisotopic mass of the ion
82/// * `charge` - charge state of the ion
83///
84/// Returns:
85///
86/// * `mz` - mass-over-charge of the ion
87///
88/// # Examples
89///
90/// ```
91/// use mscore::chemistry::formulas::calculate_mz;
92///
93/// let mz = calculate_mz(1000.0, 2);
94/// assert_eq!(mz, 501.007276466621);
95/// ```
96pub fn calculate_mz(monoisotopic_mass: f64, charge: i32) -> f64 {
97    (monoisotopic_mass + charge as f64 * MASS_PROTON) / charge as f64
98}