Exemplo n.º 1
0
def _create_phono3py_fc3(phono3py, force_to_eVperA, distance_to_A,
                         symmetrize_fc3r, symmetrize_fc2, input_filename,
                         output_filename, is_compact_fc, cutoff_pair_distance,
                         use_alm, alm_options, compression, log_level):
    if input_filename is None:
        filename = 'disp_fc3.yaml'
    else:
        filename = 'disp_fc3.' + input_filename + '.yaml'
    file_exists(filename, log_level)
    if log_level:
        print("Displacement dataset for fc3 is read from %s." % filename)
    disp_dataset = parse_disp_fc3_yaml(filename=filename)
    if cutoff_pair_distance:
        if ('cutoff_distance' not in disp_dataset
                or 'cutoff_distance' in disp_dataset
                and cutoff_pair_distance < disp_dataset['cutoff_distance']):
            disp_dataset['cutoff_distance'] = cutoff_pair_distance
            if log_level:
                print("Cutoff-pair-distance: %f" % cutoff_pair_distance)
    num_atom = phono3py.get_supercell().get_number_of_atoms()
    if disp_dataset['natom'] != num_atom:
        print("Number of atoms in supercell is not consistent with %s" %
              filename)
        if log_level:
            print_error()
        sys.exit(1)
    _convert_displacement_unit(disp_dataset, distance_to_A)

    file_exists("FORCES_FC3", log_level)
    if log_level:
        print("Sets of supercell forces are read from %s." % "FORCES_FC3")
        sys.stdout.flush()
    forces_fc3 = parse_FORCES_FC3(disp_dataset)

    _convert_force_unit(forces_fc3, force_to_eVperA)
    phono3py.produce_fc3(forces_fc3,
                         displacement_dataset=disp_dataset,
                         symmetrize_fc3r=symmetrize_fc3r,
                         is_compact_fc=is_compact_fc,
                         use_alm=use_alm,
                         alm_options=alm_options)

    if output_filename is None:
        filename = 'fc3.hdf5'
    else:
        filename = 'fc3.' + output_filename + '.hdf5'
    if log_level:
        print("Writing fc3 to %s" % filename)
    p2s_map = phono3py.get_primitive().get_primitive_to_supercell_map()
    write_fc3_to_hdf5(phono3py.get_fc3(),
                      filename=filename,
                      p2s_map=p2s_map,
                      compression=compression)

    return True
Exemplo n.º 2
0
def _create_phono3py_fc3(phono3py,
                         force_to_eVperA,
                         distance_to_A,
                         tsym_type,
                         symmetrize_fc3_r,
                         symmetrize_fc2,
                         cutoff_distance,
                         input_filename,
                         output_filename,
                         use_alm,
                         log_level):
    if input_filename is None:
        filename = 'disp_fc3.yaml'
    else:
        filename = 'disp_fc3.' + input_filename + '.yaml'
    file_exists(filename, log_level)
    if log_level:
        print("Displacement dataset is read from %s." % filename)
    disp_dataset = parse_disp_fc3_yaml(filename=filename)
    num_atom = phono3py.get_supercell().get_number_of_atoms()
    if disp_dataset['natom'] != num_atom:
        print("Number of atoms in supercell is not consistent with %s" %
              filename)
        if log_level:
            print_error()
        sys.exit(1)
    _convert_displacement_unit(disp_dataset, distance_to_A)

    file_exists("FORCES_FC3", log_level)
    if log_level:
        print("Sets of supercell forces are read from %s." % "FORCES_FC3")
    forces_fc3 = parse_FORCES_FC3(disp_dataset)
    if not forces_fc3:
        return False

    _convert_force_unit(forces_fc3, force_to_eVperA)

    phono3py.produce_fc3(
        forces_fc3,
        displacement_dataset=disp_dataset,
        cutoff_distance=cutoff_distance,
        translational_symmetry_type=tsym_type,
        is_permutation_symmetry=symmetrize_fc3_r,
        is_permutation_symmetry_fc2=symmetrize_fc2,
        use_alm=use_alm)
    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.get_fc3(), filename=filename)

    return True
Exemplo n.º 3
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)
Exemplo n.º 4
0
def _create_phono3py_fc3(phono3py, force_to_eVperA, distance_to_A,
                         symmetrize_fc3r, symmetrize_fc2, input_filename,
                         output_filename, is_compact_fc, cutoff_pair_distance,
                         fc_calculator, fc_calculator_options, compression,
                         log_level):
    if input_filename is None:
        disp_filename = 'disp_fc3.yaml'
    else:
        disp_filename = 'disp_fc3.' + input_filename + '.yaml'
    natom = phono3py.supercell.get_number_of_atoms()
    try:
        disp_dataset = parse_forces(natom,
                                    force_to_eVperA,
                                    distance_to_A,
                                    cutoff_pair_distance=cutoff_pair_distance,
                                    force_filename="FORCES_FC3",
                                    disp_filename=disp_filename,
                                    log_level=log_level)
    except RuntimeError as e:
        if log_level:
            print(str(e))
            print_error()
        sys.exit(1)
    except FileNotFoundError as e:
        file_exists(e.filename, log_level)

    phono3py.produce_fc3(displacement_dataset=disp_dataset,
                         symmetrize_fc3r=symmetrize_fc3r,
                         is_compact_fc=is_compact_fc,
                         fc_calculator=fc_calculator,
                         fc_calculator_options=fc_calculator_options)

    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=compression)

    return True
Exemplo n.º 5
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")
Exemplo n.º 6
0
def _create_phono3py_fc3(phono3py, force_to_eVperA, distance_to_A,
                         symmetrize_fc3r, symmetrize_fc2, input_filename,
                         output_filename, is_compact_fc, cutoff_pair_distance,
                         fc_calculator, fc_calculator_options, compression,
                         log_level):
    file_exists("FORCES_FC3", log_level)
    natom = phono3py.supercell.get_number_of_atoms()
    disp_dataset = _get_type2_dataset(natom, filename="FORCES_FC3")
    if disp_dataset:  # type2
        if log_level:
            print("%d snapshots were found in %s." %
                  (len(disp_dataset['displacements']), "FORCES_FC3"))
        if force_to_eVperA is not None:
            disp_dataset['forces'] *= force_to_eVperA
        if distance_to_A is not None:
            disp_dataset['displacements'] *= distance_to_A
    else:  # type1
        if input_filename is None:
            filename = 'disp_fc3.yaml'
        else:
            filename = 'disp_fc3.' + input_filename + '.yaml'
        file_exists(filename, log_level)
        if log_level:
            print("Displacement dataset for fc3 is read from %s." % filename)
        disp_dataset = parse_disp_fc3_yaml(filename=filename)
        if cutoff_pair_distance:
            if ('cutoff_distance' not in disp_dataset
                    or 'cutoff_distance' in disp_dataset and
                    cutoff_pair_distance < disp_dataset['cutoff_distance']):
                disp_dataset['cutoff_distance'] = cutoff_pair_distance
                if log_level:
                    print("Cutoff-pair-distance: %f" % cutoff_pair_distance)
        num_atom = phono3py.get_supercell().get_number_of_atoms()
        if disp_dataset['natom'] != num_atom:
            print("Number of atoms in supercell is not consistent with %s" %
                  filename)
            if log_level:
                print_error()
            sys.exit(1)
        _convert_displacement_unit(disp_dataset, distance_to_A)
        if log_level:
            print("Sets of supercell forces are read from %s." % "FORCES_FC3")
            sys.stdout.flush()
        # forces are stored in disp_dataset.
        parse_FORCES_FC3(disp_dataset, unit_conversion_factor=force_to_eVperA)

    phono3py.produce_fc3(displacement_dataset=disp_dataset,
                         symmetrize_fc3r=symmetrize_fc3r,
                         is_compact_fc=is_compact_fc,
                         fc_calculator=fc_calculator,
                         fc_calculator_options=fc_calculator_options)

    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.get_fc3(),
                      filename=filename,
                      p2s_map=phono3py.primitive.p2s_map,
                      compression=compression)

    return True
Exemplo n.º 7
0
def write_fc3_to_hdf5_file(force_constants, filename):
    from phono3py.file_IO import write_fc3_to_hdf5
    write_fc3_to_hdf5(force_constants.get_data(), filename)
Exemplo n.º 8
0
                    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.
                                  write_kappa=True)
Exemplo n.º 9
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,
        )