예제 #1
0
def test_write_phonopy_yaml_extra(ph_nacl_nofcsym: Phonopy):
    """Test PhonopyYaml.set_phonon_info, __str__, yaml_data, parse.

    settings parameter controls amount of yaml output. In this test,
    more data than the default are dumped and those are tested.

    """
    phonon = ph_nacl_nofcsym
    settings = {
        "force_sets": True,
        "displacements": True,
        "force_constants": True,
        "born_effective_charge": True,
        "dielectric_constant": True,
    }
    phpy_yaml = PhonopyYaml(calculator="vasp", settings=settings)
    phpy_yaml.set_phonon_info(phonon)
    phpy_yaml_test = PhonopyYaml()
    phpy_yaml_test.yaml_data = yaml.safe_load(StringIO(str(phpy_yaml)))
    phpy_yaml_test.parse()
    np.testing.assert_allclose(phpy_yaml.force_constants,
                               phpy_yaml_test.force_constants,
                               atol=1e-8)
    np.testing.assert_allclose(phpy_yaml.nac_params["born"],
                               phpy_yaml_test.nac_params["born"],
                               atol=1e-8)
    np.testing.assert_allclose(
        phpy_yaml.nac_params["dielectric"],
        phpy_yaml_test.nac_params["dielectric"],
        atol=1e-8,
    )
    np.testing.assert_allclose(
        phpy_yaml.nac_params["factor"],
        phpy_yaml_test.nac_params["factor"],
        atol=1e-8,
    )
    disps, forces = get_displacements_and_forces(phpy_yaml.dataset)
    disps_test, forces_test = get_displacements_and_forces(
        phpy_yaml_test.dataset)
    np.testing.assert_allclose(forces, forces_test, atol=1e-8)
    np.testing.assert_allclose(disps, disps_test, atol=1e-8)
예제 #2
0
def get_force_sets_wien2k(num_displacements,
                          force_filenames,
                          disp_filename,
                          supercell,
                          disp_dataset,
                          wien2k_P1_mode=False,
                          symmetry_tolerance=None,
                          verbose=False):
    from phonopy.interface.wien2k import parse_set_of_forces
    disps, _ = get_displacements_and_forces(disp_dataset)
    force_sets = parse_set_of_forces(disps,
                                     force_filenames,
                                     supercell,
                                     wien2k_P1_mode=wien2k_P1_mode,
                                     symmetry_tolerance=symmetry_tolerance,
                                     verbose=verbose)
    return force_sets
예제 #3
0
def _extract_dataset_from_db(forces_in_db, ph_info_in_db):
    nitems = len(forces_in_db)
    displacements = []
    forces = []
    energies = []

    for i in range(nitems):
        force_sets = forces_in_db[i].get_array('force_sets')
        dataset = ph_info_in_db[i]['displacement_dataset']
        disps, _ = get_displacements_and_forces(dataset)

        forces.append(force_sets)
        if 'energies' in forces_in_db[i].get_arraynames():
            energy_sets = forces_in_db[i].get_array('energies')
            energies.append(energy_sets)
        displacements.append(disps)

    return displacements, forces, energies
예제 #4
0
def _get_dataset(f, natom=None, to_type2=False):
    first_line_ary = _get_line_ignore_blank(f).split()
    f.seek(0)
    if len(first_line_ary) == 1:
        if natom is None or int(first_line_ary[0]) == natom:
            dataset = _get_dataset_type1(f)
        else:
            msg = "Number of forces is not consistent with supercell setting."
            raise RuntimeError(msg)

        if to_type2:
            disps, forces = get_displacements_and_forces(dataset)
            return {"displacements": disps, "forces": forces}
        else:
            return dataset

    elif len(first_line_ary) == 6:
        return get_dataset_type2(f, natom)
예제 #5
0
def get_force_sets_wien2k(
    force_filenames,
    supercell,
    disp_dataset,
    wien2k_P1_mode=False,
    symmetry_tolerance=None,
    verbose=False,
):
    """Read Wien2k output files and parse force sets."""
    from phonopy.interface.wien2k import parse_set_of_forces

    disps, _ = get_displacements_and_forces(disp_dataset)
    force_sets = parse_set_of_forces(
        disps,
        force_filenames,
        supercell,
        wien2k_P1_mode=wien2k_P1_mode,
        symmetry_tolerance=symmetry_tolerance,
        verbose=verbose,
    )
    return force_sets