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.

Below are so called internal keys which are not supposed to be set by the user.

List of internally used keys:

  • <INTERNAL_KEY> DSIZE <int>

    Total dimension of a descriptor. DSIZE = SIZE2B + SIZE3B + SIZEMB. Set by a Calculator.

  • <INTERNAL_KEY> SIZE2B <int>

    Dimension of a two-body descriptor. Set by a Calculator.

  • <INTERNAL_KEY> SIZE3B <int>

    Dimension of a three-body descriptor. Set by a Calculator.

  • <INTERNAL_KEY> SIZEMB <int>

    Dimension of a many-body descriptor. Set by a Calculator.

  • ATOMS <string> A1 A2 …

    List of atom types. Read from training database files. e.g. ATOMS Ti Nb

  • RCUTMAX <string> A1 A2 …

    Maximum cutoff distance, max(RCUT2B,RCUT3B,RCUTMB)

  • ESTDEV <double> N

    Energy standard deviation (energy/atom).

  • FSTDEV <double> N

    Force standard deviation (energy/distance).

  • SSTDEV <double> xx xy xz yy yz zz

    Stress standard deviations (energy units).

Warning

INTERNAL_KEY Do not try to set internal keys. Corresponding values are calculated by the library when required. User can access internal key-value pairs as usually.

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:

# 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");
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:

# 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);
Template Parameters:

T – indexable array

template<typename T>
inline T get(const std::string key) const

Return the first value for the key.

Usage example:

# 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");
Template Parameters:

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:

# 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);
Template Parameters:

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.

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_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.