n2p2 - A neural network potential package
nnp Namespace Reference

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...
 
class  GradientDescent
 Weight updates based on simple gradient descent methods. More...
 
class  InterfaceLammps
 
class  KalmanFilter
 Implementation of the Kalman filter method. More...
 
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  Settings
 Reads and analyzes settings file and stores parameters. 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...
 

Functions

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

Function Documentation

◆ 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::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::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::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::ElementMap::info(), nnp::NeuralNetwork::info(), nnp::Structure::info(), nnp::GradientDescent::info(), nnp::KalmanFilter::info(), nnp::InterfaceLammps::initialize(), nnp::Training::initializeWeightsMemory(), nnp::Mode::loadSettingsFile(), 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::parseLines(), nnp::Dataset::prepareNumericForces(), nnp::Training::printEpoch(), nnp::Training::printHeader(), nnp::Training::randomizeNeuralNetworkWeights(), nnp::Settings::readFile(), nnp::Mode::readNeuralNetworkWeights(), runTest(), nnp::Settings::sanityCheck(), nnp::SymFnc::scalingLine(), nnp::ElementCabana::scalingLine(), nnp::Training::selectSets(), nnp::SymFncBaseComp::setCompactFunction(), nnp::SymFncBaseCutoff::setCutoffFunction(), nnp::Element::setScalingNone(), nnp::Mode::setupCutoff(), 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::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().

◆ 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 104 of file utility.cpp.

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

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 218 of file utility.cpp.

219{
220 for (vector<string>::const_iterator it = lines.begin();
221 it != lines.end(); ++it)
222 {
223 file << (*it);
224 }
225
226 return;
227}

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 229 of file utility.cpp.

230{
231 for (vector<string>::const_iterator it = lines.begin();
232 it != lines.end(); ++it)
233 {
234 fprintf(file, "%s", it->c_str());
235 }
236
237 return;
238}

◆ readColumnsFromFile() [1/2]

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

Definition at line 240 of file utility.cpp.

243{
244 map<size_t, vector<double>> result;
245
246 sort(columns.begin(), columns.end());
247 for (auto col : columns)
248 {
249 result[col] = vector<double>();
250 }
251
252 ifstream file;
253 file.open(fileName.c_str());
254 if (!file.is_open())
255 {
256 throw runtime_error("ERROR: Could not open file: \"" + fileName
257 + "\".\n");
258 }
259 string line;
260 while (getline(file, line))
261 {
262 if (line.size() == 0) continue;
263 if (line.at(0) != comment)
264 {
265 vector<string> splitLine = split(reduce(line));
266 for (auto col : columns)
267 {
268 if (col >= splitLine.size())
269 {
270 result[col].push_back(
271 std::numeric_limits<double>::quiet_NaN());
272 }
273 else
274 {
275 result[col].push_back(atof(splitLine.at(col).c_str()));
276 }
277 }
278 }
279 }
280 file.close();
281
282 return result;
283}
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().

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 285 of file utility.cpp.

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

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 135 of file utility.h.

138{
139 if (stdMap.find(key) == stdMap.end())
140 {
141 std::stringstream message;
142 message << "ERROR: No map entry found for key \"";
143 message << key;
144 message << "\".\n";
145 throw std::range_error(message.str());
146 }
147 return stdMap.find(key)->second;
148}

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:

◆ 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 158 of file utility.h.

159{
160 return ((*lhs) < (*rhs));
161}

◆ operator+()

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

Overload + operator to implement vector addition.

Returns
Sum of two vectors.

Definition at line 292 of file Vec3D.h.

293{
294 return lhs += rhs;
295}

◆ 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 297 of file Vec3D.h.

298{
299 return lhs -= rhs;
300}

◆ operator-() [2/2]

Vec3D nnp::operator- ( Vec3D  v)
inline

Overload - operator to implement vector sign change.

Returns
Negative vector.

Definition at line 302 of file Vec3D.h.

303{
304 v *= -1.0;
305 return v;
306}

◆ operator*() [1/2]

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

Overload * operator to implement multiplication with scalar.

Returns
Vector multiplied with scalar.

Definition at line 308 of file Vec3D.h.

309{
310 return v *= a;
311}

◆ 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 313 of file Vec3D.h.

314{
315 return v /= a;
316}

◆ operator*() [2/2]

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 318 of file Vec3D.h.

319{
320 return v *= a;
321}