def test_addExperimentDefinition(cal): calc = CryspyCalculator('') interface = CalculatorInterface(calc) interface.addExperimentDefinition(exp_path) exp_added = interface.getExperiment('pd') exp_ref = cal.getExperiment('pd') assert exp_added['name'] == exp_ref['name'] assert exp_added['wavelength'].value == exp_ref['wavelength'].value assert exp_added['offset'].value == exp_ref['offset'].value assert exp_added['phase']['Fe3O4']['name'] == exp_ref['phase']['Fe3O4']['name'] assert exp_added['phase']['Fe3O4']['scale'].value == exp_ref['phase']['Fe3O4']['scale'].value
def no_project_proxy(): no_project_proxy = ProxyPyQml(release_config_file_path) cal = CryspyCalculator(None) no_project_proxy._calculator_interface = CalculatorInterface(cal) no_project_proxy.initialize() no_project_proxy._calculator_interface.setPhaseDefinition('Tests/Data/samples.cif') return no_project_proxy
def test_addPhaseDefinition(cal): calc = CryspyCalculator('') interface = CalculatorInterface(calc) interface.addPhaseDefinition(phase_path) phase_added = interface.getPhase('Fe3O4') phase_ref = cal.getPhase('Fe3O4') assert phase_added['phasename'] == phase_ref['phasename'] assert phase_added['spacegroup']['crystal_system'].value == phase_ref['spacegroup']['crystal_system'].value assert phase_added['spacegroup']['space_group_name_HM_ref'].value == phase_ref['spacegroup'][ 'space_group_name_HM_ref'].value assert phase_added['spacegroup']['space_group_IT_number'].value == phase_ref['spacegroup'][ 'space_group_IT_number'].value assert phase_added['spacegroup']['origin_choice'].value == phase_ref['spacegroup']['origin_choice'].value assert phase_added['cell']['length_a'].value == phase_ref['cell']['length_a'].value assert phase_added['cell']['length_b'].value == phase_ref['cell']['length_b'].value assert phase_added['cell']['length_c'].value == phase_ref['cell']['length_c'].value assert phase_added['cell']['angle_alpha'].value == phase_ref['cell']['angle_alpha'].value assert phase_added['cell']['angle_beta'].value == phase_ref['cell']['angle_beta'].value assert phase_added['cell']['angle_gamma'].value == phase_ref['cell']['angle_gamma'].value assert phase_added['atoms']['Fe3A']['fract_x'].value == phase_ref['atoms']['Fe3A']['fract_x'].value assert phase_added['atoms']['Fe3B']['fract_y'].value == phase_ref['atoms']['Fe3B']['fract_y'].value assert phase_added['atoms']['O']['fract_z'].value == phase_ref['atoms']['O']['fract_z'].value
def test_setExperimentDefinitionFromString(): calc = CryspyCalculator() interface = CalculatorInterface(calc) interface.setPhaseDefinition(phase_path) with open(exp_path, 'r') as file_reader: exp_content = file_reader.read() interface.addExperimentDefinitionFromString(exp_content) experiment_dict = interface.project_dict['experiments'] assert len(experiment_dict) == 1 assert len(experiment_dict['pd']) == 10 # wavelength assert len(experiment_dict['pd']['wavelength']) == 5 assert experiment_dict['pd']['wavelength'].value == 0.84 assert experiment_dict['pd']['wavelength']['url'] == '' # offset assert len(experiment_dict['pd']['offset']) == 5 assert experiment_dict['pd']['offset'].value == -0.385404 assert experiment_dict['pd']['offset']['store']['error'] == 0.0 assert experiment_dict['pd']['offset']['store']['refine'] is False # phase assert len(experiment_dict['pd']['phase']) == 1 assert len(experiment_dict['pd']['phase']['Fe3O4']['scale']) == 5 assert experiment_dict['pd']['phase']['Fe3O4']['scale'].value == 0.02381 assert experiment_dict['pd']['phase']['Fe3O4']['scale']['store']['refine'] is False assert experiment_dict['pd']['phase']['Fe3O4']['scale']['store']['error'] == 0.0 # background assert len(experiment_dict['pd']['background']) == 3 assert experiment_dict['pd']['background']['4.5']['ttheta'] == 4.5 assert len(experiment_dict['pd']['background']['4.5']['intensity']) == 5 assert experiment_dict['pd']['background']['4.5']['intensity'].value == 256.0 assert experiment_dict['pd']['background']['80.0']['ttheta'] == 80.0 assert len(experiment_dict['pd']['background']['80.0']['intensity']) == 5 assert experiment_dict['pd']['background']['80.0']['intensity'].value == 65.0 # resolution assert len(experiment_dict['pd']['resolution']) == 5 assert len(experiment_dict['pd']['resolution']['u']) == 5 assert experiment_dict['pd']['resolution']['u'].value == 16.9776 assert experiment_dict['pd']['resolution']['u']['store']['refine'] is False assert len(experiment_dict['pd']['resolution']['y']) == 5 assert experiment_dict['pd']['resolution']['v'].value == -2.8357 assert experiment_dict['pd']['resolution']['v']['store']['error'] == 0.0 assert experiment_dict['pd']['resolution']['v']['store']['hide'] is False # measured_pattern assert len(experiment_dict['pd']['measured_pattern']) == 9 assert 5.0 in experiment_dict['pd']['measured_pattern']['x'] assert len(experiment_dict['pd']['measured_pattern'].y_obs_lower) == 381 assert experiment_dict['pd']['measured_pattern'].y_obs_lower[380] == pytest.approx(762.959046)
def test_addPhaseToExp(): calc = CryspyCalculator('') interface = CalculatorInterface(calc) interface.addExperimentDefinition(exp_path) interface.addPhaseDefinition(phase_path) interface.removePhaseFromExp('pd', 'Fe3O4') interface.addPhaseToExp('pd', 'Fe3O4', scale=1.0) exp_ref = interface.getExperiment('pd') assert exp_ref['name'] == 'pd' assert 'Fe3O4' in exp_ref['phase'].keys() assert exp_ref['phase']['Fe3O4']['scale'].value == 1.0
def test_setPhaseDefinition_EmptyStr(): calc = CryspyCalculator('') interface = CalculatorInterface(calc) interface.setPhaseDefinition('')
def test_setPhaseDefinition_None(): calc = CryspyCalculator('') interface = CalculatorInterface(calc) interface.setPhaseDefinition(None)
def test_creation_Empty(): calc = CryspyCalculator() interface = CalculatorInterface(calc)
def test_creation_WrongStr(): path = os.path.join(test_data, 'mainf.cif') calc = CryspyCalculator(path) interface = CalculatorInterface(calc)
def test_creation_None(): calc = CryspyCalculator(None) interface = CalculatorInterface(calc)
def cal(): calc = CryspyCalculator(file_path) interface = CalculatorInterface(calc) return interface
This demonstrates an example of how to load an example and create a interface to a cryspy calculator and then fit a value. """ import os from easyInterface.Utils.Helpers import getExamplesDir from easyInterface.Diffraction.Calculators import CryspyCalculator from easyInterface.Diffraction.Interface import CalculatorInterface data_dir = getExamplesDir() main_rcif = os.path.join(data_dir, 'PbSO4_powder-1d_neutrons-unpol_D1A(ILL)', 'main.cif') calculator = CryspyCalculator(main_rcif) interface = CalculatorInterface(calculator) print(interface.project_dict) phase_ids = interface.phasesIds() print(phase_ids) phase = interface.getPhase(phase_ids[0]) phase['phasename'] = 'PbSO5' interface.addPhase(phase) interface.removePhase('PbSO5') phase = interface.getPhase(phase_ids[0]) interface.setPhaseValue(phase_ids[0], ['atoms', 'Pb', 'fract_x'], 0.18) interface.setPhases(phase)
""" Creating a interface ==================== This demonstrates an example of how to load an example and create a interface to a cryspy calculator. Information about the project is then displayed. """ import os from easyInterface.Utils.Helpers import getExamplesDir from easyInterface.Diffraction.Calculators import CryspyCalculator from easyInterface.Diffraction.Interface import CalculatorInterface data_dir = getExamplesDir() main_rcif = os.path.join(data_dir, 'Fe3O4_powder-1d_neutrons-pol_5C1(LLB)', 'main.cif') calculator = CryspyCalculator(main_rcif) interface = CalculatorInterface(calculator) print(interface.project_dict) print(interface.phasesIds()) print(interface.getPhase(interface.phasesIds()[0]))