Exemplo n.º 1
0
def _get_irt(ph3: Phono3py,
             mesh,
             nac_params=None,
             solve_dynamical_matrices=True):
    ph3.mesh_numbers = mesh
    itr = Interaction(ph3.primitive,
                      ph3.grid,
                      ph3.primitive_symmetry,
                      ph3.fc3,
                      cutoff_frequency=1e-4)
    if nac_params is None:
        itr.init_dynamical_matrix(
            ph3.fc2,
            ph3.phonon_supercell,
            ph3.phonon_primitive,
        )
    else:
        itr.init_dynamical_matrix(
            ph3.fc2,
            ph3.phonon_supercell,
            ph3.phonon_primitive,
            nac_params=nac_params,
        )
    if solve_dynamical_matrices:
        itr.run_phonon_solver()
    return itr
Exemplo n.º 2
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)
Exemplo n.º 3
0
def test_jdos_nacl_nac_gamma_at_300K_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]
    jdos = Phono3pyJointDos(
        nacl_pbe.phonon_supercell,
        nacl_pbe.phonon_primitive,
        nacl_pbe.fc2,
        mesh=nacl_pbe.mesh_numbers,
        nac_params=nacl_pbe.nac_params,
        nac_q_direction=[1, 0, 0],
        num_frequency_points=10,
        temperatures=[
            300,
        ],
        log_level=1,
    )
    jdos.run([nacl_pbe.grid.gp_Gamma])
    # print(", ".join(["%.7f" % fp for fp in jdos.frequency_points]))
    np.testing.assert_allclose(nacl_freq_points_gamma_at_300K,
                               jdos.frequency_points,
                               atol=1e-5)
    # print(", ".join(["%.7f" % jd for jd in jdos.joint_dos.ravel()]))
    np.testing.assert_allclose(nacl_jdos_gamma_at_300K[2:],
                               jdos.joint_dos.ravel()[2:],
                               rtol=1e-2,
                               atol=1e-5)
Exemplo n.º 4
0
def test_jdos_nacl_at_300K(nacl_pbe: Phono3py, gp: int,
                           store_dense_gp_map: bool):
    """Test joint-DOS at 300K by NaCl."""
    nacl_pbe.mesh_numbers = [9, 9, 9]
    jdos = Phono3pyJointDos(
        nacl_pbe.phonon_supercell,
        nacl_pbe.phonon_primitive,
        nacl_pbe.fc2,
        mesh=nacl_pbe.mesh_numbers,
        nac_params=nacl_pbe.nac_params,
        num_frequency_points=10,
        temperatures=[
            300,
        ],
        store_dense_gp_map=store_dense_gp_map,
        log_level=1,
    )
    jdos.run([gp])
    # print(", ".join(["%.7f" % fp for fp in jdos.frequency_points]))
    np.testing.assert_allclose(nacl_freq_points_at_300K,
                               jdos.frequency_points,
                               atol=1e-5)
    # print(", ".join(["%.7f" % jd for jd in jdos.joint_dos.ravel()]))
    np.testing.assert_allclose(nacl_jdos_12_at_300K[2:],
                               jdos.joint_dos.ravel()[2:],
                               rtol=1e-2,
                               atol=1e-5)
Exemplo n.º 5
0
def test_jdos_si(si_pbesol: Phono3py, gp: int, store_dense_gp_map: bool):
    """Test joint-DOS by Si.

    store_dense_gp_map=False : 103
    store_dense_gp_map=True : 105

    """
    si_pbesol.mesh_numbers = [9, 9, 9]
    jdos = Phono3pyJointDos(
        si_pbesol.phonon_supercell,
        si_pbesol.phonon_primitive,
        si_pbesol.fc2,
        mesh=si_pbesol.mesh_numbers,
        num_frequency_points=10,
        store_dense_gp_map=store_dense_gp_map,
        log_level=1,
    )
    jdos.run([gp])

    # print(", ".join(["%.7f" % fp for fp in jdos.frequency_points]))
    np.testing.assert_allclose(si_freq_points,
                               jdos.frequency_points,
                               atol=1e-5)
    # print(", ".join(["%.7f" % jd for jd in jdos.joint_dos.ravel()]))
    np.testing.assert_allclose(si_jdos_12[2:],
                               jdos.joint_dos.ravel()[2:],
                               rtol=1e-2,
                               atol=1e-5)
Exemplo n.º 6
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,
    )
Exemplo n.º 7
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)
Exemplo n.º 8
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)