OpenMS
ElementDB.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2022.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Andreas Bertsch, Timo Sachsenberg, Chris Bielow, Jang Jang Jin$
33 // --------------------------------------------------------------------------
34 //
35 
36 #pragma once
37 
40 
41 #include <map>
42 #include <memory>
43 #include <unordered_map>
44 #include <string>
45 
46 namespace OpenMS
47 {
48  class Element;
49 
70  class OPENMS_DLLAPI ElementDB
71  {
72 public:
73 
77  static ElementDB* getInstance();
80 
82  const std::unordered_map<std::string, const Element*>& getNames() const;
83 
85  const std::unordered_map<std::string, const Element*>& getSymbols() const;
86 
88  const std::unordered_map<unsigned int, const Element*>& getAtomicNumbers() const;
89 
94  const Element* getElement(const std::string& name) const;
95 
97  const Element* getElement(unsigned int atomic_number) const;
98 
111  void addElement(const std::string& name,
112  const std::string& symbol,
113  const unsigned int an,
114  const std::map<unsigned int, double>& abundance,
115  const std::map<unsigned int, double>& mass,
116  bool replace_existing);
118 
122  bool hasElement(const std::string& name) const;
124 
126  bool hasElement(unsigned int atomic_number) const;
128 
129 protected:
130 
134  IsotopeDistribution parseIsotopeDistribution_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
135 
138  double calculateAvgWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
139 
142  double calculateMonoWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
143 
145  void storeElements_();
146 
148  void buildElement_(const std::string& name, const std::string& symbol, const unsigned int an, const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
149 
151  void addElementToMaps_(const std::string& name, const std::string& symbol, const unsigned int an, std::unique_ptr<const Element> e);
152 
154  void storeIsotopes_(const std::string& name, const std::string& symbol, const unsigned int an, const std::map<unsigned int, double>& Z_to_mass, const IsotopeDistribution& isotopes);
155 
158  void clear_();
159 
160  std::unordered_map<std::string, const Element*> names_;
161 
162  std::unordered_map<std::string, const Element*> symbols_;
163 
164  std::unordered_map<unsigned int, const Element*> atomic_numbers_;
165 
166 private:
167  ElementDB();
168  ~ElementDB();
169  ElementDB(const ElementDB& db) = delete;
170  ElementDB(const ElementDB&& db) = delete;
171  ElementDB& operator=(const ElementDB& db) = delete;
172 
173  };
174 
175 } // namespace OpenMS
std::unordered_map< std::string, const Element * > symbols_
Definition: ElementDB.h:162
std::unordered_map< std::string, const Element * > names_
Definition: ElementDB.h:160
Definition: IsotopeDistribution.h:64
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::unordered_map< unsigned int, const Element * > atomic_numbers_
Definition: ElementDB.h:164
Representation of an element.
Definition: Element.h:57
Singleton that stores elements and isotopes.
Definition: ElementDB.h:70