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

#include <Prediction.h>

Inheritance diagram for nnp::Prediction:
Collaboration diagram for nnp::Prediction:

Public Member Functions

 Prediction ()
 
void readStructureFromFile (std::string const &fileName="input.data")
 
void setup ()
 
void predict ()
 
- 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...
 

Public Attributes

std::string fileNameSettings
 
std::string fileNameScaling
 
std::string formatWeightsFilesShort
 
std::string formatWeightsFilesCharge
 
Structure structure
 
- Public Attributes inherited from nnp::Mode
ElementMap elementMap
 Global element map, populated by setupElementMap(). More...
 
Log log
 Global log file. More...
 

Additional Inherited Members

- Public Types inherited from nnp::Mode
enum class  NNPType { HDNNP_2G = 2 , HDNNP_4G = 4 , HDNNP_Q = 10 }
 
- 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 27 of file Prediction.h.

Constructor & Destructor Documentation

◆ Prediction()

Prediction::Prediction ( )

Definition at line 26 of file Prediction.cpp.

26 : Mode(),
27 fileNameSettings ("input.nn" ),
28 fileNameScaling ("scaling.data" ),
29 formatWeightsFilesShort ("weights.%03zu.data" ),
30 formatWeightsFilesCharge("weightse.%03zu.data")
31{
32}
Mode()
Definition: Mode.cpp:40
std::string fileNameSettings
Definition: Prediction.h:35
std::string formatWeightsFilesShort
Definition: Prediction.h:37
std::string formatWeightsFilesCharge
Definition: Prediction.h:38
std::string fileNameScaling
Definition: Prediction.h:36

Member Function Documentation

◆ readStructureFromFile()

void Prediction::readStructureFromFile ( std::string const &  fileName = "input.data")

Definition at line 48 of file Prediction.cpp.

49{
50 ifstream file;
51 file.open(fileName.c_str());
54 structure.readFromFile(fileName);
56 if (normalize)
57 {
59 }
60 file.close();
61
62 return;
63}
bool normalize
Definition: Mode.h:629
double convEnergy
Definition: Mode.h:637
ElementMap elementMap
Global element map, populated by setupElementMap().
Definition: Mode.h:591
double convLength
Definition: Mode.h:638
double meanEnergy
Definition: Mode.h:636
double convCharge
Definition: Mode.h:639
void removeEnergyOffset(Structure &structure, bool ref=true)
Remove atomic energy offsets from reference energy.
Definition: Mode.cpp:2037
Structure structure
Definition: Prediction.h:39
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
Definition: Structure.cpp:71
void readFromFile(std::string const fileName="input.data")
Read configuration from file.
Definition: Structure.cpp:97
void toNormalizedUnits(double meanEnergy, double convEnergy, double convLength, double convCharge)
Normalize structure, shift energy and change energy, length and charge unit.
Definition: Structure.cpp:1249
void reset()
Reset everything but elementMap.
Definition: Structure.cpp:1319

References nnp::Mode::convCharge, nnp::Mode::convEnergy, nnp::Mode::convLength, nnp::Mode::elementMap, nnp::Mode::meanEnergy, nnp::Mode::normalize, nnp::Structure::readFromFile(), nnp::Mode::removeEnergyOffset(), nnp::Structure::reset(), nnp::Structure::setElementMap(), structure, and nnp::Structure::toNormalizedUnits().

Referenced by main().

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

◆ setup()

void Prediction::setup ( )

Definition at line 34 of file Prediction.cpp.

35{
36 initialize();
40 map<string, string> formatWeights {
41 {"short", formatWeightsFilesShort},
43 };
44 setupNeuralNetworkWeights(formatWeights);
45 setupSymmetryFunctionStatistics(false, false, true, false);
46}
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
void setupGeneric(std::string const &nnpDir="", bool skipNormalize=false, bool initialHardness=false)
Combine multiple setup routines and provide a basic NNP setup.
Definition: Mode.cpp:212
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.
Definition: Mode.cpp:1445
virtual void setupSymmetryFunctionScaling(std::string const &fileName="scaling.data")
Set up symmetry function scaling from file.
Definition: Mode.cpp:712
void setupSymmetryFunctionStatistics(bool collectStatistics, bool collectExtrapolationWarnings, bool writeExtrapolationWarnings, bool stopOnExtrapolationWarnings)
Set up symmetry function statistics collection.
Definition: Mode.cpp:1103
void loadSettingsFile(std::string const &fileName="input.nn")
Open settings file and load all keywords into memory.
Definition: Mode.cpp:161

References fileNameScaling, fileNameSettings, formatWeightsFilesCharge, formatWeightsFilesShort, nnp::Mode::initialize(), nnp::Mode::loadSettingsFile(), nnp::Mode::setupGeneric(), nnp::Mode::setupNeuralNetworkWeights(), nnp::Mode::setupSymmetryFunctionScaling(), and nnp::Mode::setupSymmetryFunctionStatistics().

Referenced by main().

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

◆ predict()

void Prediction::predict ( )

Definition at line 65 of file Prediction.cpp.

66{
68 if (normalize)
69 {
71 }
74
75 return;
76}
void addEnergyOffset(Structure &structure, bool ref=true)
Add atomic energy offsets to reference energy.
Definition: Mode.cpp:2018
void evaluateNNP(Structure &structure, bool useForces=true, bool useDEdG=true)
Evaluate neural network potential (includes total energy, optionally forces and in some cases charges...
Definition: Mode.cpp:1967
void toPhysicalUnits(double meanEnergy, double convEnergy, double convLength, double convCharge)
Switch to physical units, shift energy and change energy, length and charge unit.
Definition: Structure.cpp:1278

References nnp::Mode::addEnergyOffset(), nnp::Mode::convCharge, nnp::Mode::convEnergy, nnp::Mode::convLength, nnp::Mode::evaluateNNP(), nnp::Mode::meanEnergy, nnp::Mode::normalize, structure, and nnp::Structure::toPhysicalUnits().

Referenced by main().

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

Member Data Documentation

◆ fileNameSettings

std::string nnp::Prediction::fileNameSettings

Definition at line 35 of file Prediction.h.

Referenced by setup().

◆ fileNameScaling

std::string nnp::Prediction::fileNameScaling

Definition at line 36 of file Prediction.h.

Referenced by setup().

◆ formatWeightsFilesShort

std::string nnp::Prediction::formatWeightsFilesShort

Definition at line 37 of file Prediction.h.

Referenced by setup().

◆ formatWeightsFilesCharge

std::string nnp::Prediction::formatWeightsFilesCharge

Definition at line 38 of file Prediction.h.

Referenced by setup().

◆ structure

Structure nnp::Prediction::structure

Definition at line 39 of file Prediction.h.

Referenced by main(), predict(), and readStructureFromFile().


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