n2p2 - A neural network potential package
Settings.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 SETTINGS_H
18#define SETTINGS_H
19
20#include "Key.h"
21#include "ISettings.h"
22#include <cstddef> // std::size_t
23#include <fstream> // std::ofstream
24#include <map> // std::multimap
25#include <memory> // std::shared_ptr
26#include <string> // std::string
27#include <utility> // std::pair
28#include <vector> // std::vector
29
30namespace nnp
31{
32namespace settings
33{
34
35
37class Settings : public ISettings
38{
39public:
40
41 typedef std::multimap<std::string,
42 std::pair<std::string, std::size_t> > KeyMap;
43 typedef std::pair<KeyMap::const_iterator,
44 KeyMap::const_iterator> KeyRange;
45 typedef std::map<std::string,
46 std::shared_ptr<Key>> const KeywordList;
47
55 std::string operator[](std::string const& keyword) const;
62 std::size_t loadFile(
63 std::string const& fileName = "input.nn");
64 bool keywordExists(Key const& key,
65 bool const exact = false) const override;
77 bool keywordExists(
78 std::string const& keyword,
79 bool exact = false) const;
87 std::string keywordCheck(std::string const& keyword) const;
88 std::string getValue(Key const& key) const override;
98 std::string getValue(std::string const& keyword) const;
119 KeyRange getValues(std::string const& keyword) const;
124 std::vector<std::string> info() const;
129 std::vector<std::string> getSettingsLines() const;
136 std::ofstream* const& file,
137 std::map<std::size_t,
138 std::string> const& replacements
139 = {}) const;
140
141private:
143 std::vector<std::string> lines;
145 std::vector<std::string> log;
151 std::string fileName;
152
155 void readFile();
160 std::size_t parseLines();
166 std::pair<
167 std::size_t, std::size_t> sanityCheck();
168};
169
170}
171}
172
173#endif
Keyword properties.
Definition: Key.h:18
Reads and analyzes settings file and stores parameters.
Definition: Settings.h:38
std::vector< std::string > info() const
Get logged information about settings file.
Definition: Settings.cpp:266
std::string keywordCheck(std::string const &keyword) const
Check for keyword and alternatives, throw exception if not present.
Definition: Settings.cpp:221
static KeywordList knownKeywords
Map containing all known keywords and a description.
Definition: Settings.h:149
std::vector< std::string > lines
Vector of all lines in settings file.
Definition: Settings.h:143
std::multimap< std::string, std::pair< std::string, std::size_t > > KeyMap
Definition: Settings.h:42
std::string getValue(Key const &key) const override
Definition: Settings.cpp:251
void writeSettingsFile(std::ofstream *const &file, std::map< std::size_t, std::string > const &replacements={}) const
Write complete settings file.
Definition: Settings.cpp:301
std::pair< KeyMap::const_iterator, KeyMap::const_iterator > KeyRange
Definition: Settings.h:44
std::size_t loadFile(std::string const &fileName="input.nn")
Load a file with settings.
Definition: Settings.cpp:187
std::map< std::string, std::shared_ptr< Key > > const KeywordList
Definition: Settings.h:46
KeyRange getValues(std::string const &keyword) const
Get all keyword-value pairs for given keyword.
Definition: Settings.cpp:261
std::vector< std::string > log
Vector with log lines.
Definition: Settings.h:145
std::string fileName
Settings file name.
Definition: Settings.h:151
KeyMap contents
Map containing all keyword-value pairs.
Definition: Settings.h:147
std::vector< std::string > getSettingsLines() const
Get complete settings file.
Definition: Settings.cpp:271
bool keywordExists(Key const &key, bool const exact=false) const override
Definition: Settings.cpp:194
std::size_t parseLines()
Parse lines and create contents map.
Definition: Settings.cpp:323
void readFile()
Read file once and save all lines in lines vector.
Definition: Settings.cpp:276
std::pair< std::size_t, std::size_t > sanityCheck()
Check if all keywords are in known-keywords database and for duplicates.
Definition: Settings.cpp:391
std::string operator[](std::string const &keyword) const
Overload [] operator.
Definition: Settings.cpp:181
Definition: Atom.h:29