def create_from_castep(self, request): material, phonon_file, json_file = request.param qpt_freqs = QpointFrequencies.from_castep( get_castep_path(material, phonon_file)) expected_qpt_freqs = ExpectedQpointFrequencies( os.path.join(get_qpt_freqs_dir(material), json_file)) return qpt_freqs, expected_qpt_freqs
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)
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)
def test_read_data(self, material, phonon_dos_file, expected_data_file): dos_data = read_phonon_dos_data( get_castep_path(material, phonon_dos_file)) with open(get_filepath(expected_data_file), 'r') as fp: expected_dos_data = json.loads(fp.read()) dos_crystal = ExpectedCrystal(dos_data.pop('crystal')) expected_dos_crystal = ExpectedCrystal( expected_dos_data.pop('crystal')) check_crystal(dos_crystal, expected_dos_crystal) def check_dict(dct, expected_dct): for exp_key, exp_val in expected_dct.items(): if isinstance(exp_val, list): npt.assert_allclose(dct[exp_key], np.array(exp_val)) elif isinstance(exp_val, dict): check_dict(dct[exp_key], exp_val) else: assert dct[exp_key] == exp_val check_dict(dos_data, expected_dos_data)
def create_from_castep_phonon_dos(self, request): material, phonon_dos_file, json_file = request.param spec = Spectrum1DCollection.from_castep_phonon_dos( get_castep_path(material, phonon_dos_file)) expected_spec = get_expected_spectrum1dcollection(json_file) return spec, expected_spec
def get_si2_qpt_ph_modes(): return QpointPhononModes.from_castep( get_castep_path('Si2-sc-skew', 'Si2-sc-skew.phonon'))
def get_quartz_qpt_ph_modes(): return QpointPhononModes.from_castep( get_castep_path('quartz', 'quartz_nosplit.phonon'))
def get_si2_qpt_ph_modes(self, request): fc = ForceConstants.from_castep( get_castep_path('Si2-sc-skew', 'Si2-sc-skew.castep_bin')) kwargs = self.get_multithreaded_kwargs(request.param) return fc.calculate_qpoint_phonon_modes(get_test_qpts(), **kwargs)
def get_quartz_qpt_ph_modes(self, request): fc = ForceConstants.from_castep( get_castep_path('quartz', 'quartz.castep_bin')) kwargs = self.get_multithreaded_kwargs(request.param) return fc.calculate_qpoint_phonon_modes( get_test_qpts('split'), **kwargs)
def test_create_from_castep_with_no_fc_raises_runtime_error(self): with pytest.raises(RuntimeError): ForceConstants.from_castep( get_castep_path('h-BN', 'h-BN_no_force_constants.castep_bin'))
def get_si2_fc(): return ForceConstants.from_castep( get_castep_path('Si2-sc-skew', 'Si2-sc-skew.castep_bin'))
def get_lzo_fc(): return ForceConstants.from_castep( get_castep_path('LZO', 'La2Zr2O7.castep_bin'))
from unittest.mock import patch import pytest import numpy.testing as npt # Required for mocking import matplotlib.pyplot from tests_and_analysis.test.utils import get_data_path, get_castep_path from tests_and_analysis.test.script_tests.utils import ( get_script_test_data_path, get_current_plot_image_data, args_to_key) import euphonic.cli.intensity_map quartz_phonon_file = os.path.join( get_data_path(), 'qpoint_phonon_modes', 'quartz', 'quartz_bandstructure_qpoint_phonon_modes.json') lzo_phonon_file = get_castep_path('LZO', 'La2Zr2O7.phonon') graphite_fc_file = get_castep_path('graphite', 'graphite.castep_bin') intensity_map_output_file = os.path.join(get_script_test_data_path(), 'intensity-map.json') intensity_map_params = [ [graphite_fc_file], [graphite_fc_file, '--v-min=0', '--v-max=1e-10'], [graphite_fc_file, '--energy-unit=meV'], [graphite_fc_file, '--weights=coherent', '--cmap=bone'], [graphite_fc_file, '--weights=coherent', '--temperature=800'], [graphite_fc_file, '-w', 'dos', '--y-label=DOS', '--title=DOS TITLE'], [graphite_fc_file, '--e-min=50', '-u=cm^-1', '--x-label=wavenumber'], [ graphite_fc_file, '--e-min=-100', '--e-max=1000', '--ebins=100', '--energy-unit=cm^-1' ], [graphite_fc_file, '--energy-broadening=2e-3', '-u=eV'], [
def create_from_castep_phonon_dos(self, request): material, phonon_dos_file, kwargs, json_file = request.param expected_spec1d = get_expected_spectrum1d(json_file) spec1d = Spectrum1D.from_castep_phonon_dos( get_castep_path(material, phonon_dos_file), **kwargs) return spec1d, expected_spec1d
import os import json from unittest.mock import patch import pytest import numpy.testing as npt # Required for mocking import matplotlib.pyplot from tests_and_analysis.test.utils import get_data_path, get_castep_path, get_phonopy_path from tests_and_analysis.test.script_tests.utils import ( get_script_test_data_path, get_current_plot_image_data, args_to_key) import euphonic.cli.powder_map graphite_fc_file = get_castep_path('graphite', 'graphite.castep_bin') nacl_prim_fc_file = get_phonopy_path('NaCl_prim', 'phonopy_nacl.yaml') powder_map_output_file = os.path.join(get_script_test_data_path(), 'powder-map.json') quick_calc_params = ['--npts=10', '--npts-min=10', '--q-spacing=1'] powder_map_params = [ [nacl_prim_fc_file], [nacl_prim_fc_file, *quick_calc_params], [nacl_prim_fc_file, '--temperature=1000', *quick_calc_params], [ nacl_prim_fc_file, '--temperature=1000', '--weights=coherent', *quick_calc_params ], [nacl_prim_fc_file, '--v-min=0', '--v-max=1e-10', *quick_calc_params], [nacl_prim_fc_file, '--energy-unit=meV', *quick_calc_params], [nacl_prim_fc_file, '--weights=coherent', '--cmap=bone'], [ graphite_fc_file, '-w', 'dos', '--y-label=DOS', '--title=DOS TITLE',
def get_quartz_fc(): return ForceConstants.from_castep( get_castep_path('quartz', 'quartz.castep_bin'))
def create_from_castep(self, request): material, castep_bin_file = request.param expected_fc = get_expected_fc(material) castep_filepath = get_castep_path(material, castep_bin_file) fc = ForceConstants.from_castep(castep_filepath) return fc, expected_fc