n2p2 - A neural network potential package
|
Derived Cabana main NNP class. More...
#include <ModeCabana.h>
Public Types | |
using | device_type = t_device |
using | exe_space = typename device_type::execution_space |
using | memory_space = typename device_type::memory_space |
typedef exe_space::array_layout | layout |
using | host_space = Kokkos::HostSpace |
using | d_t_mass = Kokkos::View< T_V_FLOAT *, memory_space > |
using | h_t_mass = Kokkos::View< T_V_FLOAT *, layout, host_space > |
using | d_t_int = Kokkos::View< T_INT *, memory_space > |
using | h_t_int = Kokkos::View< T_INT *, layout, host_space > |
using | d_t_SF = Kokkos::View< T_FLOAT **[15], memory_space > |
using | t_SF = Kokkos::View< T_FLOAT **[15], layout, host_space > |
using | d_t_SFscaling = Kokkos::View< T_FLOAT **[8], memory_space > |
using | t_SFscaling = Kokkos::View< T_FLOAT **[8], layout, host_space > |
using | d_t_SFGmemberlist = Kokkos::View< T_INT ***, memory_space > |
using | t_SFGmemberlist = Kokkos::View< T_INT ***, layout, host_space > |
using | d_t_bias = Kokkos::View< T_FLOAT ***, memory_space > |
using | t_bias = Kokkos::View< T_FLOAT ***, layout, host_space > |
using | d_t_weights = Kokkos::View< T_FLOAT ****, memory_space > |
using | t_weights = Kokkos::View< T_FLOAT ****, layout, host_space > |
using | d_t_NN = Kokkos::View< T_FLOAT ***, memory_space > |
Public Types inherited from nnp::Mode | |
enum class | NNPType { HDNNP_2G = 2 , HDNNP_4G = 4 , HDNNP_Q = 10 } |
Public Member Functions | |
void | setupElementMap () override |
Set up the element map. More... | |
void | setupElements () override |
Set up all Element instances. More... | |
void | setupSymmetryFunctions () override |
Set up all symmetry functions. More... | |
void | setupSymmetryFunctionScaling (std::string const &fileName="scaling.data") override |
Set up symmetry function scaling from file. More... | |
void | setupSymmetryFunctionGroups () override |
Set up symmetry function groups. More... | |
void | setupNeuralNetwork () override |
Set up neural networks for all elements. More... | |
void | setupNeuralNetworkWeights (std::string const &fileNameFormat="weights.%03zu.data") override |
Set up neural network weights from files. More... | |
KOKKOS_INLINE_FUNCTION void | compute_cutoff (CutoffFunction::CutoffType cutoffType, double cutoffAlpha, double &fc, double &dfc, double r, double rc, bool derivative) const |
KOKKOS_INLINE_FUNCTION double | scale (int attype, double value, int k, d_t_SFscaling SFscaling) const |
template<class t_slice_x , class t_slice_f , class t_slice_type , class t_slice_dEdG , class t_neigh_list , class t_neigh_parallel , class t_angle_parallel > | |
void | calculateForces (t_slice_x x, t_slice_f f, t_slice_type type, t_slice_dEdG dEdG, t_neigh_list neigh_list, int N_local, t_neigh_parallel neigh_op, t_angle_parallel angle_op) |
Calculate forces for all atoms in given structure. More... | |
template<class t_slice_type , class t_slice_G , class t_slice_dEdG , class t_slice_E > | |
void | calculateAtomicNeuralNetworks (t_slice_type type, t_slice_G G, t_slice_dEdG dEdG, t_slice_E E, int N_local) |
Calculate atomic neural networks for all atoms in given structure. More... | |
template<class t_slice_x , class t_slice_type , class t_slice_G , class t_neigh_list , class t_neigh_parallel , class t_angle_parallel > | |
void | calculateSymmetryFunctionGroups (t_slice_x x, t_slice_type type, t_slice_G G, t_neigh_list neigh_list, int N_local, t_neigh_parallel neigh_op, t_angle_parallel angle_op) |
Calculate all symmetry function groups for all atoms in given structure. More... | |
Mode () | |
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... | |
Additional Inherited Members | |
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... | |
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< Element > | elements |
std::vector< std::string > | nnk |
std::map< std::string, NNSetup > | nns |
std::vector< std::vector< double > > | cutoffs |
Matrix storing all symmetry function cut-offs for all elements. More... | |
ErfcBuf | erfcBuf |
Derived Cabana main NNP class.
The main n2p2 functions for computing energies and forces are replaced to use the Kokkos and Cabana libraries. Most setup functions are overridden; some are replaced as needed to work within device kernels.
Definition at line 46 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::device_type = t_device |
Definition at line 53 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::exe_space = typename device_type::execution_space |
Definition at line 54 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::memory_space = typename device_type::memory_space |
Definition at line 55 of file ModeCabana.h.
typedef exe_space::array_layout nnp::ModeCabana< t_device >::layout |
Definition at line 56 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::host_space = Kokkos::HostSpace |
Definition at line 57 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_mass = Kokkos::View<T_V_FLOAT *, memory_space> |
Definition at line 60 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::h_t_mass = Kokkos::View<T_V_FLOAT *, layout, host_space> |
Definition at line 61 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_int = Kokkos::View<T_INT *, memory_space> |
Definition at line 62 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::h_t_int = Kokkos::View<T_INT *, layout, host_space> |
Definition at line 63 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_SF = Kokkos::View<T_FLOAT * * [15], memory_space> |
Definition at line 66 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::t_SF = Kokkos::View<T_FLOAT * * [15], layout, host_space> |
Definition at line 67 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_SFscaling = Kokkos::View<T_FLOAT * * [8], memory_space> |
Definition at line 68 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::t_SFscaling = Kokkos::View<T_FLOAT * * [8], layout, host_space> |
Definition at line 69 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_SFGmemberlist = Kokkos::View<T_INT ***, memory_space> |
Definition at line 70 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::t_SFGmemberlist = Kokkos::View<T_INT ***, layout, host_space> |
Definition at line 71 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_bias = Kokkos::View<T_FLOAT ***, memory_space> |
Definition at line 74 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::t_bias = Kokkos::View<T_FLOAT ***, layout, host_space> |
Definition at line 75 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_weights = Kokkos::View<T_FLOAT ****, memory_space> |
Definition at line 76 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::t_weights = Kokkos::View<T_FLOAT ****, layout, host_space> |
Definition at line 77 of file ModeCabana.h.
using nnp::ModeCabana< t_device >::d_t_NN = Kokkos::View<T_FLOAT ***, memory_space> |
Definition at line 78 of file ModeCabana.h.
|
overridevirtual |
Set up the element map.
Uses keyword elements
. This function should follow immediately after settings are loaded via loadSettingsFile().
Reimplemented from nnp::Mode.
Definition at line 34 of file ModeCabana_impl.h.
References nnp::reduce(), nnp::split(), and nnp::strpr().
|
overridevirtual |
Set up all Element instances.
Uses keywords number_of_elements
and atom_energy
. This function should follow immediately after setupElementMap().
Reimplemented from nnp::Mode.
Definition at line 60 of file ModeCabana_impl.h.
References nnp::reduce(), nnp::split(), and nnp::strpr().
|
overridevirtual |
Set up all symmetry functions.
Uses keyword symfunction_short
. Reads all symmetry functions from settings and automatically assigns them to the correct element.
Reimplemented from nnp::Mode.
Definition at line 113 of file ModeCabana_impl.h.
References nnp::reduce(), nnp::split(), and nnp::strpr().
|
overridevirtual |
Set up symmetry function scaling from file.
[in] | fileName | Scaling file name. |
Uses keywords scale_symmetry_functions
, center_symmetry_functions
, scale_symmetry_functions_sigma
, scale_min_short
and scale_max_short
. Reads in scaling information and sets correct scaling behavior for all symmetry functions. Call after setupSymmetryFunctions().
Reimplemented from nnp::Mode.
Definition at line 237 of file ModeCabana_impl.h.
References ST_CENTER, ST_NONE, ST_SCALE, ST_SCALECENTER, ST_SCALESIGMA, and nnp::strpr().
|
overridevirtual |
Set up symmetry function groups.
Does not use any keywords. Call after setupSymmetryFunctions() and ensure that correct scaling behavior has already been set.
Reimplemented from nnp::Mode.
Definition at line 381 of file ModeCabana_impl.h.
References nnp::strpr().
|
overridevirtual |
Set up neural networks for all elements.
Uses keywords global_hidden_layers_short
, global_nodes_short
, global_activation_short
, normalize_nodes
. Call after setupSymmetryFunctions(), only then the number of input layer neurons is known.
Reimplemented from nnp::Mode.
Definition at line 443 of file ModeCabana_impl.h.
References nnp::reduce(), nnp::split(), and nnp::strpr().
|
override |
Set up neural network weights from files.
[in] | fileNameFormat | Format for weights file name. The string must contain one placeholder for the atomic number. |
Does not use any keywords. The weight files should contain one weight per line, see NeuralNetwork::setConnections() for the correct order.
Definition at line 530 of file ModeCabana_impl.h.
References nnp::reduce(), nnp::split(), and nnp::strpr().
KOKKOS_INLINE_FUNCTION void nnp::ModeCabana< t_device >::compute_cutoff | ( | CutoffFunction::CutoffType | cutoffType, |
double | cutoffAlpha, | ||
double & | fc, | ||
double & | dfc, | ||
double | r, | ||
double | rc, | ||
bool | derivative | ||
) | const |
Definition at line 285 of file ModeCabana.h.
References nnp::CutoffFunction::CT_COS, nnp::CutoffFunction::CT_TANHU, and fc.
KOKKOS_INLINE_FUNCTION double nnp::ModeCabana< t_device >::scale | ( | int | attype, |
double | value, | ||
int | k, | ||
d_t_SFscaling | SFscaling | ||
) | const |
Definition at line 316 of file ModeCabana.h.
void nnp::ModeCabana< t_device >::calculateForces | ( | t_slice_x | x, |
t_slice_f | f, | ||
t_slice_type | type, | ||
t_slice_dEdG | dEdG, | ||
t_neigh_list | neigh_list, | ||
int | N_local, | ||
t_neigh_parallel | neigh_op, | ||
t_angle_parallel | angle_op | ||
) |
Calculate forces for all atoms in given structure.
[in] | x | Cabana slice of atom positions. |
[in] | f | Cabana slice of atom forces. |
[in] | type | Cabana slice of atom types. |
[in] | dEdG | Cabana slice of the derivative of energy with respect to symmetry functions per atom. |
[in] | N_local | Number of atoms. |
[in] | neigh_op | Cabana tag for neighbor parallelism. |
[in] | angle_op | Cabana tag for angular parallelism. |
Combine intermediate results from symmetry function and neural network computation to atomic forces. Results are stored in f.
Definition at line 932 of file ModeCabana_impl.h.
void nnp::ModeCabana< t_device >::calculateAtomicNeuralNetworks | ( | t_slice_type | type, |
t_slice_G | G, | ||
t_slice_dEdG | dEdG, | ||
t_slice_E | E, | ||
int | N_local | ||
) |
Calculate atomic neural networks for all atoms in given structure.
[in] | type | Cabana slice of atom types. |
[in] | G | Cabana slice of symmetry functions per atom. |
[in] | dEdG | Cabana slice of the derivative of energy with respect to symmetry functions per atom. |
[in] | E | Cabana slice of energy per atom. |
[in] | N_local | Number of atoms. |
The atomic energy is stored in E.
Definition at line 836 of file ModeCabana_impl.h.
void nnp::ModeCabana< t_device >::calculateSymmetryFunctionGroups | ( | t_slice_x | x, |
t_slice_type | type, | ||
t_slice_G | G, | ||
t_neigh_list | neigh_list, | ||
int | N_local, | ||
t_neigh_parallel | neigh_op, | ||
t_angle_parallel | angle_op | ||
) |
Calculate all symmetry function groups for all atoms in given structure.
[in] | x | Cabana slice of atom positions. |
[in] | type | Cabana slice of atom types. |
[in] | G | Cabana slice of symmetry functions per atom. |
[in] | neigh_list | Cabana neighbor list. |
[in] | N_local | Number of atoms. |
[in] | neigh_op | Cabana tag for neighbor parallelism. |
[in] | angle_op | Cabana tag for angular parallelism. |
Note there is no calculateSymmetryFunctions() within this derived class. Results are stored in G.
Definition at line 607 of file ModeCabana_impl.h.
References CFLENGTH.
Mode::Mode | ( | ) |
Definition at line 105 of file Mode.cpp.
std::vector<std::string> nnp::ModeCabana< t_device >::knownElements |
list of element symbols in order of periodic table
Definition at line 226 of file ModeCabana.h.
d_t_SF nnp::ModeCabana< t_device >::d_SF |
Definition at line 238 of file ModeCabana.h.
t_SF nnp::ModeCabana< t_device >::SF |
Definition at line 239 of file ModeCabana.h.
d_t_SFGmemberlist nnp::ModeCabana< t_device >::d_SFGmemberlist |
Definition at line 240 of file ModeCabana.h.
t_SFGmemberlist nnp::ModeCabana< t_device >::SFGmemberlist |
Definition at line 241 of file ModeCabana.h.
d_t_SFscaling nnp::ModeCabana< t_device >::d_SFscaling |
Definition at line 242 of file ModeCabana.h.
t_SFscaling nnp::ModeCabana< t_device >::SFscaling |
Definition at line 243 of file ModeCabana.h.
d_t_bias nnp::ModeCabana< t_device >::bias |
Definition at line 246 of file ModeCabana.h.
d_t_weights nnp::ModeCabana< t_device >::weights |
Definition at line 247 of file ModeCabana.h.
t_bias nnp::ModeCabana< t_device >::h_bias |
Definition at line 248 of file ModeCabana.h.
t_weights nnp::ModeCabana< t_device >::h_weights |
Definition at line 249 of file ModeCabana.h.
int nnp::ModeCabana< t_device >::numLayers |
Definition at line 250 of file ModeCabana.h.
int nnp::ModeCabana< t_device >::numHiddenLayers |
Definition at line 250 of file ModeCabana.h.
int nnp::ModeCabana< t_device >::maxNeurons |
Definition at line 250 of file ModeCabana.h.
d_t_int nnp::ModeCabana< t_device >::numNeuronsPerLayer |
Definition at line 251 of file ModeCabana.h.
h_t_int nnp::ModeCabana< t_device >::h_numNeuronsPerLayer |
Definition at line 252 of file ModeCabana.h.
d_t_int nnp::ModeCabana< t_device >::AF |
Definition at line 253 of file ModeCabana.h.
h_t_int nnp::ModeCabana< t_device >::h_AF |
Definition at line 254 of file ModeCabana.h.
h_t_mass nnp::ModeCabana< t_device >::atomicEnergyOffset |
Definition at line 257 of file ModeCabana.h.
h_t_int nnp::ModeCabana< t_device >::h_numSFperElem |
Definition at line 258 of file ModeCabana.h.
d_t_int nnp::ModeCabana< t_device >::numSFperElem |
Definition at line 259 of file ModeCabana.h.
h_t_int nnp::ModeCabana< t_device >::h_numSFGperElem |
Definition at line 260 of file ModeCabana.h.
d_t_int nnp::ModeCabana< t_device >::numSFGperElem |
Definition at line 261 of file ModeCabana.h.
int nnp::ModeCabana< t_device >::maxSFperElem |
Definition at line 262 of file ModeCabana.h.
double nnp::ModeCabana< t_device >::meanEnergy |
Definition at line 269 of file ModeCabana.h.
ScalingType nnp::ModeCabana< t_device >::scalingType |
Definition at line 272 of file ModeCabana.h.
std::vector<ElementCabana> nnp::ModeCabana< t_device >::elements |
Definition at line 275 of file ModeCabana.h.
std::vector<std::string> nnp::ModeCabana< t_device >::elementStrings |
Definition at line 276 of file ModeCabana.h.
Log nnp::Mode::log |
std::vector<std::size_t> nnp::Mode::minNeighbors |
std::vector<double> nnp::Mode::minCutoffRadius |
settings::Settings nnp::Mode::settings |
CutoffFunction::CutoffType nnp::Mode::cutoffType |