n2p2 - A neural network potential package
nnp::SetupAnalysis Class Reference

#include <SetupAnalysis.h>

Inheritance diagram for nnp::SetupAnalysis:
Collaboration diagram for nnp::SetupAnalysis:

Public Member Functions

void writeSymmetryFunctionShape (std::size_t numPoints, std::string const fileNameFormat="sf.%03zu.%04zu.out")
 Write radial and angular part of symmetry functions to file. More...
 
- Public Member Functions inherited from nnp::Mode
 Mode ()
 
void initialize ()
 Write welcome message with version information. More...
 
void loadSettingsFile (std::string const &fileName="input.nn")
 Open settings file and load all keywords into memory. More...
 
void setupGeneric (std::string const &nnpDir="", bool skipNormalize=false, bool initialHardness=false)
 Combine multiple setup routines and provide a basic NNP setup. More...
 
void setupNormalization (bool standalone=true)
 Set up normalization. More...
 
virtual void setupElementMap ()
 Set up the element map. More...
 
virtual void setupElements ()
 Set up all Element instances. More...
 
void setupCutoff ()
 Set up cutoff function for all symmetry functions. More...
 
virtual void setupSymmetryFunctions ()
 Set up all symmetry functions. More...
 
void setupSymmetryFunctionScalingNone ()
 Set up "empy" symmetry function scaling. More...
 
virtual void setupSymmetryFunctionScaling (std::string const &fileName="scaling.data")
 Set up symmetry function scaling from file. More...
 
virtual void setupSymmetryFunctionGroups ()
 Set up symmetry function groups. More...
 
virtual void setupSymmetryFunctionCache (bool verbose=false)
 Set up symmetry function cache. More...
 
void setupSymmetryFunctionMemory (bool verbose=false)
 Extract required memory dimensions for symmetry function derivatives. More...
 
void setupSymmetryFunctionStatistics (bool collectStatistics, bool collectExtrapolationWarnings, bool writeExtrapolationWarnings, bool stopOnExtrapolationWarnings)
 Set up symmetry function statistics collection. More...
 
void setupCutoffMatrix ()
 Setup matrix storing all symmetry function cut-offs for each element. More...
 
virtual void setupNeuralNetwork ()
 Set up neural networks for all elements. More...
 
virtual void setupNeuralNetworkWeights (std::map< std::string, std::string > fileNameFormats=std::map< std::string, std::string >())
 Set up neural network weights from files with given name format. More...
 
virtual void setupNeuralNetworkWeights (std::string directoryPrefix, std::map< std::string, std::string > fileNameFormats=std::map< std::string, std::string >())
 Set up neural network weights from files with given name format. More...
 
virtual void setupElectrostatics (bool initialHardness=false, std::string directoryPrefix="", std::string fileNameFormat="hardness.%03zu.data")
 Set up electrostatics related stuff (hardness, screening, ...). More...
 
void calculateSymmetryFunctions (Structure &structure, bool const derivatives)
 Calculate all symmetry functions for all atoms in given structure. More...
 
void calculateSymmetryFunctionGroups (Structure &structure, bool const derivatives)
 Calculate all symmetry function groups for all atoms in given structure. More...
 
void calculateAtomicNeuralNetworks (Structure &structure, bool const derivatives, std::string id="")
 Calculate atomic neural networks for all atoms in given structure. More...
 
void chargeEquilibration (Structure &structure, bool const derivativesElec)
 Perform global charge equilibration method. More...
 
void calculateEnergy (Structure &structure) const
 Calculate potential energy for a given structure. More...
 
void calculateCharge (Structure &structure) const
 Calculate total charge for a given structure. More...
 
void calculateForces (Structure &structure) const
 Calculate forces for all atoms in given structure. More...
 
void evaluateNNP (Structure &structure, bool useForces=true, bool useDEdG=true)
 Evaluate neural network potential (includes total energy, optionally forces and in some cases charges. More...
 
void addEnergyOffset (Structure &structure, bool ref=true)
 Add atomic energy offsets to reference energy. More...
 
void removeEnergyOffset (Structure &structure, bool ref=true)
 Remove atomic energy offsets from reference energy. More...
 
double getEnergyOffset (Structure const &structure) const
 Get atomic energy offset for given structure. More...
 
double getEnergyWithOffset (Structure const &structure, bool ref=true) const
 Add atomic energy offsets and return energy. More...
 
double normalized (std::string const &property, double value) const
 Apply normalization to given property. More...
 
double normalizedEnergy (Structure const &structure, bool ref=true) const
 Apply normalization to given energy of structure. More...
 
double physical (std::string const &property, double value) const
 Undo normalization for a given property. More...
 
double physicalEnergy (Structure const &structure, bool ref=true) const
 Undo normalization for a given energy of structure. More...
 
void convertToNormalizedUnits (Structure &structure) const
 Convert one structure to normalized units. More...
 
void convertToPhysicalUnits (Structure &structure) const
 Convert one structure to physical units. More...
 
void logEwaldCutoffs ()
 Logs Ewald params whenever they change. More...
 
std::size_t getNumExtrapolationWarnings () const
 Count total number of extrapolation warnings encountered for all elements and symmetry functions. More...
 
void resetExtrapolationWarnings ()
 Erase all extrapolation warnings and reset counters. More...
 
NNPType getNnpType () const
 Getter for Mode::nnpType. More...
 
double getMeanEnergy () const
 Getter for Mode::meanEnergy. More...
 
double getConvEnergy () const
 Getter for Mode::convEnergy. More...
 
double getConvLength () const
 Getter for Mode::convLength. More...
 
double getConvCharge () const
 Getter for Mode::convCharge. More...
 
double getMaxCutoffRadius () const
 Getter for Mode::maxCutoffRadius. More...
 
std::size_t getNumElements () const
 Getter for Mode::numElements. More...
 
std::vector< std::size_t > getNumSymmetryFunctions () const
 Get number of symmetry functions per element. More...
 
bool useNormalization () const
 Check if normalization is enabled. More...
 
bool settingsKeywordExists (std::string const &keyword) const
 Check if keyword was found in settings file. More...
 
std::string settingsGetValue (std::string const &keyword) const
 Get value for given keyword in Settings instance. More...
 
std::vector< std::size_t > pruneSymmetryFunctionsRange (double threshold)
 Prune symmetry functions according to their range and write settings file. More...
 
std::vector< std::size_t > pruneSymmetryFunctionsSensitivity (double threshold, std::vector< std::vector< double > > sensitivity)
 Prune symmetry functions with sensitivity analysis data. More...
 
void writePrunedSettingsFile (std::vector< std::size_t > prune, std::string fileName="output.nn") const
 Copy settings file but comment out lines provided. More...
 
void writeSettingsFile (std::ofstream *const &file) const
 Write complete settings file. More...
 

Additional Inherited Members

- Public Types inherited from nnp::Mode
enum class  NNPType { HDNNP_2G = 2 , HDNNP_4G = 4 , HDNNP_Q = 10 }
 
- Public Attributes inherited from nnp::Mode
ElementMap elementMap
 Global element map, populated by setupElementMap(). More...
 
Log log
 Global log file. More...
 
- Protected Member Functions inherited from nnp::Mode
void readNeuralNetworkWeights (std::string const &id, std::string const &fileName)
 Read in weights for a specific type of neural network. More...
 
- Protected Attributes inherited from nnp::Mode
NNPType nnpType
 
bool normalize
 
bool checkExtrapolationWarnings
 
std::size_t numElements
 
std::vector< std::size_t > minNeighbors
 
std::vector< double > minCutoffRadius
 
double maxCutoffRadius
 
double cutoffAlpha
 
double meanEnergy
 
double convEnergy
 
double convLength
 
double convCharge
 
double fourPiEps
 
EwaldSetup ewaldSetup
 
settings::Settings settings
 
SymFnc::ScalingType scalingType
 
CutoffFunction::CutoffType cutoffType
 
ScreeningFunction screeningFunction
 
std::vector< Elementelements
 
std::vector< std::string > nnk
 
std::map< std::string, NNSetupnns
 
std::vector< std::vector< double > > cutoffs
 Matrix storing all symmetry function cut-offs for all elements. More...
 
ErfcBuf erfcBuf
 

Detailed Description

Definition at line 26 of file SetupAnalysis.h.

Member Function Documentation

◆ writeSymmetryFunctionShape()

void SetupAnalysis::writeSymmetryFunctionShape ( std::size_t  numPoints,
std::string const  fileNameFormat = "sf.%03zu.%04zu.out" 
)

Write radial and angular part of symmetry functions to file.

Parameters
[in]numPointsNumber of symmetry function points to plot.
[in]fileNameFormatFile name with place holder for element and symmetry function number.

Definition at line 24 of file SetupAnalysis.cpp.

26{
27 log << "\n";
28 log << "*** ANALYSIS: SYMMETRY FUNCTION SHAPE ***"
29 "**************************************\n";
30 log << "\n";
31
32 log << strpr("Symmetry function file name format: %s\n",
33 fileNameFormat.c_str());
34 log << strpr("Number of points : %zu\n", numPoints);
35 double dr = getMaxCutoffRadius() / numPoints;
36 log << strpr("Distance step : %f\n", dr);
37 double da = M_PI / numPoints;
38 log << strpr("Angle step (radians) : %f\n", da);
39
40 for (size_t i = 0; i < numElements; ++i)
41 {
42 Element const& e = elements.at(i);
43 for (size_t j = 0; j < e.numSymmetryFunctions(); ++j)
44 {
45 SymFnc const& s = e.getSymmetryFunction(j);
46 ofstream file;
47 file.open(strpr(fileNameFormat.c_str(),
49 j + 1).c_str());
50 vector<string> info = e.infoSymmetryFunction(s.getIndex());
51 for (vector<string>::const_iterator it = info.begin();
52 it != info.end(); ++it)
53 {
54 file << strpr("#SFINFO %s\n", it->c_str());
55 }
56
57 // File header.
58 vector<string> title;
59 vector<string> colName;
60 vector<string> colInfo;
61 vector<size_t> colSize;
62 title.push_back("Symmetry function shape.");
63 colSize.push_back(16);
64 colName.push_back("distance");
65 colInfo.push_back("Distance from center.");
66 colSize.push_back(16);
67 colName.push_back("sf_radial");
68 colInfo.push_back("Radial part of symmetry function at given "
69 "distance.");
70 colSize.push_back(16);
71 colName.push_back("angle");
72 colInfo.push_back("Angle in degrees.");
73 colSize.push_back(16);
74 colName.push_back("sf_angular");
75 colInfo.push_back("Angular part of symmetry function at given "
76 "angle.");
78 createFileHeader(title,
79 colSize,
80 colName,
81 colInfo));
82
83 for (size_t k = 0; k < numPoints + 1; ++k)
84 {
85 file << strpr("%16.8E %16.8E %16.8E %16.8E\n",
86 k * dr,
87 s.calculateRadialPart(k * dr),
88 k * da,
89 s.calculateAngularPart(k * da));
90 }
91 file.close();
92 }
93 }
94
95 log << "*****************************************"
96 "**************************************\n";
97
98 return;
99}
Contains element-specific data.
Definition: Element.h:39
SymFnc const & getSymmetryFunction(std::size_t index) const
Get symmetry function instance.
Definition: Element.h:358
std::vector< std::string > infoSymmetryFunction(std::size_t index) const
Print symmetry function parameter names and values.
Definition: Element.h:348
std::size_t numSymmetryFunctions() const
Get number of symmetry functions.
Definition: Element.h:353
std::size_t getAtomicNumber() const
Get atomicNumber.
Definition: Element.h:310
std::vector< Element > elements
Definition: Mode.h:646
double getMaxCutoffRadius() const
Getter for Mode::maxCutoffRadius.
Definition: Mode.h:693
std::size_t numElements
Definition: Mode.h:631
Log log
Global log file.
Definition: Mode.h:593
Symmetry function base class.
Definition: SymFnc.h:40
virtual double calculateRadialPart(double distance) const =0
Calculate (partial) symmetry function value for one given distance.
std::size_t getIndex() const
Get private index member variable.
Definition: SymFnc.h:357
virtual double calculateAngularPart(double angle) const =0
Calculate (partial) symmetry function value for one given angle.
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90
vector< string > createFileHeader(vector< string > const &title, vector< size_t > const &colSize, vector< string > const &colName, vector< string > const &colInfo, char const &commentChar)
Definition: utility.cpp:111
void appendLinesToFile(ofstream &file, vector< string > const lines)
Append multiple lines of strings to open file stream.
Definition: utility.cpp:225

References nnp::appendLinesToFile(), nnp::SymFnc::calculateAngularPart(), nnp::SymFnc::calculateRadialPart(), nnp::createFileHeader(), nnp::Mode::elements, nnp::Element::getAtomicNumber(), nnp::SymFnc::getIndex(), nnp::Mode::getMaxCutoffRadius(), nnp::Element::getSymmetryFunction(), nnp::Element::infoSymmetryFunction(), nnp::Mode::log, nnp::Mode::numElements, nnp::Element::numSymmetryFunctions(), and nnp::strpr().

Referenced by main().

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

The documentation for this class was generated from the following files: