n2p2 - A neural network potential package
SetupAnalysis.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 "SetupAnalysis.h"
18#include "utility.h"
19#include <cmath> // M_PI
20
21using namespace std;
22using namespace nnp;
23
24void SetupAnalysis::writeSymmetryFunctionShape(size_t numPoints,
25 string const fileNameFormat)
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.
Definition: Atom.h:29
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