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
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user