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 tolerance = symprec for _ in range(20): is_found = phonoc.compute_permutation(permutation, lattice, positions_a, positions_b, tolerance) if is_found: break else: tolerance *= 1.05 if tolerance / symprec > 1.5: import warnings msg = ("Crystal structure is distorted in a tricky way so that " "phonopy could not handle the crystal symmetry properly. " "It is recommended to symmetrize crystal structure well " "and then re-start phonon calculation from scratch.") warnings.warn(msg) 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
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
def _compute_permutation_c( positions_a, # scaled positions positions_b, lattice, # column vectors symprec): 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