def label_nearest_point(self): ann = AnnAdaptorSelfInclude(self.points.as_double(), 3) ann.query(self.rotation_center) i = ann.nn[0] gltbx.fonts.ucs_bitmap_8x13.setup_call_lists() gl.glDisable(gl.GL_LIGHTING) gl.glColor3f(1.0, 1.0, 1.0) gl.glLineWidth(1.0) xyz = self.points_data["xyz"][i] exp_id = self.points_data["id"][i] panel = self.points_data["panel"][i] d_spacing = self.points_data["d_spacing"][i] label = (f"id: {exp_id}; panel: {panel}\n" f"xyz: {xyz[0]:.1f} {xyz[1]:.1f} {xyz[2]:.1f}\n" f"res: {d_spacing:.2f} Angstrom") if "miller_index" in self.points_data and exp_id != -1: hkl = self.points_data["miller_index"][i] label += f"\nhkl: {hkl}" line_spacing = round(gltbx.fonts.ucs_bitmap_8x13.height()) for j, string in enumerate(label.splitlines()): gl.glRasterPos3f(*self.points[i]) gl.glBitmap(0, 0, 0.0, 0.0, line_spacing, -j * line_spacing, b" ") gltbx.fonts.ucs_bitmap_8x13.render_string(string)
def match(a, b, max_separation=2, key="xyzobs.px.value", scale=(1, 1, 1)): """Match reflections from list a and list b, returning tuple of flex.size_t indices, optionally specifying the maximum distance and key to search on (which is assumed to be a 3-vector column). Can also apply relative scales to the vectors before matching in case e.g. very wide or very fine slicing.""" xyz_a = a[key] xyz_b = b[key] if scale != (1, 1, 1): x, y, z = xyz_a.parts() x *= scale[0] y *= scale[1] z *= scale[2] xyz_a = flex.vec3_double(x, y, z) x, y, z = xyz_b.parts() x *= scale[0] y *= scale[1] z *= scale[2] xyz_b = flex.vec3_double(x, y, z) a = xyz_a.as_double().as_1d() b = xyz_b.as_double().as_1d() ann = AnnAdaptorSelfInclude(a, 3) ann.query(b) mm = flex.size_t(range(xyz_b.size())) nn, distance = ann.nn, flex.sqrt(ann.distances) sel = distance <= max_separation mm = mm.select(sel) nn = nn.select(sel) distance = distance.select(sel) return nn, mm, distance
def excercise_nearest_neighbor(): data = data_from_files() A = AnnAdaptor(data, 2) # construct k-d tree for reference set A.query(data) # find nearest neighbors of query points for i in range(len(A.nn)): #print "Neighbor of (%7.1f,%7.1f), index %6d distance %4.1f"%( #data[2*i],data[2*i+1],A.nn[i],math.sqrt(A.distances[i])) assert A.nn[i] != i A = AnnAdaptorSelfInclude(data, 2) # construct k-d tree for reference set A.query(data) # find nearest neighbors of query points for i in range(len(A.nn)): #print "Neighbor of (%7.1f,%7.1f), index %6d distance %4.1f"%( #data[2*i],data[2*i+1],A.nn[i],math.sqrt(A.distances[i])) assert A.nn[i] == i
def check_memory(): data = data_from_files() for x in range(1000): AnnAdaptorSelfInclude(data, 2).query(data)