Using the mapping θ -1 (φ(v r )), we now aim to determine the optimal alignment (rotation and translation) of the replacement fragment onto the substructure of the parent crystal that matched the query fragment. For this task, we rely on labeled point cloud representations to specify the geometry in which the replacement fragment is installed. First, we center the D coordinates of the (i) replacement fragment and (ii) the corresponding substructure of the parent structure at the origin of a Cartesian coordinate system. If the substructure of the parent is split across a periodic boundary, we reconstruct it using the nearest images of atoms so that Euclidean distance is equal to periodic distance. Let x v ∈ R 3 be the centered D coordinates of the atom represented by node v ∈ V p ∪ V r of the graph of the parent substructure or replacement fragment. Second, we find the 3×3 orthogonal (rotation) matrix Q opt that optimally rotates the replacement fragment about the origin to align it with the matching parent substructure by solving the orthogonal Procrustes problem [ ]: