Example #1
0
    def find_peaks(self):
        grid_real_binary = self.grid_real.deep_copy()
        rmsd = math.sqrt(
            flex.mean(
                flex.pow2(grid_real_binary.as_1d() -
                          flex.mean(grid_real_binary.as_1d()))))
        grid_real_binary.set_selected(
            grid_real_binary < (self.params.rmsd_cutoff) * rmsd, 0)
        grid_real_binary.as_1d().set_selected(grid_real_binary.as_1d() > 0, 1)
        grid_real_binary = grid_real_binary.iround()
        from cctbx import masks
        flood_fill = masks.flood_fill(grid_real_binary, self.fft_cell)
        if flood_fill.n_voids() < 4:
            # Require at least peak at origin and one peak for each basis vector
            raise Sorry(
                "Indexing failed: fft3d peak search failed to find sufficient number of peaks."
            )
        # the peak at the origin might have a significantly larger volume than the
        # rest so exclude this peak from determining maximum volume
        isel = (flood_fill.grid_points_per_void() > int(
            self.params.fft3d.peak_volume_cutoff *
            flex.max(flood_fill.grid_points_per_void()[1:]))).iselection()

        if self.params.optimise_initial_basis_vectors:
            self.volumes = flood_fill.grid_points_per_void().select(isel)
            sites_cart = flood_fill.centres_of_mass_cart().select(isel)
            sites_cart_optimised = optimise_basis_vectors(
                self.reflections['rlp'].select(
                    self.reflections_used_for_indexing), sites_cart)

            self.sites = self.fft_cell.fractionalize(sites_cart_optimised)

            diffs = (sites_cart_optimised - sites_cart)
            norms = diffs.norms()
            flex.min_max_mean_double(norms).show()
            perm = flex.sort_permutation(norms, reverse=True)
            for p in perm[:10]:
                logger.debug(sites_cart[p], sites_cart_optimised[p], norms[p])

            # only use those vectors which haven't shifted too far from starting point
            sel = norms < (5 * self.fft_cell.parameters()[0] /
                           self.gridding[0])
            self.sites = self.sites.select(sel)
            self.volumes = self.volumes.select(sel)
            #diff = (self.sites - flood_fill.centres_of_mass_frac().select(isel))
            #flex.min_max_mean_double(diff.norms()).show()

        else:
            self.sites = flood_fill.centres_of_mass_frac().select(isel)
            self.volumes = flood_fill.grid_points_per_void().select(isel)
Example #2
0
 def extract_from_scatterers_in_place(self, scatterers, tolerance=1.e-4):
     fps = flex.double()
     fdps = flex.double()
     fps.reserve(self.iselection.size())
     fdps.reserve(fps.size())
     for i_seq in self.iselection:
         fps.append(scatterers[i_seq].fp)
         fdps.append(scatterers[i_seq].fdp)
         for values, label in [(fps, "f_prime"), (fdps, "f_double_prime")]:
             stats = flex.min_max_mean_double(values)
             if (stats.max - stats.min <= tolerance):
                 setattr(self, label, stats.mean)
             else:
                 msg = [
                     "Anomalous scatterer group with significantly different %s:"
                     % label
                 ]
                 if (self.selection_string is not None):
                     msg.append("  Selection: %s" %
                                show_string(self.selection_string))
                 msg.append("  Number of selected scatterers: %d" % stats.n)
                 s = StringIO()
                 stats.show(out=s, prefix="  %s " % label, show_n=False)
                 msg.extend(s.getvalue().splitlines())
                 msg.append("  tolerance: %.6g" % tolerance)
                 raise RuntimeError("\n".join(msg))
Example #3
0
File: fft3d.py Project: dials/dials
  def find_peaks(self):
    grid_real_binary = self.grid_real.deep_copy()
    rmsd = math.sqrt(
      flex.mean(flex.pow2(grid_real_binary.as_1d()-flex.mean(grid_real_binary.as_1d()))))
    grid_real_binary.set_selected(grid_real_binary < (self.params.rmsd_cutoff)*rmsd, 0)
    grid_real_binary.as_1d().set_selected(grid_real_binary.as_1d() > 0, 1)
    grid_real_binary = grid_real_binary.iround()
    from cctbx import masks
    flood_fill = masks.flood_fill(grid_real_binary, self.fft_cell)
    if flood_fill.n_voids() < 4:
      # Require at least peak at origin and one peak for each basis vector
      raise Sorry("Indexing failed: fft3d peak search failed to find sufficient number of peaks.")
    # the peak at the origin might have a significantly larger volume than the
    # rest so exclude this peak from determining maximum volume
    isel = (flood_fill.grid_points_per_void() > int(
        self.params.fft3d.peak_volume_cutoff * flex.max(
          flood_fill.grid_points_per_void()[1:]))).iselection()

    if self.params.optimise_initial_basis_vectors:
      self.volumes = flood_fill.grid_points_per_void().select(isel)
      sites_cart = flood_fill.centres_of_mass_cart().select(isel)
      sites_cart_optimised = optimise_basis_vectors(
        self.reflections['rlp'].select(self.reflections_used_for_indexing),
        sites_cart)

      self.sites = self.fft_cell.fractionalize(sites_cart_optimised)

      diffs = (sites_cart_optimised - sites_cart)
      norms = diffs.norms()
      flex.min_max_mean_double(norms).show()
      perm = flex.sort_permutation(norms, reverse=True)
      for p in perm[:10]:
        logger.debug(sites_cart[p], sites_cart_optimised[p], norms[p])

      # only use those vectors which haven't shifted too far from starting point
      sel = norms < (5 * self.fft_cell.parameters()[0]/self.gridding[0])
      self.sites = self.sites.select(sel)
      self.volumes = self.volumes.select(sel)
      #diff = (self.sites - flood_fill.centres_of_mass_frac().select(isel))
      #flex.min_max_mean_double(diff.norms()).show()

    else:
      self.sites = flood_fill.centres_of_mass_frac().select(isel)
      self.volumes = flood_fill.grid_points_per_void().select(isel)
Example #4
0
 def extract_from_scatterers_in_place(self, scatterers, tolerance=1.0e-4):
     fps = flex.double()
     fdps = flex.double()
     fps.reserve(self.iselection.size())
     fdps.reserve(fps.size())
     for i_seq in self.iselection:
         fps.append(scatterers[i_seq].fp)
         fdps.append(scatterers[i_seq].fdp)
         for values, label in [(fps, "f_prime"), (fdps, "f_double_prime")]:
             stats = flex.min_max_mean_double(values)
             if stats.max - stats.min <= tolerance:
                 setattr(self, label, stats.mean)
             else:
                 msg = ["Anomalous scatterer group with significantly different %s:" % label]
                 if self.selection_string is not None:
                     msg.append("  Selection: %s" % show_string(self.selection_string))
                 msg.append("  Number of selected scatterers: %d" % stats.n)
                 s = StringIO()
                 stats.show(out=s, prefix="  %s " % label, show_n=False)
                 msg.extend(s.getvalue().splitlines())
                 msg.append("  tolerance: %.6g" % tolerance)
                 raise RuntimeError("\n".join(msg))