n2p2 - A neural network potential package
Prediction.cpp
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#include "Prediction.h"
18#include <fstream> // std::ifstream
19#include <map> // std::map
20#include <stdexcept> // std::runtime_error
21#include "utility.h"
22
23using namespace std;
24using namespace nnp;
25
26Prediction::Prediction() : Mode(),
27 fileNameSettings ("input.nn" ),
28 fileNameScaling ("scaling.data" ),
29 formatWeightsFilesShort ("weights.%03zu.data" ),
30 formatWeightsFilesCharge("weightse.%03zu.data")
31{
32}
33
35{
36 initialize();
40 map<string, string> formatWeights {
41 {"short", formatWeightsFilesShort},
43 };
44 setupNeuralNetworkWeights(formatWeights);
45 setupSymmetryFunctionStatistics(false, false, true, false);
46}
47
48void Prediction::readStructureFromFile(string const& fileName)
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}
64
66{
68 if (normalize)
69 {
71 }
74
75 return;
76}
Base class for all NNP applications.
Definition: Mode.h:87
bool normalize
Definition: Mode.h:629
double convEnergy
Definition: Mode.h:637
ElementMap elementMap
Global element map, populated by setupElementMap().
Definition: Mode.h:591
void addEnergyOffset(Structure &structure, bool ref=true)
Add atomic energy offsets to reference energy.
Definition: Mode.cpp:2018
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
double convLength
Definition: Mode.h:638
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
double meanEnergy
Definition: Mode.h:636
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
double convCharge
Definition: Mode.h:639
void removeEnergyOffset(Structure &structure, bool ref=true)
Remove atomic energy offsets from reference energy.
Definition: Mode.cpp:2037
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 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
void readStructureFromFile(std::string const &fileName="input.data")
Definition: Prediction.cpp:48
std::string fileNameSettings
Definition: Prediction.h:35
Structure structure
Definition: Prediction.h:39
std::string formatWeightsFilesShort
Definition: Prediction.h:37
std::string formatWeightsFilesCharge
Definition: Prediction.h:38
std::string fileNameScaling
Definition: Prediction.h:36
Definition: Atom.h:29
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
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