Exemplo n.º 1
0
    def test_create_from_phonopy_without_installed_modules_raises_err(
            self, material, subdir, phonopy_args, mocker):
        phonopy_args['path'] = get_phonopy_path(material, subdir)
        # Mock import of yaml, h5py to raise ModuleNotFoundError
        import builtins
        real_import = builtins.__import__

        def mocked_import(name, *args, **kwargs):
            if name == 'h5py' or name == 'yaml':
                raise ModuleNotFoundError
            return real_import(name, *args, **kwargs)

        mocker.patch('builtins.__import__', side_effect=mocked_import)
        with pytest.raises(ImportPhonopyReaderError):
            QpointPhononModes.from_phonopy(**phonopy_args)
Exemplo n.º 2
0
 def create_from_phonopy(self, request):
     material, subdir, phonopy_args, json_file = request.param
     phonopy_args['path'] = get_phonopy_path(material, subdir)
     qpt_ph_modes = QpointPhononModes.from_phonopy(**phonopy_args)
     json_path = os.path.join(get_qpt_ph_modes_dir(material), json_file)
     expected_qpt_ph_modes = ExpectedQpointPhononModes(json_path)
     return qpt_ph_modes, expected_qpt_ph_modes
Exemplo n.º 3
0
def modes_from_file(filename: Union[str, os.PathLike]
                    ) -> QpointPhononModes:
    """
    Load phonon mode data from file

    Parameters
    ----------
    filename
        Data file

    Returns
    -------
    QpointPhononmodes
    """
    path = pathlib.Path(filename)
    if path.suffix == '.phonon':
        return QpointPhononModes.from_castep(path)
    elif path.suffix == '.json':
        return QpointPhononModes.from_json_file(path)
    elif path.suffix in ('.yaml', '.hdf5'):
        return QpointPhononModes.from_phonopy(path=path.parent,
                                              phonon_name=path.name)
    else:
        raise ValueError("File not recognised. Should have extension "
                         ".yaml or .hdf5 (phonopy), "
                         ".phonon (castep) or .json (JSON from Euphonic).")
Exemplo n.º 4
0
 def test_calculate_dos(self, material, qpt_ph_modes_file,
                        expected_dos_json, ebins):
     if qpt_ph_modes_file.endswith('.phonon'):
         qpt_ph_modes = QpointPhononModes.from_castep(
             get_castep_path(material, qpt_ph_modes_file))
     else:
         qpt_ph_modes = QpointPhononModes.from_phonopy(
             phonon_name=get_phonopy_path(material, qpt_ph_modes_file))
     dos = qpt_ph_modes.calculate_dos(ebins)
     expected_dos = get_expected_spectrum1d(expected_dos_json)
     check_spectrum1d(dos, expected_dos)
Exemplo n.º 5
0
    def test_calculate_debye_waller(self, material, qpt_ph_modes_file,
                                    expected_dw_json, temperature, kwargs):
        if qpt_ph_modes_file.endswith('.phonon'):
            qpt_ph_modes = QpointPhononModes.from_castep(
                get_castep_path(material, qpt_ph_modes_file))
        else:
            qpt_ph_modes = QpointPhononModes.from_phonopy(
                phonon_name=get_phonopy_path(material, qpt_ph_modes_file))

        dw = qpt_ph_modes.calculate_debye_waller(temperature * ureg('K'),
                                                 **kwargs)
        expected_dw = get_expected_dw(material, expected_dw_json)
        check_debye_waller(dw, expected_dw, dw_atol=1e-12)
Exemplo n.º 6
0
    def test_create_from_phonopy_without_cloader_is_ok(self, material, subdir,
                                                       phonopy_args, json_file,
                                                       mocker):
        # Mock 'from yaml import CLoader as Loader' to raise ImportError
        import builtins
        real_import = builtins.__import__

        def mocked_import(name, globals, locals, fromlist, level):
            if name == 'yaml':
                if fromlist is not None and fromlist[0] == 'CSafeLoader':
                    raise ImportError
            return real_import(name, globals, locals, fromlist, level)

        mocker.patch('builtins.__import__', side_effect=mocked_import)

        phonopy_args['path'] = get_phonopy_path(material, subdir)
        qpt_ph_modes = QpointPhononModes.from_phonopy(**phonopy_args)
        json_path = os.path.join(get_qpt_ph_modes_dir(material), json_file)
        expected_qpt_ph_modes = ExpectedQpointPhononModes(json_path)
        check_qpt_ph_modes(qpt_ph_modes,
                           expected_qpt_ph_modes,
                           check_evecs=True)
 def get_cahgo2_qpt_ph_modes():
     return QpointPhononModes.from_phonopy(
         path=get_phonopy_path('CaHgO2', ''),
         summary_name='mp-7041-20180417.yaml',
         phonon_name='qpoints.yaml')
Exemplo n.º 8
0
 def test_create_from_phonopy_with_bad_inputs_raises_err(
         self, material, subdir, phonopy_args, err):
     phonopy_args['path'] = get_phonopy_path(material, subdir)
     with pytest.raises(err):
         QpointPhononModes.from_phonopy(**phonopy_args)