n2p2 - A neural network potential package
nnp Namespace Reference

Namespaces

namespace  settings
 

Classes

struct  Atom
 Storage for a single atom. More...
 
class  CompactFunction
 A general function with compact support. More...
 
class  CoreFunction
 
class  CutoffFunction
 
class  Dataset
 Collect and process large data sets. More...
 
class  Element
 Contains element-specific data. More...
 
class  ElementCabana
 Derived Cabana class for element-specific data. More...
 
class  ElementMap
 Contains element map. More...
 
struct  ErfcBuf
 Helper class to store previously calculated values of erfc() that are needed during the charge equilibration. More...
 
struct  EwaldGlobalSettings
 
struct  EwaldParameters
 
class  EwaldSetup
 Setup data for Ewald summation. More...
 
class  EwaldStructureData
 
class  EwaldTruncJackson
 
class  EwaldTruncKolafaFixR
 
class  EwaldTruncKolafaOptEta
 
class  GradientDescent
 Weight updates based on simple gradient descent methods. More...
 
class  IEwaldTrunc
 
class  InterfaceLammps
 
class  KalmanFilter
 Implementation of the Kalman filter method. More...
 
class  KspaceGrid
 
class  Kvector
 
class  Log
 Logging class for library output. More...
 
class  Mode
 Base class for all NNP applications. More...
 
class  ModeCabana
 Derived Cabana main NNP class. More...
 
class  NeuralNetwork
 This class implements a feed-forward neural network. More...
 
class  Prediction
 
class  ScreeningFunction
 A screening functions for use with electrostatics. More...
 
class  SetupAnalysis
 
class  Stopwatch
 Implements a simple stopwatch on different platforms. More...
 
struct  Structure
 Storage for one atomic configuration. More...
 
class  SymFnc
 Symmetry function base class. More...
 
class  SymFncBaseComp
 Symmetry function base class for SFs with compact support. More...
 
class  SymFncBaseCompAng
 Intermediate symmetry function class for angular SFs with compact support. More...
 
class  SymFncBaseCompAngWeighted
 Intermediate symmetry function class for weighted angular compact SFs. More...
 
class  SymFncBaseCutoff
 Intermediate class for SFs based on cutoff functions. More...
 
class  SymFncBaseExpAng
 Intermediate class for angular SFs based on cutoffs and exponentials. More...
 
class  SymFncCompAngn
 Narrow angular symmetry function with compact support (type 21) More...
 
class  SymFncCompAngnWeighted
 Weighted narrow angular symmetry function with compact support (type 24) More...
 
class  SymFncCompAngw
 Wide angular symmetry function with compact support (type 22) More...
 
class  SymFncCompAngwWeighted
 Weighted wide angular symmetry function with compact support (type 25) More...
 
class  SymFncCompRad
 Radial symmetry function with compact support (type 20) More...
 
class  SymFncCompRadWeighted
 Weighted radial symmetry function with compact support (type 23) More...
 
class  SymFncExpAngn
 Angular symmetry function (type 3) More...
 
class  SymFncExpAngnWeighted
 Weighted angular symmetry function (type 13) More...
 
class  SymFncExpAngw
 Angular symmetry function (type 9) More...
 
class  SymFncExpRad
 Radial symmetry function (type 2) More...
 
class  SymFncExpRadWeighted
 Weighted radial symmetry function (type 12) More...
 
class  SymFncStatistics
 
class  SymGrp
 
class  SymGrpBaseComp
 
class  SymGrpBaseCompAng
 
class  SymGrpBaseCompAngWeighted
 
class  SymGrpBaseCutoff
 
class  SymGrpBaseExpAng
 
class  SymGrpCompAngn
 Narrow angular symmetry function with compact support (type 21) More...
 
class  SymGrpCompAngnWeighted
 Weighted narrow angular symmetry function with compact support (type 24) More...
 
class  SymGrpCompAngw
 Wide angular symmetry function with compact support (type 22) More...
 
class  SymGrpCompAngwWeighted
 Weighted wide angular symmetry function with compact support (type 25) More...
 
class  SymGrpCompRad
 Radial symmetry function with compact support (type 20) More...
 
class  SymGrpCompRadWeighted
 Weighted radial symmetry function with compact support (type 23) More...
 
class  SymGrpExpAngn
 Angular symmetry function group (type 3) More...
 
class  SymGrpExpAngnWeighted
 Weighted angular symmetry function group (type 13) More...
 
class  SymGrpExpAngw
 Angular symmetry function group (type 3) More...
 
class  SymGrpExpRad
 Radial symmetry function group (type 2) More...
 
class  SymGrpExpRadWeighted
 Weighted radial symmetry function group (type 12) More...
 
class  Training
 Training methods. More...
 
class  Updater
 Base class for different weight update methods. More...
 
struct  Vec3D
 Vector in 3 dimensional real space. More...
 

Enumerations

enum class  EWALDTruncMethod { JACKSON_CATLOW , KOLAFA_PERRAM }
 

Functions

NeuralNetwork::ActivationFunction activationFromString (std::string c)
 Convert string to activation function. More...
 
vector< string > split (std::string const &input, char delimiter=' ')
 Split string at each delimiter. More...
 
string trim (std::string const &line, std::string const &whitespace=" \t")
 Remove leading and trailing whitespaces from string. More...
 
string reduce (std::string const &line, std::string const &whitespace=" \t", std::string const &fill=" ")
 Replace multiple whitespaces with fill. More...
 
string pad (string const &input, size_t num, char fill, bool right)
 
string strpr (const char *format,...)
 String version of printf function. More...
 
string cap (std::string word)
 Capitalize first letter of word. More...
 
vector< string > createFileHeader (vector< string > const &title, vector< size_t > const &colSize, vector< string > const &colName, vector< string > const &colInfo, char const &commentChar)
 
void appendLinesToFile (std::ofstream &file, std::vector< std::string > const lines)
 Append multiple lines of strings to open file stream. More...
 
void appendLinesToFile (FILE *const &file, std::vector< std::string > const lines)
 Append multiple lines of strings to open file pointer. More...
 
map< size_t, vector< double > > readColumnsFromFile (string fileName, vector< size_t > columns, char comment)
 
double pow_int (double x, int n)
 Integer version of power function, "fast exponentiation algorithm". More...
 
std::string pad (std::string const &input, std::size_t num, char fill=' ', bool right=true)
 Pad string to given length with fill character. More...
 
std::vector< std::string > createFileHeader (std::vector< std::string > const &title, std::vector< std::size_t > const &colLength, std::vector< std::string > const &colName, std::vector< std::string > const &colInfo, char const &commentChar='#')
 Generate output file header with info section and column labels. More...
 
std::map< std::size_t, std::vector< double > > readColumnsFromFile (std::string fileName, std::vector< std::size_t > columns, char comment='#')
 Read multiple columns of data from file. More...
 
template<typename K , typename V >
V const & safeFind (std::map< K, V > const &stdMap, typename std::map< K, V >::key_type const &key)
 Safely access map entry. More...
 
template<typename T >
bool vectorContains (std::vector< T > const &stdVec, T value)
 Test if vector contains specified value. More...
 
template<typename T , typename U >
bool unorderedMapContainsKey (std::unordered_map< T, U > const &stdMap, T key)
 Test if unordered map contains specified key. More...
 
template<typename T >
bool comparePointerTargets (T *lhs, T *rhs)
 Compare pointer targets. More...
 
Vec3D operator+ (Vec3D lhs, Vec3D const &rhs)
 Overload + operator to implement vector addition. More...
 
Vec3D operator- (Vec3D lhs, Vec3D const &rhs)
 Overload - operator to implement vector subtraction. More...
 
Vec3D operator- (Vec3D v)
 Overload - operator to implement vector sign change. More...
 
Vec3D operator* (Vec3D v, double const a)
 Overload * operator to implement multiplication with scalar. More...
 
Vec3D operator* (Vec3D const (&A)[3], Vec3D v)
 Overload * operator to implement (left) multiplication with a matrix. More...
 
Vec3D operator/ (Vec3D v, double const a)
 Overload / operator to implement division by scalar. More...
 
Vec3D operator* (double const a, Vec3D v)
 Overload * operator to implement multiplication with scalar (scalar first). More...
 

Variables

double constexpr TrOverTk = 3.676
 

Enumeration Type Documentation

◆ EWALDTruncMethod

enum class nnp::EWALDTruncMethod
strong
Enumerator
JACKSON_CATLOW 

Method 0: Used by RuNNer (DOI: 10.1080/08927028808080944).

KOLAFA_PERRAM 

Method 1: Optimized in n2p2 (DOI: 10.1080/08927029208049126).

Definition at line 29 of file EwaldSetup.h.

29 {
34};
@ KOLAFA_PERRAM
Method 1: Optimized in n2p2 (DOI: 10.1080/08927029208049126).
@ JACKSON_CATLOW
Method 0: Used by RuNNer (DOI: 10.1080/08927028808080944).

Function Documentation

◆ activationFromString()

NeuralNetwork::ActivationFunction nnp::activationFromString ( std::string  c)

Convert string to activation function.

Parameters
[in]letterString representing activation function.
Returns
Activation corresponding to string.

Definition at line 1078 of file NeuralNetwork.cpp.

1079{
1081
1082 if (c == "l") a = NeuralNetwork::AF_IDENTITY;
1083 else if (c == "t") a = NeuralNetwork::AF_TANH;
1084 else if (c == "s") a = NeuralNetwork::AF_LOGISTIC;
1085 else if (c == "p") a = NeuralNetwork::AF_SOFTPLUS;
1086 else if (c == "r") a = NeuralNetwork::AF_RELU;
1087 else if (c == "g") a = NeuralNetwork::AF_GAUSSIAN;
1088 else if (c == "c") a = NeuralNetwork::AF_COS;
1089 else if (c == "S") a = NeuralNetwork::AF_REVLOGISTIC;
1090 else if (c == "e") a = NeuralNetwork::AF_EXP;
1091 else if (c == "h") a = NeuralNetwork::AF_HARMONIC;
1092 else
1093 {
1094 throw runtime_error("ERROR: Unknown activation function.\n");
1095 }
1096
1097 return a;
1098}
ActivationFunction
List of available activation function types.
Definition: NeuralNetwork.h:33

References nnp::NeuralNetwork::AF_COS, nnp::NeuralNetwork::AF_EXP, nnp::NeuralNetwork::AF_GAUSSIAN, nnp::NeuralNetwork::AF_HARMONIC, nnp::NeuralNetwork::AF_IDENTITY, nnp::NeuralNetwork::AF_LOGISTIC, nnp::NeuralNetwork::AF_RELU, nnp::NeuralNetwork::AF_REVLOGISTIC, nnp::NeuralNetwork::AF_SOFTPLUS, and nnp::NeuralNetwork::AF_TANH.

Referenced by nnp::Mode::setupNeuralNetwork().

Here is the caller graph for this function:

◆ split()

std::vector< std::string > nnp::split ( std::string const &  input,
char  delimiter = ' ' 
)

Split string at each delimiter.

Parameters
[in]inputInput string.
[in]delimiterDelimiter character (default ' ').
Returns
Vector containing the string parts.

Definition at line 33 of file utility.cpp.

34{
35 vector<string> parts;
36 stringstream ss;
37
38 ss.str(input);
39 string item;
40 while (getline(ss, item, delimiter)) {
41 parts.push_back(item);
42 }
43
44 return parts;
45}

Referenced by nnp::SymFnc::addCacheIndex(), nnp::Element::addSymmetryFunction(), nnp::ElementCabana::addSymmetryFunction(), nnp::Training::dataSetNormalization(), nnp::Dataset::getNumStructures(), nnp::InterfaceLammps::initialize(), main(), readColumnsFromFile(), nnp::Structure::readFromFile(), nnp::Structure::readFromLines(), nnp::ElementMap::registerElements(), nnp::SymFncBaseCompAng::setParameters(), nnp::SymFncBaseCompAngWeighted::setParameters(), nnp::SymFncBaseExpAng::setParameters(), nnp::SymFncCompRad::setParameters(), nnp::SymFncCompRadWeighted::setParameters(), nnp::SymFncExpAngnWeighted::setParameters(), nnp::SymFncExpRad::setParameters(), nnp::SymFncExpRadWeighted::setParameters(), nnp::SymFnc::setScalingType(), nnp::ElementCabana::setScalingType(), nnp::Mode::setupCutoff(), nnp::Mode::setupElectrostatics(), nnp::ModeCabana< t_device >::setupElementMap(), nnp::Mode::setupElements(), nnp::ModeCabana< t_device >::setupElements(), nnp::Training::setupFileOutput(), nnp::Mode::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetworkWeights(), nnp::Training::setupSelectionMode(), nnp::Mode::setupSymmetryFunctionCache(), nnp::Mode::setupSymmetryFunctions(), nnp::ModeCabana< t_device >::setupSymmetryFunctions(), and nnp::Structure::writeToFilePoscar().

Here is the caller graph for this function:

◆ trim()

std::string nnp::trim ( std::string const &  line,
std::string const &  whitespace = " \t" 
)

Remove leading and trailing whitespaces from string.

Parameters
[in]lineInput string.
[in]whitespaceAll characters identified as whitespace (default: " \t").
Returns
String without leading and trailing whitespaces.

Definition at line 47 of file utility.cpp.

48{
49 size_t const begin = line.find_first_not_of(whitespace);
50 if (begin == string::npos)
51 {
52 return "";
53 }
54 size_t const end = line.find_last_not_of(whitespace);
55 size_t const range = end - begin + 1;
56
57 return line.substr(begin, range);
58}

Referenced by nnp::InterfaceLammps::initialize(), and reduce().

Here is the caller graph for this function:

◆ reduce()

std::string nnp::reduce ( std::string const &  line,
std::string const &  whitespace = " \t",
std::string const &  fill = " " 
)

Replace multiple whitespaces with fill.

Parameters
[in]lineInput string.
[in]whitespaceAll characters identified as whitespace (default: " \t").
[in]fillReplacement character (default: " ").
Returns
String with fill replacements.

Calls trim() at the beginning.

Definition at line 60 of file utility.cpp.

63{
64 string result = trim(line, whitespace);
65
66 size_t begin = result.find_first_of(whitespace);
67 while (begin != string::npos)
68 {
69 size_t const end = result.find_first_not_of(whitespace, begin);
70 size_t const range = end - begin;
71 result.replace(begin, range, fill);
72 size_t const newBegin = begin + fill.length();
73 begin = result.find_first_of(whitespace, newBegin);
74 }
75
76 return result;
77}
string trim(string const &line, string const &whitespace)
Remove leading and trailing whitespaces from string.
Definition: utility.cpp:47

References trim().

Referenced by nnp::Element::addSymmetryFunction(), nnp::ElementCabana::addSymmetryFunction(), nnp::Dataset::getNumStructures(), nnp::InterfaceLammps::initialize(), main(), nnp::settings::Settings::parseLines(), readColumnsFromFile(), nnp::Structure::readFromFile(), nnp::Structure::readFromLines(), nnp::ElementMap::registerElements(), nnp::SymFncBaseCompAng::setParameters(), nnp::SymFncBaseCompAngWeighted::setParameters(), nnp::SymFncBaseExpAng::setParameters(), nnp::SymFncCompRad::setParameters(), nnp::SymFncCompRadWeighted::setParameters(), nnp::SymFncExpAngnWeighted::setParameters(), nnp::SymFncExpRad::setParameters(), nnp::SymFncExpRadWeighted::setParameters(), nnp::SymFnc::setScalingType(), nnp::ElementCabana::setScalingType(), nnp::Mode::setupElectrostatics(), nnp::ModeCabana< t_device >::setupElementMap(), nnp::Mode::setupElements(), nnp::ModeCabana< t_device >::setupElements(), nnp::Training::setupFileOutput(), nnp::Mode::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetworkWeights(), nnp::Mode::setupSymmetryFunctions(), and nnp::ModeCabana< t_device >::setupSymmetryFunctions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pad() [1/2]

string nnp::pad ( string const &  input,
size_t  num,
char  fill,
bool  right 
)

Definition at line 79 of file utility.cpp.

80{
81 string result = input;
82
83 if (input.size() >= num) return result;
84
85 string pad(num - input.size(), fill);
86 if (right) return result + pad;
87 else return pad + result;
88}
string pad(string const &input, size_t num, char fill, bool right)
Definition: utility.cpp:79

References pad().

Referenced by pad(), nnp::SymFnc::parameterInfo(), nnp::SymFncBaseComp::parameterInfo(), nnp::SymFncBaseCompAng::parameterInfo(), nnp::SymFncBaseCompAngWeighted::parameterInfo(), nnp::SymFncBaseCutoff::parameterInfo(), nnp::SymFncBaseExpAng::parameterInfo(), nnp::SymFncCompRad::parameterInfo(), nnp::SymFncExpAngnWeighted::parameterInfo(), nnp::SymFncExpRad::parameterInfo(), and nnp::SymFncExpRadWeighted::parameterInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strpr()

std::string nnp::strpr ( const char *  format,
  ... 
)

String version of printf function.

Definition at line 90 of file utility.cpp.

91{
92 char buffer[STRPR_MAXBUF];
93
94 va_list args;
95 va_start(args, format);
96 vsprintf(buffer, format, args);
97 va_end(args);
98
99 string s(buffer);
100
101 return s;
102}
#define STRPR_MAXBUF
Definition: utility.cpp:26

References STRPR_MAXBUF.

Referenced by nnp::SymFnc::addCacheIndex(), nnp::Training::addTrainingLogEntry(), nnp::Training::allocateArrays(), nnp::Training::calculateError(), nnp::Training::calculateErrorEpoch(), nnp::Training::calculateNeighborLists(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), nnp::Training::checkSelectionMode(), nnp::Dataset::collectSymmetryFunctionStatistics(), nnp::Dataset::combineFiles(), nnp::Training::dataSetNormalization(), nnp::Dataset::distributeStructures(), nnp::SymFncBaseCompAng::getCacheIdentifiers(), nnp::SymFncBaseCompAngWeighted::getCacheIdentifiers(), nnp::SymFncBaseExpAng::getCacheIdentifiers(), nnp::SymFncCompRad::getCacheIdentifiers(), nnp::SymFncCompRadWeighted::getCacheIdentifiers(), nnp::SymFncExpAngnWeighted::getCacheIdentifiers(), nnp::SymFncExpRad::getCacheIdentifiers(), nnp::SymFncExpRadWeighted::getCacheIdentifiers(), nnp::Atom::getChargeLine(), nnp::ElementMap::getElementsString(), nnp::Structure::getEnergyLine(), nnp::SymFncStatistics::getExtrapolationWarningLines(), nnp::Atom::getForcesLines(), nnp::SymFncBaseCompAng::getSettingsLine(), nnp::SymFncBaseCompAngWeighted::getSettingsLine(), nnp::SymFncBaseExpAng::getSettingsLine(), nnp::SymFncCompRad::getSettingsLine(), nnp::SymFncCompRadWeighted::getSettingsLine(), nnp::SymFncExpAngnWeighted::getSettingsLine(), nnp::SymFncExpRad::getSettingsLine(), nnp::SymFncExpRadWeighted::getSettingsLine(), nnp::Atom::Neighbor::info(), nnp::Atom::info(), nnp::CoreFunction::info(), nnp::ElementMap::info(), nnp::NeuralNetwork::info(), nnp::ScreeningFunction::info(), nnp::Structure::info(), nnp::GradientDescent::info(), nnp::KalmanFilter::info(), nnp::InterfaceLammps::initialize(), nnp::Training::initializeWeightsMemory(), nnp::Mode::loadSettingsFile(), nnp::EwaldSetup::logEwaldCutoffs(), nnp::Training::loop(), main(), nnp::SymFnc::parameterInfo(), nnp::SymFncBaseComp::parameterInfo(), nnp::SymFncBaseCompAng::parameterInfo(), nnp::SymFncBaseCompAngWeighted::parameterInfo(), nnp::SymFncBaseCutoff::parameterInfo(), nnp::SymFncBaseExpAng::parameterInfo(), nnp::SymFncCompRad::parameterInfo(), nnp::SymFncExpAngnWeighted::parameterInfo(), nnp::SymFncExpRad::parameterInfo(), nnp::SymFncExpRadWeighted::parameterInfo(), nnp::SymFncBaseCompAng::parameterLine(), nnp::SymFncBaseCompAngWeighted::parameterLine(), nnp::SymFncBaseExpAng::parameterLine(), nnp::SymFncCompRad::parameterLine(), nnp::SymFncCompRadWeighted::parameterLine(), nnp::SymFncExpAngnWeighted::parameterLine(), nnp::SymFncExpRad::parameterLine(), nnp::SymFncExpRadWeighted::parameterLine(), nnp::SymGrpBaseCompAng::parameterLines(), nnp::SymGrpBaseCompAngWeighted::parameterLines(), nnp::SymGrpBaseExpAng::parameterLines(), nnp::SymGrpCompRad::parameterLines(), nnp::SymGrpCompRadWeighted::parameterLines(), nnp::SymGrpExpAngnWeighted::parameterLines(), nnp::SymGrpExpRad::parameterLines(), nnp::SymGrpExpRadWeighted::parameterLines(), nnp::settings::Settings::parseLines(), nnp::Dataset::prepareNumericForces(), nnp::Training::printEpoch(), nnp::Training::printHeader(), nnp::Training::randomizeNeuralNetworkWeights(), nnp::settings::Settings::readFile(), nnp::Mode::readNeuralNetworkWeights(), runTest(), nnp::settings::Settings::sanityCheck(), nnp::SymFnc::scalingLine(), nnp::ElementCabana::scalingLine(), nnp::Training::selectSets(), nnp::SymFncBaseComp::setCompactFunction(), nnp::SymFncBaseCutoff::setCutoffFunction(), nnp::Element::setScalingNone(), nnp::Training::setStage(), nnp::Mode::setupCutoff(), nnp::Mode::setupElectrostatics(), nnp::Mode::setupElementMap(), nnp::ModeCabana< t_device >::setupElementMap(), nnp::Mode::setupElements(), nnp::ModeCabana< t_device >::setupElements(), nnp::Training::setupFileOutput(), nnp::Dataset::setupMPI(), nnp::Mode::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetwork(), nnp::ModeCabana< t_device >::setupNeuralNetworkWeights(), nnp::Mode::setupNeuralNetworkWeights(), nnp::Mode::setupNormalization(), nnp::Dataset::setupRandomNumberGenerator(), nnp::Training::setupSelectionMode(), nnp::Mode::setupSymmetryFunctionCache(), nnp::Mode::setupSymmetryFunctionGroups(), nnp::ModeCabana< t_device >::setupSymmetryFunctionGroups(), nnp::Mode::setupSymmetryFunctionMemory(), nnp::Mode::setupSymmetryFunctions(), nnp::ModeCabana< t_device >::setupSymmetryFunctions(), nnp::Mode::setupSymmetryFunctionScaling(), nnp::ModeCabana< t_device >::setupSymmetryFunctionScaling(), nnp::Mode::setupSymmetryFunctionStatistics(), nnp::Training::setupTraining(), nnp::Training::setupUpdatePlan(), nnp::GradientDescent::status(), nnp::KalmanFilter::status(), nnp::ElementMap::symbolFromAtomicNumber(), nnp::Element::updateSymmetryFunctionStatistics(), nnp::Dataset::writeAtomicEnvironmentFile(), nnp::NeuralNetwork::writeConnections(), nnp::Training::writeHardness(), nnp::Training::writeHardnessEpoch(), nnp::Training::writeLearningCurve(), nnp::Dataset::writeNeighborHistogram(), nnp::Dataset::writeNeighborLists(), nnp::Training::writeNeuronStatistics(), nnp::Training::writeNeuronStatisticsEpoch(), nnp::Training::writeSetsToFiles(), nnp::Dataset::writeSymmetryFunctionFile(), nnp::Dataset::writeSymmetryFunctionHistograms(), nnp::Dataset::writeSymmetryFunctionScaling(), nnp::SetupAnalysis::writeSymmetryFunctionShape(), nnp::Training::writeTimingData(), nnp::Structure::writeToFile(), nnp::Structure::writeToFilePoscar(), nnp::Structure::writeToFileXyz(), nnp::Training::writeUpdaterStatus(), nnp::Training::writeWeights(), and nnp::Training::writeWeightsEpoch().

◆ cap()

std::string nnp::cap ( std::string  word)

Capitalize first letter of word.

Parameters
[in]wordString to capitalize.
Returns
Input string with first letter in capital letters.

Definition at line 104 of file utility.cpp.

105{
106 word[0] = toupper(word[0]);
107
108 return word;
109}

Referenced by nnp::Mode::setupNeuralNetworkWeights().

Here is the caller graph for this function:

◆ createFileHeader() [1/2]

vector< string > nnp::createFileHeader ( vector< string > const &  title,
vector< size_t > const &  colSize,
vector< string > const &  colName,
vector< string > const &  colInfo,
char const &  commentChar 
)

Definition at line 111 of file utility.cpp.

116{
117 size_t const stdWidth = 80;
118 vector<string> h;
119 if (!(colSize.size() == colName.size() &&
120 colName.size() == colInfo.size()))
121 {
122 throw runtime_error("ERROR: Could not create file header, column sizes"
123 " are not equal.\n");
124 }
125 size_t numCols = colSize.size();
126
127 // Separator line definition.
128 string sepLine(stdWidth, commentChar);
129 sepLine += '\n';
130 // Start string.
131 string startStr(1, commentChar);
132
133 // Add title lines.
134 h.push_back(sepLine);
135 for (vector<string>::const_iterator it = title.begin();
136 it != title.end(); ++it)
137 {
138 h.push_back(startStr + ' ' + (*it) + '\n');
139 }
140 h.push_back(sepLine);
141
142 // Determine maximum width of names.
143 size_t widthNames = 0;
144 for (vector<string>::const_iterator it = colName.begin();
145 it != colName.end(); ++it)
146 {
147 widthNames = max(widthNames, it->size());
148 }
149
150 // Column description section.
151 stringstream s;
152 s << startStr << ' '
153 << left << setw(4) << "Col" << ' '
154 << left << setw(widthNames) << "Name" << ' '
155 << left << "Description\n";
156 h.push_back(s.str());
157 h.push_back(sepLine);
158 for (size_t i = 0; i < numCols; ++i)
159 {
160 s.clear();
161 s.str(string());
162 s << startStr << ' '
163 << left << setw(4) << i + 1 << ' '
164 << left << setw(widthNames) << colName.at(i) << ' '
165 << colInfo.at(i) << '\n';
166 h.push_back(s.str());
167 }
168
169 // Determine total data width.
170 size_t widthData = 0;
171 for (vector<size_t>::const_iterator it = colSize.begin();
172 it != colSize.end(); ++it)
173 {
174 widthData += (*it) + 1;
175 }
176 widthData -= 1;
177
178 if (widthData > stdWidth)
179 {
180 // Long separator line.
181 h.push_back(string(widthData, commentChar) + "\n");
182 }
183 else
184 {
185 h.push_back(sepLine);
186 }
187
188 // Write column number.
189 s.clear();
190 s.str(string());
191 s << startStr;
192 for (size_t i = 0; i < numCols; ++i)
193 {
194 size_t n = colSize.at(i);
195 if (i == 0) n -= 2;
196 s << ' ' << right << setw(n) << i + 1;
197 }
198 s << '\n';
199 h.push_back(s.str());
200
201 // Write column name.
202 s.clear();
203 s.str(string());
204 s << startStr;
205 for (size_t i = 0; i < numCols; ++i)
206 {
207 size_t n = colSize.at(i);
208 if (i == 0) n -= 2;
209 string name = colName.at(i);
210 if (name.size() > n)
211 {
212 name.erase(n, string::npos);
213 }
214 s << ' ' << right << setw(n) << name;
215 }
216 s << '\n';
217 h.push_back(s.str());
218
219 // Long separator line.
220 h.push_back(string(widthData, commentChar) + "\n");
221
222 return h;
223}

Referenced by nnp::Training::calculateError(), nnp::Training::dataSetNormalization(), main(), nnp::Training::setupTraining(), nnp::GradientDescent::statusHeader(), nnp::KalmanFilter::statusHeader(), nnp::NeuralNetwork::writeConnections(), nnp::Training::writeLearningCurve(), nnp::Dataset::writeNeighborHistogram(), nnp::Training::writeNeuronStatistics(), nnp::Dataset::writeSymmetryFunctionHistograms(), nnp::Dataset::writeSymmetryFunctionScaling(), nnp::SetupAnalysis::writeSymmetryFunctionShape(), and nnp::Training::writeTimingData().

Here is the caller graph for this function:

◆ appendLinesToFile() [1/2]

void nnp::appendLinesToFile ( std::ofstream &  file,
std::vector< std::string > const  lines 
)

Append multiple lines of strings to open file stream.

Parameters
[in,out]fileFile stream to append lines to.
[in]linesVector of strings with line content.

Definition at line 225 of file utility.cpp.

226{
227 for (vector<string>::const_iterator it = lines.begin();
228 it != lines.end(); ++it)
229 {
230 file << (*it);
231 }
232
233 return;
234}

Referenced by nnp::Training::calculateError(), nnp::Training::dataSetNormalization(), main(), nnp::Training::setupTraining(), nnp::NeuralNetwork::writeConnections(), nnp::Training::writeLearningCurve(), nnp::Dataset::writeNeighborHistogram(), nnp::Training::writeNeuronStatistics(), nnp::Dataset::writeSymmetryFunctionHistograms(), nnp::Dataset::writeSymmetryFunctionScaling(), nnp::SetupAnalysis::writeSymmetryFunctionShape(), nnp::Training::writeTimingData(), and nnp::Training::writeUpdaterStatus().

Here is the caller graph for this function:

◆ appendLinesToFile() [2/2]

void nnp::appendLinesToFile ( FILE *const &  file,
std::vector< std::string > const  lines 
)

Append multiple lines of strings to open file pointer.

Parameters
[in,out]fileFile pointer.
[in]linesVector of strings with line content.

Definition at line 236 of file utility.cpp.

237{
238 for (vector<string>::const_iterator it = lines.begin();
239 it != lines.end(); ++it)
240 {
241 fprintf(file, "%s", it->c_str());
242 }
243
244 return;
245}

◆ readColumnsFromFile() [1/2]

map< size_t, vector< double > > nnp::readColumnsFromFile ( string  fileName,
vector< size_t >  columns,
char  comment 
)

Definition at line 247 of file utility.cpp.

250{
251 map<size_t, vector<double>> result;
252
253 sort(columns.begin(), columns.end());
254 for (auto col : columns)
255 {
256 result[col] = vector<double>();
257 }
258
259 ifstream file;
260 file.open(fileName.c_str());
261 if (!file.is_open())
262 {
263 throw runtime_error("ERROR: Could not open file: \"" + fileName
264 + "\".\n");
265 }
266 string line;
267 while (getline(file, line))
268 {
269 if (line.size() == 0) continue;
270 if (line.at(0) != comment)
271 {
272 vector<string> splitLine = split(reduce(line));
273 for (auto col : columns)
274 {
275 if (col >= splitLine.size())
276 {
277 result[col].push_back(
278 std::numeric_limits<double>::quiet_NaN());
279 }
280 else
281 {
282 result[col].push_back(atof(splitLine.at(col).c_str()));
283 }
284 }
285 }
286 }
287 file.close();
288
289 return result;
290}
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
Definition: utility.cpp:33
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
Definition: utility.cpp:60

References reduce(), and split().

Referenced by nnp::Mode::readNeuralNetworkWeights(), and nnp::Mode::setupElectrostatics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pow_int()

double nnp::pow_int ( double  x,
int  n 
)

Integer version of power function, "fast exponentiation algorithm".

Parameters
[in]xBase number.
[in]nInteger exponent.
Returns
x^n

Definition at line 292 of file utility.cpp.

293{
294 // Need an unsigned integer for bit-shift divison.
295 unsigned int m;
296
297 // If negative exponent, take the inverse of x and change sign of n.
298 if (n < 0)
299 {
300 x = 1.0 / x;
301 m = -n;
302 }
303 else m = n;
304
305 // Exponentiation by squaring, "fast exponentiation algorithm"
306 double result = 1.0;
307 do
308 {
309 if (m & 1) result *= x;
310 // Division by 2.
311 m >>= 1;
312 x *= x;
313 }
314 while (m);
315
316 return result;
317}

Referenced by nnp::SymFncExpAngn::calculate(), nnp::SymFncExpAngnWeighted::calculate(), nnp::SymFncExpAngw::calculate(), nnp::SymGrpExpAngn::calculate(), nnp::SymGrpExpAngnWeighted::calculate(), and nnp::SymGrpExpAngw::calculate().

Here is the caller graph for this function:

◆ pad() [2/2]

std::string nnp::pad ( std::string const &  input,
std::size_t  num,
char  fill = ' ',
bool  right = true 
)

Pad string to given length with fill character.

Parameters
[in]inputInput string.
[in]numDesired width of padded string.
[in]fillPadding character.
[in]rightIf true, pad right. Pad left otherwise.
Returns
String padded to desired length or original string if length of old string is not shorter than desired length.

◆ createFileHeader() [2/2]

std::vector< std::string > nnp::createFileHeader ( std::vector< std::string > const &  title,
std::vector< std::size_t > const &  colLength,
std::vector< std::string > const &  colName,
std::vector< std::string > const &  colInfo,
char const &  commentChar = '#' 
)

Generate output file header with info section and column labels.

Parameters
[in]titleMultiple lines of title text.
[in]colLengthLength of the individual columns.
[in]colNameNames of the individual columns.
[in]colInfoDescription of the individual columns.
[in]commentCharCharacter used for starting each line and to create separator lines.
Returns
Vector of strings, one entry per line.

◆ readColumnsFromFile() [2/2]

std::map< std::size_t, std::vector< double > > nnp::readColumnsFromFile ( std::string  fileName,
std::vector< std::size_t >  columns,
char  comment = '#' 
)

Read multiple columns of data from file.

Parameters
[in]fileNameName of data file.
[in]columnsVector with column indices of interest (starting with 0).
[in]commentLines starting with comment sign are ignored.
Returns
Map from column index to vector of data.

◆ safeFind()

template<typename K , typename V >
V const & nnp::safeFind ( std::map< K, V > const &  stdMap,
typename std::map< K, V >::key_type const &  key 
)

Safely access map entry.

Parameters
[in]stdMapMap to search in.
[in]keyKey requested.

The .at() member function of maps is available only for C++11.

Definition at line 144 of file utility.h.

147{
148 if (stdMap.find(key) == stdMap.end())
149 {
150 std::stringstream message;
151 message << "ERROR: No map entry found for key \"";
152 message << key;
153 message << "\".\n";
154 throw std::range_error(message.str());
155 }
156 return stdMap.find(key)->second;
157}

Referenced by nnp::SymFnc::getPrintFormat(), nnp::SymGrp::getPrintFormatCommon(), nnp::SymGrp::getPrintFormatMember(), nnp::ElementMap::index(), nnp::ElementMap::symbol(), and nnp::Dataset::writeSymmetryFunctionHistograms().

Here is the caller graph for this function:

◆ vectorContains()

template<typename T >
bool nnp::vectorContains ( std::vector< T > const &  stdVec,
value 
)

Test if vector contains specified value.

Parameters
[in]stdVecVector to search in.
[in]valueValue to search for.
Returns
True if value is located in vector.

Definition at line 166 of file utility.h.

168{
169 return (std::find(stdVec.begin(), stdVec.end(), value) != stdVec.end());
170}

Referenced by nnp::Element::getCutoffRadii(), nnp::Mode::setupCutoffMatrix(), and nnp::Structure::setupNeighborCutoffMap().

Here is the caller graph for this function:

◆ unorderedMapContainsKey()

template<typename T , typename U >
bool nnp::unorderedMapContainsKey ( std::unordered_map< T, U > const &  stdMap,
key 
)

Test if unordered map contains specified key.

Parameters
[in]stdMapMap to search in.
[in]keyKey to search for.
Returns
True if key is located in map.

Definition at line 179 of file utility.h.

182{
183 return ( stdMap.find(key) != stdMap.end() );
184}

Referenced by nnp::Atom::calculateNumNeighbors(), and nnp::Atom::getStoredMinNumNeighbors().

Here is the caller graph for this function:

◆ comparePointerTargets()

template<typename T >
bool nnp::comparePointerTargets ( T *  lhs,
T *  rhs 
)

Compare pointer targets.

Parameters
[in]lhsPointer to left side of comparison.
[in]rhsPointer to right side of comparison.
Returns
True if dereferenced lhs < dereferenced rhs, False otherwise.

Definition at line 194 of file utility.h.

195{
196 return ((*lhs) < (*rhs));
197}

◆ operator+()

Vec3D nnp::operator+ ( Vec3D  lhs,
Vec3D const &  rhs 
)
inline

Overload + operator to implement vector addition.

Returns
Sum of two vectors.

Definition at line 330 of file Vec3D.h.

331{
332 return lhs += rhs;
333}

◆ operator-() [1/2]

Vec3D nnp::operator- ( Vec3D  lhs,
Vec3D const &  rhs 
)
inline

Overload - operator to implement vector subtraction.

Returns
Difference between two vectors.

Definition at line 335 of file Vec3D.h.

336{
337 return lhs -= rhs;
338}

◆ operator-() [2/2]

Vec3D nnp::operator- ( Vec3D  v)
inline

Overload - operator to implement vector sign change.

Returns
Negative vector.

Definition at line 340 of file Vec3D.h.

341{
342 v *= -1.0;
343 return v;
344}

◆ operator*() [1/3]

Vec3D nnp::operator* ( Vec3D  v,
double const  a 
)
inline

Overload * operator to implement multiplication with scalar.

Returns
Vector multiplied with scalar.

Definition at line 346 of file Vec3D.h.

347{
348 return v *= a;
349}

◆ operator*() [2/3]

Vec3D nnp::operator* ( Vec3D const (&)  A[3],
Vec3D  v 
)
inline

Overload * operator to implement (left) multiplication with a matrix.

Returns
Vector multiplied with a matrix.

Definition at line 361 of file Vec3D.h.

362{
363 return v *= A;
364}

◆ operator/()

Vec3D nnp::operator/ ( Vec3D  v,
double const  a 
)
inline

Overload / operator to implement division by scalar.

Returns
Vector divided by scalar.

Definition at line 351 of file Vec3D.h.

352{
353 return v /= a;
354}

◆ operator*() [3/3]

Vec3D nnp::operator* ( double const  a,
Vec3D  v 
)
inline

Overload * operator to implement multiplication with scalar (scalar first).

Returns
Vector multiplied with scalar.

Definition at line 356 of file Vec3D.h.

357{
358 return v *= a;
359}

Variable Documentation

◆ TrOverTk

double constexpr nnp::TrOverTk = 3.676
constexpr