From 53b94ac94d5cfdbd39cd8ab8c7c449b723794bb4 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 5 Aug 2021 18:10:19 -0400 Subject: [PATCH] Allow fix python/move to load class from __main__ --- src/PYTHON/fix_python_move.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PYTHON/fix_python_move.cpp b/src/PYTHON/fix_python_move.cpp index 72b61a834c..eef2c4083f 100644 --- a/src/PYTHON/fix_python_move.cpp +++ b/src/PYTHON/fix_python_move.cpp @@ -51,15 +51,15 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : // create integrator instance std::string full_cls_name = arg[3]; + std::string module_name = "__main__"; + std::string cls_name = full_cls_name; size_t lastpos = full_cls_name.rfind("."); - if (lastpos == std::string::npos) { - error->all(FLERR,"Fix python/integrate requires fully qualified class name"); + if (lastpos != std::string::npos) { + module_name = full_cls_name.substr(0, lastpos); + cls_name = full_cls_name.substr(lastpos+1); } - std::string module_name = full_cls_name.substr(0, lastpos); - std::string cls_name = full_cls_name.substr(lastpos+1); - PyObject *pModule = PyImport_ImportModule(module_name.c_str()); if (!pModule) { PyUtils::Print_Errors(); @@ -72,7 +72,7 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : PyObject *py_move_type = PyObject_GetAttrString(pModule, cls_name.c_str()); if (!py_move_type) { PyUtils::Print_Errors(); - error->all(FLERR,"Could not find integrator class in module'"); + error->all(FLERR,"Could not find integrator class {} in module {}", cls_name, module_name); } PyObject *ptr = PY_VOID_POINTER(lmp);