n2p2 - A neural network potential package
nnp::InterfaceLammps Class Reference

#include <InterfaceLammps.h>

Inheritance diagram for nnp::InterfaceLammps:
Collaboration diagram for nnp::InterfaceLammps:

Public Member Functions

 InterfaceLammps ()
 
void initialize (char const *const &directory, char const *const &emap, bool showew, bool resetew, int showewsum, int maxew, double cflength, double cfenergy, double lammpsCutoff, int lammpsNtypes, int myRank)
 Initialize the LAMMPS interface. More...
 
void setGlobalStructureStatus (bool const status)
 Specify whether n2p2 knows about global structure or only local structure. More...
 
bool getGlobalStructureStatus ()
 Check if n2p2 knows about global structure. More...
 
void setLocalAtoms (int numAtomsLocal, int const *const atomType)
 (Re)set structure to contain only local LAMMPS atoms. More...
 
void setLocalAtomPositions (double const *const *const atomPos)
 Set absolute atom positions from LAMMPS (nnp/develop only). More...
 
void setLocalTags (int const *const atomTag)
 Set atom tags (int version, -DLAMMPS_SMALLBIG). More...
 
void setLocalTags (int64_t const *const atomTag)
 Set atom tags (int64_t version, -DLAMMPS_BIGBIG). More...
 
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). More...
 
void allocateNeighborlists (int const *const numneigh)
 Allocate neighbor lists. More...
 
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). More...
 
void finalizeNeighborList ()
 Sorts neighbor list and creates cutoff map if necessary. More...
 
void process ()
 Calculate symmetry functions, atomic neural networks and sum of local energy contributions. More...
 
double getEnergy () const
 Return sum of local energy contributions. More...
 
double getAtomicEnergy (int index) const
 Return energy contribution of one atom. More...
 
void getForces (double *const *const &atomF) const
 Calculate forces and add to LAMMPS atomic force arrays. More...
 
void getCharges (double *const &atomQ) const
 Transfer charges (in units of e) to LAMMPS atomic charge vector. More...
 
bool isInitialized () const
 Check if this interface is correctly initialized. More...
 
double getMaxCutoffRadius () const
 Get largest cutoff of symmetry functions. More...
 
double getMaxCutoffRadiusOverall ()
 Get largest cutoff including structure specific cutoff and screening cutoff. More...
 
long getEWBufferSize () const
 Calculate buffer size for extrapolation warning communication. More...
 
void fillEWBuffer (char *const &buf, int bs) const
 Fill provided buffer with extrapolation warning entries. More...
 
void extractEWBuffer (char const *const &buf, int bs)
 Extract given buffer to symmetry function statistics class. More...
 
void writeExtrapolationWarnings ()
 Write extrapolation warnings to log. More...
 
void clearExtrapolationWarnings ()
 Clear extrapolation warnings storage. More...
 
void writeToFile (std::string const fileName, bool const append)
 Write current structure to file in units used in training data. More...
 
void add3DVecToArray (double *const &arr, Vec3D const &v) const
 Add a Vec3D vector to a 3D array in place. More...
 
- Public Member Functions inherited from nnp::Mode
 Mode ()
 
void initialize ()
 Write welcome message with version information. More...
 
void loadSettingsFile (std::string const &fileName="input.nn")
 Open settings file and load all keywords into memory. More...
 
void setupGeneric (std::string const &nnpDir="", bool skipNormalize=false, bool initialHardness=false)
 Combine multiple setup routines and provide a basic NNP setup. More...
 
void setupNormalization (bool standalone=true)
 Set up normalization. More...
 
virtual void setupElementMap ()
 Set up the element map. More...
 
virtual void setupElements ()
 Set up all Element instances. More...
 
void setupCutoff ()
 Set up cutoff function for all symmetry functions. More...
 
virtual void setupSymmetryFunctions ()
 Set up all symmetry functions. More...
 
void setupSymmetryFunctionScalingNone ()
 Set up "empy" symmetry function scaling. More...
 
virtual void setupSymmetryFunctionScaling (std::string const &fileName="scaling.data")
 Set up symmetry function scaling from file. More...
 
virtual void setupSymmetryFunctionGroups ()
 Set up symmetry function groups. More...
 
virtual void setupSymmetryFunctionCache (bool verbose=false)
 Set up symmetry function cache. More...
 
void setupSymmetryFunctionMemory (bool verbose=false)
 Extract required memory dimensions for symmetry function derivatives. More...
 
void setupSymmetryFunctionStatistics (bool collectStatistics, bool collectExtrapolationWarnings, bool writeExtrapolationWarnings, bool stopOnExtrapolationWarnings)
 Set up symmetry function statistics collection. More...
 
void setupCutoffMatrix ()
 Setup matrix storing all symmetry function cut-offs for each element. More...
 
virtual void setupNeuralNetwork ()
 Set up neural networks for all elements. More...
 
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. More...
 
virtual void setupNeuralNetworkWeights (std::string directoryPrefix, std::map< std::string, std::string > fileNameFormats=std::map< std::string, std::string >())
 Set up neural network weights from files with given name format. More...
 
virtual void setupElectrostatics (bool initialHardness=false, std::string directoryPrefix="", std::string fileNameFormat="hardness.%03zu.data")
 Set up electrostatics related stuff (hardness, screening, ...). More...
 
void calculateSymmetryFunctions (Structure &structure, bool const derivatives)
 Calculate all symmetry functions for all atoms in given structure. More...
 
void calculateSymmetryFunctionGroups (Structure &structure, bool const derivatives)
 Calculate all symmetry function groups for all atoms in given structure. More...
 
void calculateAtomicNeuralNetworks (Structure &structure, bool const derivatives, std::string id="")
 Calculate atomic neural networks for all atoms in given structure. More...
 
void chargeEquilibration (Structure &structure, bool const derivativesElec)
 Perform global charge equilibration method. More...
 
void calculateEnergy (Structure &structure) const
 Calculate potential energy for a given structure. More...
 
void calculateCharge (Structure &structure) const
 Calculate total charge for a given structure. More...
 
void calculateForces (Structure &structure) const
 Calculate forces for all atoms in given structure. More...
 
void evaluateNNP (Structure &structure, bool useForces=true, bool useDEdG=true)
 Evaluate neural network potential (includes total energy, optionally forces and in some cases charges. More...
 
void addEnergyOffset (Structure &structure, bool ref=true)
 Add atomic energy offsets to reference energy. More...
 
void removeEnergyOffset (Structure &structure, bool ref=true)
 Remove atomic energy offsets from reference energy. More...
 
double getEnergyOffset (Structure const &structure) const
 Get atomic energy offset for given structure. More...
 
double getEnergyWithOffset (Structure const &structure, bool ref=true) const
 Add atomic energy offsets and return energy. More...
 
double normalized (std::string const &property, double value) const
 Apply normalization to given property. More...
 
double normalizedEnergy (Structure const &structure, bool ref=true) const
 Apply normalization to given energy of structure. More...
 
double physical (std::string const &property, double value) const
 Undo normalization for a given property. More...
 
double physicalEnergy (Structure const &structure, bool ref=true) const
 Undo normalization for a given energy of structure. More...
 
void convertToNormalizedUnits (Structure &structure) const
 Convert one structure to normalized units. More...
 
void convertToPhysicalUnits (Structure &structure) const
 Convert one structure to physical units. More...
 
void logEwaldCutoffs ()
 Logs Ewald params whenever they change. More...
 
std::size_t getNumExtrapolationWarnings () const
 Count total number of extrapolation warnings encountered for all elements and symmetry functions. More...
 
void resetExtrapolationWarnings ()
 Erase all extrapolation warnings and reset counters. More...
 
NNPType getNnpType () const
 Getter for Mode::nnpType. More...
 
double getMeanEnergy () const
 Getter for Mode::meanEnergy. More...
 
double getConvEnergy () const
 Getter for Mode::convEnergy. More...
 
double getConvLength () const
 Getter for Mode::convLength. More...
 
double getConvCharge () const
 Getter for Mode::convCharge. More...
 
double getMaxCutoffRadius () const
 Getter for Mode::maxCutoffRadius. More...
 
std::size_t getNumElements () const
 Getter for Mode::numElements. More...
 
std::vector< std::size_t > getNumSymmetryFunctions () const
 Get number of symmetry functions per element. More...
 
bool useNormalization () const
 Check if normalization is enabled. More...
 
bool settingsKeywordExists (std::string const &keyword) const
 Check if keyword was found in settings file. More...
 
std::string settingsGetValue (std::string const &keyword) const
 Get value for given keyword in Settings instance. More...
 
std::vector< std::size_t > pruneSymmetryFunctionsRange (double threshold)
 Prune symmetry functions according to their range and write settings file. More...
 
std::vector< std::size_t > pruneSymmetryFunctionsSensitivity (double threshold, std::vector< std::vector< double > > sensitivity)
 Prune symmetry functions with sensitivity analysis data. More...
 
void writePrunedSettingsFile (std::vector< std::size_t > prune, std::string fileName="output.nn") const
 Copy settings file but comment out lines provided. More...
 
void writeSettingsFile (std::ofstream *const &file) const
 Write complete settings file. More...
 

Protected Attributes

int myRank
 Process rank. More...
 
bool initialized
 Initialization state. More...
 
bool hasGlobalStructure
 Whether n2p2 knows about the global structure or only a local part. More...
 
bool showew
 Corresponds to LAMMPS showew keyword. More...
 
bool resetew
 Corresponds to LAMMPS resetew keyword. More...
 
int showewsum
 Corresponds to LAMMPS showewsum keyword. More...
 
int maxew
 Corresponds to LAMMPS maxew keyword. More...
 
double cflength
 Corresponds to LAMMPS cflength keyword. More...
 
double cfenergy
 Corresponds to LAMMPS cfenergy keyword. More...
 
std::string emap
 Corresponds to LAMMPS map keyword. More...
 
std::vector< size_t > indexMap
 Map from LAMMPS index to n2p2 atom index. More...
 
std::map< int, bool > ignoreType
 True if atoms of this LAMMPS type will be ignored. More...
 
std::map< int, std::size_t > mapTypeToElement
 Map from LAMMPS type to n2p2 element index. More...
 
std::map< std::size_t, int > mapElementToType
 Map from n2p2 element index to LAMMPS type. More...
 
Structure structure
 Structure containing local atoms. More...
 
- Protected Attributes inherited from nnp::Mode
NNPType nnpType
 
bool normalize
 
bool checkExtrapolationWarnings
 
std::size_t numElements
 
std::vector< std::size_t > minNeighbors
 
std::vector< double > minCutoffRadius
 
double maxCutoffRadius
 
double cutoffAlpha
 
double meanEnergy
 
double convEnergy
 
double convLength
 
double convCharge
 
double fourPiEps
 
EwaldSetup ewaldSetup
 
settings::Settings settings
 
SymFnc::ScalingType scalingType
 
CutoffFunction::CutoffType cutoffType
 
ScreeningFunction screeningFunction
 
std::vector< Elementelements
 
std::vector< std::string > nnk
 
std::map< std::string, NNSetupnns
 
std::vector< std::vector< double > > cutoffs
 Matrix storing all symmetry function cut-offs for all elements. More...
 
ErfcBuf erfcBuf
 

Additional Inherited Members

- Public Types inherited from nnp::Mode
enum class  NNPType { HDNNP_2G = 2 , HDNNP_4G = 4 , HDNNP_Q = 10 }
 
- Public Attributes inherited from nnp::Mode
ElementMap elementMap
 Global element map, populated by setupElementMap(). More...
 
Log log
 Global log file. More...
 
- Protected Member Functions inherited from nnp::Mode
void readNeuralNetworkWeights (std::string const &id, std::string const &fileName)
 Read in weights for a specific type of neural network. More...
 

Detailed Description

Definition at line 30 of file InterfaceLammps.h.

Constructor & Destructor Documentation

◆ InterfaceLammps()

InterfaceLammps::InterfaceLammps ( )

Definition at line 38 of file InterfaceLammps.cpp.

38 : myRank (0 ),
39 initialized (false),
40 hasGlobalStructure (false),
41 showew (true ),
42 resetew (false),
43 showewsum (0 ),
44 maxew (0 ),
45 cflength (1.0 ),
46 cfenergy (1.0 )
47
48{
49}
bool initialized
Initialization state.
bool hasGlobalStructure
Whether n2p2 knows about the global structure or only a local part.
bool resetew
Corresponds to LAMMPS resetew keyword.
double cfenergy
Corresponds to LAMMPS cfenergy keyword.
bool showew
Corresponds to LAMMPS showew keyword.
int showewsum
Corresponds to LAMMPS showewsum keyword.
int myRank
Process rank.
int maxew
Corresponds to LAMMPS maxew keyword.
double cflength
Corresponds to LAMMPS cflength keyword.

Member Function Documentation

◆ initialize()

void InterfaceLammps::initialize ( char const *const &  directory,
char const *const &  emap,
bool  showew,
bool  resetew,
int  showewsum,
int  maxew,
double  cflength,
double  cfenergy,
double  lammpsCutoff,
int  lammpsNtypes,
int  myRank 
)

Initialize the LAMMPS interface.

Parameters
[in]directoryDirectory containing NNP data files (weights, scaling, settings).
[in]emapElement mapping from LAMMPS to n2p2.
[in]showewIf detailed extrapolation warnings for all atoms are shown.
[in]resetewIf extrapolation warnings counter is reset every timestep.
[in]showewsumShow number of warnings every this many timesteps.
[in]maxewAbort simulation if more than this many warnings are encountered.
[in]cflengthLength unit conversion factor.
[in]cfenergyEnergy unit conversion factor.
[in]lammpsCutoffCutoff radius from LAMMPS (via pair_coeff).
[in]lammpsNtypesNumber of atom types in LAMMPS.
[in]myRankMPI process rank (passed on to structure index).

Definition at line 51 of file InterfaceLammps.cpp.

62{
63 this->emap = emap;
64 this->showew = showew;
65 this->resetew = resetew;
66 this->showewsum = showewsum;
67 this->maxew = maxew;
68 this->cflength = cflength;
69 this->cfenergy = cfenergy;
70 this->myRank = myRank;
71 log.writeToStdout = false;
72 string dir(directory);
73 char const separator = '/';
74 if (dir.back() != separator) dir += separator;
76 loadSettingsFile(dir + "input.nn");
77 setupGeneric(dir);
78 setupSymmetryFunctionScaling(dir + "scaling.data");
79 bool collectStatistics = false;
80 bool collectExtrapolationWarnings = false;
81 bool writeExtrapolationWarnings = false;
82 bool stopOnExtrapolationWarnings = false;
83 if (showew == true || showewsum > 0 || maxew >= 0)
84 {
85 collectExtrapolationWarnings = true;
86 }
87 setupSymmetryFunctionStatistics(collectStatistics,
88 collectExtrapolationWarnings,
90 stopOnExtrapolationWarnings);
92
93 log << "\n";
94 log << "*** SETUP: LAMMPS INTERFACE *************"
95 "**************************************\n";
96 log << "\n";
97
98 if (showew)
99 {
100 log << "Individual extrapolation warnings will be shown.\n";
101 }
102 else
103 {
104 log << "Individual extrapolation warnings will not be shown.\n";
105 }
106
107 if (showewsum != 0)
108 {
109 log << strpr("Extrapolation warning summary will be shown every %d"
110 " timesteps.\n", showewsum);
111 }
112 else
113 {
114 log << "Extrapolation warning summary will not be shown.\n";
115 }
116
117 if (maxew != 0)
118 {
119 log << strpr("The simulation will be stopped when %d extrapolation"
120 " warnings are exceeded.\n", maxew);
121 }
122 else
123 {
124 log << "No extrapolation warning limit set.\n";
125 }
126
127 if (resetew)
128 {
129 log << "Extrapolation warning counter is reset every time step.\n";
130 }
131 else
132 {
133 log << "Extrapolation warnings are accumulated over all time steps.\n";
134 }
135
136 log << "-----------------------------------------"
137 "--------------------------------------\n";
138 log << "CAUTION: If the LAMMPS unit system differs from the one used\n";
139 log << " during NN training, appropriate conversion factors\n";
140 log << " must be provided (see keywords cflength and cfenergy).\n";
141 log << "\n";
142 log << strpr("Length unit conversion factor: %24.16E\n", cflength);
143 log << strpr("Energy unit conversion factor: %24.16E\n", cfenergy);
144 double sfCutoff = getMaxCutoffRadius();
145 log << "\n";
146 log << "Checking consistency of cutoff radii (in LAMMPS units):\n";
147 log << strpr("LAMMPS Cutoff (via pair_coeff) : %11.3E\n", lammpsCutoff);
148 log << strpr("Maximum symmetry function cutoff: %11.3E\n", sfCutoff);
149 if (lammpsCutoff < sfCutoff)
150 {
151 throw runtime_error("ERROR: LAMMPS cutoff via pair_coeff keyword is"
152 " smaller than maximum symmetry function"
153 " cutoff.\n");
154 }
155 else if (fabs(sfCutoff - lammpsCutoff) / lammpsCutoff > TOLCUTOFF)
156 {
157 log << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
158 log << "WARNING: Potential length units mismatch!\n";
159 log << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
160 }
161 else
162 {
163 log << "Cutoff radii are consistent.\n";
164 }
165
166 log << "-----------------------------------------"
167 "--------------------------------------\n";
168 log << "Element mapping string from LAMMPS to n2p2: \""
169 + this->emap + "\"\n";
170 // Create default element mapping.
171 if (this->emap == "")
172 {
173 if (elementMap.size() != (size_t)lammpsNtypes)
174 {
175 throw runtime_error(strpr("ERROR: No element mapping given and "
176 "number of LAMMPS atom types (%d) and "
177 "NNP elements (%zu) does not match.\n",
178 lammpsNtypes, elementMap.size()));
179 }
180 log << "Element mapping string empty, creating default mapping.\n";
181 for (int i = 0; i < lammpsNtypes; ++i)
182 {
183 mapTypeToElement[i + 1] = i;
184 mapElementToType[i] = i + 1;
185 }
186 }
187 // Read element mapping from pair_style argument.
188 else
189 {
190 vector<string> emapSplit = split(reduce(trim(this->emap), " \t", ""),
191 ',');
192 if (elementMap.size() < emapSplit.size())
193 {
194 throw runtime_error(strpr("ERROR: Element mapping is inconsistent,"
195 " NNP elements: %zu,"
196 " emap elements: %zu.\n",
198 emapSplit.size()));
199 }
200 for (string s : emapSplit)
201 {
202 vector<string> typeString = split(s, ':');
203 if (typeString.size() != 2)
204 {
205 throw runtime_error(strpr("ERROR: Invalid element mapping "
206 "string: \"%s\".\n", s.c_str()));
207 }
208 int t = stoi(typeString.at(0));
209 if (t > lammpsNtypes)
210 {
211 throw runtime_error(strpr("ERROR: LAMMPS type \"%d\" not "
212 "present, there are only %d types "
213 "defined.\n", t, lammpsNtypes));
214 }
215 size_t e = elementMap[typeString.at(1)];
216 mapTypeToElement[t] = e;
217 mapElementToType[e] = t;
218 }
219 }
220 log << "\n";
221 log << "CAUTION: Please ensure that this mapping between LAMMPS\n";
222 log << " atom types and NNP elements is consistent:\n";
223 log << "\n";
224 log << "---------------------------\n";
225 log << "LAMMPS type | NNP element\n";
226 log << "---------------------------\n";
227 for (int i = 1; i <= lammpsNtypes; ++i)
228 {
229 if (mapTypeToElement.find(i) != mapTypeToElement.end())
230 {
231 size_t e = mapTypeToElement.at(i);
232 log << strpr("%11d <-> %2s (%3zu)\n",
233 i,
234 elementMap[e].c_str(),
236 ignoreType[i] = false;
237 }
238 else
239 {
240 log << strpr("%11d <-> --\n", i);
241 ignoreType[i] = true;
242
243 }
244 }
245 log << "---------------------------\n";
246 log << "\n";
247 log << "NNP setup for LAMMPS completed.\n";
248
249 log << "*****************************************"
250 "**************************************\n";
251
253
254 initialized = true;
255}
#define TOLCUTOFF
std::size_t size() const
Get element map size.
Definition: ElementMap.h:140
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
Definition: ElementMap.h:145
Structure structure
Structure containing local atoms.
std::map< int, bool > ignoreType
True if atoms of this LAMMPS type will be ignored.
std::map< int, std::size_t > mapTypeToElement
Map from LAMMPS type to n2p2 element index.
void writeExtrapolationWarnings()
Write extrapolation warnings to log.
std::map< std::size_t, int > mapElementToType
Map from n2p2 element index to LAMMPS type.
double getMaxCutoffRadius() const
Get largest cutoff of symmetry functions.
std::string emap
Corresponds to LAMMPS map keyword.
bool writeToStdout
Turn on/off output to stdout.
Definition: Log.h:85
ElementMap elementMap
Global element map, populated by setupElementMap().
Definition: Mode.h:591
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:55
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
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
Log log
Global log file.
Definition: Mode.h:593
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
string trim(string const &line, string const &whitespace)
Remove leading and trailing whitespaces from string.
Definition: utility.cpp:47
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
Definition: utility.cpp:33
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
Definition: utility.cpp:60
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
Definition: Structure.cpp:71

References nnp::ElementMap::atomicNumber(), cfenergy, cflength, nnp::Mode::elementMap, emap, getMaxCutoffRadius(), ignoreType, nnp::Mode::initialize(), initialized, nnp::Mode::loadSettingsFile(), nnp::Mode::log, mapElementToType, mapTypeToElement, maxew, myRank, nnp::reduce(), resetew, nnp::Structure::setElementMap(), nnp::Mode::setupGeneric(), nnp::Mode::setupNeuralNetworkWeights(), nnp::Mode::setupSymmetryFunctionScaling(), nnp::Mode::setupSymmetryFunctionStatistics(), showew, showewsum, nnp::ElementMap::size(), nnp::split(), nnp::strpr(), structure, TOLCUTOFF, nnp::trim(), writeExtrapolationWarnings(), and nnp::Log::writeToStdout.

Referenced by LAMMPS_NS::PairHDNNP::init_style().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGlobalStructureStatus()

void InterfaceLammps::setGlobalStructureStatus ( bool const  status)

Specify whether n2p2 knows about global structure or only local structure.

Parameters
[in]statustrue if n2p2 has global structure.

Definition at line 257 of file InterfaceLammps.cpp.

258{
259 hasGlobalStructure = status;
260}

References hasGlobalStructure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::init_style().

Here is the caller graph for this function:

◆ getGlobalStructureStatus()

bool InterfaceLammps::getGlobalStructureStatus ( )

Check if n2p2 knows about global structure.

Definition at line 262 of file InterfaceLammps.cpp.

263{
264 return hasGlobalStructure;
265}

References hasGlobalStructure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::transferNeighborList().

Here is the caller graph for this function:

◆ setLocalAtoms()

void InterfaceLammps::setLocalAtoms ( int  numAtomsLocal,
int const *const  atomType 
)

(Re)set structure to contain only local LAMMPS atoms.

Parameters
[in]numAtomsLocalNumber of local atoms.
[in]atomTypeLAMMPS atom type.

Definition at line 267 of file InterfaceLammps.cpp.

269{
270 for (size_t i = 0; i < numElements; ++i)
271 {
273 }
279 structure.energy = 0.0;
280 structure.atoms.clear();
281 indexMap.clear();
282 structure.atoms.reserve(numAtomsLocal);
283 indexMap.resize(numAtomsLocal, numeric_limits<size_t>::max());
284 for (int i = 0; i < numAtomsLocal; i++)
285 {
286 if (ignoreType[atomType[i]]) continue;
289 structure.atoms.push_back(Atom());
290 Atom& a = structure.atoms.back();
291 a.index = i;
293 a.element = mapTypeToElement[atomType[i]];
294 a.numNeighbors = 0;
295 a.hasSymmetryFunctions = false;
297 a.neighbors.clear();
298 a.numNeighborsPerElement.clear();
301 }
302
303 return;
304}
std::vector< size_t > indexMap
Map from LAMMPS index to n2p2 atom index.
std::size_t numElements
Definition: Mode.h:631
Storage for a single atom.
Definition: Atom.h:33
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:170
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
Definition: Atom.h:97
std::size_t index
Index number of this atom.
Definition: Atom.h:101
std::size_t indexStructure
Index number of structure this atom belongs to.
Definition: Atom.h:103
std::size_t element
Element index of this atom.
Definition: Atom.h:107
bool hasSymmetryFunctions
If symmetry function values are saved for this atom.
Definition: Atom.h:95
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
Definition: Atom.h:138
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:109
std::vector< std::size_t > numAtomsPerElement
Number of atoms of each element in this structure.
Definition: Structure.h:120
std::size_t index
Index number of this structure.
Definition: Structure.h:73
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for each atom.
Definition: Structure.h:71
double energy
Potential energy determined by neural network.
Definition: Structure.h:83
std::size_t numAtoms
Total number of atoms present in this structure.
Definition: Structure.h:75
std::vector< Atom > atoms
Vector of all atoms in this structure.
Definition: Structure.h:122
bool hasNeighborList
If the neighbor list has been calculated.
Definition: Structure.h:65
bool hasSymmetryFunctions
If symmetry function values are saved for each atom.
Definition: Structure.h:69

References nnp::Structure::atoms, nnp::Atom::element, nnp::Structure::energy, nnp::Structure::hasNeighborList, nnp::Atom::hasSymmetryFunctionDerivatives, nnp::Structure::hasSymmetryFunctionDerivatives, nnp::Atom::hasSymmetryFunctions, nnp::Structure::hasSymmetryFunctions, ignoreType, nnp::Atom::index, nnp::Structure::index, indexMap, nnp::Atom::indexStructure, mapTypeToElement, myRank, nnp::Atom::neighbors, nnp::Structure::numAtoms, nnp::Structure::numAtomsPerElement, nnp::Mode::numElements, nnp::Atom::numNeighbors, nnp::Atom::numNeighborsPerElement, and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the caller graph for this function:

◆ setLocalAtomPositions()

void InterfaceLammps::setLocalAtomPositions ( double const *const *const  atomPos)

Set absolute atom positions from LAMMPS (nnp/develop only).

Parameters
[in]atomPosAtom coordinate array in LAMMPS units.

Definition at line 306 of file InterfaceLammps.cpp.

307{
308 for (size_t i = 0; i < structure.numAtoms; ++i)
309 {
310 Atom& a = structure.atoms.at(i);
311 a.r[0] = atomPos[i][0] * cflength;
312 a.r[1] = atomPos[i][1] * cflength;
313 a.r[2] = atomPos[i][2] * cflength;
314 if (normalize)
315 {
316 a.r[0] *= convLength;
317 a.r[1] *= convLength;
318 a.r[2] *= convLength;
319 }
320 }
321
322 return;
323}
bool normalize
Definition: Mode.h:629
double convLength
Definition: Mode.h:638
Vec3D r
Cartesian coordinates.
Definition: Atom.h:125

References nnp::Structure::atoms, cflength, nnp::Mode::convLength, nnp::Mode::normalize, nnp::Structure::numAtoms, nnp::Atom::r, and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the caller graph for this function:

◆ setLocalTags() [1/2]

void InterfaceLammps::setLocalTags ( int const *const  atomTag)

Set atom tags (int version, -DLAMMPS_SMALLBIG).

Parameters
[in]atomTagLAMMPS atom tag.

Definition at line 325 of file InterfaceLammps.cpp.

326{
327 for (size_t i = 0; i < structure.atoms.size(); i++)
328 {
329 // Implicit conversion from int to int64_t!
330 structure.atoms.at(i).tag = atomTag[i];
331 }
332
333 return;
334}

References nnp::Structure::atoms, and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the caller graph for this function:

◆ setLocalTags() [2/2]

void InterfaceLammps::setLocalTags ( int64_t const *const  atomTag)

Set atom tags (int64_t version, -DLAMMPS_BIGBIG).

Parameters
[in]atomTagLAMMPS atom tag.

Definition at line 336 of file InterfaceLammps.cpp.

337{
338 for (size_t i = 0; i < structure.atoms.size(); i++)
339 {
340 structure.atoms.at(i).tag = atomTag[i];
341 }
342
343 return;
344}

References nnp::Structure::atoms, and structure.

◆ setBoxVectors()

void InterfaceLammps::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).

Parameters
[in]boxloArray containing coordinates of origin xlo, ylo, zlo.
[in]boxhiArray containing coordinates xhi, yhi, zhi.
[in]xyTilt factor for box vector b.
[in]xzFirst tilt factor for box vector c.
[in]yzSecond tilt factor for box vector c.

Definition at line 346 of file InterfaceLammps.cpp.

351{
352 structure.isPeriodic = true;
353
354 // Box vector a
355 structure.box[0][0] = boxhi[0] - boxlo[0];
356 structure.box[0][1] = 0;
357 structure.box[0][2] = 0;
358
359 // Box vector b
360 structure.box[1][0] = xy;
361 structure.box[1][1] = boxhi[1] - boxlo[1];
362 structure.box[1][2] = 0;
363
364 // Box vector c
365 structure.box[2][0] = xz;
366 structure.box[2][1] = yz;
367 structure.box[2][2] = boxhi[2] - boxlo[2];
368
369 // LAMMPS may set triclinic = 1 even if the following condition is not
370 // satisfied.
371 if (structure.box[0][1] > numeric_limits<double>::min() ||
372 structure.box[0][2] > numeric_limits<double>::min() ||
373 structure.box[1][0] > numeric_limits<double>::min() ||
374 structure.box[1][2] > numeric_limits<double>::min() ||
375 structure.box[2][0] > numeric_limits<double>::min() ||
376 structure.box[2][1] > numeric_limits<double>::min())
377 {
378 structure.isTriclinic = true;
379 }
380
381 for(size_t i = 0; i < 3; ++i)
382 {
383 structure.box[i] *= cflength;
385 }
386
389 //cout << "Box vectors: \n";
390 //for(size_t i = 0; i < 3; ++i)
391 //{
392 // for(size_t j = 0; j < 3; ++j)
393 // {
394 // cout << structure.box[i][j] / convLength << " ";
395 // }
396 // cout << endl;
397 //}
398
399}
void calculateVolume()
Calculate volume from box vectors.
Definition: Structure.cpp:581
Vec3D box[3]
Simulation box vectors.
Definition: Structure.h:112
bool isTriclinic
If the simulation box is triclinic.
Definition: Structure.h:63
bool isPeriodic
If periodic boundary conditions apply.
Definition: Structure.h:61
void calculateInverseBox()
Calculate inverse box.
Definition: Structure.cpp:519

References nnp::Structure::box, nnp::Structure::calculateInverseBox(), nnp::Structure::calculateVolume(), cflength, nnp::Mode::convLength, nnp::Structure::isPeriodic, nnp::Structure::isTriclinic, nnp::Mode::normalize, and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocateNeighborlists()

void InterfaceLammps::allocateNeighborlists ( int const *const  numneigh)

Allocate neighbor lists.

Parameters
[in]numneighArray containing number of neighbors for each local atom.

Definition at line 401 of file InterfaceLammps.cpp.

402{
403 for(size_t i = 0; i < structure.numAtoms; ++i)
404 {
405 auto& a = structure.atoms.at(i);
406 a.neighbors.reserve(numneigh[i]);
407 }
408}

References nnp::Structure::atoms, nnp::Structure::numAtoms, and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::transferNeighborList().

Here is the caller graph for this function:

◆ addNeighbor()

void InterfaceLammps::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).

Parameters
[in]iLocal atom index.
[in]jNeighbor atom index.
[in]tagNeighbor atom tag.
[in]typeNeighbor atom type.
[in]dxNeighbor atom distance in x direction.
[in]dyNeighbor atom distance in y direction.
[in]dzNeighbor atom distance in z direction.
[in]d2Square of neighbor atom distance.

If -DLAMMPS_SMALLBIG implicit conversion is applied for tag.

Definition at line 410 of file InterfaceLammps.cpp.

418{
419 if (ignoreType[type] ||
420 indexMap.at(i) == numeric_limits<size_t>::max()) return;
421 Atom& a = structure.atoms[indexMap.at(i)];
422 a.numNeighbors++;
423 a.neighbors.push_back(Atom::Neighbor());
425 Atom::Neighbor& n = a.neighbors.back();
426
427 n.index = j;
428 n.tag = tag;
429 n.element = mapTypeToElement[type];
430 n.dr[0] = dx * cflength;
431 n.dr[1] = dy * cflength;
432 n.dr[2] = dz * cflength;
433 n.d = sqrt(d2) * cflength;
434 if (normalize)
435 {
436 n.dr *= convLength;
437 n.d *= convLength;
438 }
439
440 return;
441}
Struct to store information on neighbor atoms.
Definition: Atom.h:36
std::size_t index
Index of neighbor atom.
Definition: Atom.h:38
std::size_t element
Element index of neighbor atom.
Definition: Atom.h:42
double d
Distance to neighbor atom.
Definition: Atom.h:44
Vec3D dr
Distance vector to neighbor atom.
Definition: Atom.h:46
int64_t tag
Tag of neighbor atom.
Definition: Atom.h:40

References nnp::Structure::atoms, cflength, nnp::Mode::convLength, nnp::Atom::Neighbor::d, nnp::Atom::Neighbor::dr, nnp::Atom::Neighbor::element, ignoreType, nnp::Atom::Neighbor::index, indexMap, mapTypeToElement, nnp::Atom::neighbors, nnp::Mode::normalize, nnp::Atom::numNeighbors, nnp::Atom::numNeighborsPerElement, structure, and nnp::Atom::Neighbor::tag.

Referenced by LAMMPS_NS::PairHDNNP::transferNeighborList(), and LAMMPS_NS::PairHDNNPDevelop::transferNeighborList().

Here is the caller graph for this function:

◆ finalizeNeighborList()

void InterfaceLammps::finalizeNeighborList ( )

Sorts neighbor list and creates cutoff map if necessary.

If structure is periodic, this function needs to be called after setBoxVectors!

Definition at line 444 of file InterfaceLammps.cpp.

445{
447 {
448 for (auto& a : structure.atoms)
449 {
450 a.hasNeighborList = true;
451 }
452 // Ewald summation cut-off depends on box vectors.
459 }
460
461}
std::vector< std::vector< double > > cutoffs
Matrix storing all symmetry function cut-offs for all elements.
Definition: Mode.h:652
NNPType nnpType
Definition: Mode.h:628
double maxCutoffRadius
Definition: Mode.h:634
@ HDNNP_4G
NNP with electrostatics and non-local charge transfer (4G-HDNNP).
ScreeningFunction screeningFunction
Definition: Mode.h:645
EwaldSetup ewaldSetup
Definition: Mode.h:641
double getOuter() const
Getter for outer.
void setupNeighborCutoffMap(std::vector< std::vector< double > > cutoffs)
Set up a neighbor cut-off map which gives the index (value) of the last needed neighbor corresponding...
Definition: Structure.cpp:423
void sortNeighborList()
Sort all neighbor lists of this structure with respect to the distance.
Definition: Structure.cpp:409
void calculateMaxCutoffRadiusOverall(EwaldSetup &ewaldSetup, double rcutScreen, double maxCutoffRadius)
Calculate maximal cut-off if cut-off of screening and real part Ewald summation are also considered.
Definition: Structure.cpp:273

References nnp::Structure::atoms, nnp::Structure::calculateMaxCutoffRadiusOverall(), nnp::Mode::cutoffs, nnp::Mode::ewaldSetup, nnp::ScreeningFunction::getOuter(), nnp::Mode::HDNNP_4G, nnp::Mode::maxCutoffRadius, nnp::Mode::nnpType, nnp::Mode::screeningFunction, nnp::Structure::setupNeighborCutoffMap(), nnp::Structure::sortNeighborList(), and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::transferNeighborList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

void InterfaceLammps::process ( )

Calculate symmetry functions, atomic neural networks and sum of local energy contributions.

Definition at line 463 of file InterfaceLammps.cpp.

464{
465#ifdef N2P2_NO_SF_GROUPS
467#else
469#endif
472 {
476 }
478 if (nnpType == NNPType::HDNNP_4G ||
480 if (normalize)
481 {
483 }
485
486 return;
487}
void logEwaldCutoffs(Log &log, double const lengthConversion) const
Use after Ewald summation!
Definition: EwaldSetup.cpp:95
double physicalEnergy(Structure const &structure, bool ref=true) const
Undo normalization for a given energy of structure.
Definition: Mode.cpp:2122
void addEnergyOffset(Structure &structure, bool ref=true)
Add atomic energy offsets to reference energy.
Definition: Mode.cpp:2018
@ HDNNP_Q
Short range NNP with charge NN, no electrostatics/Qeq (M.
void calculateAtomicNeuralNetworks(Structure &structure, bool const derivatives, std::string id="")
Calculate atomic neural networks for all atoms in given structure.
Definition: Mode.cpp:1642
void calculateEnergy(Structure &structure) const
Calculate potential energy for a given structure.
Definition: Mode.cpp:1803
void calculateSymmetryFunctionGroups(Structure &structure, bool const derivatives)
Calculate all symmetry function groups for all atoms in given structure.
Definition: Mode.cpp:1561
void calculateCharge(Structure &structure) const
Calculate total charge for a given structure.
Definition: Mode.cpp:1830
void chargeEquilibration(Structure &structure, bool const derivativesElec)
Perform global charge equilibration method.
Definition: Mode.cpp:1754
void calculateSymmetryFunctions(Structure &structure, bool const derivatives)
Calculate all symmetry functions for all atoms in given structure.
Definition: Mode.cpp:1480

References nnp::Mode::addEnergyOffset(), nnp::Mode::calculateAtomicNeuralNetworks(), nnp::Mode::calculateCharge(), nnp::Mode::calculateEnergy(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), cflength, nnp::Mode::chargeEquilibration(), nnp::Mode::convLength, nnp::Structure::energy, nnp::Mode::ewaldSetup, nnp::Mode::HDNNP_4G, nnp::Mode::HDNNP_Q, nnp::Mode::log, nnp::EwaldSetup::logEwaldCutoffs(), nnp::Mode::nnpType, nnp::Mode::normalize, nnp::Mode::physicalEnergy(), and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEnergy()

double InterfaceLammps::getEnergy ( ) const

Return sum of local energy contributions.

Returns
Sum of local energy contributions.

Definition at line 511 of file InterfaceLammps.cpp.

512{
513 return structure.energy / cfenergy;
514}

References cfenergy, nnp::Structure::energy, and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the caller graph for this function:

◆ getAtomicEnergy()

double InterfaceLammps::getAtomicEnergy ( int  index) const

Return energy contribution of one atom.

Parameters
[in]indexAtom index.
Returns
energy contribution of atom with given index.
Attention
These atomic contributions are not physical!

Definition at line 516 of file InterfaceLammps.cpp.

517{
518 Atom const& a = structure.atoms.at(index);
519 Element const& e = elements.at(a.element);
520
521 if (normalize)
522 {
523 return (physical("energy", a.energy)
524 + meanEnergy
526 }
527 else
528 {
529 return (a.energy + e.getAtomicEnergyOffset()) / cfenergy;
530 }
531}
Contains element-specific data.
Definition: Element.h:39
double getAtomicEnergyOffset() const
Get atomicEnergyOffset.
Definition: Element.h:315
double meanEnergy
Definition: Mode.h:636
double physical(std::string const &property, double value) const
Undo normalization for a given property.
Definition: Mode.cpp:2110
std::vector< Element > elements
Definition: Mode.h:646
double energy
Atomic energy determined by neural network.
Definition: Atom.h:115

References nnp::Structure::atoms, cfenergy, nnp::Atom::element, nnp::Mode::elements, nnp::Atom::energy, nnp::Element::getAtomicEnergyOffset(), nnp::Mode::meanEnergy, nnp::Mode::normalize, nnp::Mode::physical(), and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForces()

void InterfaceLammps::getForces ( double *const *const &  atomF) const

Calculate forces and add to LAMMPS atomic force arrays.

Parameters
[in,out]atomFLAMMPS force array for local and ghost atoms.

Definition at line 533 of file InterfaceLammps.cpp.

534{
535 double const cfforce = cflength / cfenergy;
536 double convForce = 1.0;
537 if (normalize)
538 {
539 convForce = convLength / convEnergy;
540 }
541
542 // Loop over all local atoms. Neural network and Symmetry function
543 // derivatives are saved in the dEdG arrays of atoms and dGdr arrays of
544 // atoms and their neighbors. These are now summed up to the force
545 // contributions of local and ghost atoms.
546 for (auto const& a : structure.atoms)
547 {
548 size_t const ia = a.index;
549 Vec3D selfForce = a.calculateSelfForceShort();
550 selfForce *= cfforce * convForce;
551 // TODO: ia is not the right index when some atom types are excluded / ignored
552 // (see use of indexmap)
553 add3DVecToArray(atomF[ia], selfForce);
554
555#ifndef N2P2_FULL_SFD_MEMORY
556 vector<vector<size_t> > const& tableFull
557 = elements.at(a.element).getSymmetryFunctionTable();
558#endif
559 // Loop over all neighbor atoms. Some are local, some are ghost atoms.
560
561 //for (auto const& n : a.neighbors)
562 size_t const numNeighbors = a.getStoredMinNumNeighbors(maxCutoffRadius);
563#ifdef _OPENMP
564 #pragma omp parallel for
565#endif
566 for (size_t k = 0; k < numNeighbors; ++k)
567 {
568 Atom::Neighbor const& n = a.neighbors[k];
569 // Temporarily save the neighbor index. Note: this is the index for
570 // the LAMMPS force array.
571 size_t const in = n.index;
572
573#ifndef N2P2_FULL_SFD_MEMORY
574 Vec3D pairForce = a.calculatePairForceShort(n, &tableFull);
575#else
576 Vec3D pairForce = a.calculatePairForceShort(n);
577#endif
578 pairForce *= cfforce * convForce;
579 add3DVecToArray(atomF[in], pairForce);
580 }
581 }
582
583 // Comment: Will not work with multiple MPI tasks but this routine will
584 // probably be obsolete when Emir's solution is finished.
586 {
587 Structure const& s = structure;
588 VectorXd lambdaTotal = s.calculateForceLambdaTotal();
589
590#ifdef _OPENMP
591 #pragma omp parallel for
592#endif
593 // OpenMP 4.0 doesn't support range based loops
594 for (size_t i = 0; i < s.numAtoms; ++i)
595 {
596 auto const& ai = s.atoms[i];
597 add3DVecToArray(atomF[i], -ai.pEelecpr * cfforce * convForce);
598
599 for (auto const& aj : s.atoms)
600 {
601 size_t const j = aj.index;
602
603#ifndef N2P2_FULL_SFD_MEMORY
604 vector<vector<size_t> > const& tableFull
605 = elements.at(aj.element).getSymmetryFunctionTable();
606 Vec3D dChidr = aj.calculateDChidr(ai.index,
608 &tableFull);
609#else
610 Vec3D dChidr = aj.calculateDChidr(ai.index,
612#endif
613
614 Vec3D remainingForce = -lambdaTotal(j) * (ai.dAdrQ[j] + dChidr);
615 add3DVecToArray(atomF[i], remainingForce * cfforce * convForce);
616
617 }
618 }
619 }
620 return;
621}
void add3DVecToArray(double *const &arr, Vec3D const &v) const
Add a Vec3D vector to a 3D array in place.
double convEnergy
Definition: Mode.h:637
Storage for one atomic configuration.
Definition: Structure.h:39
Eigen::VectorXd const calculateForceLambdaTotal() const
Calculate lambda_total vector which is needed for the total force calculation in 4G NN.
Definition: Structure.cpp:1188
Vector in 3 dimensional real space.
Definition: Vec3D.h:30

References add3DVecToArray(), nnp::Structure::atoms, nnp::Structure::calculateForceLambdaTotal(), cfenergy, cflength, nnp::Mode::convEnergy, nnp::Mode::convLength, nnp::Mode::elements, nnp::Mode::HDNNP_4G, nnp::Atom::Neighbor::index, nnp::Mode::maxCutoffRadius, nnp::Mode::nnpType, nnp::Mode::normalize, nnp::Structure::numAtoms, and structure.

Referenced by LAMMPS_NS::PairHDNNP::compute(), and LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCharges()

void InterfaceLammps::getCharges ( double *const &  atomQ) const

Transfer charges (in units of e) to LAMMPS atomic charge vector.

Call after getAtomicEnergy().

Parameters
[in,out]atomQLAMMPS charge vector.

Definition at line 623 of file InterfaceLammps.cpp.

624{
625 if (nnpType != NNPType::HDNNP_4G) return;
626 if (!atomQ) return;
627
628 Structure const& s = structure;
629#ifdef _OPENMP
630 #pragma omp parallel for
631#endif
632 for (size_t i = 0; i < s.numAtoms; ++i)
633 {
634 atomQ[i] = s.atoms[i].charge;
635 }
636}

References nnp::Structure::atoms, nnp::Mode::HDNNP_4G, nnp::Mode::nnpType, nnp::Structure::numAtoms, and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::compute().

Here is the caller graph for this function:

◆ isInitialized()

bool nnp::InterfaceLammps::isInitialized ( ) const
inline

Check if this interface is correctly initialized.

Returns
True if initialized, False otherwise.

Definition at line 256 of file InterfaceLammps.h.

257{
258 return initialized;
259}

References initialized.

Referenced by LAMMPS_NS::PairHDNNP::init_style().

Here is the caller graph for this function:

◆ getMaxCutoffRadius()

double InterfaceLammps::getMaxCutoffRadius ( ) const

Get largest cutoff of symmetry functions.

Returns
Largest cutoff of all symmetry functions.

Definition at line 489 of file InterfaceLammps.cpp.

490{
492 else return maxCutoffRadius / cflength;
493}

References cflength, nnp::Mode::convLength, nnp::Mode::maxCutoffRadius, and nnp::Mode::normalize.

Referenced by getMaxCutoffRadiusOverall(), and initialize().

Here is the caller graph for this function:

◆ getMaxCutoffRadiusOverall()

double InterfaceLammps::getMaxCutoffRadiusOverall ( )

Get largest cutoff including structure specific cutoff and screening cutoff.

Returns
Largest cutoff of all symmetry functions and structure specific cutoff and screening cutoff.

Definition at line 495 of file InterfaceLammps.cpp.

496{
497 double cutoff = 0;
499 {
505 if (normalize) cutoff /= convLength;
506 }
507 else cutoff = getMaxCutoffRadius();
508 return cutoff;
509}
double maxCutoffRadiusOverall
Maximum cut-off radius with respect to symmetry functions, screening function and Ewald summation.
Definition: Structure.h:103

References nnp::Structure::calculateMaxCutoffRadiusOverall(), cflength, nnp::Mode::convLength, nnp::Mode::ewaldSetup, getMaxCutoffRadius(), nnp::ScreeningFunction::getOuter(), nnp::Mode::HDNNP_4G, nnp::Mode::maxCutoffRadius, nnp::Structure::maxCutoffRadiusOverall, nnp::Mode::nnpType, nnp::Mode::normalize, nnp::Mode::screeningFunction, and structure.

Referenced by LAMMPS_NS::PairHDNNPDevelop::updateNeighborlistCutoff().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEWBufferSize()

long InterfaceLammps::getEWBufferSize ( ) const

Calculate buffer size for extrapolation warning communication.

Returns
Buffer size.

Definition at line 638 of file InterfaceLammps.cpp.

639{
640 long bs = 0;
641#ifndef N2P2_NO_MPI
642 int ss = 0; // size_t size.
643 int ds = 0; // double size.
644 int cs = 0; // char size.
645 MPI_Pack_size(1, MPI_SIZE_T, MPI_COMM_WORLD, &ss);
646 MPI_Pack_size(1, MPI_DOUBLE, MPI_COMM_WORLD, &ds);
647 MPI_Pack_size(1, MPI_CHAR , MPI_COMM_WORLD, &cs);
648
649 for (vector<Element>::const_iterator it = elements.begin();
650 it != elements.end(); ++it)
651 {
652 map<size_t, SymFncStatistics::Container> const& m
653 = it->statistics.data;
654 bs += ss; // n.
655 for (map<size_t, SymFncStatistics::Container>::const_iterator
656 it2 = m.begin(); it2 != m.end(); ++it2)
657 {
658 bs += ss; // index (it2->first).
659 bs += ss; // countEW (it2->second.countEW).
660 bs += ss; // type (it2->second.type).
661 bs += ds; // Gmin (it2->second.Gmin).
662 bs += ds; // Gmax (it2->second.Gmax).
663 bs += ss; // element.length() (it2->second.element.length()).
664 bs += (it2->second.element.length() + 1) * cs; // element.
665 size_t countEW = it2->second.countEW;
666 bs += countEW * ss; // indexStructureEW.
667 bs += countEW * ss; // indexAtomEW.
668 bs += countEW * ds; // valueEW.
669 }
670 }
671#endif
672 return bs;
673}
#define MPI_SIZE_T
Definition: mpi-extra.h:22

References nnp::Mode::elements, and MPI_SIZE_T.

Referenced by LAMMPS_NS::PairHDNNP::handleExtrapolationWarnings().

Here is the caller graph for this function:

◆ fillEWBuffer()

void InterfaceLammps::fillEWBuffer ( char *const &  buf,
int  bs 
) const

Fill provided buffer with extrapolation warning entries.

Parameters
[in,out]bufCommunication buffer to fill.
[in]bsBuffer size.

Definition at line 675 of file InterfaceLammps.cpp.

676{
677#ifndef N2P2_NO_MPI
678 int p = 0;
679 for (vector<Element>::const_iterator it = elements.begin();
680 it != elements.end(); ++it)
681 {
682 map<size_t, SymFncStatistics::Container> const& m =
683 it->statistics.data;
684 size_t n = m.size();
685 MPI_Pack((void *) &(n), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
686 for (map<size_t, SymFncStatistics::Container>::const_iterator
687 it2 = m.begin(); it2 != m.end(); ++it2)
688 {
689 MPI_Pack((void *) &(it2->first ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
690 size_t countEW = it2->second.countEW;
691 MPI_Pack((void *) &(countEW ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
692 MPI_Pack((void *) &(it2->second.type ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
693 MPI_Pack((void *) &(it2->second.Gmin ), 1, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
694 MPI_Pack((void *) &(it2->second.Gmax ), 1, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
695 // it2->element
696 size_t ts = it2->second.element.length() + 1;
697 MPI_Pack((void *) &ts , 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
698 MPI_Pack((void *) it2->second.element.c_str() , ts, MPI_CHAR , buf, bs, &p, MPI_COMM_WORLD);
699 MPI_Pack((void *) &(it2->second.indexStructureEW.front()), countEW, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
700 MPI_Pack((void *) &(it2->second.indexAtomEW.front() ), countEW, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
701 MPI_Pack((void *) &(it2->second.valueEW.front() ), countEW, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
702 }
703 }
704#endif
705 return;
706}
size_t p
Definition: nnp-cutoff.cpp:33

References nnp::Mode::elements, MPI_SIZE_T, and p.

Referenced by LAMMPS_NS::PairHDNNP::handleExtrapolationWarnings().

Here is the caller graph for this function:

◆ extractEWBuffer()

void InterfaceLammps::extractEWBuffer ( char const *const &  buf,
int  bs 
)

Extract given buffer to symmetry function statistics class.

Parameters
[in]bufBuffer with extrapolation warnings data.
[in]bsBuffer size.

Definition at line 708 of file InterfaceLammps.cpp.

709{
710#ifndef N2P2_NO_MPI
711 int p = 0;
712 for (vector<Element>::iterator it = elements.begin();
713 it != elements.end(); ++it)
714 {
715 size_t n = 0;
716 MPI_Unpack((void *) buf, bs, &p, &(n), 1, MPI_SIZE_T, MPI_COMM_WORLD);
717 for (size_t i = 0; i < n; ++i)
718 {
719 size_t index = 0;
720 MPI_Unpack((void *) buf, bs, &p, &(index), 1, MPI_SIZE_T, MPI_COMM_WORLD);
721 SymFncStatistics::Container& d = it->statistics.data[index];
722 size_t countEW = 0;
723 MPI_Unpack((void *) buf, bs, &p, &(countEW ), 1, MPI_SIZE_T, MPI_COMM_WORLD);
724 MPI_Unpack((void *) buf, bs, &p, &(d.type ), 1, MPI_SIZE_T, MPI_COMM_WORLD);
725 MPI_Unpack((void *) buf, bs, &p, &(d.Gmin ), 1, MPI_DOUBLE, MPI_COMM_WORLD);
726 MPI_Unpack((void *) buf, bs, &p, &(d.Gmax ), 1, MPI_DOUBLE, MPI_COMM_WORLD);
727 // d.element
728 size_t ts = 0;
729 MPI_Unpack((void *) buf, bs, &p, &ts , 1, MPI_SIZE_T, MPI_COMM_WORLD);
730 char* element = new char[ts];
731 MPI_Unpack((void *) buf, bs, &p, element , ts, MPI_CHAR , MPI_COMM_WORLD);
732 d.element = element;
733 delete[] element;
734 // indexStructureEW.
735 d.indexStructureEW.resize(d.countEW + countEW);
736 MPI_Unpack((void *) buf, bs, &p, &(d.indexStructureEW[d.countEW]), countEW, MPI_SIZE_T, MPI_COMM_WORLD);
737 // indexAtomEW.
738 d.indexAtomEW.resize(d.countEW + countEW);
739 MPI_Unpack((void *) buf, bs, &p, &(d.indexAtomEW[d.countEW] ), countEW, MPI_SIZE_T, MPI_COMM_WORLD);
740 // valueEW.
741 d.valueEW.resize(d.countEW + countEW);
742 MPI_Unpack((void *) buf, bs, &p, &(d.valueEW[d.countEW] ), countEW, MPI_DOUBLE, MPI_COMM_WORLD);
743
744 d.countEW += countEW;
745 }
746 }
747#endif
748 return;
749}
double d
Definition: nnp-cutoff.cpp:34
Struct containing statistics gathered during symmetry function calculation.

References d, nnp::Mode::elements, MPI_SIZE_T, and p.

Referenced by LAMMPS_NS::PairHDNNP::handleExtrapolationWarnings().

Here is the caller graph for this function:

◆ writeExtrapolationWarnings()

void InterfaceLammps::writeExtrapolationWarnings ( )

Write extrapolation warnings to log.

Definition at line 751 of file InterfaceLammps.cpp.

752{
753 for (vector<Element>::const_iterator it = elements.begin();
754 it != elements.end(); ++it)
755 {
756 vector<string> vs = it->statistics.getExtrapolationWarningLines();
757 for (vector<string>::const_iterator it2 = vs.begin();
758 it2 != vs.end(); ++it2)
759 {
760 log << (*it2);
761 }
762 }
763
764 return;
765}

References nnp::Mode::elements, and nnp::Mode::log.

Referenced by LAMMPS_NS::PairHDNNP::handleExtrapolationWarnings(), and initialize().

Here is the caller graph for this function:

◆ clearExtrapolationWarnings()

void InterfaceLammps::clearExtrapolationWarnings ( )

Clear extrapolation warnings storage.

Definition at line 767 of file InterfaceLammps.cpp.

768{
769 for (vector<Element>::iterator it = elements.begin();
770 it != elements.end(); ++it)
771 {
772 it->statistics.clear();
773 }
774
775 return;
776}

References nnp::Mode::elements.

Referenced by LAMMPS_NS::PairHDNNP::handleExtrapolationWarnings().

Here is the caller graph for this function:

◆ writeToFile()

void InterfaceLammps::writeToFile ( std::string const  fileName,
bool const  append 
)

Write current structure to file in units used in training data.

Parameters
fileNameFile name of the output structure file.
appendtrue if structure should be appended to existing file.

Definition at line 778 of file InterfaceLammps.cpp.

780{
782 structure.writeToFile(fileName, false, append);
784}
double convCharge
Definition: Mode.h:639
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 writeToFile(std::string const fileName="output.data", bool const ref=true, bool const append=false) const
Write configuration to file.
Definition: Structure.cpp:1449
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

References nnp::Mode::convCharge, nnp::Mode::convEnergy, nnp::Mode::convLength, nnp::Mode::meanEnergy, structure, nnp::Structure::toNormalizedUnits(), nnp::Structure::toPhysicalUnits(), and nnp::Structure::writeToFile().

Here is the call graph for this function:

◆ add3DVecToArray()

void InterfaceLammps::add3DVecToArray ( double *const &  arr,
Vec3D const &  v 
) const

Add a Vec3D vector to a 3D array in place.

Parameters
[in,out]arrArray which is edited in place.
[in]vVector which is added to arr.

Definition at line 786 of file InterfaceLammps.cpp.

787{
788 arr[0] += v[0];
789 arr[1] += v[1];
790 arr[2] += v[2];
791}

Referenced by getForces().

Here is the caller graph for this function:

Member Data Documentation

◆ myRank

int nnp::InterfaceLammps::myRank
protected

Process rank.

Definition at line 221 of file InterfaceLammps.h.

Referenced by initialize(), and setLocalAtoms().

◆ initialized

bool nnp::InterfaceLammps::initialized
protected

Initialization state.

Definition at line 223 of file InterfaceLammps.h.

Referenced by initialize(), and isInitialized().

◆ hasGlobalStructure

bool nnp::InterfaceLammps::hasGlobalStructure
protected

Whether n2p2 knows about the global structure or only a local part.

Definition at line 225 of file InterfaceLammps.h.

Referenced by getGlobalStructureStatus(), and setGlobalStructureStatus().

◆ showew

bool nnp::InterfaceLammps::showew
protected

Corresponds to LAMMPS showew keyword.

Definition at line 227 of file InterfaceLammps.h.

Referenced by initialize().

◆ resetew

bool nnp::InterfaceLammps::resetew
protected

Corresponds to LAMMPS resetew keyword.

Definition at line 229 of file InterfaceLammps.h.

Referenced by initialize().

◆ showewsum

int nnp::InterfaceLammps::showewsum
protected

Corresponds to LAMMPS showewsum keyword.

Definition at line 231 of file InterfaceLammps.h.

Referenced by initialize().

◆ maxew

int nnp::InterfaceLammps::maxew
protected

Corresponds to LAMMPS maxew keyword.

Definition at line 233 of file InterfaceLammps.h.

Referenced by initialize().

◆ cflength

double nnp::InterfaceLammps::cflength
protected

Corresponds to LAMMPS cflength keyword.

Definition at line 235 of file InterfaceLammps.h.

Referenced by addNeighbor(), getForces(), getMaxCutoffRadius(), getMaxCutoffRadiusOverall(), initialize(), process(), setBoxVectors(), and setLocalAtomPositions().

◆ cfenergy

double nnp::InterfaceLammps::cfenergy
protected

Corresponds to LAMMPS cfenergy keyword.

Definition at line 237 of file InterfaceLammps.h.

Referenced by getAtomicEnergy(), getEnergy(), getForces(), and initialize().

◆ emap

std::string nnp::InterfaceLammps::emap
protected

Corresponds to LAMMPS map keyword.

Definition at line 239 of file InterfaceLammps.h.

Referenced by initialize().

◆ indexMap

std::vector<size_t> nnp::InterfaceLammps::indexMap
protected

Map from LAMMPS index to n2p2 atom index.

Definition at line 241 of file InterfaceLammps.h.

Referenced by addNeighbor(), and setLocalAtoms().

◆ ignoreType

std::map<int, bool> nnp::InterfaceLammps::ignoreType
protected

True if atoms of this LAMMPS type will be ignored.

Definition at line 243 of file InterfaceLammps.h.

Referenced by addNeighbor(), initialize(), and setLocalAtoms().

◆ mapTypeToElement

std::map<int, std::size_t> nnp::InterfaceLammps::mapTypeToElement
protected

Map from LAMMPS type to n2p2 element index.

Definition at line 245 of file InterfaceLammps.h.

Referenced by addNeighbor(), initialize(), and setLocalAtoms().

◆ mapElementToType

std::map<std::size_t, int> nnp::InterfaceLammps::mapElementToType
protected

Map from n2p2 element index to LAMMPS type.

Definition at line 247 of file InterfaceLammps.h.

Referenced by initialize().

◆ structure


The documentation for this class was generated from the following files: