OpenMS
Loading...
Searching...
No Matches
Element.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: Timo Sachsenberg $
6// $Authors: Andreas Bertsch $
7// --------------------------------------------------------------------------
8//
9
10#pragma once
11
15
16#include <functional>
17#include <string>
18
19#define OPENMS_CHEMISTRY_ELEMENT_NAME_DEFAULT "unknown"
20#define OPENMS_CHEMISTRY_ELEMENT_SYMBOL_DEFAULT "??"
21#define OPENMS_CHEMISTRY_ELEMENT_WEIGHT_DEFAULT 0.0
22#define OPENMS_CHEMISTRY_ELEMENT_ATOMICNUMBER_DEFAULT 0
23
24namespace OpenMS
25{
33 class OPENMS_DLLAPI Element
34 {
35public:
36
37
43
45 Element(const Element & element);
46
48 Element(const std::string & name,
49 const std::string & symbol,
50 unsigned int atomic_number,
51 double average_weight,
52 double mono_weight,
53 const IsotopeDistribution & isotopes);
54
56 virtual ~Element();
58
63 void setAtomicNumber(unsigned int atomic_number);
64
66 unsigned int getAtomicNumber() const;
67
69 void setAverageWeight(double weight);
70
72 double getAverageWeight() const;
73
75 void setMonoWeight(double weight);
76
78 double getMonoWeight() const;
79
82
85
87 void setName(const std::string & name);
88
90 const std::string & getName() const;
91
93 void setSymbol(const std::string & symbol);
94
96 const std::string & getSymbol() const;
98
103 Element & operator=(const Element & element);
105
110 bool operator==(const Element & element) const;
111
113 bool operator!=(const Element & element) const;
114
116 bool operator<(const Element & element) const;
118
120 friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Element & element);
121
122protected:
123
125 std::string name_;
126
128 std::string symbol_;
129
131 unsigned int atomic_number_;
132
135
138
141 };
142
143 OPENMS_DLLAPI std::ostream & operator<<(std::ostream &, const Element &);
144
145} // namespace OpenMS
146
147// Hash function specialization for Element
148namespace std
149{
150 template<>
151 struct hash<OpenMS::Element>
152 {
153 std::size_t operator()(const OpenMS::Element& e) const noexcept
154 {
155 std::size_t seed = OpenMS::fnv1a_hash_string(e.getName());
157 OpenMS::hash_combine(seed, OpenMS::hash_int(e.getAtomicNumber()));
158 OpenMS::hash_combine(seed, OpenMS::hash_float(e.getAverageWeight()));
159 OpenMS::hash_combine(seed, OpenMS::hash_float(e.getMonoWeight()));
160 OpenMS::hash_combine(seed, std::hash<OpenMS::IsotopeDistribution>{}(e.getIsotopeDistribution()));
161 return seed;
162 }
163 };
164} // namespace std
165
Representation of an element.
Definition Element.h:34
const std::string & getSymbol() const
returns symbol of the element
virtual ~Element()
destructor
bool operator==(const Element &element) const
equality operator
double getMonoWeight() const
returns the mono isotopic weight of the element
const std::string & getName() const
returns the name of the element
bool operator<(const Element &element) const
less operator
bool operator!=(const Element &element) const
inequality operator
std::string name_
name of the element
Definition Element.h:125
Element(const std::string &name, const std::string &symbol, unsigned int atomic_number, double average_weight, double mono_weight, const IsotopeDistribution &isotopes)
detailed constructor
IsotopeDistribution isotopes_
distribution of the isotopes (mass and natural frequency)
Definition Element.h:140
unsigned int getAtomicNumber() const
returns the unique atomic number
Element & operator=(const Element &element)
assignment operator
unsigned int atomic_number_
atomic number of the element
Definition Element.h:131
double getAverageWeight() const
returns the average weight of the element
void setName(const std::string &name)
set the name of the element
double average_weight_
average weight over all isotopes
Definition Element.h:134
Element()
default constructor
void setAverageWeight(double weight)
sets the average weight of the element
const IsotopeDistribution & getIsotopeDistribution() const
returns the isotope distribution of the element
Element(const Element &element)
copy constructor
void setSymbol(const std::string &symbol)
sets symbol of the element
friend std::ostream & operator<<(std::ostream &os, const Element &element)
writes the element to an output stream
void setAtomicNumber(unsigned int atomic_number)
sets unique atomic number
double mono_weight_
mono isotopic weight of the most frequent isotope
Definition Element.h:137
std::string symbol_
symbol of the element
Definition Element.h:128
void setIsotopeDistribution(const IsotopeDistribution &isotopes)
sets the isotope distribution of the element
void setMonoWeight(double weight)
sets the mono isotopic weight of the element
Definition IsotopeDistribution.h:40
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
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::Element &e) const noexcept
Definition Element.h:153