OpenMS  2.7.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-2021.
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 
42 
43 #include <map>
44 #include <string>
45 
46 namespace OpenMS
47 {
48 
69  class OPENMS_DLLAPI ElementDB
70  {
71 public:
72 
78  static const ElementDB* getInstance();
79 
81  const std::map<std::string, const Element *> & getNames() const;
82 
84  const std::map<std::string, const Element *> & getSymbols() const;
85 
87  const std::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 
99 
104  bool hasElement(const std::string& name) const;
105 
107  bool hasElement(unsigned int atomic_number) const;
109 
110 protected:
111 
112  /*_ parses a Histogram given as a OpenMS String and return the distribution
113 
114  @throw throws exception ParseError
115  */
116  IsotopeDistribution parseIsotopeDistribution_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
117 
118  /*_ calculates the average weight based on isotope abundance and mass
119  */
120  double calculateAvgWeight_(const std::map<unsigned int, double> & abundance, const std::map<unsigned int, double> & mass);
121 
122  /*_ calculates the mono weight based on the smallest isotope mass
123  */
124  double calculateMonoWeight_(const std::map<unsigned int, double> & Z_to_mass);
125 
126  // constructs element objects
128 
129  // build element objects from given abundances, masses, name, symbol, and atomic number
130  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);
131 
132  // add element objects to documentation maps
133  void addElementToMaps_(const std::string& name, const std::string& symbol, const unsigned int an, const Element* e);
134 
135  // constructs isotope objects
136  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);
137 
138  /*_ resets all containers
139  */
140  void clear_();
141 
142  std::map<std::string, const Element *> names_;
143 
144  std::map<std::string, const Element *> symbols_;
145 
146  std::map<unsigned int, const Element *> atomic_numbers_;
147 
148 private:
151  ElementDB(const ElementDB& db) = delete;
152  ElementDB(const ElementDB&& db) = delete;
153  ElementDB& operator=(const ElementDB& db) = delete;
154 
155  };
156 
157 } // namespace OpenMS
Singleton that stores elements.
Definition: ElementDB.h:70
double calculateMonoWeight_(const std::map< unsigned int, double > &Z_to_mass)
IsotopeDistribution parseIsotopeDistribution_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
std::map< std::string, const Element * > names_
Definition: ElementDB.h:142
void addElementToMaps_(const std::string &name, const std::string &symbol, const unsigned int an, const Element *e)
ElementDB(const ElementDB &&db)=delete
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)
ElementDB & operator=(const ElementDB &db)=delete
const std::map< std::string, const Element * > & getNames() const
returns a hashmap that contains names mapped to pointers to the elements
ElementDB(const ElementDB &db)=delete
bool hasElement(unsigned int atomic_number) const
returns true if the db contains an element with the given atomic_number
std::map< std::string, const Element * > symbols_
Definition: ElementDB.h:144
const Element * getElement(const std::string &name) const
bool hasElement(const std::string &name) const
returns true if the db contains an element with the given name
const std::map< unsigned int, const Element * > & getAtomicNumbers() const
returns a hashmap that contains atomic numbers mapped to pointers of the elements
double calculateAvgWeight_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
static const ElementDB * getInstance()
const std::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)
std::map< unsigned int, const Element * > atomic_numbers_
Definition: ElementDB.h:146
Representation of an element.
Definition: Element.h:56
Definition: IsotopeDistribution.h:65
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47