This commit is contained in:
Axel Kohlmeyer
2021-07-02 14:17:00 -04:00
parent 34fa0da60e
commit dbeaec4957

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -18,16 +17,17 @@
#ifdef MLIAP_PYTHON
#include <Python.h>
#include "mliap_model_python.h"
#include "error.h"
#include "lmppython.h"
#include "mliap_data.h"
#include "mliap_model_python_couple.h"
#include "pair_mliap.h"
#include "mliap_data.h"
#include "error.h"
#include "utils.h"
#include "lmppython.h"
#include "python_compat.h"
#include "utils.h"
#include <Python.h>
using namespace LAMMPS_NS;
@ -62,9 +62,7 @@ MLIAPModelPython::MLIAPModelPython(LAMMPS* lmp, char* coefffilename) :
// if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well
const char *potentials_path = getenv("LAMMPS_POTENTIALS");
if (potentials_path != NULL) {
PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path));
}
if (potentials_path != NULL) { PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); }
PyGILState_Release(gstate);
if (coefffilename) read_coeffs(coefffilename);
@ -74,7 +72,8 @@ MLIAPModelPython::MLIAPModelPython(LAMMPS* lmp, char* coefffilename) :
/* ---------------------------------------------------------------------- */
MLIAPModelPython::~MLIAPModelPython() {
MLIAPModelPython::~MLIAPModelPython()
{
MLIAPPY_unload_model(this);
}
@ -82,7 +81,6 @@ MLIAPModelPython::~MLIAPModelPython() {
get number of parameters
---------------------------------------------------------------------- */
int MLIAPModelPython::get_nparams()
{
return nparams;
@ -103,8 +101,7 @@ void MLIAPModelPython::read_coeffs(char *fname)
if (loaded) {
this->connect_param_counts();
}
else {
} else {
utils::logmesg(lmp, "Loading python model deferred.\n");
}
}
@ -126,10 +123,8 @@ void MLIAPModelPython::connect_param_counts()
PyGILState_Release(gstate);
model_loaded = 1;
utils::logmesg(lmp, "Loading python model complete.\n");
}
/* ----------------------------------------------------------------------
Calculate model gradients w.r.t descriptors
for each atom beta_i = dE(B_i)/dB_i
@ -137,9 +132,7 @@ void MLIAPModelPython::connect_param_counts()
void MLIAPModelPython::compute_gradients(MLIAPData *data)
{
if (not model_loaded) {
error->all(FLERR,"Model not loaded.");
}
if (not model_loaded) { error->all(FLERR, "Model not loaded."); }
PyGILState_STATE gstate = PyGILState_Ensure();
MLIAPPY_compute_gradients(this, data);
@ -150,7 +143,6 @@ void MLIAPModelPython::compute_gradients(MLIAPData *data)
error->all(FLERR, "Running python model failure.");
}
PyGILState_Release(gstate);
}
/* ----------------------------------------------------------------------
@ -193,7 +185,6 @@ int MLIAPModelPython::get_gamma_nnz(class MLIAPData *)
return 0;
}
double MLIAPModelPython::memory_usage()
{
// todo: get approximate memory usage in coupling code.