1 /* -*- c++ -*- ---------------------------------------------------------- 2 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator 3 https://www.lammps.org/ Sandia National Laboratories 4 Steve Plimpton, sjplimp@sandia.gov 5 6 Copyright (2003) Sandia Corporation. Under the terms of Contract 7 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 8 certain rights in this software. This software is distributed under 9 the GNU General Public License. 10 11 See the README file in the top-level LAMMPS directory. 12 ------------------------------------------------------------------------- */ 13 /* ---------------------------------------------------------------------- 14 Contributing authors: Christopher Barrett (MSU) barrett@me.msstate.edu 15 Doyl Dickel (MSU) doyl@me.msstate.edu 16 ----------------------------------------------------------------------*/ 17 /* 18 “The research described and the resulting data presented herein, unless 19 otherwise noted, was funded under PE 0602784A, Project T53 "Military 20 Engineering Applied Research", Task 002 under Contract No. W56HZV-17-C-0095, 21 managed by the U.S. Army Combat Capabilities Development Command (CCDC) and 22 the Engineer Research and Development Center (ERDC). The work described in 23 this document was conducted at CAVS, MSU. Permission was granted by ERDC 24 to publish this information. Any opinions, findings and conclusions or 25 recommendations expressed in this material are those of the author(s) and 26 do not necessarily reflect the views of the United States Army.” 27 28 DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 29 */ 30 31 #ifdef PAIR_CLASS 32 // clang-format off 33 PairStyle(rann,PairRANN); 34 // clang-format on 35 #else 36 37 #ifndef LMP_PAIR_RANN 38 #define LMP_PAIR_RANN 39 40 #include "pair.h" 41 42 namespace LAMMPS_NS { 43 44 namespace RANN { 45 //forward declarations 46 class Activation; 47 class Fingerprint; 48 } // namespace RANN 49 50 class PairRANN : public Pair { 51 public: 52 //inherited functions 53 PairRANN(class LAMMPS *); 54 ~PairRANN(); 55 void compute(int, int); 56 void settings(int, char **); 57 void coeff(int, char **); 58 void init_style(); 59 double init_one(int, int); 60 void init_list(int, NeighList *); 61 void errorf(const char *, int, const char *); 62 int factorial(int); 63 64 RANN::Fingerprint *create_fingerprint(const char *); 65 RANN::Activation *create_activation(const char *); 66 67 //global variables 68 int nelements; // # of elements (distinct from LAMMPS atom types since multiple atom types can be mapped to one element) 69 int nelementsp; // nelements+1 70 char **elements; // names of elements 71 char **elementsp; // names of elements with "all" appended as the last "element" 72 double *mass; // mass of each element 73 double cutmax; // max radial distance for neighbor lists 74 int *map; // mapping from atom types to elements 75 int *fingerprintcount; // static variable used in initialization 76 int *fingerprintlength; // # of input neurons defined by fingerprints of each element. 77 int *fingerprintperelement; // # of fingerprints for each element 78 bool doscreen; //screening is calculated if any defined fingerprint uses it 79 bool 80 allscreen; //all fingerprints use screening so screened neighbors can be completely ignored 81 bool dospin; 82 int res; //Resolution of function tables for cubic interpolation. 83 int memguess; 84 double *screening_min; 85 double *screening_max; 86 bool **weightdefined; 87 bool **biasdefined; 88 int nmax1; 89 int nmax2; 90 int fmax; 91 int fnmax; 92 //memory actively written to during each compute: 93 double *xn, *yn, *zn, *Sik, *dSikx, *dSiky, *dSikz, *dSijkx, *dSijky, *dSijkz, *sx, *sy, *sz, 94 **dSijkxc, **dSijkyc, **dSijkzc, *dfeaturesx, *dfeaturesy, *dfeaturesz, *features; 95 double *layer, *sum, *sum1, **dlayerx, **dlayery, **dlayerz, **dlayersumx, **dlayersumy, 96 **dlayersumz; 97 double **dsx, **dsy, **dsz, **dssumx, **dssumy, **dssumz; 98 int *tn, *jl; 99 bool *Bij; 100 101 struct Simulation { 102 int *id; 103 bool forces; 104 bool spins; 105 double **x; 106 double **f; 107 double **s; 108 double box[3][3]; 109 double origin[3]; 110 double **features; 111 double **dfx; 112 double **dfy; 113 double **dfz; 114 double **dsx; 115 double **dsy; 116 double **dsz; 117 int *ilist, *numneigh, **firstneigh, *type, inum, gnum; 118 }; 119 120 struct NNarchitecture { 121 int layers; 122 int *dimensions; //vector of length layers with entries for neurons per layer 123 double **Weights; 124 double **Biases; 125 int *activations; //unused 126 int maxlayer; //longest layer (for memory allocation) 127 }; 128 129 Simulation *sims; 130 NNarchitecture *net; //array of networks, 1 for each element. 131 132 protected: 133 RANN::Activation ***activation; 134 RANN::Fingerprint ***fingerprints; 135 136 private: 137 //new functions 138 void allocate( 139 const std::vector<std::string> 140 &); //called after reading element list, but before reading the rest of the potential 141 void deallocate(); 142 void read_file(char *); //read potential file 143 void read_atom_types(std::vector<std::string>, char *, int); 144 void read_fpe( 145 std::vector<std::string>, std::vector<std::string>, char *, 146 int); //fingerprints per element. Count total fingerprints defined for each 1st element in element combinations 147 void read_fingerprints(std::vector<std::string>, std::vector<std::string>, char *, int); 148 void read_fingerprint_constants(std::vector<std::string>, std::vector<std::string>, char *, int); 149 void read_network_layers(std::vector<std::string>, std::vector<std::string>, char *, 150 int); //include input and output layer (hidden layers + 2) 151 void read_layer_size(std::vector<std::string>, std::vector<std::string>, char *, int); 152 void read_weight(std::vector<std::string>, std::vector<std::string>, FILE *, char *, 153 int *); //weights should be formatted as properly shaped matrices 154 void read_bias(std::vector<std::string>, std::vector<std::string>, FILE *, char *, 155 int *); //biases should be formatted as properly shaped vectors 156 void read_activation_functions(std::vector<std::string>, std::vector<std::string>, char *, int); 157 void read_screening(std::vector<std::string>, std::vector<std::string>, char *, int); 158 void read_mass(const std::vector<std::string> &, const std::vector<std::string> &, const char *, 159 int); 160 bool check_potential(); //after finishing reading potential file 161 void propagateforward(double *, double **, int, 162 int); //called by compute to get force and energy 163 void propagateforwardspin(double *, double **, double **, int, 164 int); //called by compute to get force and energy 165 void screening(int, int, int); 166 void cull_neighbor_list(int *, int, int); 167 void screen_neighbor_list(int *); 168 }; 169 170 } // namespace LAMMPS_NS 171 172 #endif 173 #endif 174