示例#1
0
文件: utils.py 项目: mducle/Euphonic
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).")
示例#2
0
 def test_serialise_to_json_file(self, qpt_ph_modes, tmpdir):
     output_file = str(tmpdir.join('tmp.test'))
     qpt_ph_modes.to_json_file(output_file)
     check_json_metadata(output_file, 'QpointPhononModes')
     deserialised_qpt_ph_modes = QpointPhononModes.from_json_file(
         output_file)
     check_qpt_ph_modes(qpt_ph_modes,
                        deserialised_qpt_ph_modes,
                        check_evecs=True)
示例#3
0
def get_qpt_ph_modes_from_json(material, file):
    return QpointPhononModes.from_json_file(
        os.path.join(get_qpt_ph_modes_dir(material), file))