move initializers for structs from header file to implementation, add constructors

This commit is contained in:
Axel Kohlmeyer
2024-06-25 20:18:37 -04:00
parent e5250a76ac
commit baaa9dbedd
2 changed files with 811 additions and 703 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,6 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS #ifdef COMMAND_CLASS
// clang-format off // clang-format off
CommandStyle(fitpod,FitPOD); CommandStyle(fitpod,FitPOD);
@ -33,14 +32,17 @@ public:
private: private:
struct datastruct { struct datastruct {
std::string file_format = "extxyz"; datastruct();
std::string file_extension = "xyz"; void copydatainfo(datastruct &data) const;
std::string file_format;
std::string file_extension;
std::string data_path; std::string data_path;
std::vector<std::string> data_files; // sorted file names std::vector<std::string> data_files; // sorted file names
std::vector<std::string> group_names; // sorted group names std::vector<std::string> group_names; // sorted group names
std::vector<std::string> filenames; std::vector<std::string> filenames;
std::string filenametag = "pod"; std::string filenametag;
std::string group_weight_type = "global"; std::string group_weight_type;
std::vector<int> num_atom; std::vector<int> num_atom;
std::vector<int> num_atom_cumsum; std::vector<int> num_atom_cumsum;
@ -52,86 +54,65 @@ private:
int num_atom_max; int num_atom_max;
int num_config_sum; int num_config_sum;
double *lattice=nullptr; double *lattice;
double *energy=nullptr; double *energy;
double *stress=nullptr; double *stress;
double *position=nullptr; double *position;
double *force=nullptr; double *force;
int *atomtype=nullptr; int *atomtype;
// Group weights will have same size as energy. // Group weights will have same size as energy.
double *we=nullptr; double *we;
double *wf=nullptr; double *wf;
int training = 1; int training;
int normalizeenergy = 1; int normalizeenergy;
int training_analysis = 1; int training_analysis;
int test_analysis = 1; int test_analysis;
int training_calculation = 0; int training_calculation;
int test_calculation = 0; int test_calculation;
int randomize = 1; int randomize;
int precision = 8; int precision;
double fraction = 1.0; double fraction;
std::unordered_map<std::string, double> we_map; std::unordered_map<std::string, double> we_map;
std::unordered_map<std::string, double> wf_map; std::unordered_map<std::string, double> wf_map;
double fitting_weights[12] = {100.0, 1.0, 0.0, 1, 1, 0, 0, 1, 1, 1, 1, 1e-10}; double fitting_weights[12];
void copydatainfo(datastruct &data) const
{
data.data_path = data_path;
data.file_format = file_format;
data.file_extension = file_extension;
data.data_files = data_files;
data.filenametag = filenametag;
data.filenames = filenames;
data.training_analysis = training_analysis;
data.test_analysis = test_analysis;
data.training_calculation = training_calculation;
data.test_calculation = test_calculation;
data.fraction = fraction;
data.randomize = randomize;
data.precision = precision;
data.training = training;
data.normalizeenergy = normalizeenergy;
for (int i = 0; i < 12; i++)
data.fitting_weights[i] = fitting_weights[i];
data.we_map = we_map;
data.wf_map = wf_map;
}
}; };
struct neighborstruct { struct neighborstruct {
int *alist=nullptr; neighborstruct();
int *pairnum=nullptr;
int *pairnum_cumsum=nullptr;
int *pairlist=nullptr;
double *y=nullptr;
//int natom; int *alist;
//int nalist; int *pairnum;
int natom_max = 0; int *pairnum_cumsum;
int sze = 0; int *pairlist;
int sza = 0; double *y;
int szy = 0;
int szp = 0; int natom_max;
int sze;
int sza;
int szy;
int szp;
}; };
struct descriptorstruct { struct descriptorstruct {
double *bd=nullptr; // base descriptors descriptorstruct();
double *pd=nullptr; // multi-environment descriptors (probabilities)
double *gd=nullptr; // global descriptors double *bd; // base descriptors
double *gdd=nullptr; // derivatives of global descriptors and peratom descriptors double *pd; // multi-environment descriptors (probabilities)
double *A=nullptr; // least-square matrix for all descriptors double *gd; // global descriptors
double *b=nullptr; // least-square vector for all descriptors double *gdd; // derivatives of global descriptors and peratom descriptors
double *c=nullptr; // coefficents of descriptors double *A; // least-square matrix for all descriptors
int szd = 0; double *b; // least-square vector for all descriptors
int nCoeffAll = 0; // number of global descriptors double *c; // coefficents of descriptors
int nClusters = 0; // number of environment clusters int szd;
int nCoeffAll; // number of global descriptors
int nClusters; // number of environment clusters
}; };
int save_descriptors = 0; int save_descriptors;
int compute_descriptors = 0; int compute_descriptors;
datastruct traindata; datastruct traindata;
datastruct testdata; datastruct testdata;
datastruct envdata; datastruct envdata;
@ -159,9 +140,12 @@ private:
void matrix33_inverse(double *invA, double *A1, double *A2, double *A3); void matrix33_inverse(double *invA, double *A1, double *A2, double *A3);
double squareDistance(const double *a, const double *b, int DIMENSIONS); double squareDistance(const double *a, const double *b, int DIMENSIONS);
void assignPointsToClusters(double *points, double *centroids, int *assignments, int *clusterSizes, int NUM_POINTS, int NUM_CLUSTERS, int DIMENSION); void assignPointsToClusters(double *points, double *centroids, int *assignments,
void updateCentroids(double *points, double *centroids, int *assignments, int *clusterSizes, int NUM_POINTS, int NUM_CLUSTERS, int DIMENSIONS); int *clusterSizes, int NUM_POINTS, int NUM_CLUSTERS, int DIMENSION);
void KmeansClustering(double *points, double *centroids, int *assignments, int *clusterSizes, int NUM_POINTS, int NUM_CLUSTERS, int DIMENSIONS, int MAX_ITER); void updateCentroids(double *points, double *centroids, int *assignments, int *clusterSizes,
int NUM_POINTS, int NUM_CLUSTERS, int DIMENSIONS);
void KmeansClustering(double *points, double *centroids, int *assignments, int *clusterSizes,
int NUM_POINTS, int NUM_CLUSTERS, int DIMENSIONS, int MAX_ITER);
void savedata2textfile(std::string filename, std::string text, double *A, int n, int m, int dim); void savedata2textfile(std::string filename, std::string text, double *A, int n, int m, int dim);
void savematrix2binfile(std::string filename, double *A, int nrows, int ncols); void savematrix2binfile(std::string filename, double *A, int nrows, int ncols);
@ -169,14 +153,20 @@ private:
// functions for reading input files and fitting // functions for reading input files and fitting
int read_data_file(double *fitting_weights, std::string &file_format, std::string &file_extension, std::string &env_path, int read_data_file(double *fitting_weights, std::string &file_format, std::string &file_extension,
std::string &test_path, std::string &training_path, std::string &filenametag, const std::string &data_file, std::string &group_weight_type, std::string &env_path, std::string &test_path, std::string &training_path,
std::unordered_map<std::string, double> &we_map, std::unordered_map<std::string, double> &wf_map); std::string &filenametag, const std::string &data_file,
void get_exyz_files(std::vector<std::string> &, std::vector<std::string> &, const std::string &, const std::string &); std::string &group_weight_type,
std::unordered_map<std::string, double> &we_map,
std::unordered_map<std::string, double> &wf_map);
void get_exyz_files(std::vector<std::string> &, std::vector<std::string> &, const std::string &,
const std::string &);
int get_number_atom_exyz(std::vector<int> &num_atom, int &num_atom_sum, std::string file); int get_number_atom_exyz(std::vector<int> &num_atom, int &num_atom_sum, std::string file);
int get_number_atoms(std::vector<int>& num_atom, std::vector<int> &num_atom_sum, std::vector<int>& num_config, std::vector<std::string> training_files); int get_number_atoms(std::vector<int> &num_atom, std::vector<int> &num_atom_sum,
void read_exyz_file(double *lattice, double *stress, double *energy, double *we, double *wf, double *pos, double *forces, std::vector<int> &num_config, std::vector<std::string> training_files);
int *atomtype, std::string file, std::vector<std::string> species, double we_group, double wf_group); void read_exyz_file(double *lattice, double *stress, double *energy, double *we, double *wf,
double *pos, double *forces, int *atomtype, std::string file,
std::vector<std::string> species, double we_group, double wf_group);
void get_data(datastruct &data, const std::vector<std::string> &species); void get_data(datastruct &data, const std::vector<std::string> &species);
std::vector<int> linspace(int start_in, int end_in, int num_in); std::vector<int> linspace(int start_in, int end_in, int num_in);
std::vector<int> shuffle(int start_in, int end_in, int num_in); std::vector<int> shuffle(int start_in, int end_in, int num_in);
@ -188,7 +178,8 @@ private:
int podneighborlist(int *neighlist, int *numneigh, double *r, double rcutsq, int nx, int N, int podneighborlist(int *neighlist, int *numneigh, double *r, double rcutsq, int nx, int N,
int dim); int dim);
int podfullneighborlist(double *y, int *alist, int *neighlist, int *numneigh, int *numneighsum, int podfullneighborlist(double *y, int *alist, int *neighlist, int *numneigh, int *numneighsum,
double *x, double *a1, double *a2, double *a3, double rcut, int *pbc, int nx); double *x, double *a1, double *a2, double *a3, double rcut, int *pbc,
int nx);
void estimate_memory_neighborstruct(const datastruct &data, int *pbc, double rcut, int nelements); void estimate_memory_neighborstruct(const datastruct &data, int *pbc, double rcut, int nelements);
void allocate_memory_neighborstruct(); void allocate_memory_neighborstruct();
void allocate_memory_descriptorstruct(int nd); void allocate_memory_descriptorstruct(int nd);
@ -204,8 +195,6 @@ private:
double energyforce_calculation_fastpod(double *force, const datastruct &data, int ci); double energyforce_calculation_fastpod(double *force, const datastruct &data, int ci);
void energyforce_calculation(const datastruct &data); void energyforce_calculation(const datastruct &data);
}; };
} // namespace LAMMPS_NS } // namespace LAMMPS_NS
#endif #endif
#endif #endif