Ejemplo n.º 1
0
 def from_dict(cls, obj):
     assert obj['__id__'] == 'XSweep'
     return_obj = cls(name=None, sample=None, wavelength=None)
     for k, v in obj.iteritems():
         if k in ('_indexer', '_refiner', '_integrater') and v is not None:
             from libtbx.utils import import_python_object
             cls = import_python_object(import_path=".".join(
                 (v['__module__'], v['__name__'])),
                                        error_prefix='',
                                        target_must_be='',
                                        where_str='').object
             v = cls.from_dict(v)
             if k == '_indexer':
                 v.add_indexer_sweep(return_obj)
             elif k == '_refiner':
                 v.add_refiner_sweep(return_obj)
             elif k == '_integrater':
                 v.set_integrater_sweep(return_obj, reset=False)
         if isinstance(v, dict):
             #if v.get('__id__') == 'ExperimentList':
             #from dxtbx.model.experiment_list import ExperimentListFactory
             #v = ExperimentListFactory.from_dict(v)
             if v.get('__id__') == 'imageset':
                 from dxtbx.serialize.imageset import imageset_from_dict
                 v = imageset_from_dict(v, check_format=False)
         setattr(return_obj, k, v)
     if return_obj._indexer is not None and return_obj._integrater is not None:
         return_obj._integrater._intgr_indexer = return_obj._indexer
     if return_obj._integrater is not None and return_obj._refiner is not None:
         return_obj._integrater._intgr_refiner = return_obj._refiner
     if return_obj._indexer is not None and return_obj._refiner is not None:
         return_obj._refiner._refinr_indexers[return_obj.get_epoch(1)] \
           = return_obj._indexer
     return return_obj
Ejemplo n.º 2
0
def get_module_tests (module_name, valgrind=False) :
  dist_path = libtbx.env.dist_path(module_name)
  if (dist_path is None) :
    raise Sorry("'%s' is not a valid CCTBX module." % module_name)
  elif (not os.path.isfile(os.path.join(dist_path, "run_tests.py"))) :
    raise Sorry("%s/run_tests.py does not exist." % module_name)
  tst_list = import_python_object(
    import_path="%s.run_tests.tst_list" % module_name,
    error_prefix="",
    target_must_be="",
    where_str="").object
  assert (isinstance(tst_list, tuple) or isinstance(tst_list, list))
  build_path = libtbx.env.under_build(module_name)
  assert (build_path is not None) and (dist_path is not None)
  commands = []
  co = group_args(
    verbose=False,
    quick=True,
    valgrind=valgrind)
  for cmd in test_utils.iter_tests_cmd(
      co=co,
      build_dir=build_path,
      dist_dir=dist_path,
      tst_list=tst_list) :
    commands.append(cmd)
  return commands
Ejemplo n.º 3
0
 def from_dict(cls, obj):
     import json
     assert obj['__id__'] == 'Scaler'
     return_obj = cls()
     for k, v in obj.iteritems():
         if k == '_scalr_integraters':
             for k_, v_ in v.iteritems():
                 from libtbx.utils import import_python_object
                 integrater_cls = import_python_object(import_path=".".join(
                     (v_['__module__'], v_['__name__'])),
                                                       error_prefix='',
                                                       target_must_be='',
                                                       where_str='').object
                 v[k_] = integrater_cls.from_dict(v_)
         elif k == '_scalr_statistics' and v is not None:
             d = {}
             for k_, v_ in v.iteritems():
                 k_ = tuple(str(s) for s in json.loads(k_))
                 d[k_] = v_
             v = d
         elif k in ('_scalr_resolution_limits'):
             d = {}
             for k_, v_ in v.iteritems():
                 k_ = tuple(str(s) for s in json.loads(k_))
                 d[k_] = v_
             v = d
         setattr(return_obj, k, v)
     return return_obj
Ejemplo n.º 4
0
Archivo: XSweep.py Proyecto: xia2/xia2
 def from_dict(cls, obj):
   assert obj['__id__'] == 'XSweep'
   return_obj = cls(name=None, sample=None, wavelength=None)
   for k, v in obj.iteritems():
     if k in ('_indexer', '_refiner', '_integrater') and v is not None:
       from libtbx.utils import import_python_object
       cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = cls.from_dict(v)
       if k == '_indexer':
         v.add_indexer_sweep(return_obj)
       elif k == '_refiner':
         v.add_refiner_sweep(return_obj)
       elif k == '_integrater':
         v.set_integrater_sweep(return_obj, reset=False)
     if isinstance(v, dict):
       #if v.get('__id__') == 'ExperimentList':
         #from dxtbx.model.experiment.experiment_list import ExperimentListFactory
         #v = ExperimentListFactory.from_dict(v)
       if v.get('__id__') == 'imageset':
         from dxtbx.serialize.imageset import imageset_from_dict
         v = imageset_from_dict(v, check_format=False)
     setattr(return_obj, k, v)
   if return_obj._indexer is not None and return_obj._integrater is not None:
     return_obj._integrater._intgr_indexer = return_obj._indexer
   if return_obj._integrater is not None and return_obj._refiner is not None:
     return_obj._integrater._intgr_refiner = return_obj._refiner
   if return_obj._indexer is not None and return_obj._refiner is not None:
     return_obj._refiner._refinr_indexers[return_obj.get_epoch(1)] \
       = return_obj._indexer
   return return_obj
Ejemplo n.º 5
0
    def from_dict(cls, obj):
        assert obj["__id__"] == "Integrater"
        return_obj = cls()
        for k, v in obj.iteritems():
            if k in ("_intgr_indexer", "_intgr_refiner") and v is not None:
                from libtbx.utils import import_python_object

                cls = import_python_object(
                    import_path=".".join((v["__module__"], v["__name__"])),
                    error_prefix="",
                    target_must_be="",
                    where_str="",
                ).object
                v = cls.from_dict(v)
            if isinstance(v, dict):
                if v.get("__id__") == "ExperimentList":
                    from dxtbx.model.experiment_list import ExperimentListFactory

                    v = ExperimentListFactory.from_dict(v)
                elif v.get("__id__") == "imageset":
                    from dxtbx.serialize.imageset import imageset_from_dict

                    v = imageset_from_dict(v, check_format=False)
            setattr(return_obj, k, v)
        return return_obj
Ejemplo n.º 6
0
def get_module_tests (module_name, valgrind=False) :
  dist_path = libtbx.env.dist_path(module_name)
  if (dist_path is None) :
    raise Sorry("'%s' is not a valid CCTBX module." % module_name)
  # XXX don't check for file name, because import conventions differ among
  # derived modules - dist_path can be either the sys.path entry or the actual
  # module contents.  If the file is missing the import below will fail, which
  # is okay for testing purposes.
  tst_list = import_python_object(
    import_path="%s.run_tests.tst_list" % module_name,
    error_prefix="",
    target_must_be="",
    where_str="").object
  assert (isinstance(tst_list, tuple) or isinstance(tst_list, list))
  build_path = libtbx.env.under_build(module_name)
  assert (build_path is not None) and (dist_path is not None)
  commands = []
  co = group_args(
    verbose=False,
    quick=True,
    valgrind=valgrind)
  for cmd in test_utils.iter_tests_cmd(
      co=co,
      build_dir=build_path,
      dist_dir=dist_path,
      tst_list=tst_list) :
    commands.append(cmd)
  return commands
Ejemplo n.º 7
0
Archivo: Scaler.py Proyecto: hainm/xia2
 def from_dict(cls, obj):
   import json
   assert obj['__id__'] == 'Scaler'
   return_obj = cls()
   for k, v in obj.iteritems():
     if k == '_scalr_integraters':
       for k_, v_ in v.iteritems():
         from libtbx.utils import import_python_object
         integrater_cls = import_python_object(
           import_path=".".join((v_['__module__'], v_['__name__'])),
           error_prefix='', target_must_be='', where_str='').object
         v[k_] = integrater_cls.from_dict(v_)
     elif k == '_scalr_statistics' and v is not None:
       d = {}
       for k_, v_ in v.iteritems():
         k_ = tuple(str(s) for s in json.loads(k_))
         d[k_] = v_
       v = d
     elif k == '_scalr_resolution_limits':
       d = {}
       for k_, v_ in v.iteritems():
         k_ = tuple(str(s) for s in json.loads(k_))
         d[k_] = v_
       v = d
     setattr(return_obj, k, v)
   return return_obj
Ejemplo n.º 8
0
 def from_dict(cls, obj):
     from xia2.Schema.XWavelength import XWavelength
     from xia2.Schema.XSample import XSample
     assert obj['__id__'] == 'XCrystal'
     return_obj = cls(name=None, project=None)
     for k, v in obj.iteritems():
         if k == '_scaler' and v is not None:
             from libtbx.utils import import_python_object
             cls = import_python_object(import_path=".".join(
                 (v['__module__'], v['__name__'])),
                                        error_prefix='',
                                        target_must_be='',
                                        where_str='').object
             v = cls.from_dict(v)
             v._scalr_xcrystal = return_obj
         elif k == '_wavelengths':
             v_ = {}
             for wname, wdict in v.iteritems():
                 wav = XWavelength.from_dict(wdict)
                 wav._crystal = return_obj
                 v_[wname] = wav
             v = v_
         elif k == '_samples':
             v_ = {}
             for sname, sdict in v.iteritems():
                 sample = XSample.from_dict(sdict)
                 sample._crystal = return_obj
                 v_[sname] = sample
             v = v_
         elif k == '_aa_sequence' and v is not None:
             v = _aa_sequence.from_dict(v)
         elif k == '_ha_info' and v is not None:
             for k_, v_ in v.iteritems():
                 v[k_] = _ha_info.from_dict(v_)
         setattr(return_obj, k, v)
     sweep_dict = {}
     for sample in return_obj._samples.values():
         for i, sname in enumerate(sample._sweeps):
             found_sweep = False
             for wav in return_obj._wavelengths.values():
                 if found_sweep: break
                 for sweep in wav._sweeps:
                     if sweep.get_name() == sname:
                         sample._sweeps[i] = sweep
                         sweep._sample = sample
                         found_sweep = True
                         break
         for s in sample._sweeps:
             assert not isinstance(s, basestring)
     if return_obj._scaler is not None:
         for intgr in return_obj._get_integraters():
             return_obj._scaler._scalr_integraters[intgr.get_integrater_epoch()] \
               = intgr
             if (hasattr(return_obj._scaler, '_sweep_handler')
                     and return_obj._scaler._sweep_handler is not None):
                 if intgr.get_integrater_epoch() in \
                    return_obj._scaler._sweep_handler._sweep_information:
                     return_obj._scaler._sweep_handler._sweep_information[
                         intgr.get_integrater_epoch()]._integrater = intgr
     return return_obj
Ejemplo n.º 9
0
 def from_dict(cls, obj):
   import json
   assert obj['__id__'] == 'Refiner'
   return_obj = cls()
   for k, v in obj.iteritems():
     if k == '_refinr_indexers':
       v_new = {}
       for k_, v_ in v.iteritems():
         from libtbx.utils import import_python_object
         integrater_cls = import_python_object(
           import_path=".".join((v_['__module__'], v_['__name__'])),
           error_prefix='', target_must_be='', where_str='').object
         v_new[float(k_)] = integrater_cls.from_dict(v_)
       v = v_new
     elif k == '_refinr_payload':
       v_new = {}
       for k_, v_ in v.iteritems():
         try:
           v_new[float(k_)] = v_
         except ValueError, e:
           v_new[k_] = v_
       v = v_new
     if isinstance(v, dict):
       if v.get('__id__', None) == 'ExperimentList':
         from dxtbx.model.experiment.experiment_list import ExperimentListFactory
         v = ExperimentListFactory.from_dict(v, check_format=False)
     setattr(return_obj, k, v)
Ejemplo n.º 10
0
 def from_dict(cls, obj):
     import json
     assert obj['__id__'] == 'Refiner'
     return_obj = cls()
     for k, v in obj.iteritems():
         if k == '_refinr_indexers':
             v_new = {}
             for k_, v_ in v.iteritems():
                 from libtbx.utils import import_python_object
                 integrater_cls = import_python_object(import_path=".".join(
                     (v_['__module__'], v_['__name__'])),
                                                       error_prefix='',
                                                       target_must_be='',
                                                       where_str='').object
                 v_new[float(k_)] = integrater_cls.from_dict(v_)
             v = v_new
         elif k == '_refinr_payload':
             v_new = {}
             for k_, v_ in v.iteritems():
                 try:
                     v_new[float(k_)] = v_
                 except ValueError:
                     v_new[k_] = v_
             v = v_new
         if isinstance(v, dict):
             if v.get('__id__') == 'ExperimentList':
                 from dxtbx.model.experiment_list import ExperimentListFactory
                 v = ExperimentListFactory.from_dict(v, check_format=False)
         setattr(return_obj, k, v)
     return return_obj
Ejemplo n.º 11
0
def get_test_list(module_name,
                  test_type='tst_list',
                  valgrind=False,
                  python_keyword_text=None):
    dist_path = libtbx.env.dist_path(module_name)
    if dist_path is None:
        raise Sorry("'%s' is not a valid CCTBX module." % module_name)
    # XXX don't check for file name, because import conventions differ among
    # derived modules - dist_path can be either the sys.path entry or the actual
    # module contents.  If the file is missing the import below will fail, which
    # is okay for testing purposes.
    try:
        tst_list = list(
            import_python_object(import_path="%s.run_tests.%s" %
                                 (module_name, test_type),
                                 error_prefix="",
                                 target_must_be="",
                                 where_str="").object)
    except AttributeError:
        tst_list = list()
    build_path = libtbx.env.under_build(module_name)
    assert (build_path is not None) and (dist_path is not None)
    commands = []
    co = group_args(verbose=False,
                    quick=True,
                    valgrind=valgrind,
                    python_keyword_text=python_keyword_text)
    for cmd in test_utils.iter_tests_cmd(co=co,
                                         build_dir=build_path,
                                         dist_dir=dist_path,
                                         tst_list=tst_list):
        commands.append(cmd)
    return commands
Ejemplo n.º 12
0
 def from_dict(cls, obj):
   from xia2.Schema.XWavelength import XWavelength
   from xia2.Schema.XSample import XSample
   assert obj['__id__'] == 'XCrystal'
   return_obj = cls(name=None, project=None)
   for k, v in obj.iteritems():
     if k == '_scaler' and v is not None:
       from libtbx.utils import import_python_object
       cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = cls.from_dict(v)
       v._scalr_xcrystal = return_obj
     elif k == '_wavelengths':
       v_ = {}
       for wname, wdict in v.iteritems():
         wav = XWavelength.from_dict(wdict)
         wav._crystal = return_obj
         v_[wname] = wav
       v = v_
     elif k == '_samples':
       v_ = {}
       for sname, sdict in v.iteritems():
         sample = XSample.from_dict(sdict)
         sample._crystal = return_obj
         v_[sname] = sample
       v = v_
     elif k == '_aa_sequence' and v is not None:
       v = _aa_sequence.from_dict(v)
     elif k == '_ha_info' and v is not None:
       for k_, v_ in v.iteritems():
         v[k_] = _ha_info.from_dict(v_)
     setattr(return_obj, k, v)
   sweep_dict = {}
   for sample in return_obj._samples.values():
     for i, sname in enumerate(sample._sweeps):
       found_sweep = False
       for wav in return_obj._wavelengths.values():
         if found_sweep: break
         for sweep in wav._sweeps:
           if sweep.get_name() == sname:
             sample._sweeps[i] = sweep
             sweep._sample = sample
             found_sweep = True
             break
     for s in sample._sweeps: assert not isinstance(s, basestring)
   if return_obj._scaler is not None:
     for intgr in return_obj._get_integraters():
       return_obj._scaler._scalr_integraters[intgr.get_integrater_epoch()] \
         = intgr
       if (hasattr(return_obj._scaler, '_sweep_handler') and
           return_obj._scaler._sweep_handler is not None):
         if intgr.get_integrater_epoch() in \
            return_obj._scaler._sweep_handler._sweep_information:
           return_obj._scaler._sweep_handler._sweep_information[
             intgr.get_integrater_epoch()]._integrater = intgr
   return return_obj
Ejemplo n.º 13
0
def get_module_tests(module_name, valgrind=False, slow_tests=False):
    dist_path = libtbx.env.dist_path(module_name)
    if dist_path is None:
        raise Sorry("'%s' is not a valid CCTBX module." % module_name)
    # XXX don't check for file name, because import conventions differ among
    # derived modules - dist_path can be either the sys.path entry or the actual
    # module contents.  If the file is missing the import below will fail, which
    # is okay for testing purposes.
    tst_list = import_python_object(import_path="%s.run_tests.tst_list" %
                                    module_name,
                                    error_prefix="",
                                    target_must_be="",
                                    where_str="").object
    assert (isinstance(tst_list, tuple) or isinstance(tst_list, list))
    if slow_tests:
        try:
            tst_list_slow = import_python_object(
                import_path="%s.run_tests.tst_list_slow" % module_name,
                error_prefix="",
                target_must_be="",
                where_str="").object
        except AttributeError:
            pass
        else:
            assert (isinstance(tst_list_slow, tuple)
                    or isinstance(tst_list_slow, list))
            if isinstance(tst_list, tuple):
                tst_list = list(tst_list)
                tst.list.extend(tst_list_slow)
                tst_list = tuple(tst_list)
            else:
                tst_list.extend(tst_list_slow)
    build_path = libtbx.env.under_build(module_name)
    assert (build_path is not None) and (dist_path is not None)
    commands = []
    co = group_args(verbose=False, quick=True, valgrind=valgrind)
    for cmd in test_utils.iter_tests_cmd(co=co,
                                         build_dir=build_path,
                                         dist_dir=dist_path,
                                         tst_list=tst_list):
        commands.append(cmd)
    return commands
Ejemplo n.º 14
0
 def load_from_cache_if_possible(self, phil_path):
     import libtbx.load_env
     full_path = os.path.join(abs(libtbx.env.build_path), "phil_cache",
                              "%s.phil" % phil_path)
     if (os.path.exists(full_path)):
         return parse(file_name=full_path)
     else:
         return import_python_object(import_path=phil_path,
                                     error_prefix="",
                                     target_must_be="",
                                     where_str="").object
Ejemplo n.º 15
0
 def from_dict(cls, obj):
   assert obj['__id__'] == 'SweepInformation'
   return_obj = cls.__new__(cls)
   for k, v in obj.iteritems():
     if k == '_integrater':
       from libtbx.utils import import_python_object
       integrater_cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = integrater_cls.from_dict(v)
     setattr(return_obj, k, v)
   return return_obj
Ejemplo n.º 16
0
 def from_dict(cls, obj):
   assert obj['__id__'] == 'SweepInformation'
   return_obj = cls.__new__(cls)
   for k, v in obj.iteritems():
     if k == '_integrater':
       from libtbx.utils import import_python_object
       integrater_cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = integrater_cls.from_dict(v)
     setattr(return_obj, k, v)
   return return_obj
Ejemplo n.º 17
0
def load_from_cache_if_possible (phil_path) :
  import libtbx.load_env
  full_path = os.path.join(abs(libtbx.env.build_path), "phil_cache",
    "%s.phil" % phil_path)
  if (os.path.exists(full_path)) :
    return parse(file_name=full_path)
  else :
    return import_python_object(
      import_path=phil_path,
      error_prefix="",
      target_must_be="",
      where_str="").object
Ejemplo n.º 18
0
Archivo: XSample.py Proyecto: xia2/xia2
 def from_dict(cls, obj):
   assert obj['__id__'] == 'XSample'
   return_obj = cls(name=None, crystal=None)
   for k, v in obj.iteritems():
     if k == '_sweeps':
       v = [s_dict['_name'] for s_dict in v]
     elif k == '_multi_indexer' and v is not None:
       from libtbx.utils import import_python_object
       cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = cls.from_dict(v)
     setattr(return_obj, k, v)
   return return_obj
Ejemplo n.º 19
0
 def from_dict(cls, obj):
   return_obj = super(XDSScalerA, cls).from_dict(obj)
   for i in return_obj._sweep_information.keys():
     d = return_obj._sweep_information[i]['integrater']
     from libtbx.utils import import_python_object
     integrater_cls = import_python_object(
       import_path=".".join((d['__module__'], d['__name__'])),
       error_prefix='', target_must_be='', where_str='').object
     return_obj._sweep_information[i]['integrater'] \
       = integrater_cls.from_dict(d)
     # expects epoch as number (or int?)
     if isinstance(i, basestring):
       return_obj._sweep_information[float(i)] = return_obj._sweep_information[i]
       del return_obj._sweep_information[i]
   return return_obj
Ejemplo n.º 20
0
 def from_dict(cls, obj):
     assert obj['__id__'] == 'XSample'
     return_obj = cls(name=None, crystal=None)
     for k, v in obj.iteritems():
         if k == '_sweeps':
             v = [s_dict['_name'] for s_dict in v]
         elif k == '_multi_indexer' and v is not None:
             from libtbx.utils import import_python_object
             cls = import_python_object(import_path=".".join(
                 (v['__module__'], v['__name__'])),
                                        error_prefix='',
                                        target_must_be='',
                                        where_str='').object
             v = cls.from_dict(v)
         setattr(return_obj, k, v)
     return return_obj
Ejemplo n.º 21
0
    def from_dict(cls, obj):
        assert obj["__id__"] == "SweepInformation"
        return_obj = cls.__new__(cls)
        for k, v in obj.items():
            if k == "_integrater":
                from libtbx.utils import import_python_object

                integrater_cls = import_python_object(
                    import_path=".".join((v["__module__"], v["__name__"])),
                    error_prefix="",
                    target_must_be="",
                    where_str="",
                ).object
                v = integrater_cls.from_dict(v)
            setattr(return_obj, k, v)
        return return_obj
Ejemplo n.º 22
0
    def from_dict(cls, obj):
        assert obj["__id__"] == "XSample"
        return_obj = cls(name=None, crystal=None)
        for k, v in obj.items():
            if k == "_sweeps":
                v = [s_dict["_name"] for s_dict in v]
            elif k in ["multi_indexer", "multi_refiner"] and v is not None:
                from libtbx.utils import import_python_object

                cls = import_python_object(
                    import_path=".".join((v["__module__"], v["__name__"])),
                    error_prefix="",
                    target_must_be="",
                    where_str="",
                ).object
                v = cls.from_dict(v)
            setattr(return_obj, k, v)
        return return_obj
Ejemplo n.º 23
0
 def from_dict(cls, obj):
   assert obj['__id__'] == 'Integrater'
   return_obj = cls()
   for k, v in obj.iteritems():
     if k in ('_intgr_indexer', '_intgr_refiner') and v is not None:
       from libtbx.utils import import_python_object
       cls = import_python_object(
         import_path=".".join((v['__module__'], v['__name__'])),
         error_prefix='', target_must_be='', where_str='').object
       v = cls.from_dict(v)
     if isinstance(v, dict):
       if v.get('__id__') == 'ExperimentList':
         from dxtbx.model.experiment.experiment_list import ExperimentListFactory
         v = ExperimentListFactory.from_dict(v)
       elif v.get('__id__') == 'imageset':
         from dxtbx.serialize.imageset import imageset_from_dict
         v = imageset_from_dict(v, check_format=False)
     setattr(return_obj, k, v)
   return return_obj
Ejemplo n.º 24
0
def run(args):
    phil_path = args[-1]
    phil_inp = import_python_object(import_path=phil_path,
                                    error_prefix="",
                                    target_must_be="",
                                    where_str="").object
    if (isinstance(phil_inp, str)):
        phil_object = phil.parse(phil_inp)
    elif (hasattr(phil_inp, "__call__")):
        phil_object = phil_inp()
    else:
        assert isinstance(phil_inp, phil.scope)
        phil_object = phil_inp
    cache_dir = os.path.join(libtbx.env.build_path, "phil_cache")
    if (not os.path.isdir(cache_dir)):
        os.mkdir(cache_dir)
    full_path = os.path.join(cache_dir, phil_path)
    f = open("%s.phil" % full_path, "w")
    phil_object.show(out=f, attributes_level=3)
    f.close()
    print("Wrote master parameters to %s.phil" % full_path)
Ejemplo n.º 25
0
def run (args) :
  phil_path = args[-1]
  phil_inp = import_python_object(
    import_path=phil_path,
    error_prefix="",
    target_must_be="",
    where_str="").object
  if (isinstance(phil_inp, str)) :
    phil_object = phil.parse(phil_inp)
  elif (hasattr(phil_inp, "__call__")) :
    phil_object = phil_inp()
  else :
    assert isinstance(phil_inp, phil.scope)
    phil_object = phil_inp
  cache_dir = os.path.join(libtbx.env.build_path, "phil_cache")
  if (not os.path.isdir(cache_dir)) :
    os.mkdir(cache_dir)
  full_path = os.path.join(cache_dir, phil_path)
  f = open("%s.phil" % full_path, "w")
  phil_object.show(out=f, attributes_level=3)
  f.close()
  print "Wrote master parameters to %s.phil" % full_path
Ejemplo n.º 26
0
def get_module_tests(module_name, valgrind=False):
    dist_path = libtbx.env.dist_path(module_name)
    if (dist_path is None):
        raise Sorry("'%s' is not a valid CCTBX module." % module_name)
    elif (not os.path.isfile(os.path.join(dist_path, "run_tests.py"))):
        raise Sorry("%s/run_tests.py does not exist." % module_name)
    tst_list = import_python_object(import_path="%s.run_tests.tst_list" %
                                    module_name,
                                    error_prefix="",
                                    target_must_be="",
                                    where_str="").object
    assert (isinstance(tst_list, tuple) or isinstance(tst_list, list))
    build_path = libtbx.env.under_build(module_name)
    assert (build_path is not None) and (dist_path is not None)
    commands = []
    co = group_args(verbose=False, quick=True, valgrind=valgrind)
    for cmd in test_utils.iter_tests_cmd(co=co,
                                         build_dir=build_path,
                                         dist_dir=dist_path,
                                         tst_list=tst_list):
        commands.append(cmd)
    return commands
Ejemplo n.º 27
0
    def from_dict(cls, obj):
        assert obj["__id__"] == "Scaler"
        base_path = obj.get("_base_path")
        if base_path:
            base_path = pathlib.Path(base_path)
        else:
            base_path = None
        return_obj = cls(base_path=base_path)
        for k, v in obj.items():
            if k == "_scalr_integraters":
                for k_, v_ in v.items():
                    from libtbx.utils import import_python_object

                    integrater_cls = import_python_object(
                        import_path=".".join(
                            (v_["__module__"], v_["__name__"])),
                        error_prefix="",
                        target_must_be="",
                        where_str="",
                    ).object
                    v[k_] = integrater_cls.from_dict(v_)
            elif k == "_scalr_statistics" and v is not None:
                d = {}
                for k_, v_ in v.items():
                    k_ = tuple(str(s) for s in json.loads(k_))
                    d[k_] = v_
                v = d
            elif k == "_scalr_resolution_limits":
                d = {}
                for k_, v_ in v.items():
                    k_ = tuple(str(s) for s in json.loads(k_))
                    d[k_] = v_
                v = d
            elif k == "_base_path":
                continue
            setattr(return_obj, k, v)
        return return_obj