OpenMS  2.9.1
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 
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 
122  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 
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:
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
Singleton that stores elements and isotopes.
Definition: ElementDB.h:70
std::unordered_map< unsigned int, const Element * > atomic_numbers_
Definition: ElementDB.h:163
IsotopeDistribution parseIsotopeDistribution_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
void addElementToMaps_(const std::string &name, const std::string &symbol, const unsigned int an, const Element *e)
add element objects to documentation maps
ElementDB(const ElementDB &&db)=delete
std::unordered_map< std::string, const Element * > symbols_
Definition: ElementDB.h:161
const Element * getElement(unsigned int atomic_number) const
returns a pointer to the element of atomic number; if no element is found 0 is returned
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)
build element objects from given abundances, masses, name, symbol, and atomic number
ElementDB & operator=(const ElementDB &db)=delete
ElementDB(const ElementDB &db)=delete
const std::unordered_map< unsigned int, const Element * > & getAtomicNumbers() const
returns a hashmap that contains atomic numbers mapped to pointers of the elements
bool hasElement(unsigned int atomic_number) const
returns true if the db contains an element with the given atomic_number
void addElement(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, bool replace_existing)
const std::unordered_map< std::string, const Element * > & getNames() const
returns a hashmap that contains names mapped to pointers to the elements
double calculateMonoWeight_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
const Element * getElement(const std::string &name) const
static ElementDB * getInstance()
bool hasElement(const std::string &name) const
returns true if the db contains an element with the given name
void storeElements_()
constructs element objects
double calculateAvgWeight_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
const std::unordered_map< std::string, const Element * > & getSymbols() const
returns a hashmap that contains symbols mapped to pointers to the elements
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)
constructs isotope objects
std::unordered_map< std::string, const Element * > names_
Definition: ElementDB.h:159
Representation of an element.
Definition: Element.h:58
Definition: IsotopeDistribution.h:65
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48