OpenMS
ElementDB.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Andreas Bertsch, Timo Sachsenberg, Chris Bielow, Jang Jang Jin$
7 // --------------------------------------------------------------------------
8 //
9 
10 #pragma once
11 
14 
15 #include <map>
16 #include <memory>
17 #include <unordered_map>
18 #include <string>
19 
20 namespace OpenMS
21 {
22  class Element;
23 
44  class OPENMS_DLLAPI ElementDB
45  {
46 public:
47 
54 
56  const std::unordered_map<std::string, const Element*>& getNames() const;
57 
59  const std::unordered_map<std::string, const Element*>& getSymbols() const;
60 
62  const std::unordered_map<unsigned int, const Element*>& getAtomicNumbers() const;
63 
68  const Element* getElement(const std::string& name) const;
69 
71  const Element* getElement(unsigned int atomic_number) const;
72 
85  void addElement(const std::string& name,
86  const std::string& symbol,
87  const unsigned int an,
88  const std::map<unsigned int, double>& abundance,
89  const std::map<unsigned int, double>& mass,
90  bool replace_existing);
92 
97  bool hasElement(const std::string& name) const;
98 
100  bool hasElement(unsigned int atomic_number) const;
102 
103 protected:
104 
108  IsotopeDistribution parseIsotopeDistribution_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
109 
112  double calculateAvgWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
113 
116  double calculateMonoWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
117 
120 
122  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);
123 
125  void addElementToMaps_(const std::string& name, const std::string& symbol, const unsigned int an, std::unique_ptr<const Element> e);
126 
128  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);
129 
132  void clear_();
133 
134  std::unordered_map<std::string, const Element*> names_;
135 
136  std::unordered_map<std::string, const Element*> symbols_;
137 
138  std::unordered_map<unsigned int, const Element*> atomic_numbers_;
139 
140 private:
143  ElementDB(const ElementDB& db) = delete;
144  ElementDB(const ElementDB&& db) = delete;
145  ElementDB& operator=(const ElementDB& db) = delete;
146 
147  };
148 
149 } // namespace OpenMS
Singleton that stores elements and isotopes.
Definition: ElementDB.h:45
std::unordered_map< unsigned int, const Element * > atomic_numbers_
Definition: ElementDB.h:138
IsotopeDistribution parseIsotopeDistribution_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
ElementDB(const ElementDB &&db)=delete
std::unordered_map< std::string, const Element * > symbols_
Definition: ElementDB.h:136
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
void addElementToMaps_(const std::string &name, const std::string &symbol, const unsigned int an, std::unique_ptr< const Element > e)
add element objects to documentation maps
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:134
Representation of an element.
Definition: Element.h:32
Definition: IsotopeDistribution.h:39
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22