diff --git a/python/lammps.py b/python/lammps.py index 85fbd1217b..6f88ee86a7 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -505,7 +505,7 @@ class lammps(object): self.FIX_EXTERNAL_CALLBACK_FUNC = CFUNCTYPE(None, py_object, self.c_bigint, c_int, POINTER(self.c_tagint), POINTER(POINTER(c_double)), POINTER(POINTER(c_double))) self.lib.lammps_set_fix_external_callback.argtypes = [c_void_p, c_char_p, self.FIX_EXTERNAL_CALLBACK_FUNC, py_object] self.lib.lammps_set_fix_external_callback.restype = None - + self.mliappy = MLIAPPY(self) # ------------------------------------------------------------------------- @@ -2931,12 +2931,12 @@ class MLIAPPY(): def __init__(self,lammps): self._module = None self.lammps = lammps - + @property def module(self): if self._module: return self._module - + try: # Begin Importlib magic to find the embedded python module # This is needed because the filename for liblammps does not @@ -2959,10 +2959,10 @@ class MLIAPPY(): # End Importlib magic to find the embedded python module except: raise ImportError("Could not load MLIAPPY coupling module") - + def activate(self): self.module - + def load_model(self,model): self.module.load_from_python(model) - + diff --git a/src/MLIAP/mliap_data.cpp b/src/MLIAP/mliap_data.cpp index 2559f5330d..c310f0efc7 100644 --- a/src/MLIAP/mliap_data.cpp +++ b/src/MLIAP/mliap_data.cpp @@ -29,7 +29,7 @@ MLIAPData::MLIAPData(LAMMPS *lmp, int gradgradflag_in, int *map_in, class MLIAPModel* model_in, class MLIAPDescriptor* descriptor_in, class PairMLIAP* pairmliap_in) : - Pointers(lmp), gradforce(nullptr), betas(nullptr), + Pointers(lmp), gradforce(nullptr), betas(nullptr), descriptors(nullptr), eatoms(nullptr), gamma(nullptr), gamma_row_index(nullptr), gamma_col_index(nullptr), egradient(nullptr), numneighs(nullptr), iatoms(nullptr), ielems(nullptr), jatoms(nullptr), jelems(nullptr), diff --git a/src/MLIAP/mliap_model_python.cpp b/src/MLIAP/mliap_model_python.cpp index 2aa588ff32..e47356390f 100644 --- a/src/MLIAP/mliap_model_python.cpp +++ b/src/MLIAP/mliap_model_python.cpp @@ -15,6 +15,8 @@ Contributing author: Nicholas Lubbers (LANL) ------------------------------------------------------------------------- */ +#ifdef MLIAP_PYTHON + #include #include "mliap_model_python.h" #include "mliap_model_python_couple.h" @@ -43,9 +45,9 @@ MLIAPModelPython::MLIAPModelPython(LAMMPS* lmp, char* coefffilename) : PyGILState_Release(gstate); error->all(FLERR,"Could not initialize embedded Python"); } - + PyObject* coupling_module = PyImport_ImportModule("mliap_model_python_couple"); - + if (!coupling_module) { PyErr_Print(); PyErr_Clear(); @@ -97,7 +99,7 @@ void MLIAPModelPython::read_coeffs(char * fname) error->all(FLERR,"Loading python model failure."); } PyGILState_Release(gstate); - + if (loaded) { this->connect_param_counts(); } @@ -113,7 +115,7 @@ void MLIAPModelPython::connect_param_counts() nelements = MLIAPPY_nelements(this); nparams = MLIAPPY_nparams(this); ndescriptors = MLIAPPY_ndescriptors(this); - + if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); @@ -137,7 +139,7 @@ void MLIAPModelPython::compute_gradients(MLIAPData* data) if (not model_loaded) { error->all(FLERR,"Model not loaded."); } - + PyGILState_STATE gstate = PyGILState_Ensure(); MLIAPPY_compute_gradients(this, data); if (PyErr_Occurred()) { @@ -196,3 +198,5 @@ double MLIAPModelPython::memory_usage() // todo: get approximate memory usage in coupling code. return 0; } + +#endif diff --git a/src/MLIAP/mliap_model_python.h b/src/MLIAP/mliap_model_python.h index 0ef87f86fd..57110f36e2 100644 --- a/src/MLIAP/mliap_model_python.h +++ b/src/MLIAP/mliap_model_python.h @@ -38,7 +38,7 @@ protected: virtual void read_coeffs(char *); private: - + }; } diff --git a/src/MLIAP/mliap_model_python_couple.pyx b/src/MLIAP/mliap_model_python_couple.pyx index ad95ea2c48..49bdd47412 100644 --- a/src/MLIAP/mliap_model_python_couple.pyx +++ b/src/MLIAP/mliap_model_python_couple.pyx @@ -1,12 +1,5 @@ # cython: language_level=3 # distutils: language = c++ -# distutils: define_macros="LMP_MLIAPPY" -# distutils: extra_compile_args= -stdlib=libc++ -std=c++11 -# distutils: include_dirs = ../STUBS .. ../MLIAP -# distutils: extra_link_args= -stdlib=libc++ -# Note: only the language_level and language commands are needed, the rest pertain -# to building mliap_model_python_couple as a standalone python extension, which -# is experimental. cimport cython @@ -88,11 +81,11 @@ def load_from_python(model): LOADED_MODELS[c_id]=model lmp_model = c_id lmp_model.connect_param_counts() - + cdef public void MLIAPPY_unload_model(MLIAPModelPython * c_model) with gil: del LOADED_MODELS[c_id(c_model)] - + cdef public int MLIAPPY_nparams(MLIAPModelPython * c_model) with gil: return int(retrieve(c_model).n_params) @@ -107,7 +100,7 @@ cdef public void MLIAPPY_compute_gradients(MLIAPModelPython * c_model, MLIAPData n_d = data.ndescriptors n_a = data.natoms - + # Make numpy arrays from pointers beta_np = np.asarray( &data.betas[0][0]) desc_np = np.asarray( &data.descriptors[0][0]) @@ -116,7 +109,7 @@ cdef public void MLIAPPY_compute_gradients(MLIAPModelPython * c_model, MLIAPData # Invoke python model on numpy arrays. model(elem_np,desc_np,beta_np,en_np) - + # Get the total energy from the atom energy. energy = np.sum(en_np) data.energy = energy diff --git a/src/MLIAP/pair_mliap.cpp b/src/MLIAP/pair_mliap.cpp index 6f75ef542e..0c6f3903f6 100644 --- a/src/MLIAP/pair_mliap.cpp +++ b/src/MLIAP/pair_mliap.cpp @@ -73,17 +73,17 @@ PairMLIAP::~PairMLIAP() void PairMLIAP::compute(int eflag, int vflag) { - + // consistency checks if (data->ndescriptors != model->ndescriptors) { error->all(FLERR,"Incompatible model and descriptor descriptor count"); }; - + if (data->nelements != model->nelements) { error->all(FLERR,"Incompatible model and descriptor element count"); }; - + ev_init(eflag,vflag); data->generate_neighdata(list, eflag, vflag); @@ -249,7 +249,7 @@ void PairMLIAP::coeff(int narg, char **arg) void PairMLIAP::e_tally(MLIAPData* data) { if (eflag_global) eng_vdwl += data->energy; - if (eflag_atom) + if (eflag_atom) for (int ii = 0; ii < data->natoms; ii++) { const int i = data->iatoms[ii]; eatom[i] += data->eatoms[ii];