1 """@namespace IMP.EMageFit.utility
8 import importlib.machinery
14 Snippet from Python website to process multiple values for
15 an option with OptionParser
28 for arg
in parser.rargs:
30 if arg[:2] ==
"--" and len(arg) > 2:
33 if arg[:1] ==
"-" and len(arg) > 1
and not floatable(arg):
37 del parser.rargs[:len(value)]
38 setattr(parser.values, option.dest, value)
45 Imports the configuration file
46 @param fn_params configuration file
47 @return Experiment Class with all the information from the config file
49 name, ext = os.path.splitext(fn_params)
50 foo = _import_from_path(name, fn_params)
51 exp = foo.Experiment()
54 if hasattr(exp,
"sampling_positions"):
56 fn_params, exp.sampling_positions.read)
57 if hasattr(exp,
"benchmark"):
58 if hasattr(exp.benchmark,
"fn_pdb_native"):
60 fn_params, exp.benchmark.fn_pdb_native)
61 if hasattr(exp.benchmark,
"fn_pdbs_native"):
63 for fn
in exp.benchmark.fn_pdbs_native:
65 exp.benchmark.fn_pdbs_native = fns
67 if hasattr(exp,
"dock_transforms"):
68 for i
in range(len(exp.dock_transforms)):
70 fn_params, exp.dock_transforms[i][2])
71 if hasattr(exp,
"em2d_restraints"):
72 for i
in range(len(exp.em2d_restraints)):
74 fn_params, exp.em2d_restraints[i][1])
78 def _import_from_path(module_name, file_path):
79 """Import a Python source file directly as a module"""
80 loader = importlib.machinery.SourceFileLoader(module_name, file_path)
81 spec = importlib.util.spec_from_loader(module_name, loader)
82 module = importlib.util.module_from_spec(spec)
83 sys.modules[module_name] = module
84 spec.loader.exec_module(module)
def vararg_callback
Snippet from Python website to process multiple values for an option with OptionParser.
def get_experiment_params
Imports the configuration file.
std::string get_relative_path(std::string base, std::string relative)
Return a path to a file relative to another file.