use distance matrix in Structure.is_valid