Example #1
0
def run():
    show_times = libtbx.utils.show_times()
    from scitbx.python_utils import command_line
    flags = command_line.parse_options(sys.argv[1:], [
        "RandomSeed",
        "Verbose",
    ])
    if (not flags.RandomSeed): random.seed(0)
    assert fftpack.adjust_gridding(13, 5) == 15
    assert fftpack.adjust_gridding(13, 5, 6) == 18
    assert fftpack.adjust_gridding_triple((13, 22, 34), 5) == (15, 24, 36)
    assert fftpack.adjust_gridding_triple((13, 22, 34), 5,
                                          (6, 10, 8)) == (18, 30, 40)
    f = fftpack.factorization(30, False)
    assert f.n() == 30
    assert tuple(f.factors()) == (2, 3, 5)
    test_complex_to_complex(flags.Verbose)
    test_real_to_complex(flags.Verbose)
    test_complex_to_complex_2d(flags.Verbose)
    test_complex_to_complex_3d(flags.Verbose)
    test_real_to_complex_3d(flags.Verbose)
    exercise_real_to_complex_padding_area()
    max_transform_size = 300
    test_comprehensive_cc_1d(max_transform_size)
    test_comprehensive_rc_1d(max_transform_size)
    show_times()
Example #2
0
def run():
  show_times = libtbx.utils.show_times()
  from scitbx.python_utils import command_line
  flags = command_line.parse_options(sys.argv[1:], [
    "RandomSeed",
    "Verbose",
  ])
  if (not flags.RandomSeed): random.seed(0)
  assert fftpack.adjust_gridding(13, 5) == 15
  assert fftpack.adjust_gridding(13, 5, 6) == 18
  assert fftpack.adjust_gridding_triple((13,22,34), 5) == (15,24,36)
  assert fftpack.adjust_gridding_triple((13,22,34), 5, (6,10,8)) == (18,30,40)
  f = fftpack.factorization(30, False)
  assert f.n() == 30
  assert tuple(f.factors()) == (2, 3, 5)
  test_complex_to_complex(flags.Verbose)
  test_real_to_complex(flags.Verbose)
  test_complex_to_complex_2d(flags.Verbose)
  test_complex_to_complex_3d(flags.Verbose)
  test_real_to_complex_3d(flags.Verbose)
  exercise_real_to_complex_padding_area()
  max_transform_size = 300
  test_comprehensive_cc_1d(max_transform_size)
  test_comprehensive_rc_1d(max_transform_size)
  show_times()
Example #3
0
    def __init__(self, max_cell, min_cell=3, params=None, *args, **kwargs):
        """Construct an FFT3D object.

        Args:
            max_cell (float): An estimate of the maximum cell dimension of the primitive
                cell.
            n_points (int): The size of the fft3d grid.
            d_min (float): The high resolution limit in Angstrom for spots to include in
                the initial indexing. If `Auto` then calculated as
                `d_min = 5 * max_cell/n_points`.
            b_iso (float): Apply an isotropic b_factor weight to the points when doing
                the FFT. If `Auto` then calculated as
                `b_iso = -4 * d_min ** 2 * math.log(0.05)`.
            rmsd_cutoff (float): RMSD cutoff applied to the transformed real-space map
                prior to performing the peak search.
            peak_volume_cutoff (float): Only include peaks that are larger than this
                fraction of the volume of the largest peak in the transformed real-space
                map.
            min_cell (float): A conservative lower bound on the minimum possible
                primitive unit cell dimension.
        """
        super(FFT3D, self).__init__(max_cell, params=params, *args, **kwargs)
        n_points = self._params.reciprocal_space_grid.n_points
        self._gridding = fftpack.adjust_gridding_triple(
            (n_points, n_points, n_points), max_prime=5)
        self._n_points = self._gridding[0]
        self._min_cell = min_cell
Example #4
0
    def fft(self):
        if self.params.fft3d.reciprocal_space_grid.d_min is libtbx.Auto:
            # rough calculation of suitable d_min based on max cell
            # see also Campbell, J. (1998). J. Appl. Cryst., 31(3), 407-413.
            # fft_cell should be greater than twice max_cell, so say:
            #   fft_cell = 2.5 * max_cell
            # then:
            #   fft_cell = n_points * d_min/2
            #   2.5 * max_cell = n_points * d_min/2
            # a little bit of rearrangement:
            #   d_min = 5 * max_cell/n_points

            max_cell = self.params.max_cell
            d_min = (5 * max_cell /
                     self.params.fft3d.reciprocal_space_grid.n_points)
            d_spacings = 1 / self.reflections['rlp'].norms()
            self.params.fft3d.reciprocal_space_grid.d_min = max(
                d_min, min(d_spacings))
            logger.info("Setting d_min: %.2f" %
                        self.params.fft3d.reciprocal_space_grid.d_min)
        n_points = self.params.fft3d.reciprocal_space_grid.n_points
        self.gridding = fftpack.adjust_gridding_triple(
            (n_points, n_points, n_points), max_prime=5)
        n_points = self.gridding[0]
        self.map_centroids_to_reciprocal_space_grid()
        self.d_min = self.params.fft3d.reciprocal_space_grid.d_min

        logger.info("Number of centroids used: %i" %
                    ((self.reciprocal_space_grid > 0).count(True)))

        #gb_to_bytes = 1073741824
        #bytes_to_gb = 1/gb_to_bytes
        #(128**3)*8*2*bytes_to_gb
        #0.03125
        #(256**3)*8*2*bytes_to_gb
        #0.25
        #(512**3)*8*2*bytes_to_gb
        #2.0

        fft = fftpack.complex_to_complex_3d(self.gridding)
        grid_complex = flex.complex_double(
            reals=self.reciprocal_space_grid,
            imags=flex.double(self.reciprocal_space_grid.size(), 0))
        grid_transformed = fft.forward(grid_complex)
        #self.grid_real = flex.pow2(flex.abs(grid_transformed))
        self.grid_real = flex.pow2(flex.real(grid_transformed))
        #self.grid_real = flex.pow2(flex.imag(self.grid_transformed))
        del grid_transformed

        if self.params.debug:
            self.debug_write_ccp4_map(map_data=self.grid_real,
                                      file_name="fft3d.map")
        if self.params.fft3d.peak_search == 'flood_fill':
            self.find_peaks()
        elif self.params.fft3d.peak_search == 'clean':
            self.find_peaks_clean()
Example #5
0
  def find_lattices(self):
    if self.params.fft3d.reciprocal_space_grid.d_min is libtbx.Auto:
      # rough calculation of suitable d_min based on max cell
      # see also Campbell, J. (1998). J. Appl. Cryst., 31(3), 407-413.
      # fft_cell should be greater than twice max_cell, so say:
      #   fft_cell = 2.5 * max_cell
      # then:
      #   fft_cell = n_points * d_min/2
      #   2.5 * max_cell = n_points * d_min/2
      # a little bit of rearrangement:
      #   d_min = 5 * max_cell/n_points

      max_cell = self.params.max_cell
      d_min = (
        5 * max_cell / self.params.fft3d.reciprocal_space_grid.n_points)
      d_spacings = 1/self.reflections['rlp'].norms()
      self.params.fft3d.reciprocal_space_grid.d_min = max(
        d_min, min(d_spacings))
      logger.info("Setting d_min: %.2f" %self.params.fft3d.reciprocal_space_grid.d_min)
    n_points = self.params.fft3d.reciprocal_space_grid.n_points
    self.gridding = fftpack.adjust_gridding_triple(
      (n_points,n_points,n_points), max_prime=5)
    n_points = self.gridding[0]
    self.map_centroids_to_reciprocal_space_grid()
    self.d_min = self.params.fft3d.reciprocal_space_grid.d_min

    logger.info("Number of centroids used: %i" %(
      (self.reciprocal_space_grid>0).count(True)))
    self.fft()
    if self.params.debug:
      self.debug_write_ccp4_map(map_data=self.grid_real, file_name="fft3d.map")
    if self.params.fft3d.peak_search == 'flood_fill':
      self.find_peaks()
    elif self.params.fft3d.peak_search == 'clean':
      self.find_peaks_clean()
    if self.params.multiple_lattice_search.cluster_analysis_search:
      self.find_basis_vector_combinations_cluster_analysis()
      self.debug_show_candidate_basis_vectors()
      if self.params.debug_plots:
        self.debug_plot_candidate_basis_vectors()
      crystal_models = self.candidate_crystal_models
      if self.params.multiple_lattice_search.max_lattices is not None:
        crystal_models = \
          crystal_models[:self.params.multiple_lattice_search.max_lattices]
    else:
      self.find_candidate_basis_vectors()
      self.debug_show_candidate_basis_vectors()
      if self.params.debug_plots:
        self.debug_plot_candidate_basis_vectors()
      self.candidate_crystal_models = self.find_candidate_orientation_matrices(
        self.candidate_basis_vectors,
        max_combinations=self.params.basis_vector_combinations.max_try)
      crystal_model, n_indexed = self.choose_best_orientation_matrix(
        self.candidate_crystal_models)
      if crystal_model is not None:
        crystal_models = [crystal_model]
      else:
        crystal_models = []
    experiments = ExperimentList()
    for cm in crystal_models:
      for imageset in self.imagesets:
        experiments.append(Experiment(imageset=imageset,
                                      beam=imageset.get_beam(),
                                      detector=imageset.get_detector(),
                                      goniometer=imageset.get_goniometer(),
                                      scan=imageset.get_scan(),
                                      crystal=cm))
    return experiments