diff --git a/addie/processing/idl/run_sum_scans.py b/addie/processing/idl/run_sum_scans.py index f5cd77e2..ed945e79 100644 --- a/addie/processing/idl/run_sum_scans.py +++ b/addie/processing/idl/run_sum_scans.py @@ -2,11 +2,20 @@ import os from qtpy.QtCore import Qt from addie.processing.idl.step2_gui_handler import Step2GuiHandler +from addie.processing.mantid.master_table.periodic_table.material_handler \ + import get_periodictable_formatted_element_and_number_of_atoms as format_ele +import numpy as np +import re class RunSumScans(object): output_file = '' + # Variable for Jeorg's new routine, controlling maximum r one could get to. + # For almost all situations, we don't need to change it, but it is good to + # put the variable explicitly just in case we may need to change it for + # whatever reason in the future. + q_interval_min = 0.02 def __init__(self, parent=None): self.parent = parent.ui.postprocessing_ui @@ -60,7 +69,7 @@ def create_output_file(self): f = open(_full_output_file_name, 'w') for _label in self._runs: - f.write("%s %s\n" % (_label, self._runs[_label])) + f.write("%s %s\n" % (_label, self._runs[_label]["runs"])) f.write("endsamples\n") f.write("Background %s\n" % self._background) @@ -94,15 +103,61 @@ def create_output_file(self): f.close() print("[LOG] created file %s" % _full_output_file_name) + # redpar file + r_max_possible = "{0:6.2F}".format(np.pi / self.q_interval_min) + r_range = o_gui_handler.get_r_range(r_max_possible) + self._runs["r_range"] = r_range + self._runs["q_range"] = [q_range_min, q_range_max] + for _label in self._runs: + if _label != "r_range" and _label != "q_range": + self._runs = self.collect_info_for_redpar(self._runs, _label) + self.write_redpar(self._runs, _label) + + def collect_info_for_redpar(self, runs_info, _label): + chem_form_temp = runs_info[_label]["sam_formula"] + list_element = chem_form_temp.split(" ") + formated_ele_list = [] + for _element in list_element: + [formated_element, number_of_atoms, case] = format_ele(_element) + formated_ele_list.append(formated_element) + sample_form_str = "" + for item in formated_ele_list: + if case == 1: + to_append = item + "_" + elif case == 2: + to_append = re.findall('[A-Z][a-z]*', item)[-1] + to_append += ("_" + re.findall('[0-9]+', item)[-1] + "_") + else: + to_append = item.split("[")[1].split("]")[0] + item.split("[")[0] + "_" + item.split("]")[1] + "_" + sample_form_str += to_append + runs_info[_label]["sam_form_used"] = sample_form_str[:-1] + + return runs_info + + def write_redpar(self, runs_info, _label): + file_name = runs_info[_label]["sam_name"] + ".redpar" + with open(file_name, 'w') as f: + f.write("{0:13s}{1:[A-Z]{1}[a-z]{0,1}$)' m1 = re.search(regular_expression_1, element) if m1 is not None: - return [m1.group('stable_element'), 1.] + case = 1 + return [m1.group('stable_element'), 1., case] # stable with stochiometric coefficient regular_expression_2 = r'^(?P[A-Z]{1}[a-z]{0,1})(?P\d*\.{0,1}\d*)$' m2 = re.search(regular_expression_2, element) if m2 is not None: + case = 2 return ["{}{}".format(m2.group('stable_element'), m2.group('stochiometric_coefficient')), - np.float(m2.group('stochiometric_coefficient'))] + np.float(m2.group('stochiometric_coefficient')), case] # isotope with or without stochiometric coefficient regular_expression_3 = r'\((?P[A-Z]{1}[a-z]{0,1})(?P\d+)\)' \ r'(?P\d*\.{0,1}\d*)' m3 = re.search(regular_expression_3, element) if m3 is not None: + case = 3 if m3.group('stochiometric_coefficient') == "": number_of_atoms = 1. else: number_of_atoms = np.float( m3.group('stochiometric_coefficient')) return ["{}[{}]{}".format(m3.group('isotope_element'), m3.group('isotope_number'), - m3.group('stochiometric_coefficient')), number_of_atoms] + m3.group('stochiometric_coefficient')), number_of_atoms, case] raise ValueError diff --git a/tests/test_files/SiO2.redpar b/tests/test_files/SiO2.redpar new file mode 100644 index 00000000..dc293a88 --- /dev/null +++ b/tests/test_files/SiO2.redpar @@ -0,0 +1,7 @@ +formula Si_1_O_2 +massdensity 2.5 +radius 0.15 +packfrac 0.7 +geometry Cylinder +rfilter 1.5,50,157.08 +qfilter 0.2,31.4