Example #1
0
def create_phono3py_force_constants(phono3py, phonon_supercell_matrix,
                                    settings, read_fc3, read_fc2, tsym_type,
                                    symmetrize_fc3_r, symmetrize_fc3_q,
                                    symmetrize_fc2, input_filename,
                                    output_filename, log_level):
    if log_level:
        show_phono3py_force_constants_settings(read_fc3, read_fc2, tsym_type,
                                               symmetrize_fc3_r,
                                               symmetrize_fc3_q,
                                               symmetrize_fc2, settings)

    # fc3
    if (settings.get_is_joint_dos()
            or (settings.get_is_isotope()
                and not (settings.get_is_bterta() or settings.get_is_lbte()))
            or settings.get_read_gamma() or settings.get_read_amplitude()
            or settings.get_constant_averaged_pp_interaction() is not None):
        pass
    else:
        if read_fc3:  # Read fc3.hdf5
            if input_filename is None:
                filename = 'fc3.hdf5'
            else:
                filename = 'fc3.' + input_filename + '.hdf5'
            file_exists(filename, log_level)
            if log_level:
                print("Reading fc3 from %s" % filename)
            fc3 = read_fc3_from_hdf5(filename=filename)
            phono3py.set_fc3(fc3)
        else:  # fc3 from FORCES_THIRD and FORCES_SECOND
            _create_phono3py_fc3(phono3py, tsym_type, symmetrize_fc3_r,
                                 symmetrize_fc2,
                                 settings.get_cutoff_fc3_distance(),
                                 input_filename, output_filename, log_level)
        if log_level:
            show_drift_fc3(phono3py.get_fc3())

    # fc2
    if read_fc2:
        if input_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + input_filename + '.hdf5'
        file_exists(filename, log_level)
        if log_level:
            print("Reading fc2 from %s" % filename)
        phonon_supercell = phono3py.get_phonon_supercell()
        phonon_fc2 = read_fc2_from_hdf5(filename=filename)
        if phonon_fc2.shape[0] != phonon_supercell.get_number_of_atoms():
            print("Matrix shape of fc2 doesn't agree with supercell.")
            if log_level:
                print_error()
            sys.exit(1)

        phono3py.set_fc2(phonon_fc2)
    else:
        if log_level:
            print("Solving fc2")

        if phonon_supercell_matrix is None:
            if phono3py.get_fc2() is None:
                _create_phono3py_fc2(phono3py, tsym_type, symmetrize_fc2,
                                     input_filename, log_level)
        else:
            _create_phono3py_phonon_fc2(phono3py, tsym_type, symmetrize_fc2,
                                        input_filename, log_level)
        if output_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + output_filename + '.hdf5'
        if log_level:
            print("Writing fc2 to %s" % filename)
        write_fc2_to_hdf5(phono3py.get_fc2(), filename=filename)

    if log_level:
        show_drift_force_constants(phono3py.get_fc2(), name='fc2')
Example #2
0
def create_phono3py_force_constants(phono3py,
                                    phonon_supercell_matrix,
                                    settings,
                                    energy_to_eV=None,
                                    distance_to_A=None,
                                    input_filename=None,
                                    output_filename=None,
                                    log_level=1):
    read_fc3 = settings.get_read_fc3()
    read_fc2 = settings.get_read_fc2()
    symmetrize_fc3_r = settings.get_is_symmetrize_fc3_r()
    symmetrize_fc3_q = settings.get_is_symmetrize_fc3_q()
    symmetrize_fc2 = settings.get_is_symmetrize_fc2()
    if settings.get_is_translational_symmetry():
        tsym_type = 1
    elif settings.get_tsym_type() > 0:
        tsym_type = settings.get_tsym_type()
    else:
        tsym_type = 0

    if log_level:
        show_phono3py_force_constants_settings(read_fc3, read_fc2, tsym_type,
                                               symmetrize_fc3_r,
                                               symmetrize_fc3_q,
                                               symmetrize_fc2, settings)

    # fc3
    if (settings.get_is_joint_dos()
            or (settings.get_is_isotope()
                and not (settings.get_is_bterta() or settings.get_is_lbte()))
            or settings.get_read_gamma() or settings.get_read_amplitude()
            or settings.get_constant_averaged_pp_interaction() is not None):
        pass
    else:
        if read_fc3:  # Read fc3.hdf5
            if input_filename is None:
                filename = 'fc3.hdf5'
            else:
                filename = 'fc3.' + input_filename + '.hdf5'
            file_exists(filename, log_level)
            if log_level:
                print("Reading fc3 from %s" % filename)
            fc3 = read_fc3_from_hdf5(filename=filename)
            num_atom = phono3py.get_supercell().get_number_of_atoms()
            if fc3.shape[0] != num_atom:
                print("Matrix shape of fc3 doesn't agree with supercell size.")
                if log_level:
                    print_error()
                sys.exit(1)
            phono3py.set_fc3(fc3)
        else:  # fc3 from FORCES_FC3
            if not _create_phono3py_fc3(
                    phono3py, energy_to_eV, distance_to_A, tsym_type,
                    symmetrize_fc3_r, symmetrize_fc2,
                    settings.get_cutoff_fc3_distance(), input_filename,
                    output_filename, log_level):
                print("fc3 was not created properly.")
                if log_level:
                    print_error()
                sys.exit(1)
        if log_level:
            show_drift_fc3(phono3py.get_fc3())

    # fc2
    if read_fc2:
        if input_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + input_filename + '.hdf5'
        file_exists(filename, log_level)
        if log_level:
            print("Reading fc2 from %s" % filename)
        num_atom = phono3py.get_phonon_supercell().get_number_of_atoms()
        phonon_fc2 = read_fc2_from_hdf5(filename=filename)
        if phonon_fc2.shape[0] != num_atom:
            print("Matrix shape of fc2 doesn't agree with supercell size.")
            if log_level:
                print_error()
            sys.exit(1)

        phono3py.set_fc2(phonon_fc2)
    else:
        if log_level:
            print("Solving fc2")

        if phonon_supercell_matrix is None:
            if phono3py.get_fc2() is None:
                if not _create_phono3py_fc2(
                        phono3py, energy_to_eV, distance_to_A, tsym_type,
                        symmetrize_fc2, input_filename, log_level):
                    print("fc2 was not created properly.")
                    if log_level:
                        print_error()
                    sys.exit(1)

        else:
            if not _create_phono3py_phonon_fc2(
                    phono3py, energy_to_eV, distance_to_A, tsym_type,
                    symmetrize_fc2, input_filename, log_level):
                print("fc2 was not created properly.")
                if log_level:
                    print_error()
                sys.exit(1)
        if output_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + output_filename + '.hdf5'
        if log_level:
            print("Writing fc2 to %s" % filename)
        write_fc2_to_hdf5(phono3py.get_fc2(), filename=filename)

    if log_level:
        show_drift_force_constants(phono3py.get_fc2(), name='fc2')
def create_phono3py_force_constants(phono3py,
                                    phonon_supercell_matrix,
                                    settings,
                                    energy_to_eV=None,
                                    distance_to_A=None,
                                    input_filename=None,
                                    output_filename=None,
                                    log_level=1):
    read_fc3 = settings.get_read_fc3()
    read_fc2 = settings.get_read_fc2()
    symmetrize_fc3_r = settings.get_is_symmetrize_fc3_r()
    symmetrize_fc3_q = settings.get_is_symmetrize_fc3_q()
    symmetrize_fc2 = settings.get_is_symmetrize_fc2()
    if settings.get_is_translational_symmetry():
        tsym_type = 1
    elif settings.get_tsym_type() > 0:
        tsym_type = settings.get_tsym_type()
    else:
        tsym_type = 0

    if log_level:
        show_phono3py_force_constants_settings(read_fc3,
                                               read_fc2,
                                               tsym_type,
                                               symmetrize_fc3_r,
                                               symmetrize_fc3_q,
                                               symmetrize_fc2,
                                               settings)

    # fc3
    if (settings.get_is_joint_dos() or
        (settings.get_is_isotope() and
         not (settings.get_is_bterta() or settings.get_is_lbte())) or
        settings.get_read_gamma() or
        settings.get_read_amplitude() or
        settings.get_constant_averaged_pp_interaction() is not None):
        pass
    else:
        if read_fc3: # Read fc3.hdf5
            if input_filename is None:
                filename = 'fc3.hdf5'
            else:
                filename = 'fc3.' + input_filename + '.hdf5'
            file_exists(filename, log_level)
            if log_level:
                print("Reading fc3 from %s" % filename)
            fc3 = read_fc3_from_hdf5(filename=filename)
            num_atom = phono3py.get_supercell().get_number_of_atoms()
            if fc3.shape[0] != num_atom:
                print("Matrix shape of fc3 doesn't agree with supercell size.")
                if log_level:
                    print_error()
                sys.exit(1)
            phono3py.set_fc3(fc3)
        else: # fc3 from FORCES_FC3
            if not _create_phono3py_fc3(phono3py,
                                        energy_to_eV,
                                        distance_to_A,
                                        tsym_type,
                                        symmetrize_fc3_r,
                                        symmetrize_fc2,
                                        settings.get_cutoff_fc3_distance(),
                                        input_filename,
                                        output_filename,
                                        log_level):
                    print("fc3 was not created properly.")
                    if log_level:
                        print_error()
                    sys.exit(1)
        if log_level:
            show_drift_fc3(phono3py.get_fc3())
    
    # fc2
    if read_fc2:
        if input_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + input_filename + '.hdf5'
        file_exists(filename, log_level)
        if log_level:
            print("Reading fc2 from %s" % filename)
        num_atom = phono3py.get_phonon_supercell().get_number_of_atoms()
        phonon_fc2 = read_fc2_from_hdf5(filename=filename)
        if phonon_fc2.shape[0] != num_atom:
            print("Matrix shape of fc2 doesn't agree with supercell size.")
            if log_level:
                print_error()
            sys.exit(1)
        
        phono3py.set_fc2(phonon_fc2)
    else:
        if log_level:
            print("Solving fc2")
            
        if phonon_supercell_matrix is None:
            if phono3py.get_fc2() is None:
                if not _create_phono3py_fc2(phono3py,
                                            energy_to_eV,
                                            distance_to_A,
                                            tsym_type,
                                            symmetrize_fc2,
                                            input_filename,
                                            log_level):
                    print("fc2 was not created properly.")
                    if log_level:
                        print_error()
                    sys.exit(1)

        else:
            if not _create_phono3py_phonon_fc2(phono3py,
                                               energy_to_eV,
                                               distance_to_A,
                                               tsym_type,
                                               symmetrize_fc2,
                                               input_filename,
                                               log_level):
                    print("fc2 was not created properly.")
                    if log_level:
                        print_error()
                    sys.exit(1)
        if output_filename is None:
            filename = 'fc2.hdf5'
        else:
            filename = 'fc2.' + output_filename + '.hdf5'
        if log_level:
            print("Writing fc2 to %s" % filename)
        write_fc2_to_hdf5(phono3py.get_fc2(), filename=filename)
    
    if log_level:    
        show_drift_force_constants(phono3py.get_fc2(), name='fc2')