diff --git a/lib/kim/KIM_LAMMPS_PlugIn.h b/lib/kim/KIM_LAMMPS_PlugIn.h deleted file mode 100644 index 33706e220d..0000000000 --- a/lib/kim/KIM_LAMMPS_PlugIn.h +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2018 Regents of the University of Minnesota -// All rights reserved. -// -// Contributing authors: Ryan S. Elliott - -#define KIM_STATUS_OK 1 -#define KIM_STATUS_NEIGH_ITER_PAST_END 2 -#define KIM_STATUS_NEIGH_ITER_INIT_OK 3 -#define KIM_STATUS_NEIGH_INVALID_REQUEST -11 -#define KIM_STATUS_NEIGH_INVALID_MODE -6 -#define KIM_COMPUTE_FALSE 0 -#define KIM_COMPUTE_TRUE 1 -#define KIM_STATUS_FAIL 0 - -#include "dlfcn.h" -#include "error.h" - -namespace LAMMPS_NS { - -class KIM_LAMMPS_PlugIn { - public: - ~KIM_LAMMPS_PlugIn() {}; - KIM_LAMMPS_PlugIn() : library(NULL) {}; - - bool setup_kim_api_library(Error * const error); - bool is_strictly_between_1_5_and_2_0; - - // KIM symbols - void* library; - int (*report_error)(int line, const char *, const char *, int); - void (*setm_compute_by_index)(void *, int *, ...); - int (*model_compute)(void *); - int (*model_init)(void *); - int (*model_reinit)(void *); - void * (*get_sim_buffer)(void *, int *); - void * (*get_data_by_index)(void *, int, int *); - int (*model_destroy)(void *); - void (*free)(void *, int *); - int (*string_init)(void *, const char *, const char *); - int (*is_half_neighbors)(void *, int *); - int (*get_NBC_method)(void *, const char **); - int (*get_index)(void *, const char *, int *); - int (*getm_index)(void *, int *, int, ...); - int (*get_species_code)(void *, const char *, int *); - void (*setm_data_by_index)(void *, int *, int, ...); - int (*set_method_by_index)(void *, int, intptr_t, void (*)()); - void (*set_sim_buffer)(void *, void *, int *); - int (*set_data_by_index)(void *, int, intptr_t, void *); - void (*set_compute_by_index)(void *, int, int, int*); - int (*get_num_params)(void *, int *, int *); - int (*get_free_parameter)(void *, const int, const char **); - void * (*get_data)(void *, const char *, int *); - intptr_t (*get_rank)(void *, const char *, int *); - intptr_t (*get_shape)(void *, const char *, int *, int *); - int (*model_info)(void *, const char *); -}; - - -bool KIM_LAMMPS_PlugIn::setup_kim_api_library(Error * error) -{ - if (library == NULL) - { -#ifdef KIM_INSTALL_DIR - library = dlopen(KIM_INSTALL_DIR "/lib/libkim-api-v1.so", RTLD_NOW); -#endif - - if (library == NULL) - library = dlopen("kim-api-v1.so", RTLD_NOW); - - if (library == NULL) - { - error->all(FLERR,"KIM API library cannot be found"); - return false; - } - else - { - // check for version and set is_strictly_between_1_5_and_2_0 - void * ver = dlsym(library, "KIM_API_get_version"); - if (ver == NULL) - is_strictly_between_1_5_and_2_0 = false; - else - is_strictly_between_1_5_and_2_0 = true; - - std::string error_prefix("KIM API library error: "); - // get symbols - if (NULL == (report_error = - (int (*)(int, const char *, const char *, int)) - dlsym(library, "KIM_API_report_error"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (setm_compute_by_index = - (void (*)(void *, int *, ...)) - dlsym(library, "KIM_API_setm_compute_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (model_compute = (int (*)(void *)) - dlsym(library, "KIM_API_model_compute"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (model_init = (int (*)(void *)) - dlsym(library, "KIM_API_model_init"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (model_reinit = (int (*)(void *)) - dlsym(library, "KIM_API_model_reinit"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_sim_buffer = (void * (*)(void *, int *)) - dlsym(library, "KIM_API_get_sim_buffer"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_data_by_index = (void * (*)(void *, int, int *)) - dlsym(library, "KIM_API_get_data_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (model_destroy = (int (*)(void *)) - dlsym(library, "KIM_API_model_destroy"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (free = (void (*)(void *, int *)) - dlsym(library, "KIM_API_free"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (string_init = - (int (*)(void *, const char *, const char *)) - dlsym(library, "KIM_API_string_init"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (is_half_neighbors = (int (*)(void *, int *)) - dlsym(library, "KIM_API_is_half_neighbors"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_NBC_method = (int (*)(void *, const char **)) - dlsym(library, "KIM_API_get_NBC_method"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_index = (int (*)(void *, const char *, int *)) - dlsym(library, "KIM_API_get_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (getm_index = (int (*)(void *, int *, int, ...)) - dlsym(library, "KIM_API_getm_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_species_code = - (int (*)(void *, const char *, int *)) - dlsym(library, "KIM_API_get_species_code"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (setm_data_by_index = - (void (*)(void *, int *, int, ...)) - dlsym(library, "KIM_API_setm_data_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (set_method_by_index = - (int (*)(void *, int, intptr_t, void (*)())) - dlsym(library, "KIM_API_set_method_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (set_sim_buffer = (void (*)(void *, void *, int *)) - dlsym(library, "KIM_API_set_sim_buffer"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (set_data_by_index = - (int (*)(void *, int, intptr_t, void *)) - dlsym(library, "KIM_API_set_data_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (set_compute_by_index = - (void (*)(void *, int, int, int*)) - dlsym(library, "KIM_API_set_compute_by_index"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_num_params = (int (*)(void *, int *, int *)) - dlsym(library, "KIM_API_get_num_params"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_free_parameter = - (int (*)(void *, const int, const char **)) - dlsym(library, "KIM_API_get_free_parameter"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_data = (void * (*)(void *, const char *, int *)) - dlsym(library, "KIM_API_get_data"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_rank = - (intptr_t (*)(void *, const char *, int *)) - dlsym(library, "KIM_API_get_rank"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (get_shape = - (intptr_t (*)(void *, const char *, int *, int *)) - dlsym(library, "KIM_API_get_shape"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - if (NULL == (model_info = (int (*)(void *, const char *)) - dlsym(library, "KIM_API_model_info"))) - error->all(FLERR,(error_prefix + std::string(dlerror())).c_str()); - - return true; - } - } - else - { - return true; - } -} - -} // namespace LAMMPS_NS diff --git a/lib/kim/Makefile.lammps b/lib/kim/Makefile.lammps index 39afb1286a..d73891d1e2 100644 --- a/lib/kim/Makefile.lammps +++ b/lib/kim/Makefile.lammps @@ -18,6 +18,15 @@ include ../../lib/kim/Makefile.KIM_DIR -kim_SYSINC = -I../../lib/kim -DKIM_INSTALL_DIR=\"$(KIM_INSTALL_DIR)\" -kim_SYSLIB = -ldl -kim_SYSPATH = +ifeq ($(wildcard $(KIM_INSTALL_DIR)/bin/kim-api-v1-build-config),) + KIM_CONFIG_HELPER = kim-api-v1-build-config +else + KIM_CONFIG_HELPER = $(KIM_INSTALL_DIR)/bin/kim-api-v1-build-config +endif +ifeq ($(shell $(KIM_CONFIG_HELPER) --version 2> /dev/null),) + $(error $(KIM_CONFIG_HELPER) utility is not available. Something is wrong with your KIM API package setup) +endif + +kim_SYSINC = $(shell $(KIM_CONFIG_HELPER) --includes) +kim_SYSLIB = $(shell $(KIM_CONFIG_HELPER) --ldlibs) +kim_SYSPATH = $(shell $(KIM_CONFIG_HELPER) --ldflags) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 57bb6cb894..46e843158a 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -38,14 +38,21 @@ #include "domain.h" #include "error.h" -#include "KIM_LAMMPS_PlugIn.h" +// includes from KIM +#include "KIM_API.h" +#include "KIM_API_status.h" + +#ifndef KIM_API_VERSION_MAJOR +// support v1.5.0 +#define KIM_API_VERSION_MAJOR 1 +#define KIM_API_VERSION_MINOR 5 +#define KIM_API_VERSION_PATCH 0 +#endif using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -void * (*PairKIM::kim_get_sim_buffer)(void *, int *); - PairKIM::PairKIM(LAMMPS *lmp) : Pair(lmp), settings_call_count(0), @@ -55,7 +62,6 @@ PairKIM::PairKIM(LAMMPS *lmp) : lmps_unique_elements(0), lmps_num_unique_elements(0), lmps_units(METAL), - kim(new KIM_LAMMPS_PlugIn), pkim(0), kim_ind_coordinates(-1), kim_ind_numberOfParticles(-1), @@ -98,42 +104,35 @@ PairKIM::PairKIM(LAMMPS *lmp) : PairKIM::~PairKIM() { - if (kim->library != NULL) - { - // clean up kim_modelname - if (kim_modelname != 0) delete [] kim_modelname; + // clean up kim_modelname + if (kim_modelname != 0) delete [] kim_modelname; - // clean up lammps atom species number to unique particle names mapping - if (lmps_unique_elements) + // clean up lammps atom species number to unique particle names mapping + if (lmps_unique_elements) for (int i = 0; i < lmps_num_unique_elements; i++) delete [] lmps_unique_elements[i]; - delete [] lmps_unique_elements; + delete [] lmps_unique_elements; - // clean up local memory used to support KIM interface - memory->destroy(kim_particleSpecies); - memory->destroy(lmps_force_tmp); - memory->destroy(lmps_stripped_neigh_list); + // clean up local memory used to support KIM interface + memory->destroy(kim_particleSpecies); + memory->destroy(lmps_force_tmp); + memory->destroy(lmps_stripped_neigh_list); - // clean up allocated memory for standard Pair class usage - // also, we allocate lmps_map_species_to_uniuqe in the allocate() function - if (allocated) { + // clean up allocated memory for standard Pair class usage + // also, we allocate lmps_map_species_to_uniuqe in the allocate() function + if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); delete [] lmps_map_species_to_unique; - } + } - // clean up Rij array - memory->destroy(Rij); + // clean up Rij array + memory->destroy(Rij); - // clean up KIM interface (if necessary) - kim_free(); + // clean up KIM interface (if necessary) + kim_free(); - dlclose(kim->library); - } - - delete kim; - - return; + return; } /* ---------------------------------------------------------------------- */ @@ -179,17 +178,17 @@ void PairKIM::compute(int eflag , int vflag) // pass current atom pointers to KIM set_volatiles(); - kim->setm_compute_by_index(pkim, &kimerror,3*3, - kim_ind_particleEnergy, eflag_atom, - (int) kim_model_has_particleEnergy, - kim_ind_particleVirial, vflag_atom, - (int) kim_model_has_particleVirial, - kim_ind_virial, vflag_global!=0, - no_virial_fdotr_compute); + pkim->setm_compute_by_index(&kimerror,3*3, + kim_ind_particleEnergy, eflag_atom, + (int) kim_model_has_particleEnergy, + kim_ind_particleVirial, vflag_atom, + (int) kim_model_has_particleVirial, + kim_ind_virial, vflag_global!=0, + no_virial_fdotr_compute); kim_error(__LINE__,"setm_compute_by_index",kimerror); // compute via KIM model - kimerror = kim->model_compute(pkim); + kimerror = pkim->model_compute(); kim_error(__LINE__,"PairKIM::pkim->model_compute() error",kimerror); // assemble force and particleVirial if needed if (!lmps_using_newton) comm->reverse_comm_pair(this); @@ -265,10 +264,6 @@ void PairKIM::settings(int narg, char **arg) { // This is called when "pair_style kim ..." is read from input // may be called multiple times - - kim->setup_kim_api_library(error); // exits on failure - kim_get_sim_buffer = kim->get_sim_buffer; - ++settings_call_count; init_style_call_count = 0; @@ -418,7 +413,7 @@ void PairKIM::init_style() if (!kim_init_ok) { kim_init(); - kimerror = kim->model_init(pkim); + kimerror = pkim->model_init(); if (kimerror != KIM_STATUS_OK) kim_error(__LINE__, "KIM API:model_init() failed", kimerror); else @@ -490,7 +485,7 @@ void PairKIM::reinit() // Then reinit KIM model int kimerror; - kimerror = kim->model_reinit(pkim); + kimerror = pkim->model_reinit(); kim_error(__LINE__,"model_reinit unsuccessful", kimerror); } @@ -632,7 +627,7 @@ double PairKIM::memory_usage() void PairKIM::kim_error(int ln, const char* msg, int errcode) { if (errcode == KIM_STATUS_OK) return; - kim->report_error(ln,(char *) __FILE__, (char *) msg,errcode); + KIM_API_model::report_error(ln,(char *) __FILE__, (char *) msg,errcode); error->all(__FILE__,ln,"Internal KIM error"); return; @@ -643,10 +638,10 @@ void PairKIM::kim_error(int ln, const char* msg, int errcode) int PairKIM::get_neigh(void **kimmdl,int *mode,int *request, int *atom, int *numnei, int **nei1atom, double **pRij) { - void * pkim = *kimmdl; + KIM_API_model *pkim = (KIM_API_model *) *kimmdl; int kimerror; - PairKIM *self = (PairKIM *) kim_get_sim_buffer(pkim, &kimerror); + PairKIM *self = (PairKIM *) pkim->get_sim_buffer(&kimerror); if (self->kim_model_using_Rij) { *pRij = &(self->Rij[0]); @@ -697,8 +692,8 @@ int PairKIM::get_neigh(void **kimmdl,int *mode,int *request, // set Rij if needed if (self->kim_model_using_Rij) { double* x = (double *) - self->kim->get_data_by_index(pkim, self->kim_ind_coordinates, - &kimerror); + (*pkim).get_data_by_index(self->kim_ind_coordinates, + &kimerror); for (jj=0; jj < *numnei; jj++) { int i = *atom; j = (*nei1atom)[jj]; @@ -745,8 +740,7 @@ int PairKIM::get_neigh(void **kimmdl,int *mode,int *request, // set Rij if needed if (self->kim_model_using_Rij){ double* x = (double *) - self->kim->get_data_by_index(pkim, self->kim_ind_coordinates, - &kimerror); + (*pkim).get_data_by_index(self->kim_ind_coordinates, &kimerror); for(int jj=0; jj < *numnei; jj++){ int i = *atom; int j = (*nei1atom)[jj]; @@ -777,16 +771,17 @@ void PairKIM::kim_free() if (kim_model_init_ok) { - kimerror = kim->model_destroy(pkim); + kimerror = pkim->model_destroy(); kim_model_init_ok = false; } if (kim_init_ok) { - kim->free(&pkim, &kimerror); + pkim->free(&kimerror); kim_init_ok = false; } if (pkim != 0) { + delete pkim; pkim = 0; } if (kim_particle_codes_ok) @@ -821,7 +816,8 @@ void PairKIM::kim_init() } // initialize KIM model - kimerror = kim->string_init(&pkim, test_descriptor_string, kim_modelname); + pkim = new KIM_API_model(); + kimerror = pkim->string_init(test_descriptor_string, kim_modelname); if (kimerror != KIM_STATUS_OK) kim_error(__LINE__,"KIM initialization failed", kimerror); else @@ -834,10 +830,10 @@ void PairKIM::kim_init() // determine kim_model_using_* true/false values // // check for half or full list - kim_model_using_half = kim->is_half_neighbors(pkim, &kimerror); + kim_model_using_half = (pkim->is_half_neighbors(&kimerror)); // const char* NBC_method; - kimerror = kim->get_NBC_method(pkim, &NBC_method); + kimerror = pkim->get_NBC_method(&NBC_method); kim_error(__LINE__,"NBC method not set",kimerror); // check for CLUSTER mode kim_model_using_cluster = (strcmp(NBC_method,"CLUSTER")==0); @@ -846,18 +842,17 @@ void PairKIM::kim_init() (strcmp(NBC_method,"NEIGH_RVEC_F")==0)); // get correct index of each variable in kim_api object - kim->getm_index(pkim, &kimerror, 3*15, + pkim->getm_index(&kimerror, 3*13, "coordinates", &kim_ind_coordinates, 1, "cutoff", &kim_ind_cutoff, 1, "numberOfParticles", &kim_ind_numberOfParticles, 1, - "numberParticleTypes", &kim_ind_numberOfSpecies, - ! kim->is_strictly_between_1_5_and_2_0, - "particleTypes", &kim_ind_particleSpecies, - ! kim->is_strictly_between_1_5_and_2_0, - "numberOfSpecies", &kim_ind_numberOfSpecies, - kim->is_strictly_between_1_5_and_2_0, - "particleSpecies", &kim_ind_particleSpecies, - kim->is_strictly_between_1_5_and_2_0, +#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSON_MINOR == 5 + "numberParticleTypes", &kim_ind_numberOfSpecies, 1, + "particleTypes", &kim_ind_particleSpecies, 1, +#else + "numberOfSpecies", &kim_ind_numberOfSpecies, 1, + "particleSpecies", &kim_ind_particleSpecies, 1, +#endif "numberContributingParticles", &kim_ind_numberContributingParticles, kim_model_using_half, "particleEnergy", &kim_ind_particleEnergy, @@ -877,7 +872,7 @@ void PairKIM::kim_init() for(int i = 0; i < lmps_num_unique_elements; i++){ int kimerror; kim_particle_codes[i] - = kim->get_species_code(pkim, lmps_unique_elements[i], &kimerror); + = pkim->get_species_code(lmps_unique_elements[i], &kimerror); kim_error(__LINE__, "create_kim_particle_codes: symbol not found ", kimerror); } @@ -896,7 +891,7 @@ void PairKIM::set_statics() lmps_local_tot_num_atoms = (int) (atom->nghost + atom->nlocal); int kimerror; - kim->setm_data_by_index(pkim, &kimerror, 4*6, + pkim->setm_data_by_index(&kimerror, 4*6, kim_ind_numberOfSpecies, 1, (void *) &(atom->ntypes), 1, kim_ind_cutoff, 1, (void *) &(kim_global_cutoff), 1, kim_ind_numberOfParticles, 1, (void *) &lmps_local_tot_num_atoms, 1, @@ -907,12 +902,12 @@ void PairKIM::set_statics() kim_error(__LINE__, "setm_data_by_index", kimerror); if (!kim_model_using_cluster) { - kimerror = kim->set_method_by_index(pkim, kim_ind_get_neigh, 1, - (void (*)()) &get_neigh); + kimerror = pkim->set_method_by_index(kim_ind_get_neigh, 1, + (func_ptr) &get_neigh); kim_error(__LINE__, "set_method_by_index", kimerror); } - kim->set_sim_buffer(pkim, (void *)this, &kimerror); + pkim->set_sim_buffer((void *)this, &kimerror); kim_error(__LINE__, "set_sim_buffer", kimerror); return; @@ -926,33 +921,33 @@ void PairKIM::set_volatiles() lmps_local_tot_num_atoms = (int) (atom->nghost + atom->nlocal); intptr_t nall = (intptr_t) lmps_local_tot_num_atoms; - kim->setm_data_by_index(pkim, &kimerror, 4*2, + pkim->setm_data_by_index(&kimerror, 4*2, kim_ind_coordinates, 3*nall, (void*) &(atom->x[0][0]), 1, kim_ind_particleSpecies, nall, (void*) kim_particleSpecies, 1); kim_error(__LINE__, "setm_data_by_index", kimerror); if (kim_model_has_particleEnergy && (eflag_atom == 1)) { - kimerror = kim->set_data_by_index(pkim, kim_ind_particleEnergy, nall, - (void*) eatom); + kimerror = pkim->set_data_by_index(kim_ind_particleEnergy, nall, + (void*) eatom); kim_error(__LINE__, "set_data_by_index", kimerror); } if (kim_model_has_particleVirial && (vflag_atom == 1)) { - kimerror = kim->set_data_by_index(pkim, kim_ind_particleVirial, 6*nall, - (void*) &(vatom[0][0])); + kimerror = pkim->set_data_by_index(kim_ind_particleVirial, 6*nall, + (void*) &(vatom[0][0])); kim_error(__LINE__, "set_data_by_index", kimerror); } if (kim_model_has_forces) { if (lmps_hybrid) - kimerror = kim->set_data_by_index(pkim, kim_ind_forces, nall*3, - (void*) &(lmps_force_tmp[0][0])); + kimerror = pkim->set_data_by_index(kim_ind_forces, nall*3, + (void*) &(lmps_force_tmp[0][0])); else - kimerror = kim->set_data_by_index(pkim, kim_ind_forces, nall*3, - (void*) &(atom->f[0][0])); + kimerror = pkim->set_data_by_index(kim_ind_forces, nall*3, + (void*) &(atom->f[0][0])); kim_error(__LINE__, "setm_data_by_index", kimerror); } @@ -965,17 +960,17 @@ void PairKIM::set_volatiles() if (kim_model_has_particleVirial) { if(vflag_atom != 1) { - kim->set_compute_by_index(pkim, kim_ind_particleVirial, - KIM_COMPUTE_FALSE, &kimerror); + pkim->set_compute_by_index(kim_ind_particleVirial, KIM_COMPUTE_FALSE, + &kimerror); } else { - kim->set_compute_by_index(pkim, kim_ind_particleVirial, - KIM_COMPUTE_TRUE, &kimerror); + pkim->set_compute_by_index(kim_ind_particleVirial, KIM_COMPUTE_TRUE, + &kimerror); } } if (no_virial_fdotr_compute == 1) { - kim->set_compute_by_index(pkim, kim_ind_virial, + pkim->set_compute_by_index(kim_ind_virial, ((vflag_global != 1) ? KIM_COMPUTE_FALSE : KIM_COMPUTE_TRUE), &kimerror); } @@ -1033,37 +1028,39 @@ void PairKIM::set_lmps_flags() void PairKIM::set_kim_model_has_flags() { + KIM_API_model mdl; + int kimerror; // get KIM API object representing the KIM Model only - kimerror = kim->model_info(&pkim, kim_modelname); + kimerror = mdl.model_info(kim_modelname); kim_error(__LINE__,"KIM initialization failed", kimerror); // determine if the KIM Model can compute the total energy - kim->get_index(pkim, (char*) "energy", &kimerror); + mdl.get_index((char*) "energy", &kimerror); kim_model_has_energy = (kimerror == KIM_STATUS_OK); if (!kim_model_has_energy) error->warning(FLERR,"KIM Model does not provide `energy'; " "Potential energy will be zero"); // determine if the KIM Model can compute the forces - kim->get_index(pkim, (char*) "forces", &kimerror); + mdl.get_index((char*) "forces", &kimerror); kim_model_has_forces = (kimerror == KIM_STATUS_OK); if (!kim_model_has_forces) error->warning(FLERR,"KIM Model does not provide `forces'; " "Forces will be zero"); // determine if the KIM Model can compute the particleEnergy - kim->get_index(pkim, (char*) "particleEnergy", &kimerror); + mdl.get_index((char*) "particleEnergy", &kimerror); kim_model_has_particleEnergy = (kimerror == KIM_STATUS_OK); if (!kim_model_has_particleEnergy) error->warning(FLERR,"KIM Model does not provide `particleEnergy'; " "energy per atom will be zero"); // determine if the KIM Model can compute the particleVerial - kim->get_index(pkim, (char*) "particleVirial", &kimerror); + mdl.get_index((char*) "particleVirial", &kimerror); kim_model_has_particleVirial = (kimerror == KIM_STATUS_OK); - kim->get_index(pkim, (char*) "process_dEdr", &kimerror); + mdl.get_index((char*) "process_dEdr", &kimerror); kim_model_has_particleVirial = kim_model_has_particleVirial || (kimerror == KIM_STATUS_OK); if (!kim_model_has_particleVirial) @@ -1071,7 +1068,7 @@ void PairKIM::set_kim_model_has_flags() "virial per atom will be zero"); // tear down KIM API object - kim->free(&pkim, &kimerror); + mdl.free(&kimerror); // now destructor will do the remaining tear down for mdl return; @@ -1096,7 +1093,6 @@ void PairKIM::write_descriptor(char** test_descriptor_string) "#\n" "# This file is automatically generated from LAMMPS pair_style " "kim command\n"); - char tmp_version[100]; strcat(*test_descriptor_string, "\n" "# The call number is (pair_style).(init_style): "); @@ -1105,13 +1101,11 @@ void PairKIM::write_descriptor(char** test_descriptor_string) strcat(*test_descriptor_string, tmp_num); strcat(*test_descriptor_string, "#\n" - "\n"); - - if (kim->is_strictly_between_1_5_and_2_0) - strcat(*test_descriptor_string, - "KIM_API_Version := 1.6.0\n\n"); - - strcat(*test_descriptor_string, + "\n" +#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSION_MINOR == 5 +#else + "KIM_API_Version := 1.6.0\n\n" +#endif "# Base units\n"); switch (lmps_units) { @@ -1158,15 +1152,13 @@ void PairKIM::write_descriptor(char** test_descriptor_string) } // Write Supported species section - if (kim->is_strictly_between_1_5_and_2_0) - strcat(*test_descriptor_string, - "\n" - "PARTICLE_SPECIES:\n"); - else - strcat(*test_descriptor_string, - "\n" - "SUPPORTED_ATOM/PARTICLES_TYPES:\n"); strcat(*test_descriptor_string, + "\n" +#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSON_MINOR == 5 + "SUPPORTED_ATOM/PARTICLES_TYPES:\n" +#else + "PARTICLE_SPECIES:\n" +#endif "# Symbol/name Type code\n"); int code=1; char* tmp_line = 0; @@ -1199,7 +1191,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string) "NEIGH_PURE_F flag\n" "NEIGH_RVEC_H flag\n" "NEIGH_RVEC_F flag\n"); - + // @@ add code for MI_OPBC_? support ???? if (lmps_support_cluster) { strcat(*test_descriptor_string, @@ -1216,16 +1208,14 @@ void PairKIM::write_descriptor(char** test_descriptor_string) "MODEL_INPUT:\n" "# Name Type Unit Shape\n" "numberOfParticles integer none []\n" - "numberContributingParticles integer none []\n"); - if (kim->is_strictly_between_1_5_and_2_0) - strcat(*test_descriptor_string, - "numberOfSpecies integer none []\n" - "particleSpecies integer none "); - else - strcat(*test_descriptor_string, + "numberContributingParticles integer none []\n" +#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSON_MINOR == 5 "numberParticleTypes integer none []\n" - "particleTypes integer none "); - strcat(*test_descriptor_string, + "particleTypes integer none " +#else + "numberOfSpecies integer none []\n" + "particleSpecies integer none " +#endif "[numberOfParticles]\n" "coordinates double length " "[numberOfParticles,3]\n" @@ -1324,13 +1314,12 @@ void *PairKIM::extract(const char *str, int &dim) // check to make sure that the requested parameter is a valid free parameter - kimerror = kim->get_num_params(pkim, &numParams, &dummyint); + kimerror = pkim->get_num_params(&numParams, &dummyint); kim_error(__LINE__, "get_num_free_params", kimerror); char **freeParamNames = new char*[numParams]; for (int k = 0; k < numParams; k++) { - kimerror = kim->get_free_parameter(pkim, k, - (const char**) &freeParamNames[k]); + kimerror = pkim->get_free_parameter(k, (const char**) &freeParamNames[k]); kim_error(__LINE__, "get_free_parameter", kimerror); if (0 == strcmp(paramName, freeParamNames[k])) { @@ -1348,7 +1337,7 @@ void *PairKIM::extract(const char *str, int &dim) } // get the parameter arry from pkim object - paramData = kim->get_data(pkim, paramName, &kimerror); + paramData = pkim->get_data(paramName, &kimerror); if (kimerror == KIM_STATUS_FAIL) { delete [] speciesIndex, speciesIndex = 0; @@ -1357,7 +1346,7 @@ void *PairKIM::extract(const char *str, int &dim) kim_error(__LINE__,"get_data",kimerror); // get rank and shape of parameter - rank = kim->get_rank(pkim, paramName, &kimerror); + rank = (*pkim).get_rank(paramName, &kimerror); if (kimerror == KIM_STATUS_FAIL) { delete [] speciesIndex, speciesIndex = 0; @@ -1366,7 +1355,7 @@ void *PairKIM::extract(const char *str, int &dim) kim_error(__LINE__,"get_rank",kimerror); int *shape = new int[maxLine]; - dummyint = kim->get_shape(pkim, paramName, shape, &kimerror); + dummyint = (*pkim).get_shape(paramName, shape, &kimerror); if (kimerror == KIM_STATUS_FAIL) { delete [] speciesIndex, speciesIndex = 0; diff --git a/src/KIM/pair_kim.h b/src/KIM/pair_kim.h index 3b12cbe8b0..07947f9d18 100644 --- a/src/KIM/pair_kim.h +++ b/src/KIM/pair_kim.h @@ -31,11 +31,12 @@ PairStyle(kim,PairKIM) #ifndef LMP_PAIR_KIM_H #define LMP_PAIR_KIM_H +// includes from KIM & LAMMPS +class KIM_API_model; #include "pair.h" + namespace LAMMPS_NS { - // Forward declare KIM_LAMMPS_PlugIn - class KIM_LAMMPS_PlugIn; class PairKIM : public Pair { public: @@ -86,8 +87,7 @@ namespace LAMMPS_NS { unit_sys lmps_units; // values set in set_kim_model_has_flags(), called by kim_init() - KIM_LAMMPS_PlugIn * kim; - void * pkim; + KIM_API_model* pkim; bool kim_model_has_energy; bool kim_model_has_forces; bool kim_model_has_particleEnergy; @@ -145,7 +145,6 @@ namespace LAMMPS_NS { void set_kim_model_has_flags(); void write_descriptor(char** test_descriptor_string); // static methods used as callbacks from KIM - static void * (*kim_get_sim_buffer)(void *, int *); static int get_neigh(void** kimmdl, int* mode, int* request, int* atom, int* numnei, int** nei1atom, double** pRij); @@ -163,10 +162,6 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: KIM API library cannot be found - -Self-explanatory. - E: Unrecognized virial argument in pair_style command Only two options are supported: LAMMPSvirial and KIMvirial