Allow fix python/move to load class from __main__
This commit is contained in:
@ -51,15 +51,15 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
// create integrator instance
|
// create integrator instance
|
||||||
std::string full_cls_name = arg[3];
|
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(".");
|
size_t lastpos = full_cls_name.rfind(".");
|
||||||
|
|
||||||
if (lastpos == std::string::npos) {
|
if (lastpos != std::string::npos) {
|
||||||
error->all(FLERR,"Fix python/integrate requires fully qualified class name");
|
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());
|
PyObject *pModule = PyImport_ImportModule(module_name.c_str());
|
||||||
if (!pModule) {
|
if (!pModule) {
|
||||||
PyUtils::Print_Errors();
|
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());
|
PyObject *py_move_type = PyObject_GetAttrString(pModule, cls_name.c_str());
|
||||||
if (!py_move_type) {
|
if (!py_move_type) {
|
||||||
PyUtils::Print_Errors();
|
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);
|
PyObject *ptr = PY_VOID_POINTER(lmp);
|
||||||
|
|||||||
Reference in New Issue
Block a user