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