n2p2 - A neural network potential package
|
#include <InterfaceLammps.h>
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 | setLocalAtoms (int numAtomsLocal, int const *const atomType) |
(Re)set structure to contain only local LAMMPS atoms. 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 | 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 | 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... | |
bool | isInitialized () const |
Check if this interface is correctly initialized. More... | |
double | getMaxCutoffRadius () const |
Get largest 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... | |
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 (bool skipNormalize=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... | |
virtual void | setupNeuralNetwork () |
Set up neural networks for all elements. More... | |
virtual void | setupNeuralNetworkWeights (std::string const &fileNameFormatShort="weights.%03zu.data", std::string const &fileNameFormatCharge="weightse.%03zu.data") |
Set up neural network weights from files. 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) |
Calculate a single atomic neural network for a given atom and nn type. 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 | 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... | |
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 | 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 | 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 |
bool | useChargeNN |
std::size_t | numElements |
std::vector< std::size_t > | minNeighbors |
std::vector< double > | minCutoffRadius |
double | maxCutoffRadius |
double | cutoffAlpha |
double | meanEnergy |
double | convEnergy |
double | convLength |
Settings | settings |
SymFnc::ScalingType | scalingType |
CutoffFunction::CutoffType | cutoffType |
std::vector< Element > | elements |
Additional Inherited Members | |
Public Types inherited from nnp::Mode | |
enum class | NNPType { SHORT_ONLY , SHORT_CHARGE_NN } |
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 &type, std::string const &fileName) |
Read in weights for a specific type of neural network. More... | |
Definition at line 30 of file InterfaceLammps.h.
InterfaceLammps::InterfaceLammps | ( | ) |
Definition at line 35 of file InterfaceLammps.cpp.
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.
[in] | directory | Directory containing NNP data files (weights, scaling, settings). |
[in] | emap | Element mapping from LAMMPS to n2p2. |
[in] | showew | If detailed extrapolation warnings for all atoms are shown. |
[in] | resetew | If extrapolation warnings counter is reset every timestep. |
[in] | showewsum | Show number of warnings every this many timesteps. |
[in] | maxew | Abort simulation if more than this many warnings are encountered. |
[in] | cflength | Length unit conversion factor. |
[in] | cfenergy | Energy unit conversion factor. |
[in] | lammpsCutoff | Cutoff radius from LAMMPS (via pair_coeff). |
[in] | lammpsNtypes | Number of atom types in LAMMPS. |
[in] | myRank | MPI process rank (passed on to structure index). |
Definition at line 47 of file InterfaceLammps.cpp.
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::PairNNP::init_style().
void InterfaceLammps::setLocalAtoms | ( | int | numAtomsLocal, |
int const *const | atomType | ||
) |
(Re)set structure to contain only local LAMMPS atoms.
[in] | numAtomsLocal | Number of local atoms. |
[in] | atomType | LAMMPS atom type. |
Definition at line 253 of file InterfaceLammps.cpp.
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::PairNNP::compute().
void InterfaceLammps::setLocalTags | ( | int const *const | atomTag | ) |
Set atom tags (int version, -DLAMMPS_SMALLBIG).
[in] | atomTag | LAMMPS atom tag. |
Definition at line 291 of file InterfaceLammps.cpp.
References nnp::Structure::atoms, and structure.
Referenced by LAMMPS_NS::PairNNP::compute().
void InterfaceLammps::setLocalTags | ( | int64_t const *const | atomTag | ) |
Set atom tags (int64_t version, -DLAMMPS_BIGBIG).
[in] | atomTag | LAMMPS atom tag. |
Definition at line 302 of file InterfaceLammps.cpp.
References nnp::Structure::atoms, and structure.
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).
[in] | i | Local atom index. |
[in] | j | Neighbor atom index. |
[in] | tag | Neighbor atom tag. |
[in] | type | Neighbor atom type. |
[in] | dx | Neighbor atom distance in x direction. |
[in] | dy | Neighbor atom distance in y direction. |
[in] | dz | Neighbor atom distance in z direction. |
[in] | d2 | Square of neighbor atom distance. |
If -DLAMMPS_SMALLBIG implicit conversion is applied for tag.
Definition at line 312 of file InterfaceLammps.cpp.
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::PairNNP::transferNeighborList().
void InterfaceLammps::process | ( | ) |
Calculate symmetry functions, atomic neural networks and sum of local energy contributions.
Definition at line 346 of file InterfaceLammps.cpp.
References nnp::Mode::addEnergyOffset(), nnp::Mode::calculateAtomicNeuralNetworks(), nnp::Mode::calculateEnergy(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), nnp::Structure::energy, nnp::Mode::normalize, nnp::Mode::physicalEnergy(), and structure.
Referenced by LAMMPS_NS::PairNNP::compute().
double InterfaceLammps::getEnergy | ( | ) | const |
Return sum of local energy contributions.
Definition at line 370 of file InterfaceLammps.cpp.
References cfenergy, nnp::Structure::energy, and structure.
Referenced by LAMMPS_NS::PairNNP::compute().
double InterfaceLammps::getAtomicEnergy | ( | int | index | ) | const |
Return energy contribution of one atom.
[in] | index | Atom index. |
Definition at line 375 of file InterfaceLammps.cpp.
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::PairNNP::compute().
void InterfaceLammps::getForces | ( | double *const *const & | atomF | ) | const |
Calculate forces and add to LAMMPS atomic force arrays.
[in,out] | atomF | LAMMPS force array for local and ghost atoms. |
Definition at line 392 of file InterfaceLammps.cpp.
References nnp::Structure::atoms, cfenergy, cflength, nnp::Mode::convEnergy, nnp::Mode::convLength, nnp::Atom::dEdG, nnp::Atom::dGdr, nnp::Atom::element, nnp::Mode::elements, nnp::Atom::index, nnp::Atom::neighbors, nnp::Mode::normalize, nnp::Atom::numSymmetryFunctions, and structure.
Referenced by LAMMPS_NS::PairNNP::compute().
|
inline |
Check if this interface is correctly initialized.
True
if initialized, False
otherwise. Definition at line 194 of file InterfaceLammps.h.
References initialized.
Referenced by LAMMPS_NS::PairNNP::init_style().
double InterfaceLammps::getMaxCutoffRadius | ( | ) | const |
Get largest cutoff.
Definition at line 364 of file InterfaceLammps.cpp.
References cflength, nnp::Mode::convLength, nnp::Mode::maxCutoffRadius, and nnp::Mode::normalize.
Referenced by LAMMPS_NS::PairNNP::init_style(), and initialize().
long InterfaceLammps::getEWBufferSize | ( | ) | const |
Calculate buffer size for extrapolation warning communication.
Definition at line 459 of file InterfaceLammps.cpp.
References nnp::Mode::elements, and MPI_SIZE_T.
Referenced by LAMMPS_NS::PairNNP::handleExtrapolationWarnings().
void InterfaceLammps::fillEWBuffer | ( | char *const & | buf, |
int | bs | ||
) | const |
Fill provided buffer with extrapolation warning entries.
[in,out] | buf | Communication buffer to fill. |
[in] | bs | Buffer size. |
Definition at line 496 of file InterfaceLammps.cpp.
References nnp::Mode::elements, MPI_SIZE_T, and p.
Referenced by LAMMPS_NS::PairNNP::handleExtrapolationWarnings().
void InterfaceLammps::extractEWBuffer | ( | char const *const & | buf, |
int | bs | ||
) |
Extract given buffer to symmetry function statistics class.
[in] | buf | Buffer with extrapolation warnings data. |
[in] | bs | Buffer size. |
Definition at line 529 of file InterfaceLammps.cpp.
References d, nnp::Mode::elements, MPI_SIZE_T, and p.
Referenced by LAMMPS_NS::PairNNP::handleExtrapolationWarnings().
void InterfaceLammps::writeExtrapolationWarnings | ( | ) |
Write extrapolation warnings to log.
Definition at line 572 of file InterfaceLammps.cpp.
References nnp::Mode::elements, and nnp::Mode::log.
Referenced by LAMMPS_NS::PairNNP::handleExtrapolationWarnings(), and initialize().
void InterfaceLammps::clearExtrapolationWarnings | ( | ) |
Clear extrapolation warnings storage.
Definition at line 588 of file InterfaceLammps.cpp.
References nnp::Mode::elements.
Referenced by LAMMPS_NS::PairNNP::handleExtrapolationWarnings().
|
protected |
Process rank.
Definition at line 161 of file InterfaceLammps.h.
Referenced by initialize(), and setLocalAtoms().
|
protected |
Initialization state.
Definition at line 163 of file InterfaceLammps.h.
Referenced by initialize(), and isInitialized().
|
protected |
Corresponds to LAMMPS showew
keyword.
Definition at line 165 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Corresponds to LAMMPS resetew
keyword.
Definition at line 167 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Corresponds to LAMMPS showewsum
keyword.
Definition at line 169 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Corresponds to LAMMPS maxew
keyword.
Definition at line 171 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Corresponds to LAMMPS cflength
keyword.
Definition at line 173 of file InterfaceLammps.h.
Referenced by addNeighbor(), getForces(), getMaxCutoffRadius(), and initialize().
|
protected |
Corresponds to LAMMPS cfenergy
keyword.
Definition at line 175 of file InterfaceLammps.h.
Referenced by getAtomicEnergy(), getEnergy(), getForces(), and initialize().
|
protected |
Corresponds to LAMMPS map
keyword.
Definition at line 177 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Map from LAMMPS index to n2p2 atom index.
Definition at line 179 of file InterfaceLammps.h.
Referenced by addNeighbor(), and setLocalAtoms().
|
protected |
True if atoms of this LAMMPS type will be ignored.
Definition at line 181 of file InterfaceLammps.h.
Referenced by addNeighbor(), initialize(), and setLocalAtoms().
|
protected |
Map from LAMMPS type to n2p2 element index.
Definition at line 183 of file InterfaceLammps.h.
Referenced by addNeighbor(), initialize(), and setLocalAtoms().
|
protected |
Map from n2p2 element index to LAMMPS type.
Definition at line 185 of file InterfaceLammps.h.
Referenced by initialize().
|
protected |
Structure containing local atoms.
Definition at line 187 of file InterfaceLammps.h.
Referenced by addNeighbor(), getAtomicEnergy(), getEnergy(), getForces(), initialize(), process(), setLocalAtoms(), and setLocalTags().