OpenMS
Loading...
Searching...
No Matches
Adduct.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/OpenMSConfig.h>
15
16#include <functional>
17
18namespace OpenMS
19{
20
86 class OPENMS_DLLAPI Adduct
87 {
88public:
89
91 typedef std::vector<Adduct> AdductsType;
92
99
109 Adduct(Int charge);
110
129 Adduct(Int charge, Int amount, double singleMass, const std::string& formula, double log_prob, double rt_shift, const std::string& label = "");
130
141 Adduct operator*(const Int m) const;
142
156
165 void operator+=(const Adduct& rhs);
166
167
170 friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Adduct& a);
171
177 friend OPENMS_DLLAPI bool operator==(const Adduct& a, const Adduct& b);
178
180
182 const Int& getCharge() const;
183
188 void setCharge(const Int& charge);
189
191 const Int& getAmount() const;
192
198 void setAmount(const Int& amount);
199
201 const double& getSingleMass() const;
202
207 void setSingleMass(const double& singleMass);
208
210 const double& getLogProb() const;
211
217 void setLogProb(const double& log_prob);
218
221 const std::string& getFormula() const;
222
231 void setFormula(const std::string& formula);
232
235 const double& getRTShift() const;
236
238 const std::string& getLabel() const;
239
253 std::string toAdductString(const std::string& ion_string, const Int& charge);
254
276 static std::string toAdductString(const std::string& ion_string, const Int& charge, Int mol_multiplier);
277 //}
278
279private:
282 double singleMass_;
283 double log_prob_;
284 std::string formula_;
285 double rt_shift_;
286 std::string label_;
287
290 std::string checkFormula_(const std::string& formula);
291
292 };
293
294} // namespace OpenMS
295
296// Hash function specialization for Adduct.
297//
298// Note: only the fields compared by operator== (charge, amount, singleMass,
299// log_prob, formula) feed into the hash. rt_shift and label are deliberately
300// excluded so two Adducts that compare equal also hash equal.
301namespace std
302{
303 template<>
304 struct hash<OpenMS::Adduct>
305 {
306 std::size_t operator()(const OpenMS::Adduct& a) const noexcept
307 {
308 std::size_t seed = OpenMS::hash_int(a.getCharge());
309 OpenMS::hash_combine(seed, OpenMS::hash_int(a.getAmount()));
310 OpenMS::hash_combine(seed, OpenMS::hash_float(a.getSingleMass()));
311 OpenMS::hash_combine(seed, OpenMS::hash_float(a.getLogProb()));
312 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(a.getFormula()));
313 return seed;
314 }
315 };
316} // namespace std
One elementary adduct contribution to a feature's ionization state.
Definition Adduct.h:87
const double & getRTShift() const
RT shift induced by one entity (seconds). Non-zero only for adducts attached prior to ESI (e....
void setLogProb(const double &log_prob)
Set the log-prior on observing this adduct.
Adduct operator+(const Adduct &rhs)
Sum two Adducts that describe the same chemical entity.
Adduct()
Default constructor. All numeric fields zero-initialised; formula and label empty....
std::string label_
free-form tag (e.g. heavy-isotope label name)
Definition Adduct.h:286
double log_prob_
log-prior on observing this adduct
Definition Adduct.h:283
void setCharge(const Int &charge)
Set the per-entity charge.
Adduct operator*(const Int m) const
Multiply the stoichiometric amount by an integer factor.
friend bool operator==(const Adduct &a, const Adduct &b)
Equality on charge, amount, singleMass, log_prob, and formula. Deliberately ignores rt_shift and labe...
void setFormula(const std::string &formula)
Set the chemical formula of one entity. The input is parsed as an EmpiricalFormula and re-emitted in ...
void setAmount(const Int &amount)
Set the stoichiometric count. Logs a warning on negative values but accepts them.
const double & getSingleMass() const
Monoisotopic mass of one entity (Dalton).
std::string checkFormula_(const std::string &formula)
std::string toAdductString(const std::string &ion_string, const Int &charge)
Render ion_string + charge as a canonical adduct string, assuming a monomer (n=1).
const Int & getAmount() const
Stoichiometric count of this adduct in the ion.
Adduct(Int charge, Int amount, double singleMass, const std::string &formula, double log_prob, double rt_shift, const std::string &label="")
Construct with all fields populated.
const Int & getCharge() const
Per-entity charge; +1 for typical cation adducts (Na+, H+).
void operator+=(const Adduct &rhs)
In-place version of operator+. Same precondition (matching formulas).
Adduct(Int charge)
Construct with only the per-entity charge set.
const std::string & getLabel() const
Free-form label (typically a heavy-isotope tag).
double rt_shift_
RT shift induced by one entity (s); non-zero only for pre-ESI labels.
Definition Adduct.h:285
friend std::ostream & operator<<(std::ostream &os, const Adduct &a)
std::vector< Adduct > AdductsType
Convenience typedef for a list of Adducts (used by feature deconvolution).
Definition Adduct.h:91
void setSingleMass(const double &singleMass)
Set the monoisotopic mass of one entity.
std::string formula_
chemical formula of one entity (EmpiricalFormula-parseable, canonicalised)
Definition Adduct.h:284
static std::string toAdductString(const std::string &ion_string, const Int &charge, Int mol_multiplier)
Render ion_string + charge as a canonical adduct string, with an explicit n-mer multiplier.
double singleMass_
monoisotopic mass of one entity (Da)
Definition Adduct.h:282
const double & getLogProb() const
Log-prior on observing this adduct.
Int amount_
stoichiometric count of this entity
Definition Adduct.h:281
Int charge_
per-entity charge (e.g. +1 for Na+)
Definition Adduct.h:280
const std::string & getFormula() const
Chemical formula of one entity (canonicalised by EmpiricalFormula, e.g. "H2O" — not "OH2").
int Int
Signed integer type.
Definition Types.h:72
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
std::size_t hash_float(T value) noexcept
Hash for a floating point type (float or double).
Definition HashUtils.h:142
std::size_t fnv1a_hash_string(const std::string &s) noexcept
FNV-1a hash for a string.
Definition HashUtils.h:70
STL namespace.
std::size_t operator()(const OpenMS::Adduct &a) const noexcept
Definition Adduct.h:306