Пример #1
0
def distribute_fc4(fc4_least_atoms,
                   first_disp_atoms,
                   lattice,
                   positions,
                   rotations,
                   translations,
                   symprec,
                   overwrite=True,
                   verbose=False):
    num_atom = len(positions)

    if overwrite:
        fc4 = fc4_least_atoms
    else:
        fc4 = np.zeros((num_atom, num_atom, num_atom, num_atom, 3, 3, 3, 3),
                       dtype='double')

    for i in range(num_atom):
        if i in first_disp_atoms:
            continue

        for atom_index_done in first_disp_atoms:
            rot_num = get_atom_mapping_by_symmetry(positions, i,
                                                   atom_index_done, rotations,
                                                   translations, symprec)
            if rot_num > -1:
                i_rot = atom_index_done
                rot = rotations[rot_num]
                trans = translations[rot_num]
                break

        if rot_num < 0:
            print "Position or symmetry may be wrong."
            raise ValueError

        atom_mapping = np.zeros(num_atom, dtype='intc')
        for j in range(num_atom):
            atom_mapping[j] = get_atom_by_symmetry(positions, rot, trans, j,
                                                   symprec)

        rot_cart_inv = np.array(similarity_transformation(lattice, rot).T,
                                order='C',
                                dtype='double')

        if not (overwrite and i == i_rot):
            if verbose > 1:
                print "  [ %d, x, x, x ] to [ %d, x, x, x ]" % (i_rot + 1,
                                                                i + 1)
                sys.stdout.flush()

            try:
                import anharmonic._phono4py as phono4c
                phono4c.distribute_fc4(fc4, fc4_least_atoms, i, atom_mapping,
                                       rot_cart_inv)

            except ImportError:
                for j in range(num_atom):
                    j_rot = atom_mapping[j]
                    for k in range(num_atom):
                        k_rot = atom_mapping[k]
                        for l in range(num_atom):
                            l_rot = atom_mapping[l]
                            fc4[i, j, k, l] = _fourth_rank_tensor_rotation(
                                rot_cart_inv, fc4[i_rot, j_rot, k_rot, l_rot])

    if not overwrite:
        return fc4
Пример #2
0
def distribute_fc4(fc4,
                   first_disp_atoms,
                   lattice,
                   positions,
                   rotations,
                   translations,
                   symprec,
                   verbose):
    num_atom = len(positions)

    for i in range(num_atom):
        if i in first_disp_atoms:
            continue

        for atom_index_done in first_disp_atoms:
            rot_num = get_atom_mapping_by_symmetry(positions,
                                                   i,
                                                   atom_index_done,
                                                   rotations,
                                                   translations,
                                                   symprec)
            if rot_num > -1:
                i_rot = atom_index_done
                rot = rotations[rot_num]
                trans = translations[rot_num]
                break

        if rot_num < 0:
            print "Position or symmetry may be wrong."
            raise ValueError

        if verbose > 1:
            print "  [ %d, x, x, x ] to [ %d, x, x, x ]" % (i_rot + 1, i + 1)
            sys.stdout.flush()

        atom_mapping = np.zeros(num_atom, dtype='intc')
        for j in range(num_atom):
            atom_mapping[j] = get_atom_by_symmetry(positions,
                                                   rot,
                                                   trans,
                                                   j,
                                                   symprec)
            
        rot_cart_inv = np.double(
            similarity_transformation(lattice, rot).T.copy())

        try:
            import anharmonic._phono4py as phono4c
            phono4c.distribute_fc4(fc4,
                                   i,
                                   atom_mapping,
                                   rot_cart_inv)
        
        except ImportError:
            for j in range(num_atom):
                j_rot = atom_mapping[j]
                for k in range(num_atom):
                    k_rot = atom_mapping[k]
                    for l in range(num_atom):
                        l_rot = atom_mapping[l]
                        fc4[i, j, k, l] = _fourth_rank_tensor_rotation(
                            rot_cart_inv, fc4[i_rot, j_rot, k_rot, l_rot])