OpenMS
Loading...
Searching...
No Matches
ElementDB.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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
20namespace OpenMS
21{
22 class Element;
23
44 class OPENMS_DLLAPI ElementDB
45 {
46public:
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
88 void addElement(const std::string& name,
89 const std::string& symbol,
90 const unsigned int an,
91 const std::map<unsigned int, double>& abundance,
92 const std::map<unsigned int, double>& mass,
93 bool replace_existing);
95
100 bool hasElement(const std::string& name) const;
101
103 bool hasElement(unsigned int atomic_number) const;
105
106protected:
107
111 IsotopeDistribution parseIsotopeDistribution_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
112
115 double calculateAvgWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
116
119 double calculateMonoWeight_(const std::map<unsigned int, double>& abundance, const std::map<unsigned int, double>& mass);
120
123
125 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);
126
128 void addElementToMaps_(const std::string& name, const std::string& symbol, const unsigned int an, std::unique_ptr<const Element> e);
129
131 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);
132
135 void clear_();
136
137 std::unordered_map<std::string, const Element*> names_;
138
139 std::unordered_map<std::string, const Element*> symbols_;
140
141 std::unordered_map<unsigned int, const Element*> atomic_numbers_;
142
143private:
146 ElementDB(const ElementDB& db) = delete;
147 ElementDB(const ElementDB&& db) = delete;
148 ElementDB& operator=(const ElementDB& db) = delete;
149
150 };
151
152} // namespace OpenMS
Singleton that stores elements and isotopes.
Definition ElementDB.h:45
const std::unordered_map< std::string, const Element * > & getSymbols() const
returns a hashmap that contains symbols mapped to pointers to the elements
std::unordered_map< unsigned int, const Element * > atomic_numbers_
Definition ElementDB.h:141
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:139
const Element * getElement(const std::string &name) const
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(const ElementDB &db)=delete
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)
double calculateMonoWeight_(const std::map< unsigned int, double > &abundance, const std::map< unsigned int, double > &mass)
ElementDB & operator=(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
bool hasElement(const std::string &name) const
returns true if the db contains an element with the given name
static ElementDB * getInstance()
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< unsigned int, const Element * > & getAtomicNumbers() const
returns a hashmap that contains atomic numbers mapped to pointers of 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:137
const std::unordered_map< std::string, const Element * > & getNames() const
returns a hashmap that contains names mapped to pointers to the elements
Representation of an element.
Definition Element.h:34
Definition IsotopeDistribution.h:40
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19