Config

class Config

A dictionary for key - value pairs.

This dictionary object must be used in the workflow to configure other objects in the training process.

A Config object stores information such as:

  • cutoff distances

  • descriptor parameters

  • paths to training database files

  • and many more…

Every object using a Config class specifies a list of required and optional KEY - VALUE pairs.

The config keys and values are case insensitive.

See documentation for the list of supported KEYS.

Public Functions

Config()

Create object with default values.

Config(std::string fn)

Create object and read config values from the file.

 The values from the file take precedence over config defaults.
const std::vector<std::string> &operator()(const std::string key) const

Return all stored values for a key as a vector.

 Usage example:

 \code{.cpp}
 # Create new config object and read config file
 Config config("config_file");

 # store value(s) for key "DBFILE" in a vector v
 auto v = config("DBFILE");
 \endcode
template<typename T>
inline void get(const std::string key, T &value) const

Fill array with the values from the key.

  The array must be initialised to appropriate size.

 Usage example:

 \code{.cpp}
 # Create new config object and read config file
 Config config("config_file");

 # Fill array with config values of type double
 std::vector<double> vd(10);
 c.get<std::vector<double>>("RCUT2B", vd);
 \endcode

 \tparam T indexable array
template<typename T>
inline T get(const std::string key) const

Return the first value for the key.

 Usage example:

 \code{.cpp}
 # Create new config object and read config_file
 Config config("config_file");

 # get value from the config file and assign to d
 double d = c.get<double>("RCUT2B");
 \endcode

 \tparam T must be built-in type, e.g. int, double, char
template<typename T>
inline T get(const std::string key, size_t n) const

Return n-th value for a key with a specified type.

 Usage example:

 \code{.cpp}
 # Create new config object and read config_file
 Config config("config_file");

 # get value from the config file and assign to d
 double d = c.get<double>("CGRID2B",3);
 \endcode

 \tparam T must be built-in type, e.g. int, double, char
template<typename T>
inline void add(const std::string key, T val)

Add config value to a key.

 If the key does not exist then new entry is added.
 If the key exists and allow for multiple values then the value is appended.
 If the key exists and and is full then throw.

 This method is case insensitive, i.e.,
 added keys are always converted to upper case.

 The value is converted to string.

 This method allow to add also internal keys.
size_t remove(const std::string key)

Remove the key from the config.

 Return number of keys removed, i.e., 0 or 1

void add(const std::string fn)

Add key-value pairs to the existing config object from the file.

 const std::string fn is a filename containing config.
void clear()

Remove all ke-value pairs from this object

size_t size(const std::string key) const

Return a number of values stored by the key.

 Throws if the key does not exists.
bool exist(const std::string key) const

Return true if the key is in this object.

bool check(std::string &key, std::string &value)

Basic key-value check.

bool check_for_training()

Check is this object configured for training.

 This helper method allows to verify whether the config is
 suitable for trainig. It checks some basic properties
 but does not cover every possibility.

 TODO return false instead of throwing?
bool check_for_predict()

Check is this object configured for prediction.

 TODO Not implemented
bool check_pot_file()

Verify is this object configured as a potential file.

 TODO Not implemented
bool operator==(const Config&) const

Return true if both configs are the same.