n2p2 - A neural network potential package
nnp-atomenv.cpp File Reference
#include "Dataset.h"
#include "mpi-extra.h"
#include "utility.h"
#include <mpi.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
Include dependency graph for nnp-atomenv.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file nnp-atomenv.cpp.

31{
32 bool useForces = false;
33 int numProcs = 0;
34 int myRank = 0;
35 ofstream myLog;
36
37 if (argc < 3)
38 {
39 cout << "USAGE: " << argv[0] << " <nbins> <ncutij> \n"
40 << " <nbins> ... Number of symmetry function"
41 " histogram bins.\n"
42 << " <ncutij> ... Maximum number of neighbor symmetry "
43 "functions written (for each element combination).\n"
44 << " Execute in directory with these NNP files present:\n"
45 << " - input.data (structure file)\n"
46 << " - input.nn (NNP settings)\n"
47 << " - scaling.data (symmetry function scaling data)\n";
48 return 1;
49 }
50
51 size_t numBins = (size_t)atoi(argv[1]);
52
53 MPI_Init(&argc, &argv);
54 MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
55 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
56
57 Dataset dataset;
58 myLog.open(strpr("nnp-atomenv.log.%04d", myRank).c_str());
59 if (myRank != 0) dataset.log.writeToStdout = false;
60 dataset.log.registerStreamPointer(&myLog);
61 dataset.setupMPI();
62 dataset.initialize();
63 dataset.loadSettingsFile();
64 dataset.setupGeneric();
66 dataset.setupSymmetryFunctionStatistics(true, false, true, false);
68 dataset.distributeStructures(false);
69 if (dataset.useNormalization()) dataset.toNormalizedUnits();
70
71 size_t n = dataset.getNumElements();
72 if ((size_t)argc - 2 != n * n)
73 {
74 throw runtime_error("ERROR: Wrong number of neighbor cutoffs.\n");
75 }
76 vector<vector<size_t> > neighCutoff(n);
77 size_t count = 0;
78 for (size_t i = 0; i < n; ++i)
79 {
80 neighCutoff.at(i).resize(n, 0);
81 for (size_t j = 0; j < n; ++j)
82 {
83 neighCutoff.at(i).at(j) = atof(argv[count+2]);
84 count++;
85 }
86 }
87 useForces = dataset.settingsKeywordExists("use_short_forces");
88
89 dataset.log << "\n";
90 dataset.log << "*** CALCULATING SYMMETRY FUNCTIONS ******"
91 "**************************************\n";
92 dataset.log << "\n";
93
94 for (vector<Structure>::iterator it = dataset.structures.begin();
95 it != dataset.structures.end(); ++it)
96 {
97 it->calculateNeighborList(dataset.getMaxCutoffRadius());
98#ifdef N2P2_NO_SF_GROUPS
99 dataset.calculateSymmetryFunctions((*it), useForces);
100#else
101 dataset.calculateSymmetryFunctionGroups((*it), useForces);
102#endif
103 // Clear unneccessary memory, don't use these structures after these
104 // operations unless you know what you do!
105 for (vector<Atom>::iterator it2 = it->atoms.begin();
106 it2 != it->atoms.end(); ++it2)
107 {
108 it2->numNeighborsUnique = 0;
109 it2->neighborsUnique.clear();
110 vector<size_t>(it2->neighborsUnique).swap(it2->neighborsUnique);
111
112 it2->dEdG.clear();
113 vector<double>(it2->dEdG).swap(it2->dEdG);
114
115#ifdef N2P2_FULL_SFD_MEMORY
116 it2->dGdxia.clear();
117 vector<double>(it2->dGdxia).swap(it2->dGdxia);
118#endif
119
120 if (!useForces)
121 {
122 it2->dGdr.clear();
123 vector<Vec3D>(it2->dGdr).swap(it2->dGdr);
124 }
125 }
126 }
127 dataset.log << "*****************************************"
128 "**************************************\n";
129
131 dataset.writeSymmetryFunctionHistograms(numBins,
132 "sf-scaled.%03zu.%04zu.histo");
133 dataset.writeNeighborHistogram();
134 dataset.sortNeighborLists();
135 dataset.writeNeighborLists();
136 dataset.writeAtomicEnvironmentFile(neighCutoff, useForces);
137
138 myLog.close();
139
140 MPI_Finalize();
141
142 return 0;
143}
Collect and process large data sets.
Definition: Dataset.h:35
void collectSymmetryFunctionStatistics()
Collect symmetry function statistics from all processors.
Definition: Dataset.cpp:974
int distributeStructures(bool randomize, bool excludeRank0=false, std::string const &fileName="input.data")
Read data file and distribute structures among processors.
Definition: Dataset.cpp:724
void sortNeighborLists()
Sort all neighbor lists according to element and distance.
Definition: Dataset.cpp:1466
void writeAtomicEnvironmentFile(std::vector< std::vector< std::size_t > > neighCutoff, bool derivatives, std::string const &fileNamePrefix="atomic-env")
Write atomic environment file.
Definition: Dataset.cpp:1536
void writeNeighborLists(std::string const &fileName="neighbor-list.data")
Write neighbor list file.
Definition: Dataset.cpp:1490
void setupMPI()
Initialize MPI with MPI_COMM_WORLD.
Definition: Dataset.cpp:52
std::vector< Structure > structures
All structures in this dataset.
Definition: Dataset.h:195
void writeSymmetryFunctionHistograms(std::size_t numBins, std::string fileNameFormat="sf.%03zu.%04zu.histo")
Calculate and write symmetry function histograms.
Definition: Dataset.cpp:1103
std::size_t writeNeighborHistogram(std::string const &fileNameHisto="neighbors.histo", std::string const &fileNameStructure="neighbors.out")
Calculate and write neighbor histogram and per-structure statistics.
Definition: Dataset.cpp:1320
void setupRandomNumberGenerator()
Initialize random number generator.
Definition: Dataset.cpp:110
void toNormalizedUnits()
Switch all structures to normalized units.
Definition: Dataset.cpp:952
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
Definition: Log.cpp:91
bool writeToStdout
Turn on/off output to stdout.
Definition: Log.h:85
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
std::size_t getNumElements() const
Getter for Mode::numElements.
Definition: Mode.h:698
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 getMaxCutoffRadius() const
Getter for Mode::maxCutoffRadius.
Definition: Mode.h:693
bool useNormalization() const
Check if normalization is enabled.
Definition: Mode.h:703
void calculateSymmetryFunctionGroups(Structure &structure, bool const derivatives)
Calculate all symmetry function groups for all atoms in given structure.
Definition: Mode.cpp:1561
virtual void setupSymmetryFunctionScaling(std::string const &fileName="scaling.data")
Set up symmetry function scaling from file.
Definition: Mode.cpp:712
bool settingsKeywordExists(std::string const &keyword) const
Check if keyword was found in settings file.
Definition: Mode.cpp:2193
Log log
Global log file.
Definition: Mode.h:593
void calculateSymmetryFunctions(Structure &structure, bool const derivatives)
Calculate all symmetry functions for all atoms in given structure.
Definition: Mode.cpp:1480
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
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90

References nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), nnp::Dataset::collectSymmetryFunctionStatistics(), nnp::Dataset::distributeStructures(), nnp::Mode::getMaxCutoffRadius(), nnp::Mode::getNumElements(), nnp::Mode::initialize(), nnp::Mode::loadSettingsFile(), nnp::Mode::log, nnp::Log::registerStreamPointer(), nnp::Mode::settingsKeywordExists(), nnp::Mode::setupGeneric(), nnp::Dataset::setupMPI(), nnp::Dataset::setupRandomNumberGenerator(), nnp::Mode::setupSymmetryFunctionScaling(), nnp::Mode::setupSymmetryFunctionStatistics(), nnp::Dataset::sortNeighborLists(), nnp::strpr(), nnp::Dataset::structures, nnp::Dataset::toNormalizedUnits(), nnp::Mode::useNormalization(), nnp::Dataset::writeAtomicEnvironmentFile(), nnp::Dataset::writeNeighborHistogram(), nnp::Dataset::writeNeighborLists(), nnp::Dataset::writeSymmetryFunctionHistograms(), and nnp::Log::writeToStdout.

Here is the call graph for this function: