OpenMS  3.0.0
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 <unordered_map>
43 #include <string>
44 
45 namespace OpenMS
46 {
47  class Element;
48 
69  class OPENMS_DLLAPI ElementDB
70  {
71 public:
72 
76  static ElementDB* getInstance();
79 
81  const std::unordered_map<std::string, const Element*>& getNames() const;
82 
84  const std::unordered_map<std::string, const Element*>& getSymbols() const;
85 
87  const std::unordered_map<unsigned int, const Element*>& getAtomicNumbers() const;
88 
93  const Element* getElement(const std::string& name) const;
94 
96  const Element* getElement(unsigned int atomic_number) const;
97 
110  void addElement(const std::string& name,
111  const std::string& symbol,
112  const unsigned int an,
113  const std::map<unsigned int, double>& abundance,
114  const std::map<unsigned int, double>& mass,
115  bool replace_existing);
117 
121  bool hasElement(const std::string& name) const;
123 
125  bool hasElement(unsigned int atomic_number) const;
127 
128 protected:
129 
133  IsotopeDistribution parseIsotopeDistribution_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
134 
137  double calculateAvgWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
138 
141  double calculateMonoWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
142 
144  void storeElements_();
145 
147  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);
148 
150  void addElementToMaps_(const std::string& name, const std::string& symbol, const unsigned int an, const Element* e);
151 
153  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);
154 
157  void clear_();
158 
159  std::unordered_map<std::string, const Element*> names_;
160 
161  std::unordered_map<std::string, const Element*> symbols_;
162 
163  std::unordered_map<unsigned int, const Element*> atomic_numbers_;
164 
165 private:
166  ElementDB();
167  ~ElementDB();
168  ElementDB(const ElementDB& db) = delete;
169  ElementDB(const ElementDB&& db) = delete;
170  ElementDB& operator=(const ElementDB& db) = delete;
171 
172  };
173 
174 } // namespace OpenMS
OpenMS::ElementDB
Singleton that stores elements and isotopes.
Definition: ElementDB.h:69
OpenMS::Element
Representation of an element.
Definition: Element.h:57
OpenMS::ElementDB::atomic_numbers_
std::unordered_map< unsigned int, const Element * > atomic_numbers_
Definition: ElementDB.h:163
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
IsotopeDistribution.h
OpenMS::IsotopeDistribution
Definition: IsotopeDistribution.h:64
OpenMS::ElementDB::names_
std::unordered_map< std::string, const Element * > names_
Definition: ElementDB.h:159
String.h
OpenMS::ElementDB::symbols_
std::unordered_map< std::string, const Element * > symbols_
Definition: ElementDB.h:161