Version of '_compute_permutation_for_rotation' which just directly
    calls the C function, without any conditioning of the data.
    Skipping the conditioning step makes this EXTREMELY slow on large
    structures.

def _compute_permutation_c(positions_a,  # scaled positions
                           positions_b,
                           lattice,  # column vectors
                           symprec):
    """Version of '_compute_permutation_for_rotation' which just directly
    calls the C function, without any conditioning of the data.
    Skipping the conditioning step makes this EXTREMELY slow on large
    structures.

    """

    permutation = np.zeros(shape=(len(positions_a),), dtype='intc')

    def permutation_error():
        raise ValueError("Input forces are not enough to calculate force constants, "
                         "or something wrong (e.g. crystal structure does not match).")

    try:
        import phonopy._phonopy as phonoc
        is_found = phonoc.compute_permutation(permutation,
                                              lattice,
                                              positions_a,
                                              positions_b,
                                              symprec)

        if not is_found:
            permutation_error()

    except ImportError:
        for i, pos_b in enumerate(positions_b):
            diffs = positions_a - pos_b
            diffs -= np.rint(diffs)
            diffs = np.dot(diffs, lattice.T)

            possible_j = np.nonzero(
                np.sqrt(np.sum(diffs**2, axis=1)) < symprec)[0]
            if len(possible_j) != 1:
                permutation_error()

            permutation[i] = possible_j[0]

        if -1 in permutation:
            permutation_error()

    return permutation