IMP  2.2.1
The Integrative Modeling Platform
utility.py
1 import os
2 import IMP.base as base
3 
4 
5 def vararg_callback(option, opt_str, value, parser):
6  """
7  Snippet from Python website to process multiple values for
8  an option with OptionParser
9  """
10 
11  assert value is None
12  value = []
13 
14  def floatable(str):
15  try:
16  float(str)
17  return True
18  except ValueError:
19  return False
20 
21  for arg in parser.rargs:
22  # stop on --foo like options
23  if arg[:2] == "--" and len(arg) > 2:
24  break
25  # stop on -a, but not on -3 or -3.0
26  if arg[:1] == "-" and len(arg) > 1 and not floatable(arg):
27  break
28  value.append(arg)
29 
30  del parser.rargs[:len(value)]
31  setattr(parser.values, option.dest, value)
32 
33  return value
34 
35 
36 def get_experiment_params(fn_params):
37  """
38  Imports the configuration file
39  @param fn_params configuration file
40  @return Experiment Class with all the infomation from the config file
41  """
42 
43  name, ext = os.path.splitext(fn_params)
44  import imp
45  foo = imp.load_source(name, fn_params)
46  exp = foo.Experiment()
47  # convert to absolute paths
48  exp.fn_pdbs = [base.get_relative_path(fn_params, fn) for fn in exp.fn_pdbs]
49  if hasattr(exp, "sampling_positions"):
50  exp.sampling_positions.read = base.get_relative_path(
51  fn_params, exp.sampling_positions.read)
52  if hasattr(exp, "benchmark"):
53  if hasattr(exp.benchmark, "fn_pdb_native"):
54  exp.benchmark.fn_pdb_native = base.get_relative_path(
55  fn_params, exp.benchmark.fn_pdb_native)
56  if hasattr(exp.benchmark, "fn_pdbs_native"):
57  fns = []
58  for fn in exp.benchmark.fn_pdbs_native:
59  fns.append(base.get_relative_path(fn_params, fn))
60  exp.benchmark.fn_pdbs_native = fns
61 
62  if hasattr(exp, "dock_transforms"):
63  for i in range(len(exp.dock_transforms)):
64  exp.dock_transforms[i][2] = base.get_relative_path(
65  fn_params, exp.dock_transforms[i][2])
66  if hasattr(exp, "em2d_restraints"):
67  for i in range(len(exp.em2d_restraints)):
68  exp.em2d_restraints[i][1] = base.get_relative_path(
69  fn_params, exp.em2d_restraints[i][1])
70  return exp
See IMP.base for more information.
Definition: base/Array.h:20