예제 #1
0
def store_force_constants(phono3py, settings, ph3py_yaml, physical_units,
                          input_filename, output_filename, load_phono3py_yaml,
                          log_level):
    if load_phono3py_yaml:
        if log_level:
            print("-" * 29 + " Force constants " + "-" * 30)

        (fc_calculator,
         fc_calculator_options) = get_fc_calculator_params(settings)

        read_fc = set_dataset_and_force_constants(
            phono3py,
            ph3py_yaml=ph3py_yaml,
            fc_calculator=fc_calculator,
            fc_calculator_options=fc_calculator_options,
            symmetrize_fc=settings.fc_symmetry,
            is_compact_fc=settings.is_compact_fc,
            log_level=log_level)

        if log_level:
            if phono3py.fc3 is None:
                print("fc3 could not be obtained.")
            if phono3py.fc2 is None:
                print("fc2 could not be obtained.")
        if phono3py.fc3 is None or phono3py.fc2 is None:
            print_error()
            sys.exit(1)

        if not read_fc['fc3']:
            write_fc3_to_hdf5(phono3py.fc3,
                              p2s_map=phono3py.primitive.p2s_map,
                              compression=settings.hdf5_compression)
            if log_level:
                print("fc3 was written into \"fc3.hdf5\".")
        if not read_fc['fc2']:
            write_fc2_to_hdf5(phono3py.fc2,
                              p2s_map=phono3py.primitive.p2s_map,
                              physical_unit='eV/angstrom^2',
                              compression=settings.hdf5_compression)
            if log_level:
                print("fc2 was written into \"fc2.hdf5\".")
    else:
        create_phono3py_force_constants(phono3py,
                                        settings,
                                        ph3py_yaml=ph3py_yaml,
                                        input_filename=input_filename,
                                        output_filename=output_filename,
                                        log_level=log_level)
예제 #2
0
def create_phono3py_force_constants(
    phono3py,
    settings,
    ph3py_yaml=None,
    input_filename=None,
    output_filename=None,
    log_level=1,
):
    """Read or calculate force constants."""
    if settings.fc_calculator is None:
        symmetrize_fc3r = settings.is_symmetrize_fc3_r or settings.fc_symmetry
        symmetrize_fc2 = settings.is_symmetrize_fc2 or settings.fc_symmetry
    else:  # Rely on fc calculator the symmetrization of fc.
        symmetrize_fc2 = False
        symmetrize_fc3r = False

    if log_level:
        show_phono3py_force_constants_settings(settings)

    #######
    # fc3 #
    #######
    if (settings.is_joint_dos or
        (settings.is_isotope and not (settings.is_bterta or settings.is_lbte))
            or settings.read_gamma or settings.read_pp
            or (not settings.is_bterta and settings.write_phonon)
            or settings.constant_averaged_pp_interaction is not None):
        pass
    else:
        if settings.read_fc3:
            _read_phono3py_fc3(phono3py, symmetrize_fc3r, input_filename,
                               log_level)
        else:  # fc3 from FORCES_FC3 or ph3py_yaml
            _create_phono3py_fc3(
                phono3py,
                ph3py_yaml,
                symmetrize_fc3r,
                input_filename,
                settings.is_compact_fc,
                settings.cutoff_pair_distance,
                settings.fc_calculator,
                settings.fc_calculator_options,
                log_level,
            )
            if output_filename is None:
                filename = "fc3.hdf5"
            else:
                filename = "fc3." + output_filename + ".hdf5"
            if log_level:
                print('Writing fc3 to "%s".' % filename)
            write_fc3_to_hdf5(
                phono3py.fc3,
                filename=filename,
                p2s_map=phono3py.primitive.p2s_map,
                compression=settings.hdf5_compression,
            )

        cutoff_distance = settings.cutoff_fc3_distance
        if cutoff_distance is not None and cutoff_distance > 0:
            if log_level:
                print("Cutting-off fc3 by zero (cut-off distance: %f)" %
                      cutoff_distance)
            phono3py.cutoff_fc3_by_zero(cutoff_distance)

        if log_level:
            show_drift_fc3(phono3py.fc3, primitive=phono3py.primitive)

    #######
    # fc2 #
    #######
    phonon_primitive = phono3py.phonon_primitive
    p2s_map = phonon_primitive.p2s_map
    if settings.read_fc2:
        _read_phono3py_fc2(phono3py, symmetrize_fc2, input_filename, log_level)
    else:
        if phono3py.phonon_supercell_matrix is None:
            if settings.fc_calculator == "alm" and phono3py.fc2 is not None:
                if log_level:
                    print("fc2 that was fit simultaneously with fc3 "
                          "by ALM is used.")
            else:
                _create_phono3py_fc2(
                    phono3py,
                    ph3py_yaml,
                    symmetrize_fc2,
                    input_filename,
                    settings.is_compact_fc,
                    settings.fc_calculator,
                    settings.fc_calculator_options,
                    log_level,
                )
        else:
            _create_phono3py_phonon_fc2(
                phono3py,
                ph3py_yaml,
                symmetrize_fc2,
                input_filename,
                settings.is_compact_fc,
                settings.fc_calculator,
                settings.fc_calculator_options,
                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.fc2,
            filename=filename,
            p2s_map=p2s_map,
            physical_unit="eV/angstrom^2",
            compression=settings.hdf5_compression,
        )

    if log_level:
        show_drift_force_constants(phono3py.fc2,
                                   primitive=phonon_primitive,
                                   name="fc2")
예제 #3
0
def create_phono3py_force_constants(phono3py,
                                    phonon_supercell_matrix,
                                    settings,
                                    force_to_eVperA=None,
                                    distance_to_A=None,
                                    compression=None,
                                    input_filename=None,
                                    output_filename=None,
                                    log_level=1):
    if settings.get_fc_calculator() is None:
        symmetrize_fc3r = (settings.get_is_symmetrize_fc3_r()
                           or settings.get_fc_symmetry())
        symmetrize_fc2 = (settings.get_is_symmetrize_fc2()
                          or settings.get_fc_symmetry())
    else:  # Rely on fc calculator the symmetrization of fc.
        symmetrize_fc2 = False
        symmetrize_fc3r = False

    if log_level:
        show_phono3py_force_constants_settings(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_pp()
            or settings.get_write_phonon()
            or settings.get_constant_averaged_pp_interaction() is not None):
        pass
    else:
        if settings.get_read_fc3():  # Read fc3.hdf5
            _read_phono3py_fc3(phono3py, symmetrize_fc3r, input_filename,
                               log_level)
        else:  # fc3 from FORCES_FC3
            if not _create_phono3py_fc3(
                    phono3py, force_to_eVperA, distance_to_A, symmetrize_fc3r,
                    symmetrize_fc2, input_filename, output_filename,
                    settings.get_is_compact_fc(),
                    settings.get_cutoff_pair_distance(),
                    settings.get_fc_calculator(),
                    settings.get_fc_calculator_options(), compression,
                    log_level):

                print("fc3 was not created properly.")
                if log_level:
                    print_error()
                sys.exit(1)

        cutoff_distance = settings.get_cutoff_fc3_distance()
        if cutoff_distance is not None and cutoff_distance > 0:
            if log_level:
                print("Cutting-off fc3 by zero (cut-off distance: %f)" %
                      cutoff_distance)
            phono3py.cutoff_fc3_by_zero(cutoff_distance)

        if log_level:
            show_drift_fc3(phono3py.get_fc3(),
                           primitive=phono3py.get_primitive())

    #######
    # fc2 #
    #######
    phonon_primitive = phono3py.get_phonon_primitive()
    p2s_map = phonon_primitive.p2s_map
    if settings.get_read_fc2():
        _read_phono3py_fc2(phono3py, symmetrize_fc2, input_filename, log_level)
    else:
        if phonon_supercell_matrix is None:
            if settings.get_fc_calculator() is not None:
                pass
            elif not _create_phono3py_fc2(
                    phono3py, force_to_eVperA, distance_to_A, symmetrize_fc2,
                    input_filename, settings.get_is_compact_fc(),
                    settings.get_fc_calculator(),
                    settings.get_fc_calculator_options(), log_level):
                print("fc2 was not created properly.")
                if log_level:
                    print_error()
                sys.exit(1)
        else:
            if not _create_phono3py_phonon_fc2(
                    phono3py, force_to_eVperA, distance_to_A, symmetrize_fc2,
                    input_filename, settings.get_is_compact_fc(),
                    settings.get_fc_calculator(),
                    settings.get_fc_calculator_options(), 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,
                          p2s_map=p2s_map,
                          physical_unit='eV/Angstrom^2',
                          compression=compression)

    if log_level:
        show_drift_force_constants(phono3py.get_fc2(),
                                   primitive=phonon_primitive,
                                   name='fc2')
예제 #4
0
def write_fc2_to_hdf5_file(force_constants, filename):
    from phono3py.file_IO import write_fc2_to_hdf5
    write_fc2_to_hdf5(force_constants.get_data(), filename)
def create_phono3py_force_constants(phono3py,
                                    phonon_supercell_matrix,
                                    settings,
                                    force_to_eVperA=None,
                                    distance_to_A=None,
                                    compression=None,
                                    input_filename=None,
                                    output_filename=None,
                                    log_level=1):
    read_fc3 = settings.get_read_fc3()
    read_fc2 = settings.get_read_fc2()
    symmetrize_fc3r = (settings.get_is_symmetrize_fc3_r() or
                       settings.get_fc_symmetry())
    symmetrize_fc3q = settings.get_is_symmetrize_fc3_q()
    symmetrize_fc2 = (settings.get_is_symmetrize_fc2() or
                      settings.get_fc_symmetry())

    if settings.get_use_alm_fc2():
        symmetrize_fc2 = False
    if settings.get_use_alm_fc3():
        symmetrize_fc3r = False
    alm_options = None
    if settings.get_use_alm_fc3() or settings.get_use_alm_fc2():
        if settings.get_alm_options() is not None:
            alm_option_types = {'solver': str,
                                'cutoff_distance': float}
            alm_options = {}
            for option_str in settings.get_alm_options().split(","):
                key, val = [x.strip() for x in option_str.split('=')[:2]]
                if key.lower() in alm_option_types:
                    option_value = alm_option_types[key.lower()](val)
                    alm_options[key.lower()] = option_value

    if log_level:
        show_phono3py_force_constants_settings(read_fc3,
                                               read_fc2,
                                               symmetrize_fc3r,
                                               symmetrize_fc3q,
                                               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_pp() or
        settings.get_write_phonon() 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)

            p2s_map = phono3py.get_primitive().get_primitive_to_supercell_map()
            try:
                fc3 = read_fc3_from_hdf5(filename=filename, p2s_map=p2s_map)
            except RuntimeError:
                import traceback
                traceback.print_exc()
                if log_level:
                    print_error()
                sys.exit(1)
            num_atom = phono3py.get_supercell().get_number_of_atoms()
            if fc3.shape[1] != num_atom:
                print("Matrix shape of fc3 doesn't agree with supercell size.")
                if log_level:
                    print_error()
                sys.exit(1)

            if symmetrize_fc3r:
                set_translational_invariance_fc3(fc3)
                set_permutation_symmetry_fc3(fc3)

            phono3py.set_fc3(fc3)
        else:  # fc3 from FORCES_FC3
            if not _create_phono3py_fc3(phono3py,
                                        force_to_eVperA,
                                        distance_to_A,
                                        symmetrize_fc3r,
                                        symmetrize_fc2,
                                        input_filename,
                                        output_filename,
                                        settings.get_is_compact_fc(),
                                        settings.get_use_alm_fc3(),
                                        alm_options,
                                        compression,
                                        log_level):
                    print("fc3 was not created properly.")
                    if log_level:
                        print_error()
                    sys.exit(1)

        cutoff_distance = settings.get_cutoff_fc3_distance()
        if cutoff_distance is not None and cutoff_distance > 0:
            if log_level:
                print("Cutting-off fc3 by zero (cut-off distance: %f)" %
                      cutoff_distance)
            phono3py.cutoff_fc3_by_zero(cutoff_distance)

        if log_level:
            show_drift_fc3(phono3py.get_fc3(),
                           primitive=phono3py.get_primitive())

    # fc2
    phonon_primitive = phono3py.get_phonon_primitive()
    phonon_supercell = phono3py.get_phonon_supercell()
    p2s_map = phonon_primitive.get_primitive_to_supercell_map()
    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 = phonon_supercell.get_number_of_atoms()
        try:
            phonon_fc2 = read_fc2_from_hdf5(filename=filename, p2s_map=p2s_map)
        except RuntimeError:
            import traceback
            traceback.print_exc()
            if log_level:
                print_error()
            sys.exit(1)

        if phonon_fc2.shape[1] != num_atom:
            print("Matrix shape of fc2 doesn't agree with supercell size.")
            if log_level:
                print_error()
            sys.exit(1)

        if symmetrize_fc2:
            if phonon_fc2.shape[0] == phonon_fc2.shape[1]:
                symmetrize_force_constants(phonon_fc2)
            else:
                symmetrize_compact_force_constants(phonon_fc2,
                                                   phonon_primitive)

        phono3py.set_fc2(phonon_fc2)
    else:
        if phonon_supercell_matrix is None:
            if not _create_phono3py_fc2(phono3py,
                                        force_to_eVperA,
                                        distance_to_A,
                                        symmetrize_fc2,
                                        input_filename,
                                        settings.get_is_compact_fc(),
                                        settings.get_use_alm_fc2(),
                                        alm_options,
                                        log_level):
                print("fc2 was not created properly.")
                if log_level:
                    print_error()
                sys.exit(1)
        else:
            if not _create_phono3py_phonon_fc2(phono3py,
                                               force_to_eVperA,
                                               distance_to_A,
                                               symmetrize_fc2,
                                               input_filename,
                                               settings.get_is_compact_fc(),
                                               settings.get_use_alm_fc2(),
                                               alm_options,
                                               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,
                          p2s_map=p2s_map,
                          compression=compression)

    if log_level:
        show_drift_force_constants(phono3py.get_fc2(),
                                   primitive=phonon_primitive,
                                   name='fc2')
예제 #6
0
                    mesh=ph_settings.dict.mesh,
                    log_level=1)

phono3py.produce_fc3(force_sets.get_forces3(),
                     displacement_dataset=force_sets.get_data_sets3(),
                     is_translational_symmetry=True,
                     is_permutation_symmetry=True,
                     is_permutation_symmetry_fc2=True)

fc3 = phono3py.get_fc3()
fc2 = phono3py.get_fc2()

if True:
    from phono3py.file_IO import write_fc2_to_hdf5, write_fc3_to_hdf5
    print ('Writing FC2 and FC3 into HDF5 files')
    write_fc2_to_hdf5(fc3, filename='fc2.hdf5')
    write_fc3_to_hdf5(fc3, filename='fc3.hdf5')

show_drift_fc3(fc3)
show_drift_force_constants(fc2, name='fc2')

# Use NAC if available
use_nac = False
if 'nac_data' in wc.get_outputs():
    primitive = phono3py.get_phonon_primitive()
    nac_params = wc.out.nac_data.get_born_parameters_phonopy(primitive_cell=primitive.get_cell())
    phono3py.set_phph_interaction(nac_params=nac_params)


phono3py.run_thermal_conductivity(temperatures=range(0, 1001, 10),
                                  boundary_mfp=1e6,  # This is to avoid divergence of phonon life time.
예제 #7
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, settings.get_use_alm(), 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,
                                            settings.get_use_alm(), 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,
                    settings.get_use_alm(), 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')
예제 #8
0
def store_force_constants(
    phono3py,
    settings,
    ph3py_yaml,
    input_filename,
    output_filename,
    load_phono3py_yaml,
    log_level,
):
    """Calculate, read, and write force constants."""
    if load_phono3py_yaml:
        if log_level:
            print("-" * 29 + " Force constants " + "-" * 30)

        (fc_calculator,
         fc_calculator_options) = get_fc_calculator_params(settings)

        read_fc = set_dataset_and_force_constants(
            phono3py,
            ph3py_yaml=ph3py_yaml,
            fc_calculator=fc_calculator,
            fc_calculator_options=fc_calculator_options,
            symmetrize_fc=settings.fc_symmetry,
            is_compact_fc=settings.is_compact_fc,
            cutoff_pair_distance=settings.cutoff_pair_distance,
            log_level=log_level,
        )

        if log_level:
            if phono3py.fc3 is None:
                print("fc3 could not be obtained.")
            if phono3py.fc2 is None:
                print("fc2 could not be obtained.")
        if phono3py.fc3 is None or phono3py.fc2 is None:
            print_error()
            sys.exit(1)

        if not read_fc["fc3"]:
            write_fc3_to_hdf5(
                phono3py.fc3,
                p2s_map=phono3py.primitive.p2s_map,
                compression=settings.hdf5_compression,
            )
            if log_level:
                print('fc3 was written into "fc3.hdf5".')
        if not read_fc["fc2"]:
            write_fc2_to_hdf5(
                phono3py.fc2,
                p2s_map=phono3py.primitive.p2s_map,
                physical_unit="eV/angstrom^2",
                compression=settings.hdf5_compression,
            )
            if log_level:
                print('fc2 was written into "fc2.hdf5".')
    else:
        create_phono3py_force_constants(
            phono3py,
            settings,
            ph3py_yaml=ph3py_yaml,
            input_filename=input_filename,
            output_filename=output_filename,
            log_level=log_level,
        )