n2p2 - A neural network potential package
InterfaceLammps.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 INTERFACELAMMPS_H
18#define INTERFACELAMMPS_H
19
20#include "Mode.h"
21#include "Structure.h"
22#include <map> // std::map
23#include <cstddef> // std::size_t
24#include <cstdint> // int64_t
25#include <string> // std::string
26
27namespace nnp
28{
29
30class InterfaceLammps : public Mode
31{
32public:
34
53 void initialize(char const* const& directory,
54 char const* const& emap,
55 bool showew,
56 bool resetew,
57 int showewsum,
58 int maxew,
59 double cflength,
60 double cfenergy,
61 double lammpsCutoff,
62 int lammpsNtypes,
63 int myRank);
68 void setGlobalStructureStatus(bool const status);
76 void setLocalAtoms(int numAtomsLocal,
77 int const* const atomType);
82 void setLocalAtomPositions(double const* const* const atomPos);
87 void setLocalTags(int const* const atomTag);
92 void setLocalTags(int64_t const* const atomTag);
101 void setBoxVectors(double const* boxlo,
102 double const* boxhi,
103 double const xy,
104 double const xz,
105 double const yz);
110 void allocateNeighborlists(int const* const numneigh);
124 void addNeighbor(int i,
125 int j,
126 int64_t tag,
127 int type,
128 double dx,
129 double dy,
130 double dz,
131 double d2);
139 void process();
144 double getEnergy() const;
153 double getAtomicEnergy(int index) const;
158 void getForces(double* const* const& atomF) const;
164 void getCharges(double* const& atomQ) const;
169 bool isInitialized() const;
174 double getMaxCutoffRadius() const;
186 long getEWBufferSize() const;
192 void fillEWBuffer(char* const& buf, int bs) const;
198 void extractEWBuffer(char const* const& buf, int bs);
210 void writeToFile(std::string const fileName,
211 bool const append);
217 void add3DVecToArray(double *const & arr, Vec3D const& v) const;
218
219protected:
227 bool showew;
233 int maxew;
235 double cflength;
237 double cfenergy;
239 std::string emap;
241 std::vector<size_t> indexMap;
243 std::map<int, bool> ignoreType;
245 std::map<int, std::size_t> mapTypeToElement;
247 std::map<std::size_t, int> mapElementToType;
250};
251
253// Inlined function definitions //
255
257{
258 return initialized;
259}
260
261}
262
263#endif
Structure structure
Structure containing local atoms.
long getEWBufferSize() const
Calculate buffer size for extrapolation warning communication.
bool initialized
Initialization state.
void process()
Calculate symmetry functions, atomic neural networks and sum of local energy contributions.
void extractEWBuffer(char const *const &buf, int bs)
Extract given buffer to symmetry function statistics class.
std::map< int, bool > ignoreType
True if atoms of this LAMMPS type will be ignored.
void setLocalTags(int const *const atomTag)
Set atom tags (int version, -DLAMMPS_SMALLBIG).
void allocateNeighborlists(int const *const numneigh)
Allocate neighbor lists.
std::map< int, std::size_t > mapTypeToElement
Map from LAMMPS type to n2p2 element index.
void add3DVecToArray(double *const &arr, Vec3D const &v) const
Add a Vec3D vector to a 3D array in place.
double getMaxCutoffRadiusOverall()
Get largest cutoff including structure specific cutoff and screening cutoff.
bool hasGlobalStructure
Whether n2p2 knows about the global structure or only a local part.
void setLocalAtomPositions(double const *const *const atomPos)
Set absolute atom positions from LAMMPS (nnp/develop only).
double getEnergy() const
Return sum of local energy contributions.
void fillEWBuffer(char *const &buf, int bs) const
Fill provided buffer with extrapolation warning entries.
double getAtomicEnergy(int index) const
Return energy contribution of one atom.
void getForces(double *const *const &atomF) const
Calculate forces and add to LAMMPS atomic force arrays.
bool resetew
Corresponds to LAMMPS resetew keyword.
bool isInitialized() const
Check if this interface is correctly initialized.
void writeExtrapolationWarnings()
Write extrapolation warnings to log.
void setBoxVectors(double const *boxlo, double const *boxhi, double const xy, double const xz, double const yz)
Set box vectors of structure stored in LAMMPS (nnp/develop only).
std::vector< size_t > indexMap
Map from LAMMPS index to n2p2 atom index.
bool getGlobalStructureStatus()
Check if n2p2 knows about global structure.
double cfenergy
Corresponds to LAMMPS cfenergy keyword.
void setLocalAtoms(int numAtomsLocal, int const *const atomType)
(Re)set structure to contain only local LAMMPS atoms.
bool showew
Corresponds to LAMMPS showew keyword.
void writeToFile(std::string const fileName, bool const append)
Write current structure to file in units used in training data.
void getCharges(double *const &atomQ) const
Transfer charges (in units of e) to LAMMPS atomic charge vector.
int showewsum
Corresponds to LAMMPS showewsum keyword.
void setGlobalStructureStatus(bool const status)
Specify whether n2p2 knows about global structure or only local structure.
void finalizeNeighborList()
Sorts neighbor list and creates cutoff map if necessary.
void clearExtrapolationWarnings()
Clear extrapolation warnings storage.
std::map< std::size_t, int > mapElementToType
Map from n2p2 element index to LAMMPS type.
int myRank
Process rank.
double getMaxCutoffRadius() const
Get largest cutoff of symmetry functions.
int maxew
Corresponds to LAMMPS maxew keyword.
void addNeighbor(int i, int j, int64_t tag, int type, double dx, double dy, double dz, double d2)
Add one neighbor to atom (int64_t version, -DLAMMPS_BIGBIG).
double cflength
Corresponds to LAMMPS cflength keyword.
std::string emap
Corresponds to LAMMPS map keyword.
Base class for all NNP applications.
Definition: Mode.h:87
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
Definition: Atom.h:29
Storage for one atomic configuration.
Definition: Structure.h:39
Vector in 3 dimensional real space.
Definition: Vec3D.h:30