def exercise_two_means_clustering(): data = flex.double((0.21947204867684716, 0.21947204867684716, 0.21947204867684716, 0.21947204867684714)) c = clustering.two_means(data) assert c.cut == 4 # precision limit data = flex.double((1, 1, 1, 1)) c = clustering.two_means(data) assert c.cut == 4 data = flex.double((10, 4, 3, 2, 2, 1)) c = clustering.two_means(data) assert c.cut == 1 data = flex.double((10, 8, 5, 4, 4, 3)) assert clustering.two_means(data).cut == 2 data = flex.double((10, 9, 9, 8, 8, 8)) assert clustering.two_means(data).cut == 3 data = flex.double((1000, 900, 800, 500, 200, 200, 100)) assert clustering.two_means(data).cut == 3 data = flex.double((0.91, 0.29, 0.29, 0.27, 0.27, 0.27, 0.27)) assert clustering.two_means(data).cut == 1 data = flex.double((0.998, 0.449, 0.152, 0.152, 0.151)) clusters = clustering.two_means(data) assert clusters.cut == 2 data = flex.double((0.998, 0.449, 0.152)) clusters = clustering.two_means(data) assert clusters.cut == 1
def centring_translation_peak_sites(self): f = self.f_in_p1 cc_sf = f * f.conjugate().data() / f.sum_sq() cc_map = cc_sf.fft_map(symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.grid_resolution_factor) heights = flex.double() sites = [] cc_map_peaks = cc_map.peak_search(self.search_parameters) zero = mat.zeros(3) for cc_peak_info in itertools.islice(cc_map_peaks, 5): if abs(mat.col(cc_peak_info.site) - zero) < 0.01: continue heights.append(cc_peak_info.height) sites.append(cc_peak_info.site) if not heights: return () clusters = clustering.two_means(heights) if clusters.highest_stat < self.cross_correlation_cutoff_for_centring: return () return sites[:clusters.cut]
def centring_translation_peak_sites(self): f = self.f_in_p1 cc_sf = f * f.conjugate().data() / f.sum_sq() cc_map = cc_sf.fft_map( symmetry_flags=maptbx.use_space_group_symmetry, resolution_factor=self.grid_resolution_factor) heights = flex.double() sites = [] cc_map_peaks = cc_map.peak_search(self.search_parameters) zero = mat.zeros(3) for cc_peak_info in itertools.islice(cc_map_peaks, 5): if abs(mat.col(cc_peak_info.site) - zero) < 0.01: continue heights.append(cc_peak_info.height) sites.append(cc_peak_info.site) if not heights: return () clusters = clustering.two_means(heights) if clusters.highest_stat < self.cross_correlation_cutoff_for_centring: return () return sites[:clusters.cut]