예제 #1
0
def test_real_self_energy_with_frequency_points(si_pbesol: Phono3py):
    """Real part of self energy spectrum of Si.

    * specified frquency points

    """
    si_pbesol.mesh_numbers = [9, 9, 9]
    si_pbesol.init_phph_interaction()
    frequency_points = [1.469947, 3.085309, 14.997187, 15.129080]
    fps, delta = si_pbesol.run_real_self_energy(
        si_pbesol.grid.grg2bzg[[1, 103]],
        [
            300,
        ],
        frequency_points=frequency_points,
        write_hdf5=False,
        frequency_points_at_bands=False,
    )

    np.testing.assert_allclose(frequency_points, fps, atol=1e-5)
    np.testing.assert_allclose(si_pbesol_Delta_fps[0],
                               delta[0, 0, 0].ravel(),
                               atol=0.01)
    np.testing.assert_allclose(si_pbesol_Delta_fps[1],
                               delta[0, 0, 1].ravel(),
                               atol=0.01)
예제 #2
0
def test_SpectralFunction_band_indices(si_pbesol: Phono3py):
    """Spectral function of Si."""
    si_pbesol.mesh_numbers = [9, 9, 9]
    si_pbesol.band_indices = [[4, 5]]
    si_pbesol.init_phph_interaction()
    sf = SpectralFunction(
        si_pbesol.phph_interaction,
        si_pbesol.grid.grg2bzg[[1, 103]],
        temperatures=[
            300,
        ],
        num_frequency_points=10,
        log_level=1,
    )
    sf.run()

    # for line in np.swapaxes(sf.spectral_functions, -2, -1).reshape(-1, 6):
    #     print(("%.7f, " * 6) % tuple(line))
    # raise

    np.testing.assert_allclose(
        np.reshape(shifts, (-1, 6))[:, [4, 5]],
        np.swapaxes(sf.shifts, -2, -1).reshape(-1, 2),
        atol=1e-2,
    )
    np.testing.assert_allclose(
        np.reshape(spec_funcs, (-1, 6))[:, [4, 5]],
        np.swapaxes(sf.spectral_functions, -2, -1).reshape(-1, 2),
        atol=1e-2,
        rtol=1e-2,
    )
예제 #3
0
def test_real_self_energy_nacl_nac_npoints(nacl_pbe: Phono3py):
    """Real part of self energy spectrum of NaCl.

    * at 10 frequency points sampled uniformly.
    * at q->0

    """
    nacl_pbe.mesh_numbers = [9, 9, 9]
    nacl_pbe.init_phph_interaction(nac_q_direction=[1, 0, 0])
    fps, delta = nacl_pbe.run_real_self_energy([nacl_pbe.grid.gp_Gamma], [300],
                                               num_frequency_points=10)
    # for line in np.swapaxes(delta, -1, -2).ravel().reshape(-1, 6):
    #     print(("%10.8f, " * 6) % tuple(line))
    # print(fps.ravel())
    np.testing.assert_allclose(freq_points_nacl_nac,
                               fps.ravel(),
                               rtol=0,
                               atol=1e-5)
    np.testing.assert_allclose(delta_nacl_nac,
                               np.swapaxes(delta, -1, -2).ravel(),
                               rtol=0,
                               atol=1e-2)
예제 #4
0
def init_phph_interaction(
    phono3py: Phono3py,
    settings,
    updated_settings,
    input_filename,
    output_filename,
    log_level,
):
    """Initialize ph-ph interaction and phonons on grid."""
    if log_level:
        print("Generating grid system ... ", end="", flush=True)
    phono3py.mesh_numbers = settings.mesh_numbers
    bz_grid = phono3py.grid
    if log_level:
        if bz_grid.grid_matrix is None:
            print("[ %d %d %d ]" % tuple(phono3py.mesh_numbers))
        else:
            print("")
            print("Generalized regular grid: [ %d %d %d ]" %
                  tuple(bz_grid.D_diag))
            print("Grid generation matrix:")
            print("  [ %d %d %d ]" % tuple(bz_grid.grid_matrix[0]))
            print("  [ %d %d %d ]" % tuple(bz_grid.grid_matrix[1]))
            print("  [ %d %d %d ]" % tuple(bz_grid.grid_matrix[2]))

        if settings.is_symmetrize_fc3_q:
            print("Permutation symmetry of ph-ph interaction strengths: True")

    ave_pp = settings.constant_averaged_pp_interaction
    phono3py.init_phph_interaction(
        nac_q_direction=settings.nac_q_direction,
        constant_averaged_interaction=ave_pp,
        frequency_scale_factor=updated_settings["frequency_scale_factor"],
        symmetrize_fc3q=settings.is_symmetrize_fc3_q,
        lapack_zheev_uplo=settings.lapack_zheev_uplo,
    )

    if not settings.read_phonon:
        if log_level:
            print("-" * 27 + " Phonon calculations " + "-" * 28)
            dm = phono3py.dynamical_matrix
            if dm.is_nac() and dm.nac_method == "gonze":
                dm.show_nac_message()
            print("Running harmonic phonon calculations...")
            sys.stdout.flush()
        phono3py.run_phonon_solver()

    if settings.write_phonon:
        freqs, eigvecs, grid_address = phono3py.get_phonon_data()
        ir_grid_points, ir_grid_weights, _ = get_ir_grid_points(bz_grid)
        ir_grid_points = np.array(bz_grid.grg2bzg[ir_grid_points],
                                  dtype="int_")
        filename = write_phonon_to_hdf5(
            freqs,
            eigvecs,
            grid_address,
            phono3py.mesh_numbers,
            bz_grid=bz_grid,
            ir_grid_points=ir_grid_points,
            ir_grid_weights=ir_grid_weights,
            compression=settings.hdf5_compression,
            filename=output_filename,
        )
        if filename:
            if log_level:
                print('Phonons are written into "%s".' % filename)
        else:
            print("Writing phonons failed.")
            if log_level:
                print_error()
            sys.exit(1)

    if settings.read_phonon:
        phonons = read_phonon_from_hdf5(phono3py.mesh_numbers,
                                        filename=input_filename,
                                        verbose=(log_level > 0))
        if phonons is None:
            print("Reading phonons failed.")
            if log_level:
                print_error()
            sys.exit(1)

        try:
            phono3py.set_phonon_data(*phonons)
        except RuntimeError:
            if log_level:
                print_error()
            sys.exit(1)