n2p2 - A neural network potential package
|
Reads and analyzes settings file and stores parameters. More...
#include <Settings.h>
Public Types | |
typedef std::multimap< std::string, std::pair< std::string, std::size_t > > | KeyMap |
typedef std::pair< KeyMap::const_iterator, KeyMap::const_iterator > | KeyRange |
typedef std::map< std::string, std::shared_ptr< Key > > const | KeywordList |
Public Member Functions | |
std::string | operator[] (std::string const &keyword) const |
Overload [] operator. More... | |
std::size_t | loadFile (std::string const &fileName="input.nn") |
Load a file with settings. More... | |
bool | keywordExists (Key const &key, bool const exact=false) const override |
bool | keywordExists (std::string const &keyword, bool exact=false) const |
Check if keyword is present in settings file. More... | |
std::string | keywordCheck (std::string const &keyword) const |
Check for keyword and alternatives, throw exception if not present. More... | |
std::string | getValue (Key const &key) const override |
std::string | getValue (std::string const &keyword) const |
Get value for given keyword. More... | |
KeyRange | getValues (std::string const &keyword) const |
Get all keyword-value pairs for given keyword. More... | |
std::vector< std::string > | info () const |
Get logged information about settings file. More... | |
std::vector< std::string > | getSettingsLines () const |
Get complete settings file. More... | |
void | writeSettingsFile (std::ofstream *const &file, std::map< std::size_t, std::string > const &replacements={}) const |
Write complete settings file. More... | |
virtual bool | keywordExists (Key const &key, bool const exact=false) const =0 |
virtual std::string | getValue (Key const &key) const =0 |
Private Member Functions | |
void | readFile () |
Read file once and save all lines in lines vector. More... | |
std::size_t | parseLines () |
Parse lines and create contents map. More... | |
std::pair< std::size_t, std::size_t > | sanityCheck () |
Check if all keywords are in known-keywords database and for duplicates. More... | |
Private Attributes | |
std::vector< std::string > | lines |
Vector of all lines in settings file. More... | |
std::vector< std::string > | log |
Vector with log lines. More... | |
KeyMap | contents |
Map containing all keyword-value pairs. More... | |
std::string | fileName |
Settings file name. More... | |
Static Private Attributes | |
static KeywordList | knownKeywords = createKnownKeywordsMap() |
Map containing all known keywords and a description. More... | |
Reads and analyzes settings file and stores parameters.
Definition at line 37 of file Settings.h.
typedef std::multimap<std::string, std::pair<std::string, std::size_t> > nnp::settings::Settings::KeyMap |
Definition at line 42 of file Settings.h.
typedef std::pair<KeyMap::const_iterator, KeyMap::const_iterator> nnp::settings::Settings::KeyRange |
Definition at line 44 of file Settings.h.
typedef std::map<std::string, std::shared_ptr<Key> > const nnp::settings::Settings::KeywordList |
Definition at line 46 of file Settings.h.
string Settings::operator[] | ( | std::string const & | keyword | ) | const |
Overload [] operator.
[in] | keyword | Keyword string. |
Internally calls getValue().
Definition at line 181 of file Settings.cpp.
References getValue().
size_t Settings::loadFile | ( | std::string const & | fileName = "input.nn" | ) |
Load a file with settings.
[in] | fileName | Name of file containing settings. |
Definition at line 187 of file Settings.cpp.
References fileName, parseLines(), and readFile().
Referenced by nnp::Mode::loadSettingsFile().
|
overridevirtual |
Implements nnp::settings::ISettings.
Definition at line 194 of file Settings.cpp.
References nnp::settings::Key::getMainKeyword(), and keywordExists().
Referenced by nnp::Training::dataSetNormalization(), nnp::Training::initializeWeights(), keywordCheck(), keywordExists(), nnp::Mode::loadSettingsFile(), nnp::Training::randomizeNeuralNetworkWeights(), nnp::Training::setStage(), nnp::Mode::settingsKeywordExists(), nnp::Mode::setupElectrostatics(), nnp::Mode::setupElements(), nnp::Training::setupFileOutput(), nnp::Mode::setupNeuralNetwork(), nnp::Mode::setupNormalization(), nnp::Training::setupSelectionMode(), nnp::Mode::setupSymmetryFunctionScaling(), nnp::Training::setupTraining(), and nnp::Training::setupUpdatePlan().
bool Settings::keywordExists | ( | std::string const & | keyword, |
bool | exact = false |
||
) | const |
Check if keyword is present in settings file.
[in] | keyword | Keyword string. |
[in] | exact | If True check only for exact spelling, no alternative keywords allowed. |
True
if keyword exists, False
otherwise.Definition at line 199 of file Settings.cpp.
References contents, and knownKeywords.
string Settings::keywordCheck | ( | std::string const & | keyword | ) | const |
Check for keyword and alternatives, throw exception if not present.
[in] | keyword | Original keyword for which alternatives should be searched. |
Definition at line 221 of file Settings.cpp.
References contents, keywordExists(), and knownKeywords.
Referenced by getValue(), and getValues().
|
overridevirtual |
Implements nnp::settings::ISettings.
Definition at line 251 of file Settings.cpp.
References contents, and nnp::settings::Key::getMainKeyword().
Referenced by operator[](), and nnp::Mode::settingsGetValue().
string Settings::getValue | ( | std::string const & | keyword | ) | const |
Get value for given keyword.
[in] | keyword | Keyword string. |
If keyword is present multiple times only the value of the first keyword-value pair is returned (use getValues() instead).
Definition at line 256 of file Settings.cpp.
References contents, and keywordCheck().
Settings::KeyRange Settings::getValues | ( | std::string const & | keyword | ) | const |
Get all keyword-value pairs for given keyword.
[in] | keyword | Keyword string. |
Useful if keyword appears multiple times. Returns a pair representing begin and end for an iterator over all corresponding keyword-value pairs. Use like this:
Definition at line 261 of file Settings.cpp.
References contents, and keywordCheck().
Referenced by nnp::Mode::setupElectrostatics(), nnp::Mode::setupElements(), nnp::Mode::setupNeuralNetwork(), and nnp::Mode::setupSymmetryFunctions().
vector< string > Settings::info | ( | ) | const |
Get logged information about settings file.
Definition at line 266 of file Settings.cpp.
References log.
Referenced by nnp::Mode::loadSettingsFile().
vector< string > Settings::getSettingsLines | ( | ) | const |
Get complete settings file.
Definition at line 271 of file Settings.cpp.
References lines.
Referenced by nnp::Training::dataSetNormalization(), and nnp::Mode::writePrunedSettingsFile().
void Settings::writeSettingsFile | ( | std::ofstream *const & | file, |
std::map< std::size_t, std::string > const & | replacements = {} |
||
) | const |
Write complete settings file.
[in,out] | file | Settings file. |
[in] | replacements | Map of line numbers with alternative content. |
Definition at line 301 of file Settings.cpp.
References lines.
Referenced by nnp::Training::dataSetNormalization(), and nnp::Mode::writeSettingsFile().
|
private |
Read file once and save all lines in lines vector.
Definition at line 276 of file Settings.cpp.
References fileName, lines, log, and nnp::strpr().
Referenced by loadFile().
|
private |
Parse lines and create contents map.
Definition at line 323 of file Settings.cpp.
References contents, lines, log, nnp::reduce(), sanityCheck(), and nnp::strpr().
Referenced by loadFile().
|
private |
Check if all keywords are in known-keywords database and for duplicates.
Definition at line 391 of file Settings.cpp.
References contents, d, knownKeywords, log, and nnp::strpr().
Referenced by parseLines().
|
private |
Vector of all lines in settings file.
Definition at line 143 of file Settings.h.
Referenced by getSettingsLines(), parseLines(), readFile(), and writeSettingsFile().
|
private |
Vector with log lines.
Definition at line 145 of file Settings.h.
Referenced by info(), parseLines(), readFile(), and sanityCheck().
|
private |
Map containing all keyword-value pairs.
Definition at line 147 of file Settings.h.
Referenced by getValue(), getValues(), keywordCheck(), keywordExists(), parseLines(), and sanityCheck().
|
staticprivate |
Map containing all known keywords and a description.
Definition at line 149 of file Settings.h.
Referenced by keywordCheck(), keywordExists(), and sanityCheck().
|
private |
Settings file name.
Definition at line 151 of file Settings.h.
Referenced by loadFile(), and readFile().