예제 #1
0
def run (out=None, omit_unicode_experiment=False):
  if (out is None): out = sys.stdout
  out.write(boost.python.platform_info)
  tag = libtbx.env.under_dist("boost", "TAG")
  if (op.isfile(tag)):
    tag = open(tag).read().strip()
  else:
    tag = None
  print >> out, "boost/TAG:", tag
  print >> out, "os.name:", os.name
  print >> out, "sys.platform:", sys.platform
  print >> out, "sys.byteorder:", sys.byteorder
  print >> out, "platform.platform():", platform.platform()
  print >> out, "platform.architecture():", platform.architecture()
  for attr in ["division_by_zero", "invalid", "overflow"]:
    attr = "floating_point_exceptions.%s_trapped" % attr
    print >> out, "%s:" % attr, eval("boost.python.%s" % attr)
  print >> out, "number of processors:", introspection.number_of_processors(
    return_value_if_unknown="unknown")
  introspection.machine_memory_info().show(out=out)
  try: import thread
  except ImportError: print >> out, "import thread: NO"
  else: print >> out, "import thread: OK"
  print "Division operator semantics: %s division" % (div_probe() / 0)
  c = getattr(boost.python.ext, "str_or_unicode_as_char_list", None)
  if (c is not None and not omit_unicode_experiment):
    print >> out, '"hello" =', c("hello")
    print >> out, 'u"hello" =', c(u"hello")
    e = u"\u00C5".encode("utf-8", "strict")
    print >> out, 'u"\u00C5" =', c(u"\u00C5"), 'as utf-8 =', c(e)
    print >> out, "LATIN CAPITAL LETTER A WITH RING ABOVE =", e
  from libtbx.utils import format_cpu_times
  print format_cpu_times()
예제 #2
0
def run(args):
  from dials.util.options import OptionParser
  import libtbx.load_env

  usage = "%s [options] find_spots.json" %(
    libtbx.env.dispatcher_name)

  parser = OptionParser(
    usage=usage,
    phil=phil_scope,
    epilog=help_message)

  filenames = [arg for arg in args if os.path.isfile(arg)]
  args = [arg for arg in args if not arg in filenames]

  params, options, args = parser.parse_args(
    show_diff_phil=True, return_unhandled=True)
  if params.nproc is libtbx.Auto:
    from libtbx.introspection import number_of_processors
    params.nproc = number_of_processors(return_value_if_unknown=-1)
  print 'nproc: %i' %params.nproc
  results = work_all(filenames, args, nproc=params.nproc)
  print results

  if params.json is not None:
    import json
    with open(params.json, 'wb') as f:
      json.dump(results, f)
예제 #3
0
    def run(self):
        """Execute the script."""

        # Parse the command line
        self.params, options = self.parser.parse_args(show_diff_phil=True)

        if len(self.params.data_directory) == 0:
            raise Sorry("Please provide input in the form:\n  {0}".format(
                self.parser.usage))

        # Get full paths to datasets
        self.params.data_directory = [
            os.path.realpath(e) for e in self.params.data_directory
        ]

        # Check that these do contain datasets
        have_data = [
            self.is_dataset_dir(e) for e in self.params.data_directory
        ]
        if have_data.count(False) > 0:
            no_data = [
                e for e, h in zip(self.params.data_directory, have_data)
                if not h
            ]
            raise Sorry("No data found in found in:\n  " +
                        "\n  ".join(no_data))

        # Set nproc
        if self.params.nproc is Auto:
            from libtbx.introspection import number_of_processors

            self.params.nproc = number_of_processors(
                return_value_if_unknown=-1)

        # Look for CCP4
        if "CCP4" not in os.environ:
            raise Sorry("Please set up the CCP4 environment")

        # Create processing directory and cd to it
        if os.path.isdir(self.params.output_directory):
            raise Sorry("Output directory already exists")
        try:
            os.mkdir(self.params.output_directory)
        except OSError:
            raise Sorry("Failed to create output directory")
        os.chdir(self.params.output_directory)

        for job in self.params.data_directory:

            job_dir = os.path.basename(job)

            # For each job, do processing in its own directory
            try:
                with cd(job_dir):
                    self.process(job)
            except OSError:
                raise Sorry(
                    "Failed to create job directory {0}".format(job_dir))

        return
예제 #4
0
    def _count_processors(self, nproc=None):  # type: (Optional[int]) -> None
        """
        Determine the number of processors and save it as an instance variable.

        The user may specify the number of processors to use.  If no value is
        given, the number of available processors is returned.

        Args:
            nproc (optional):  Number of processors.
        """
        if nproc and nproc is not Auto:
            self.nproc = nproc
            return

        # if environmental variable NSLOTS is set to a number then use that
        try:
            self.nproc = int(os.environ.get("NSLOTS"))
            return
        except (ValueError, TypeError):
            pass

        self.nproc = number_of_processors(return_value_if_unknown=-1)

        if self.nproc <= 0:
            warning(
                "Could not determine number of available processors. Error code %d",
                self.nproc,
            )
            sys.exit(1)
예제 #5
0
def get_number_cpus():
  '''Portably get the number of processor cores available.'''

  # if environmental variable NSLOTS is set to a number then use that
  try:
    return int(os.environ.get('NSLOTS'))
  except (ValueError, TypeError):
    pass

  from libtbx.introspection import number_of_processors
  return number_of_processors(return_value_if_unknown=-1)
예제 #6
0
def run(args=None):
    usage = "dials.find_spots_server [options]"

    # Python 3.8 on macOS... needs fork
    if sys.hexversion >= 0x3080000 and sys.platform == "darwin":
        multiprocessing.set_start_method("fork")

    parser = OptionParser(usage=usage, phil=phil_scope, epilog=help_message)
    params, options = parser.parse_args(args, show_diff_phil=True)
    if params.nproc is libtbx.Auto:
        params.nproc = number_of_processors(return_value_if_unknown=-1)
    main(params.nproc, params.port)
예제 #7
0
def get_number_cpus():
    """Portably get the number of processor cores available."""

    if os.name == "nt":
        # Windows only has once CPU because easy_mp does not support more. #191
        return 1

    # if environmental variable NSLOTS is set to a number then use that
    try:
        return int(os.environ.get("NSLOTS"))
    except (ValueError, TypeError):
        pass

    return number_of_processors(return_value_if_unknown=-1)
예제 #8
0
def get_processes (processes) :
  """
  Determine number of processes dynamically: number of CPUs minus the current
  load average (with a minimum of 1).
  """
  if (processes in [None, Auto]) :
    if (os.name == "nt") or (sys.version_info < (2,6)) :
      return 1
    from libtbx import introspection
    auto_adjust = (processes is Auto)
    processes = introspection.number_of_processors()
    if (auto_adjust) :
      processes = max(ifloor(processes - os.getloadavg()[0]), 1)
  else :
    assert (processes > 0)
  return processes
예제 #9
0
def setup(reflections, params):
    # calculate the batches for processing
    if params.image_range:
        if not len(params.image_range.split(":")) == 2:
            raise ValueError(
                "Image range must be given in the form first:last")
        first, last = params.image_range.split(":")
        try:
            first = int(first)
        except ValueError:
            raise ValueError(f"Issue interpreting {first} as an integer")
        try:
            last = int(last)
        except ValueError:
            raise ValueError(f"Issue interpreting {last} as an integer")
        lowest_index = max(0, first - 1)
        highest_image = min(last, len(reflections))
        batches = list(
            range(lowest_index, highest_image, params.output.batch_size))
        batches.append(highest_image)
    else:
        batches = list(range(0, len(reflections), params.output.batch_size))
        batches.append(len(reflections))

    # Note, memory processing logic can go here
    if params.nproc is Auto:
        params.nproc = number_of_processors(return_value_if_unknown=1)
    logger.info(f"Using {params.nproc} processes for integration")

    # aggregate some output for json, html etc
    if params.algorithm == "ellipsoid":
        process = process_one_image_ellipsoid_integrator
        aggregator = EllipsoidOutputAggregator()
    elif params.algorithm == "stills":
        process = process_one_image_stills_integrator
        aggregator = OutputAggregator()
    else:
        raise ValueError("Invalid algorithm choice")

    configuration = {
        "process": process,
        "aggregator": aggregator,
        "params": params,
    }

    return batches, configuration
예제 #10
0
    def __init__(self):
        self._phil = parse("""
fast_ep {
  machines = 1
    .type = int
  cpu = %d
    .type = int
  data = 'fast_dp.mtz'
    .type = str
  native = None
    .type = str
  atom = Se
    .type = str
  spg = None
    .type = str
  nsites = None
    .type = int
  ntry = 200
    .type = int
  ncycle = 20
    .type = int
  rlims = None
    .type = floats(value_min=0)
  xml = ''
    .type = str
  json = ''
    .type = str
  trace = False
    .type = bool
  mode = *basic advanced
    .help = "fast_ep operation setting"
    .type = choice
  sge_project = None
    .type = str
}
""" % introspection.number_of_processors(return_value_if_unknown = 1))
        argument_interpreter = self._phil.command_line_argument_interpreter(
            home_scope = 'fast_ep')
        for argv in sys.argv[1:]:
            command_line_phil = argument_interpreter.process(arg = argv)
            self._phil = self._phil.fetch(command_line_phil)
        self._parameters = self._phil.extract()

        return
예제 #11
0
def run(args=sys.argv[1:]):
    usage = "xia2.compare_merging_stats [options] unmerged1.mtz unmerged2.mtz (..)"

    parser = OptionParser(usage=usage,
                          phil=phil_scope,
                          check_format=False,
                          epilog=help_message)

    params, options, args = parser.parse_args(args,
                                              show_diff_phil=True,
                                              return_unhandled=True)

    if params.nproc is libtbx.Auto:
        params.nproc = number_of_processors()

    results = []
    mtz_files = [arg for arg in args if os.path.isfile(arg)]

    get_merging_stats_partial = functools.partial(
        get_merging_stats,
        anomalous=params.anomalous,
        n_bins=params.n_bins,
        use_internal_variance=params.use_internal_variance,
        eliminate_sys_absent=params.eliminate_sys_absent,
        data_labels=params.data_labels,
        space_group_info=params.space_group,
        d_min=params.d_min,
        d_max=params.d_max,
    )
    with concurrent.futures.ProcessPoolExecutor(
            max_workers=params.nproc) as pool:
        results = pool.map(get_merging_stats_partial, mtz_files)

    plot_merging_stats(
        list(results),
        labels=params.plot_labels,
        size_inches=params.size_inches,
        image_dir=params.image_dir,
        format=params.format,
        style=params.style,
        small_multiples=params.small_multiples,
        alpha=params.alpha,
    )
    return results
예제 #12
0
def get_processes(processes):
    """
  Determine number of processes dynamically: number of CPUs minus the current
  load average (with a minimum of 1).

  :param processes: default number of processes (may be None or Auto)
  :returns: actual number of processes to use
  """
    if (processes in [None, Auto]):
        if os.name == "nt":
            return 1
        from libtbx import introspection
        auto_adjust = (processes is Auto)
        processes = introspection.number_of_processors()
        if (auto_adjust):
            processes = max(ifloor(processes - os.getloadavg()[0]), 1)
    else:
        assert (processes > 0)
    return processes
예제 #13
0
def run(out=None, omit_unicode_experiment=False):
  if (out is None): out = sys.stdout
  out.write(bp.platform_info)
  tag = libtbx.env.under_dist("boost", "TAG")
  if (op.isfile(tag)):
    tag = open(tag).read().strip()
  else:
    tag = None
  print("boost/TAG:", tag, file=out)
  print("os.name:", os.name, file=out)
  print("sys.platform:", sys.platform, file=out)
  print("sys.byteorder:", sys.byteorder, file=out)
  print("platform.platform():", platform.platform(), file=out)
  print("platform.architecture():", platform.architecture(), file=out)
  for attr in ["division_by_zero", "invalid", "overflow"]:
    attr = "floating_point_exceptions.%s_trapped" % attr
    print("%s:" % attr, eval("bp.%s" % attr), file=out)
  print("number of processors:", introspection.number_of_processors(
    return_value_if_unknown="unknown"), file=out)
  introspection.machine_memory_info().show(out=out)
  try: import thread
  except ImportError: print("import thread: NO", file=out)
  else: print("import thread: OK", file=out)
  print("Division operator semantics: %s division" % (div_probe() / 0))
  c = getattr(bp.ext, "str_or_unicode_as_char_list", None)
  if (c is not None and not omit_unicode_experiment):
    print('"hello" =', c("hello"), file=out)
    print('u"hello" =', c(u"hello"), file=out)
    e = u"\u00C5".encode("utf-8", "strict")
    # XXX temp fix for python3 failure: unicode failure in show_platform_info.py
    # Reason: c(u"\u00C5") fails and c(e) fails
    try:
      cc = c(u"\u00C5")
      ce = c(e)
    except Exception as ignore_exception:
      cc = u"\u00C5"
      ce = e

    print('u"\u00C5" =', cc, 'as utf-8 =', ce, file=out)
    print("LATIN CAPITAL LETTER A WITH RING ABOVE =", e, file=out)
  from libtbx.utils import format_cpu_times
  print(format_cpu_times())
예제 #14
0
def run(out=None, omit_unicode_experiment=False):
    if (out is None): out = sys.stdout
    out.write(boost.python.platform_info)
    tag = libtbx.env.under_dist("boost", "TAG")
    if (op.isfile(tag)):
        tag = open(tag).read().strip()
    else:
        tag = None
    print >> out, "boost/TAG:", tag
    print >> out, "os.name:", os.name
    print >> out, "sys.platform:", sys.platform
    print >> out, "sys.byteorder:", sys.byteorder
    print >> out, "platform.platform():", platform.platform()
    print >> out, "platform.architecture():", platform.architecture()
    for attr in ["division_by_zero", "invalid", "overflow"]:
        attr = "floating_point_exceptions.%s_trapped" % attr
        print >> out, "%s:" % attr, eval("boost.python.%s" % attr)
    print >> out, "number of processors:", introspection.number_of_processors(
        return_value_if_unknown="unknown")
    introspection.machine_memory_info().show(out=out)
    try:
        import thread
    except ImportError:
        print >> out, "import thread: NO"
    else:
        print >> out, "import thread: OK"
    print "Division operator semantics: %s division" % (div_probe() / 0)
    c = getattr(boost.python.ext, "str_or_unicode_as_char_list", None)
    if (c is not None and not omit_unicode_experiment):
        print >> out, '"hello" =', c("hello")
        print >> out, 'u"hello" =', c(u"hello")
        e = u"\u00C5".encode("utf-8", "strict")
        print >> out, 'u"\u00C5" =', c(u"\u00C5"), 'as utf-8 =', c(e)
        print >> out, "LATIN CAPITAL LETTER A WITH RING ABOVE =", e
    from libtbx.utils import format_cpu_times
    print format_cpu_times()
예제 #15
0
def run(args):
    from dials.util.options import OptionParser
    import libtbx.load_env

    usage = "%s [options] find_spots.json" % (libtbx.env.dispatcher_name)

    parser = OptionParser(usage=usage, phil=phil_scope, epilog=help_message)

    filenames = [arg for arg in args if os.path.isfile(arg)]
    args = [arg for arg in args if not arg in filenames]

    params, options, args = parser.parse_args(show_diff_phil=True,
                                              return_unhandled=True)
    if params.nproc is libtbx.Auto:
        from libtbx.introspection import number_of_processors
        params.nproc = number_of_processors(return_value_if_unknown=-1)
    print 'nproc: %i' % params.nproc
    results = work_all(filenames, args, nproc=params.nproc)
    print results

    if params.json is not None:
        import json
        with open(params.json, 'wb') as f:
            json.dump(results, f)
예제 #16
0
파일: Environment.py 프로젝트: xia2/xia2
def get_number_cpus():
  '''Portably get the number of processor cores available.'''
  from libtbx.introspection import number_of_processors
  return number_of_processors(return_value_if_unknown=-1)
예제 #17
0
          pixel_xy.append((x,y))
          use_index[h_i] = True
          use_index[y*n_x + (x+1)] = True
          use_index[(y+1)*n_x + x] = True
          use_index[(y+1)*n_x + (x+1)] = True

  # select reciprocal space vectors
  ring_h = flex.vec3_double()
  ring_h.reserve(use_index.count(True))
  for i in xrange(len(all_h)):
    if (use_index[i]):
      ring_h.append(all_h[i])

  # calculate intensities
  n_images = 50
  n_cpu = number_of_processors()
  n_cpu,parameters = generate_parameters(mp=mp,n_images=n_images,
                                         n_cpu=n_cpu)
  for p in parameters:
    p.h = ring_h
    p.use_index = use_index

  if (False):
    output = map_calculate_rings(parameters[0])
    exit()

  # run jobs
  t1 = time.time()
  pool = Pool(processes=n_cpu)
  output = pool.map(map_calculate_rings,parameters)
  pool.close()
예제 #18
0
def _nproc():
    return number_of_processors(return_value_if_unknown=-1)
예제 #19
0
  .type = int(value_min=1)
port = 1701
  .type = int(value_min=1)
''')


def main(nproc, port):
  server_class = server_base.HTTPServer
  httpd = server_class(('', port), handler)
  print time.asctime(), 'Serving %d processes on port %d' % (nproc, port)

  for j in range(nproc - 1):
    proc = Process(target=serve, args=(httpd,))
    proc.daemon = True
    proc.start()
  serve(httpd)
  httpd.server_close()
  print time.asctime(), 'done'

if __name__ == '__main__':
  usage = '%s [options]' % libtbx.env.dispatcher_name

  from dials.util.options import OptionParser
  parser = OptionParser(
    usage=usage, phil=phil_scope, epilog=help_message)
  params, options = parser.parse_args(show_diff_phil=True)
  if params.nproc is libtbx.Auto:
    from libtbx.introspection import number_of_processors
    params.nproc = number_of_processors(return_value_if_unknown=-1)
  main(params.nproc, params.port)
예제 #20
0
def main(nproc, port):
  server_class = server_base.HTTPServer
  httpd = server_class(('', port), handler)
  print time.asctime(), 'start'

  # catch TERM signal to allow finalizers to run and reap daemonic children
  signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM))

  for j in range(nproc - 1):
    proc = Process(target=serve, args=(httpd,))
    proc.daemon = True
    proc.start()
  serve(httpd)
  httpd.server_close()
  print time.asctime(), 'done'

if __name__ == '__main__':
  import sys
  import libtbx.load_env

  usage = '%s [options]' % libtbx.env.dispatcher_name

  from dials.util.options import OptionParser
  parser = OptionParser(
    usage=usage, phil=phil_scope, epilog=help_message)
  params, options = parser.parse_args(show_diff_phil=True)
  if params.nproc is libtbx.Auto:
    from libtbx.introspection import number_of_processors
    params.nproc = number_of_processors(return_value_if_unknown=-1)
  main(params.nproc, params.port)
예제 #21
0
def _nproc():
  from libtbx.introspection import number_of_processors
  return number_of_processors(return_value_if_unknown=-1)
예제 #22
0
    def run(self):

        time_total_start = time.time()
        args = sys.argv[1:]

        log = multi_out()
        out = sys.stdout
        log.register("stdout", out)

        if (self.params.write_custom_geom_only == True):

            geom_log_file_name = "geom_writing.log"
            geom_logfile = open(
                geom_log_file_name, "w"
            )  # since it is 'w', an existing file will be overwritten. (if this is "a", new info will be appended to an existing file)

            custom_geom_file_name = str(
                self.data_manager.get_default_model_name(
                )) + "_ss_stronger.eff"
            splited_custom_geom_file_name = custom_geom_file_name.split("/")
            custom_geom_file_name_wo_path = splited_custom_geom_file_name[
                len(splited_custom_geom_file_name) - 1]

            write_this = custom_geom_file_name_wo_path + " is generated at the same folder. Modify it for user's need, and provide to cryo_fit2.\n"
            print(write_this)
            geom_logfile.write(write_this)
            geom_logfile.close()
            exit(1)

        log_file_name = "cryo_fit2.log"
        logfile = open(
            log_file_name, "a"
        )  # since it is 'a', new info will be appended to an existing file. However, if it is 'w', an existing file will be overwritten.
        log.register("logfile", logfile)

        # Importantly declared initial global variables
        user_cool_rate = None
        user_HE_sigma = None
        user_HE_slack = None
        user_map_weight_multiply = None
        user_MD_in_each_cycle = None
        user_number_of_steps = None
        user_start_temperature = None

        # Save user entered params.* now
        if (self.params.cool_rate != None):
            user_cool_rate = self.params.cool_rate
        if (self.params.MD_in_each_cycle != None):
            user_MD_in_each_cycle = self.params.MD_in_each_cycle
        if (self.params.number_of_steps != None):
            user_number_of_steps = self.params.number_of_steps
        if (self.params.start_temperature != None):
            user_start_temperature = self.params.start_temperature
        if (self.params.map_weight_multiply != None):
            user_map_weight_multiply = self.params.map_weight_multiply
        if (self.params.HE_sigma != None):
            user_HE_sigma = self.params.HE_sigma
        if (self.params.HE_slack != None):
            user_HE_slack = self.params.HE_slack

        print("A user entered resolution:             ",
              str(self.params.resolution))

        print('A user input atomistic model file name: %s' %
              self.data_manager.get_default_model_name(),
              file=self.logger)
        model_inp = self.data_manager.get_model()
        #print ("model_inp:",model_inp) # "<mmtbx.model.model.manager object at 0x11901fad0>"

        ########### <begin> to deal phi, psi
        restraint_objects = None
        monomer_parameters = None
        pdb_hierarchy = model_inp.get_hierarchy(
        )  # "AttributeError: 'Program' object has no attribute 'model_inp'"
        if pdb_hierarchy is not None:
            raw_records = pdb_hierarchy.as_pdb_string()
        if raw_records is not None:
            if (isinstance(raw_records, str)):
                raw_records = flex.split_lines(raw_records)

        work_params = mmtbx.model.manager.get_default_pdb_interpretation_params(
        )
        pdb_inp = input(lines=raw_records, source_info=None)

        model = mmtbx.model.manager(model_input=pdb_inp,
                                    build_grm=True,
                                    pdb_interpretation_params=work_params,
                                    restraint_objects=restraint_objects,
                                    monomer_parameters=monomer_parameters,
                                    log=null_out())

        #print (get_dihedrals_and_phi_psi(model)) # dihedral_registry.proxies -> "<cctbx_geometry_restraints_ext.shared_dihedral_proxy object at 0x1116694c8>"
        #STOP()
        ########### <end> to deal phi, psi

        print('A user input map file name:             %s' %
              self.data_manager.get_default_real_map_name(),
              file=self.logger)
        map_inp = self.data_manager.get_real_map()

        ################# <begin> Doonam's playground ################
        ####### works
        #print ("dir(map_inp):",dir(map_inp)) # just shows list of what items are available
        #['__doc__', '__init__', '__module__', 'cannot_be_sharpened', 'crystal_symmetry', 'data', 'external_origin', 'get_additional_labels', 'get_labels', 'get_limitation', 'get_limitations', 'grid_unit_cell', 'header_max', 'header_mean', 'header_min', 'header_rms', 'is_in_limitations', 'is_similar_map', 'labels', 'map_data', 'nxstart_nystart_nzstart', 'origin', 'pixel_sizes', 'show_summary', 'space_group_number', 'statistics', 'unit_cell', 'unit_cell_crystal_symmetry', 'unit_cell_grid', 'unit_cell_parameters']

        print("map_inp.show_summary():", map_inp.show_summary())
        #print ("map_inp.unit_cell_grid():", map_inp.unit_cell_grid()) #TypeError: 'tuple' object is not callable
        #print ("map_inp.unit_cell_grid:", map_inp.unit_cell_grid)
        #print ("map_inp.unit_cell_grid[0]:", map_inp.unit_cell_grid[0])

        # for map_boxed map
        # unit cell grid: (360, 360, 360)
        # map grid:   (99, 87, 85)
        # for original map
        # unit cell grid: (360, 360, 360)
        # map grid:   (360, 360, 360)
        # it shows many items from header_min to pixel size, show_summary() itself shows "None"

        #print ("map_inp.unit_cell_crystal_symmetry().unit_cell():",map_inp.unit_cell_crystal_symmetry().unit_cell())
        #shows little bit unexpected values if a map went through phenix.map_box
        '''
    print ("map_inp.unit_cell_parameters:",map_inp.unit_cell_parameters)
    print ("map_inp.space_group_number:",(map_inp.space_group_number))
    #print ("map_inp.unit_cell_crystal_symmetry():",map_inp.unit_cell_crystal_symmetry()) # just shows the address of the object
    #print ("map_inp.crystal_symmetry():",map_inp.crystal_symmetry()) # just shows the address of the object
    '''
        map_inp_data = map_inp.map_data()
        #print ("map_inp_data:", map_inp_data) #<scitbx_array_family_flex_ext.double object at 0x119e171d0>
        #print ("map origin:", map_inp_data.origin())
        #132, 94, 203 for DN map_L1 stalk same as in util.py's target_map_data.origin()

        #'''
        #print ("map accessor:", map_inp_data.accessor()) # shows an object address
        #print ("map_inp.crystal_symmetry():",map_inp.crystal_symmetry()) # shows an object address

        ########## test
        #map_inp.space_group_number()
        #print ("map_inp.space_group_number():",map_inp.space_group_number())
        #print ("str(map_inp.space_group_number()):",str(map_inp.space_group_number()))

        ########## not works
        '''
    #print ("map_inp.origin():", map_inp.origin()) # ==> TypeError: 'list' object is not callable
    #print ("map_inp.accessor():", map_inp.accessor())
    map_inp.unit_cell_crystal_symmetry()
    print ("map_inp.space_group_number():",map_inp.space_group_number())
    map_inp.unit_cell_parameters()
    print ("map_inp.unit_cell_parameters().unit_cell():",map_inp.unit_cell_parameters().unit_cell())
    '''
        ################# <end> Doonam's playground ################

        if (self.params.loose_ss_def == True):
            self.params.pdb_interpretation.secondary_structure.nucleic_acid.hbond_distance_cutoff = 4
            # default is 3.4, the longer this value, the loose the restraint

            self.params.pdb_interpretation.secondary_structure.nucleic_acid.angle_between_bond_and_nucleobase_cutoff = 30
            # default is 35, this angle doesn't have much effect on bvht RNA structure

        # when I use phenix.secondary_structure_restraints at commandline, use
        # secondary_structure.nucleic_acid.hbond_distance_cutoff
        # not
        # pdb_interpretation.secondary_structure.nucleic_acid.hbond_distance_cutoff

        # modules/cctbx_project/mmtbx/monomer_library/pdb_interpretation.py

        print("self.params.pdb_interpretation.secondary_structure.enabled:",
              self.params.pdb_interpretation.secondary_structure.enabled)
        print(
            "self.params.pdb_interpretation.secondary_structure.protein.remove_outliers:",
            self.params.pdb_interpretation.secondary_structure.protein.
            remove_outliers)
        print(
            "self.params.pdb_interpretation.secondary_structure.nucleic_acid.enabled:",
            self.params.pdb_interpretation.secondary_structure.nucleic_acid.
            enabled)

        #print ("self.params.pdb_interpretation.secondary_structure.protein.helix.angle_sigma_scale:",self.params.pdb_interpretation.secondary_structure.protein.helix.angle_sigma_scale)
        #"AttributeError: 'scope_extract_list' object has no attribute 'angle_sigma_scale'"

        #print ("self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.enabled:",self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.enabled)
        #"AttributeError: 'scope_extract_list' object has no attribute 'enabled'"

        #print ("self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.restrain_planarity:",self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.restrain_planarity)
        # "AttributeError: 'scope_extract_list' object has no attribute 'restrain_planarity'"

        # print ("self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.restrain_hbonds:",self.params.pdb_interpretation.secondary_structure.nucleic_acid.base_pair.restrain_hbonds)
        # STOP()

        splited = self.data_manager.get_default_model_name().split("/")
        input_model_file_name_wo_path = splited[len(splited) - 1]

        if (self.params.short == True):
            self.params.start_temperature = 300
            self.params.final_temperature = 280
            self.params.MD_in_each_cycle = 2
            self.params.number_of_steps = 1
            self.params.max_steps_for_final_MD = 50

        elif (input_model_file_name_wo_path == "tutorial_cryo_fit2_model.pdb"):
            self.params.explore = False
            self.params.start_temperature = 1000
            self.params.final_temperature = 0
            self.params.MD_in_each_cycle = 5
            self.params.number_of_steps = 1000
            self.params.max_steps_for_final_MD = 2000

        ########## <begin> Automatic map weight determination
        user_map_weight = ''
        if (self.params.map_weight == None
            ):  # a user didn't specify map_weight
            self.params.map_weight = determine_optimal_weight_by_template(
                self, logfile, map_inp, '')
            logfile.write(
                "\nAn automatically optimized map_weight (before any multiplication): "
            )
        else:
            user_map_weight = self.params.map_weight  # this user_map_weight will be used later
            logfile.write("\nA user specified map_weight: ")

        write_this = str(round(self.params.map_weight, 1)) + "\n"
        logfile.write(write_this)
        ########## <end> Automatic map weight determination


        bp_in_a_user_pdb_file, H_in_a_user_pdb_file, E_in_a_user_pdb_file, ss_file = \
          know_bp_H_E_in_a_user_pdb_file(self.data_manager.get_default_model_name(), logfile)

        if ((bp_in_a_user_pdb_file == 0) and (H_in_a_user_pdb_file == 0)
                and (E_in_a_user_pdb_file == 0)):
            write_this = "A user input file has no base pair or Helix/Sheet.\nMaybe this is an intrinsically disordered molecule. Therefore, cryo_fit2 will not explore MD parameters\n"
            print(write_this)
            logfile.write(write_this)
            self.params.explore == False

        if (self.params.stronger_ss == True):
            write_this = "A user turned stronger_ss=True\n"
            print(write_this)
            logfile.write(write_this)

        ####################### <begin> Explore the optimal combination of parameters
        if ((self.params.short == False) and (self.params.explore == True)):

            ########  Based on preliminary benchmarks (~500 combinations with L1 stalk and tRNA), Doonam believes that finding an
            ######## optimum combination of different parameters is a better approach than individually finding each "optimal" parameter
            bp_cutoff = bp_in_a_user_pdb_file * 0.97
            write_this = "bp_cutoff from a user input pdb file: " + str(
                round(bp_cutoff, 1)) + "\n"
            print(write_this)
            logfile.write(write_this)

            # Stricter cutoff for H/E than bp
            H_cutoff = H_in_a_user_pdb_file * 0.99
            write_this = "H_cutoff from a user input pdb file : " + str(
                round(H_cutoff, 1)) + "\n"
            print(write_this)
            logfile.write(write_this)

            E_cutoff = E_in_a_user_pdb_file * 0.99
            write_this = "E_cutoff from a user input pdb file : " + str(
                round(E_cutoff, 1)) + "\n"
            print(write_this)
            logfile.write(write_this)

            if (os.path.isdir("parameters_exploration") == True):
                shutil.rmtree("parameters_exploration")
            os.mkdir("parameters_exploration")

            the_pdb_file_has_nucleic_acid = check_whether_the_pdb_file_has_nucleic_acid(
                self.data_manager.get_default_model_name())

            if (the_pdb_file_has_nucleic_acid == True):
                self.params.max_steps_for_exploration = 25000  # for tRNA, 15k was barely enough

            total_combi_num, argstuples = make_argstuples(self, logfile, user_map_weight, the_pdb_file_has_nucleic_acid, \
                                                          bp_cutoff, H_cutoff, E_cutoff) # user_map_weight should tag along for a later usage

            cores_to_use = ''
            if (self.params.nproc != None):
                cores_to_use = self.params.nproc
            else:
                returned_nproc = number_of_processors(
                    return_value_if_unknown=-1)
                # kaguya resulted in 32
                # sparky resulted in 40 (I expected to see 34 since I was running 6 cores at that time. \
                #It seems that number_of_processors returned just all # of processors)

                cores_to_use = math.ceil(returned_nproc / 3)
                # will use at least 1 core, since math.ceil rounds up to the next greater integer
                # just to avoid crash, it seems like sparky linux machine can't handle more than 40 cores (even 20 cores)
                # when I used 13 cores, the load average reached 20!

            write_this = "Cryo_fit2 will use " + str(
                int(cores_to_use)) + " core(s) to explore up to " + str(
                    total_combi_num) + " MD parameters.\n"
            print(write_this)
            logfile.write(write_this)

            success_exploration_count = 0
            for arguments_for_explore, res, errstr in easy_mp.multi_core_run(explore_parameters_by_multi_core, argstuples, \
                                                             cores_to_use): # the last argument is nproc
                print("explore_parameters_by_multi_core ran")

                if (res != None):
                    write_this = 'bp:' + str(res[0]) + ', H:' + str(
                        res[1]) + ', E:' + str(res[2]) + '\n'
                    print(write_this)  # 1, 0, 0
                    logfile.write(write_this)

                write_this = 'error string: %s ' % (errstr) + '\n'

                print(write_this)
                logfile.write(write_this)

                if (errstr == None):
                    success_exploration_count = success_exploration_count + 1

            optimum_MD_in_each_cycle, optimum_start_temperature, optimum_number_of_steps, optimum_map_weight_multiply = \
              extract_the_best_cc_parameters(self, logfile)

            write_this = "cryo_fit2 will run fully with optimized parameters.\n"
            print(write_this)
            logfile.write(write_this)

            self.params.MD_in_each_cycle = int(optimum_MD_in_each_cycle)
            self.params.start_temperature = float(
                optimum_start_temperature
            )  # make it as float to format it consistent as in parameter exploration and user input
            self.params.number_of_steps = int(optimum_number_of_steps)
            self.params.map_weight_multiply = float(
                optimum_map_weight_multiply)

            # Override self.params.* with user entered values
            if (user_MD_in_each_cycle != None):
                self.params.MD_in_each_cycle = user_MD_in_each_cycle
            if (user_number_of_steps != None):
                self.params.number_of_steps = user_number_of_steps
            if (user_HE_sigma != None):
                self.params.HE_sigma = user_HE_sigma
            if (user_HE_slack != None):
                self.params.HE_slack = user_HE_slack
            if (user_start_temperature != None):
                self.params.start_temperature = user_start_temperature
            if (user_map_weight_multiply != None):
                self.params.map_weight_multiply = user_map_weight_multiply
        ####################### <end> explore the optimal combination of parameters

        ###############  <begin> core cryo_fit2
        ### (begin) Assign default values if not specified till now (as a 0.998 cc full helix)
        if (self.params.MD_in_each_cycle == None):
            self.params.MD_in_each_cycle = 4
        if (self.params.number_of_steps == None):
            self.params.number_of_steps = 100
        if (self.params.start_temperature == None):
            self.params.start_temperature = 300
        if (self.params.map_weight_multiply == None):
            self.params.map_weight_multiply = 1
            #self.params.map_weight_multiply = 15
        ### (end) Assign default values if not specified till now (as a 0.998 cc full helix)

        # if (self.params.start_temperature == None):
        #   self.params.start_temperature = 600

        print("Final MD parameters after user input/automatic optimization")
        print("start_temperature     :", str(self.params.start_temperature))
        print("final_temperature     :", str(self.params.final_temperature))
        print("MD_in_each_cycle      :", str(self.params.MD_in_each_cycle))
        print("number_of_steps       :", str(self.params.number_of_steps))
        print("HE_sigma              :", str(self.params.HE_sigma))
        print("HE_slack              :", str(self.params.HE_slack))
        print("map_weight_multiply   :",
              str(round(self.params.map_weight_multiply, 1)))

        current_dir = os.getcwd()

        if (self.params.explore == True):
            dir_w_best_parameters = "output_resolution_" + str(self.params.resolution) \
                                  + "_start_" + str(self.params.start_temperature) \
                                  + "_final_" + str(self.params.final_temperature) \
                                  + "_MD_in_each_cycle_" + str(self.params.MD_in_each_cycle) \
                                  + "_step_" + str(self.params.number_of_steps) \
                                  + "_stronger_ss_" + str(self.params.stronger_ss) \
                                  + "_map_weight_multiply_" + str(round(self.params.map_weight_multiply,1))

            if (self.params.stronger_ss == True):
                dir_w_best_parameters = dir_w_best_parameters \
                                    + "_HE_sigma_" + str(self.params.HE_sigma) \
                                    + "_HE_slack_" + str(self.params.HE_slack)

            command_string = "find . -name '*" + str(
                dir_w_best_parameters) + "*' -type d"
            found_dir_w_best_parameters = libtbx.easy_run.fully_buffered(
                command=command_string).raise_if_errors().stdout_lines

            used_map_weight_before_multiplication_file_w_dir = str(
                found_dir_w_best_parameters[
                    len(found_dir_w_best_parameters) -
                    1]) + "/used_map_weight_before_multiplication.txt"
            used_map_weight_before_multiplication = get_used_map_weight(
                used_map_weight_before_multiplication_file_w_dir)
            self.params.map_weight = float(
                used_map_weight_before_multiplication)

        self.params.explore = False  # now exploration is completed

        # Override self.params.* with user entered values
        if (user_cool_rate != None):
            self.params.cool_rate = user_cool_rate
        else:
            self.params.cool_rate = (self.params.start_temperature -
                                     self.params.final_temperature) / (
                                         self.params.MD_in_each_cycle - 1)
        print("cool_rate             :", str(round(self.params.cool_rate, 1)),
              "\n")

        output_dir = get_output_dir_name(self)

        # All parameters for final MD are determined (either by a user or automatic optimization)
        cryo_fit2_input_command = "phenix.cryo_fit2" \
                                + " " + self.data_manager.get_default_model_name() \
                                + " " + self.data_manager.get_default_real_map_name()  \
                                + " resolution=" + str(self.params.resolution)  \
                                + " map_weight=" + str(round(self.params.map_weight,1)) \
                                + " map_weight_multiply=" + str(round(self.params.map_weight_multiply,1)) \
                                + " reoptimize_map_weight_after_each_cycle_during_final_MD=" + str(self.params.reoptimize_map_weight_after_each_cycle_during_final_MD) \
                                + " explore=False" \
                                + " start_temperature=" + str(self.params.start_temperature)  \
                                + " final_temperature=" + str(self.params.final_temperature) \
                                + " MD_in_each_cycle=" + str(self.params.MD_in_each_cycle) \
                                + " number_of_steps=" + str(self.params.number_of_steps) \
                                + " record_states=" + str(self.params.record_states) \
                                + " stronger_ss=" + str(self.params.stronger_ss) #\
        #+ " ignore_symmetry_conflicts=" + str(self.params.ignore_symmetry_conflicts)

        #+ " cool_rate=" + str(round(self.params.cool_rate,1)) \
        # if both cool_rate and MD_in_each_cycle exist in input_command, it may behave unexpectedly.

        #+ " secondary_structure.nucleic_acid.stacking_pair.sigma=" + str(self.params.pdb_interpretation.secondary_structure.nucleic_acid.stacking_pair.sigma)
        # secondary_structure.nucleic_acid.stacking_pair.sigma didn't cause an error at commandline,
        # but "AttributeError: 'scope_extract_list' object has no attribute 'sigma' for str(self.params.pdb_interpretation.secondary_structure.nucleic_acid.stacking_pair.sigma)"

        #+ "secondary_structure.protein.remove_outliers=" + str(self.params.pdb_interpretation.secondary_structure.protein.remove_outliers) + " " \
        #+ "secondary_structure.nucleic_acid.enabled=" + str(self.params.pdb_interpretation.secondary_structure.nucleic_acid.enabled) + " " \
        #+ "secondary_structure.nucleic_acid.hbond_distance_cutoff=" + str(self.params.pdb_interpretation.secondary_structure.nucleic_acid.hbond_distance_cutoff) + " " \
        #+ "secondary_structure.nucleic_acid.angle_between_bond_and_nucleobase_cutoff=" + str(self.params.pdb_interpretation.secondary_structure.nucleic_acid.angle_between_bond_and_nucleobase_cutoff) + " " \

        if (self.params.HE_angle_sigma_scale != 1):
            cryo_fit2_input_command = cryo_fit2_input_command + " HE_angle_sigma_scale=" + str(
                self.params.HE_angle_sigma_scale)

        if (self.params.HE_sigma != 0.05):
            cryo_fit2_input_command = cryo_fit2_input_command + " HE_sigma=" + str(
                self.params.HE_sigma)

        if (self.params.HE_slack != 0.00):
            cryo_fit2_input_command = cryo_fit2_input_command + " HE_slack=" + str(
                self.params.HE_slack)

        if (self.params.HE_top_out == True):
            cryo_fit2_input_command = cryo_fit2_input_command + " HE_top_out=" + str(
                self.params.HE_top_out)

        if (check_whether_the_pdb_file_has_nucleic_acid(
                self.data_manager.get_default_model_name()) == True):
            cryo_fit2_input_command = cryo_fit2_input_command + " parallelity_sigma=" + str(
                self.params.parallelity_sigma)
            cryo_fit2_input_command = cryo_fit2_input_command + " planarity_sigma=" + str(
                self.params.planarity_sigma)
            cryo_fit2_input_command = cryo_fit2_input_command + " secondary_structure.nucleic_acid.scale_bonds_sigma=" + str(
                self.params.pdb_interpretation.secondary_structure.
                nucleic_acid.scale_bonds_sigma)

        list_of_eff = return_list_of_eff_from_args(args)
        list_of_secondary_structure_restraints = return_list_of_secondary_structure_restraints_from_args(
            args)

        for i in (range(len(list_of_eff))):
            cryo_fit2_input_command = cryo_fit2_input_command + " " + str(
                list_of_eff[i])

        for i in (range(len(list_of_secondary_structure_restraints))):
            cryo_fit2_input_command = cryo_fit2_input_command + " " + str(
                list_of_secondary_structure_restraints[i])

        if (self.params.max_steps_for_final_MD != None):
            cryo_fit2_input_command = cryo_fit2_input_command + " max_steps_for_final_MD=" + str(
                self.params.max_steps_for_final_MD)

        cryo_fit2_input_command = cryo_fit2_input_command + "\n"

        print("\ncryo_fit2_input_command:", cryo_fit2_input_command)

        input_command_file = open("cryo_fit2.input_command.txt", "w")
        input_command_file.write(str(cryo_fit2_input_command))
        input_command_file.close()

        logfile.write("\n\nAn input command for final cryo_fit2 MD run:\n\n")
        logfile.write(str(cryo_fit2_input_command))

        task_obj = cryo_fit2_run.cryo_fit2_class(
            model=model_inp,
            model_name=self.data_manager.get_default_model_name(),
            map_inp=map_inp,
            params=self.params,
            out=self.logger,
            map_name=self.data_manager.get_default_real_map_name(),
            logfile=logfile,
            output_dir=output_dir,
            user_map_weight=user_map_weight,
            map_weight_multiply=self.params.map_weight_multiply)

        task_obj.validate()

        '''
    try:
      task_obj.validate() 
    except:
      write_this = '''#If a user sees a message like \n\t\"Sorry: Crystal symmetry mismatch between different files.\n\
        #    (52.576, 51.665, 61.692, 90, 90, 90) P 1\n\t(41.6227, 35.8785, 43.1844, 90, 90, 90) P 1\", \nisit https://phenix-online.org/documentation/faqs/cryo_fit2_FAQ.html#id5'''
        #  print (write_this)
        #  logfile.write(str(write_this))
        # exit(1)

        output_dir_final = task_obj.run()

        if (output_dir_final.find('_bp_') == -1):
            write_this = "An exception occurred. \n Maybe cryo_fit2 failed to run (\"nan\") for this condition:\n" + \
                         " map_weight (" + str(round(self.params.map_weight,2))         + ")\n" + \
                         " map_weight_multiply (" + str(self.params.map_weight_multiply)+ ")\n" + \
                         " cool_rate (" + str(round(self.params.cool_rate, 1))          + ")\n" + \
                         " MD_in_each_cycle (" + str(self.params.MD_in_each_cycle)      + ")\n" + \
                         " number_of_steps (" + str(self.params.number_of_steps)        + ")\n" + \
                         " start_temperature (" + str(self.params.start_temperature)    + ")\n" + \
                         " final_temperature (" + str(self.params.final_temperature)    + ")\n" + \
                         " max_steps_for_final_MD (" + str(self.params.max_steps_for_final_MD)  + ")"
            print(write_this)
            logfile.write(str(write_this))
            logfile.close()
            return 0
        ############### (end) core cryo_fit2

        write_geo(self, model_inp, "used_geometry_restraints.geo")
        model_inp.geometry_statistics().show()
        # if report_map_model_cc() ran before, model_inp becomes None

        crystal_symmetry = mmtbx.utils.check_and_set_crystal_symmetry(
            models=[model_inp], map_inps=[map_inp])

        write_this = ''
        if (self.params.explore == False):
            write_this = "\nCC values after cryo_fit2 (final MD)\n"
        else:
            write_this = "\nCC values after cryo_fit2 (both exploration and final MD)\n"

        print('%s' % (write_this))
        logfile.write(str(write_this))

        cc_after_cryo_fit2 = round(
            calculate_overall_cc(map_data=map_inp.map_data(),
                                 model=model_inp,
                                 resolution=self.params.resolution), 4)
        write_this = "\nCC_overall: " + str(cc_after_cryo_fit2) + "\n"
        print('%s' % (write_this))
        logfile.write(str(write_this))

        report_map_model_cc(self, map_inp, model_inp, crystal_symmetry,
                            logfile)

        ###### <begin> Clean up used files
        pymol_ss = input_model_file_name_wo_path + "_ss.pml"
        if (os.path.isfile(pymol_ss) == True):
            mv_command_string = "mv " + pymol_ss + " " + output_dir_final
            libtbx.easy_run.fully_buffered(mv_command_string)

        for i in (range(len(list_of_eff))):

            if (("_ss_nucleic_acid_sigma.eff" in str(list_of_eff[i])) == True):
                mv_command_string = "mv " + str(
                    list_of_eff[i]) + " " + output_dir_final
                libtbx.easy_run.fully_buffered(mv_command_string)

            if (("_params_for_HE.eff" in str(list_of_eff[i])) == True):
                mv_command_string = "mv " + str(
                    list_of_eff[i]) + " " + output_dir_final
                libtbx.easy_run.fully_buffered(mv_command_string)

            # if (("_ss_stronger.eff" in str(list_of_eff[i])) == True):
            #   mv_command_string = "mv " + str(list_of_eff[i]) + " " + output_dir_final
            #   libtbx.easy_run.fully_buffered(mv_command_string)
            #

        mv_command_string = "mv cryo_fit2.input_command.txt " + ss_file + " used_geometry_restraints.geo " + log_file_name + " " + output_dir_final
        libtbx.easy_run.fully_buffered(mv_command_string)
        ###### <end> Clean up used files

        write_this = "Visit <PHENIX path>/doc/faqs/cryo_fit2_FAQ.html to see how to maximize cc.\n\n"
        print(write_this)
        logfile.write(write_this)

        time_total_end = time.time()
        time_took = show_time("cryo_fit2", time_total_start, time_total_end)
        print(time_took)
        logfile.write(str(time_took))
        logfile.write("\n")

        logfile.close()
예제 #23
0
파일: ssx_index.py 프로젝트: kmdalton/dials
def run(args: List[str] = None, phil: phil.scope = phil_scope) -> None:
    """
    Run dev.dials.ssx_index as from the command line.

    This program takes an imported experiment list and a reflection table
    of strong spots and performs parallelised indexing for synchrotron
    serial crystallography experiments. This is done by calling the regular
    dials indexing code and capturing output to provide a html report, and
    outputs a multi-image indexed.expt and indexed.refl file containing the
    indexed data.
    """

    parser = ArgumentParser(
        usage="dev.dials.ssx_index imported.expt strong.refl [options]",
        read_experiments=True,
        read_reflections=True,
        phil=phil_scope,
        check_format=False,
        epilog=__doc__,
    )
    params, options = parser.parse_args(args=args, show_diff_phil=False)

    if not params.input.experiments or not params.input.reflections:
        parser.print_help()
        sys.exit()

    reflections, experiments = reflections_and_experiments_from_files(
        params.input.reflections, params.input.experiments)
    log.config(verbosity=options.verbose, logfile=params.output.log)
    params.individual_log_verbosity = options.verbose
    logger.info(dials_version())

    diff_phil = parser.diff_phil.as_str()
    if diff_phil:
        logger.info("The following parameters have been modified:\n%s",
                    diff_phil)

    if params.nproc is Auto:
        params.nproc = number_of_processors(return_value_if_unknown=1)

    if params.nproc > 1:
        params.indexing.nproc = params.nproc

    logger.info(f"Using {params.indexing.nproc} processes for indexing")

    st = time.time()
    indexed_experiments, indexed_reflections, summary_data = index(
        experiments, reflections[0], params)

    summary_table = make_summary_table(summary_data)
    logger.info("\nSummary of images sucessfully indexed\n" + summary_table)

    n_images = len({e.imageset.get_path(0) for e in indexed_experiments})
    logger.info(
        f"{indexed_reflections.size()} spots indexed on {n_images} images\n")

    crystal_symmetries = [
        crystal.symmetry(
            unit_cell=expt.crystal.get_unit_cell(),
            space_group=expt.crystal.get_space_group(),
        ) for expt in indexed_experiments
    ]
    cluster_plots, _ = report_on_crystal_clusters(
        crystal_symmetries,
        make_plots=(params.output.html or params.output.json),
    )

    logger.info(f"Saving indexed experiments to {params.output.experiments}")
    indexed_experiments.as_file(params.output.experiments)
    logger.info(f"Saving indexed reflections to {params.output.reflections}")
    indexed_reflections.as_file(params.output.reflections)

    if params.output.html or params.output.json:
        summary_plots = generate_plots(summary_data)
        if cluster_plots:
            summary_plots.update(cluster_plots)
        if params.output.html:
            generate_html_report(summary_plots, params.output.html)
        if params.output.json:
            with open(params.output.json, "w") as outfile:
                json.dump(summary_plots, outfile)

    logger.info(f"Total time: {time.time() - st:.2f}s")
    logger.info(
        "Further program documentation can be found at dials.github.io/ssx_processing_guide.html"
    )
예제 #24
0
def _nproc():
    from libtbx.introspection import number_of_processors
    return number_of_processors(return_value_if_unknown=-1)
예제 #25
0
def refined_settings_from_refined_triclinic(experiments, reflections, params):
    """Generate a RefinedSettingsList from a triclinic model.

    Args:
        experiments: The experiments refined with a triclinic model
        reflections: A reflection table containing observed centroids
        params: The working PHIL parameters.

    Returns:
        RefinedSettingsList: A list of the refined settings. The highest symmetry
        setting will be first item in the list, and the triclinic setting will be last.
    """

    if params.nproc is libtbx.Auto:
        params.nproc = number_of_processors()

    if params.refinement.reflections.outlier.algorithm in ("auto",
                                                           libtbx.Auto):
        if experiments[0].goniometer is None:
            params.refinement.reflections.outlier.algorithm = "sauter_poon"
        else:
            # different default to dials.refine
            # tukey is faster and more appropriate at the indexing step
            params.refinement.reflections.outlier.algorithm = "tukey"

    assert len(experiments.crystals()) == 1
    crystal = experiments.crystals()[0]

    used_reflections = copy.deepcopy(reflections)
    UC = crystal.get_unit_cell()

    refined_settings = RefinedSettingsList()
    for item in iotbx_converter(
            UC,
            params.lepage_max_delta,
            best_monoclinic_beta=params.best_monoclinic_beta):
        refined_settings.append(BravaisSetting(item))

    triclinic = refined_settings.triclinic()

    # assert no transformation between indexing and bravais list
    assert str(triclinic["cb_op_inp_best"]) == "a,b,c"

    Nset = len(refined_settings)
    for j in range(Nset):
        refined_settings[j].setting_number = Nset - j

    for subgroup in refined_settings:
        bravais_lattice = str(
            bravais_types.bravais_lattice(
                group=subgroup["best_subsym"].space_group()))
        space_group = lowest_symmetry_space_group_for_bravais_lattice(
            bravais_lattice)
        orient = crystal_orientation(crystal.get_A(), True).change_basis(
            scitbx.matrix.sqr(subgroup["cb_op_inp_best"].c().as_double_array()
                              [0:9]).transpose())
        constrain_orient = orient.constrain(subgroup["system"])
        subgroup["bravais"] = bravais_lattice
        subgroup.unrefined_crystal = dxtbx_crystal_from_orientation(
            constrain_orient, space_group)

    with concurrent.futures.ProcessPoolExecutor(
            max_workers=params.nproc) as pool:
        for i, result in enumerate(
                pool.map(
                    refine_subgroup,
                    ((params, subgroup, used_reflections, experiments)
                     for subgroup in refined_settings),
                )):
            refined_settings[i] = result

    identify_likely_solutions(refined_settings)
    return refined_settings
예제 #26
0
        if (denormalize):
            q_sc, sc = read_sc(filename=filename.rstrip())
            assert (len(q) == q_sc.size())
            for i in ring_indices:
                ac[i] = sc[i] * sc[i] * ac[i]

        parameters = [copy.deepcopy(p) for i in xrange(len(ring_indices))]
        for i in xrange(len(ring_indices)):
            parameters[i].q = float(q[ring_indices[i]].split()[-1])
            parameters[i].x = x[ring_indices[i]]
            parameters[i].ac = ac[ring_indices[i]]
            parameters[i].v = v[ring_indices[i]]

        # fit each q independently
        np = number_of_processors()
        if (len(ring_indices) < np):
            np = len(ring_indices)
        pool = Pool(processes=np)
        try:
            result.append(pool.map(fit_data, parameters))
            pool.close()
        except Exception:
            pool.terminate()
        finally:
            pool.join()

    output_directory = './fit_' + str(p.fit_order) + '/'
    if (os.path.exists(output_directory) is False):
        os.mkdir(output_directory)