n2p2 - A neural network potential package
Structure.h
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#ifndef STRUCTURE_H
18#define STRUCTURE_H
19
20#include "Atom.h"
21#include "ElementMap.h"
22#include "Vec3D.h"
23#include <cstddef> // std::size_t
24#include <fstream> // std::ofstream
25#include <map> // std::map
26#include <string> // std::string
27#include <vector> // std::vector
28
29namespace nnp
30{
31
34{
38 {
51 };
52
66 std::size_t index;
68 std::size_t numAtoms;
70 std::size_t numElements;
72 std::size_t numElementsPresent;
74 int pbc[3];
76 double energy;
78 double energyRef;
80 double charge;
82 double chargeRef;
84 double volume;
88 std::string comment;
94 std::vector<std::size_t> numAtomsPerElement;
96 std::vector<Atom> atoms;
97
100 Structure();
117 void addAtom(Atom const& atom,
118 std::string const& element);
125 void readFromFile(std::string const fileName
126 = "input.data");
134 void readFromFile(std::ifstream& file);
141 void readFromLines(std::vector<
142 std::string> const& lines);
148 void calculateNeighborList(double cutoffRadius);
155 void calculatePbcCopies(double cutoffRadius);
196 void calculateInverseBox();
199 void calculateVolume();
202 void remap();
207 void remap(Atom& atom);
214 void toNormalizedUnits(double meanEnergy,
215 double convEnergy,
216 double convLength);
223 void toPhysicalUnits(double meanEnergy,
224 double convEnergy,
225 double convLength);
230 std::size_t getMaxNumNeighbors() const;
235 void freeAtoms(bool all);
238 void reset();
241 void clearNeighborList();
268 void updateError(
269 std::string const& property,
270 std::map<std::string, double>& error,
271 std::size_t& count) const;
276 std::string getEnergyLine() const;
281 std::vector<std::string> getForcesLines() const;
286 std::vector<std::string> getChargesLines() const;
294 void writeToFile(
295 std::string const fileName ="output.data",
296 bool const ref = true,
297 bool const append = false) const;
304 void writeToFile(
305 std::ofstream* const& file,
306 bool const ref = true) const;
311 void writeToFileXyz(std::ofstream* const& file) const;
320 std::ofstream* const& file) const;
327 std::ofstream* const& file,
328 std::string const elements) const;
333 std::vector<std::string> info() const;
334};
335
336}
337
338#endif
Contains element map.
Definition: ElementMap.h:30
Definition: Atom.h:28
Storage for a single atom.
Definition: Atom.h:32
Storage for one atomic configuration.
Definition: Structure.h:34
void toPhysicalUnits(double meanEnergy, double convEnergy, double convLength)
Switch to physical units, shift energy and change energy and length unit.
Definition: Structure.cpp:505
void calculateVolume()
Calculate volume from box vectors.
Definition: Structure.cpp:436
SampleType
Enumerates different sample types (e.g.
Definition: Structure.h:38
@ ST_VALIDATION
Structure is part of validation set (currently unused).
Definition: Structure.h:47
@ ST_TRAINING
Structure is part of the training set.
Definition: Structure.h:44
@ ST_UNKNOWN
Sample type not assigned yet.
Definition: Structure.h:41
@ ST_TEST
Structure is part of the test set.
Definition: Structure.h:50
Vec3D invbox[3]
Inverse simulation box vectors.
Definition: Structure.h:92
Vec3D box[3]
Simulation box vectors.
Definition: Structure.h:90
bool isTriclinic
If the simulation box is triclinic.
Definition: Structure.h:58
std::size_t getMaxNumNeighbors() const
Find maximum number of neighbors.
Definition: Structure.cpp:362
std::vector< std::size_t > numAtomsPerElement
Number of atoms of each element in this structure.
Definition: Structure.h:94
void writeToFile(std::string const fileName="output.data", bool const ref=true, bool const append=false) const
Write configuration to file.
Definition: Structure.cpp:659
std::string comment
Structure comment.
Definition: Structure.h:88
bool isPeriodic
If periodic boundary conditions apply.
Definition: Structure.h:56
double charge
Charge determined by neural network potential.
Definition: Structure.h:80
ElementMap elementMap
Copy of element map provided as constructor argument.
Definition: Structure.h:54
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
Definition: Structure.cpp:60
std::size_t index
Index number of this structure.
Definition: Structure.h:66
void remap()
Translate all atoms back into box if outside.
Definition: Structure.cpp:443
std::vector< std::string > getChargesLines() const
Get reference and NN charges for all atoms.
Definition: Structure.cpp:647
double chargeRef
Reference charge.
Definition: Structure.h:82
SampleType sampleType
Sample type (training or test set).
Definition: Structure.h:86
void addAtom(Atom const &atom, std::string const &element)
Add a single atom to structure.
Definition: Structure.cpp:69
void calculateInverseBox()
Calculate inverse box.
Definition: Structure.cpp:408
void writeToFilePoscar(std::ofstream *const &file) const
Write configuration to POSCAR file.
Definition: Structure.cpp:778
void writeToFileXyz(std::ofstream *const &file) const
Write configuration to xyz file.
Definition: Structure.cpp:743
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for each atom.
Definition: Structure.h:64
void calculatePbcCopies(double cutoffRadius)
Calculate required PBC copies.
Definition: Structure.cpp:375
std::string getEnergyLine() const
Get reference and NN energy.
Definition: Structure.cpp:626
void freeAtoms(bool all)
Free symmetry function memory for all atoms, see free() in Atom class.
Definition: Structure.cpp:531
double energy
Potential energy determined by neural network.
Definition: Structure.h:76
void readFromFile(std::string const fileName="input.data")
Read configuration from file.
Definition: Structure.cpp:86
double energyRef
Reference potential energy.
Definition: Structure.h:78
int pbc[3]
Number of PBC images necessary in each direction.
Definition: Structure.h:74
void reset()
Reset everything but elementMap.
Definition: Structure.cpp:543
std::vector< std::string > getForcesLines() const
Get reference and NN forces for all atoms.
Definition: Structure.cpp:634
Structure()
Constructor, initializes to zero.
Definition: Structure.cpp:30
double volume
Simulation box volume.
Definition: Structure.h:84
void toNormalizedUnits(double meanEnergy, double convEnergy, double convLength)
Normalize structure, shift energy and change energy and length unit.
Definition: Structure.cpp:479
std::size_t numAtoms
Total number of atoms present in this structure.
Definition: Structure.h:68
std::size_t numElements
Global number of elements (all structures).
Definition: Structure.h:70
void updateError(std::string const &property, std::map< std::string, double > &error, std::size_t &count) const
Update property error metrics with this structure.
Definition: Structure.cpp:596
void calculateNeighborList(double cutoffRadius)
Calculate neighbor list for all atoms.
Definition: Structure.cpp:253
std::vector< Atom > atoms
Vector of all atoms in this structure.
Definition: Structure.h:96
std::size_t numElementsPresent
Number of elements present in this structure.
Definition: Structure.h:72
void readFromLines(std::vector< std::string > const &lines)
Read configuration from lines.
Definition: Structure.cpp:131
bool hasNeighborList
If the neighbor list has been calculated.
Definition: Structure.h:60
void clearNeighborList()
Clear neighbor list of all atoms.
Definition: Structure.cpp:580
std::vector< std::string > info() const
Get structure information as a vector of strings.
Definition: Structure.cpp:851
bool hasSymmetryFunctions
If symmetry function values are saved for each atom.
Definition: Structure.h:62
Vector in 3 dimensional real space.
Definition: Vec3D.h:29