Exemple #1
0
def solve_fc3(fc3,
              first_atom_num,
              supercell,
              site_symmetry,
              displacements_first,
              delta_fc2s,
              symprec,
              pinv="numpy",
              verbose=False):

    if verbose:
        text = "Solving fc3[ %d, x, x ] with " % (first_atom_num + 1)
        if len(displacements_first) > 1:
            text += "displacements:"
        else:
            text += "a displacement:"
        print(text)
        for i, v in enumerate(displacements_first):
            print("    [%7.4f %7.4f %7.4f]" % tuple(v))
            sys.stdout.flush()
        if verbose > 2:
            print("  Site symmetry:")
            for i, v in enumerate(site_symmetry):
                print("    [%2d %2d %2d] #%2d" % tuple(list(v[0]) + [i + 1]))
                print("    [%2d %2d %2d]" % tuple(v[1]))
                print("    [%2d %2d %2d]\n" % tuple(v[2]))
                sys.stdout.flush()

    lattice = supercell.get_cell().T
    site_sym_cart = [
        similarity_transformation(lattice, sym) for sym in site_symmetry
    ]
    num_atom = supercell.get_number_of_atoms()
    positions = supercell.get_scaled_positions()
    pos_center = positions[first_atom_num].copy()
    positions -= pos_center
    rot_map_syms = get_positions_sent_by_rot_inv(positions, site_symmetry,
                                                 symprec)

    rot_disps = get_rotated_displacement(displacements_first, site_sym_cart)

    if pinv == "numpy":
        inv_U = np.linalg.pinv(rot_disps)
    else:
        try:
            import phonopy._lapackepy as lapackepy
            inv_U = np.zeros((rot_disps.shape[1], rot_disps.shape[0]),
                             dtype='double')
            lapackepy.pinv(inv_U, rot_disps, 1e-13)
        except ImportError:
            inv_U = np.linalg.pinv(rot_disps)

    for (i, j) in list(np.ndindex(num_atom, num_atom)):
        fc3[first_atom_num, i, j] = np.dot(
            inv_U,
            _get_rotated_fc2s(i, j, delta_fc2s, rot_map_syms,
                              site_sym_cart)).reshape(3, 3, 3)
Exemple #2
0
    def _pinv(self, matrix):
        try:
            import phonopy._lapackepy as lapackepy
            mat_shape = matrix.shape
            inv_matrix = np.zeros((mat_shape[1], mat_shape[0]), dtype='double')
            lapackepy.pinv(inv_matrix, matrix, self._pinv_cutoff)
        except ImportError:
            inv_matrix = np.linalg.pinv(matrix, rcond=self._pinv_cutoff)

        return inv_matrix
Exemple #3
0
def solve_fc3(fc3,
              first_atom_num,
              supercell,
              site_symmetry,
              displacements_first,
              delta_fc2s,
              symprec,
              pinv="numpy",
              verbose=False):

    if verbose:
        text = "Solving fc3[ %d, x, x ] with " % (first_atom_num + 1)
        if len(displacements_first) > 1:
            text += "displacements:"
        else:
            text += "a displacement:"
        print(text)
        for i, v in enumerate(displacements_first):
            print("    [%7.4f %7.4f %7.4f]" % tuple(v))
            sys.stdout.flush()
        if verbose > 2:
            print("  Site symmetry:")
            for i, v in enumerate(site_symmetry):
                print("    [%2d %2d %2d] #%2d" % tuple(list(v[0])+[i + 1]))
                print("    [%2d %2d %2d]" % tuple(v[1]))
                print("    [%2d %2d %2d]\n" % tuple(v[2]))
                sys.stdout.flush()

    lattice = supercell.get_cell().T
    site_sym_cart = [similarity_transformation(lattice, sym)
                     for sym in site_symmetry]
    num_atom = supercell.get_number_of_atoms()
    positions = supercell.get_scaled_positions()
    pos_center = positions[first_atom_num].copy()
    positions -= pos_center
    rot_map_syms = get_positions_sent_by_rot_inv(positions,
                                                 site_symmetry,
                                                 symprec)

    rot_disps = get_rotated_displacement(displacements_first, site_sym_cart)

    if pinv == "numpy":
        inv_U = np.linalg.pinv(rot_disps)
    else:
        try:
            import phonopy._lapackepy as lapackepy
            inv_U = np.zeros((rot_disps.shape[1], rot_disps.shape[0]),
                             dtype='double')
            lapackepy.pinv(inv_U, rot_disps, 1e-13)
        except ImportError:
            inv_U = np.linalg.pinv(rot_disps)

    for (i, j) in list(np.ndindex(num_atom, num_atom)):
        fc3[first_atom_num, i, j] = np.dot(inv_U, _get_rotated_fc2s(
                i, j, delta_fc2s, rot_map_syms, site_sym_cart)).reshape(3, 3, 3)