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