  Finding an optimal match between two different crystal structures underpins
many important materials science problems, including describing solid-solid
phase transitions, developing models for interface and grain boundary
structures. In this work, we formulate the matching of crystals as an
optimization problem where the goal is to find the alignment and the
atom-to-atom map that minimize a given cost function such as the Euclidean
distance between the atoms. We construct an algorithm that directly solves this
problem for large finite portions of the crystals and retrieves the periodicity
of the match subsequently. We demonstrate its capacity to describe
transformation pathways between known polymorphs and to reproduce
experimentally realized structures of semi-coherent interfaces. Additionally,
from our findings we define a rigorous metric for measuring distances between
crystal structures that can be used to properly quantify their geometric
(Euclidean) closeness.
