n2p2 - A neural network potential package
ElementMap.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef ELEMENTMAP_H
18#define ELEMENTMAP_H
19
20#include <cstddef> // std::size_t
21#include <map> // std::map
22#include <string> // std::string
23#include <vector> // std::vector
24
25namespace nnp
26{
27
30{
31public:
37 std::string operator[](std::size_t const index) const;
43 std::size_t operator[](std::string const symbol) const;
48 std::size_t size() const;
53 std::string getElementsString() const;
59 std::size_t index(std::string const& symbol) const;
65 std::string symbol(std::size_t const index) const;
71 std::size_t atomicNumber(std::size_t index) const;
82 std::size_t registerElements(std::string const& elementLine);
85 void deregisterElements();
91 static std::string symbolFromAtomicNumber(
92 std::size_t const atomicNumber);
98 static std::size_t atomicNumber(std::string const& symbol);
103 std::vector<std::string> info() const;
104
105private:
107 std::map<std::string, std::size_t> forwardMap;
109 std::map<std::size_t, std::string> reverseMap;
111 static std::string const knownElements[];
112
122 static bool compareAtomicNumber(std::string const& symbol1,
123 std::string const& symbol2);
124};
125
127// Inlined function definitions //
129
130inline std::string ElementMap::operator[](std::size_t const index) const
131{
132 return symbol(index);
133}
134
135inline std::size_t ElementMap::operator[](std::string const symbol) const
136{
137 return index(symbol);
138}
139
140inline std::size_t ElementMap::size() const
141{
142 return forwardMap.size();
143}
144
145inline std::size_t ElementMap::atomicNumber(std::size_t index) const
146{
147 return atomicNumber(symbol(index));
148}
149
150inline bool ElementMap::compareAtomicNumber(std::string const& symbol1,
151 std::string const& symbol2)
152{
153 return atomicNumber(symbol1) < atomicNumber(symbol2);
154}
155
156}
157
158#endif
Contains element map.
Definition: ElementMap.h:30
std::size_t index(std::string const &symbol) const
Get index of given element.
Definition: ElementMap.cpp:71
std::size_t registerElements(std::string const &elementLine)
Extract all elements and store in element map.
Definition: ElementMap.cpp:36
std::map< std::string, std::size_t > forwardMap
Map of elements present and corresponding index number.
Definition: ElementMap.h:107
std::map< std::size_t, std::string > reverseMap
Reverse element map.
Definition: ElementMap.h:109
std::string operator[](std::size_t const index) const
Overload [] operator for index search.
Definition: ElementMap.h:130
std::vector< std::string > info() const
Get map information as a vector of strings.
Definition: ElementMap.cpp:125
std::size_t size() const
Get element map size.
Definition: ElementMap.h:140
static std::string symbolFromAtomicNumber(std::size_t const atomicNumber)
Get element symbol from atomic number.
Definition: ElementMap.cpp:106
void deregisterElements()
Clear element map.
Definition: ElementMap.cpp:81
std::string getElementsString() const
Get sorted list of elements in one string (space separated).
Definition: ElementMap.cpp:56
static bool compareAtomicNumber(std::string const &symbol1, std::string const &symbol2)
Check if arguments are sorted according to atomic number.
Definition: ElementMap.h:150
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
Definition: ElementMap.h:145
static std::string const knownElements[]
List of element symbols (e.g. "He" for Helium).
Definition: ElementMap.h:111
std::string symbol(std::size_t const index) const
Get element symbol for given element index.
Definition: ElementMap.cpp:76
Definition: Atom.h:29