Skip to content

Commit

Permalink
clean up codes and add in test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvieta1990 committed Mar 26, 2021
1 parent 7cb2b1b commit 7ea26bc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
73 changes: 42 additions & 31 deletions addie/processing/idl/run_sum_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
import get_periodictable_formatted_element_and_number_of_atoms as format_ele
import numpy as np
import re

Expand Down Expand Up @@ -104,37 +104,48 @@ def create_output_file(self):
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:
f = open(self._runs[_label]["sam_name"] + ".redpar", "w")
chem_form_temp = self._runs[_label]["sam_formula"]
list_element = chem_form_temp.split(" ")
formated_ele_list = []
for _element in list_element:
[formated_element, number_of_atoms, case] = get_periodictable_formatted_element_and_number_of_atoms(_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
sample_form_str = sample_form_str[:-1]
f.write("{0:13s}{1:<s}\n".format("formula", sample_form_str))
f.write("{0:13s}{1:<s}\n".format("massdensity", self._runs[_label]["mass_density"]))
f.write("{0:13s}{1:<s}\n".format("radius", self._runs[_label]["radius"]))
f.write("{0:13s}{1:<s}\n".format("packfrac", self._runs[_label]["packing_fraction"]))
f.write("{0:13s}{1:<s}\n".format("geometry", self._runs[_label]["geometry"]))
[r_range_min, r_range_max] = o_gui_handler.get_r_range()
r_max_possible = "{0:6.2F}".format(np.pi / self.q_interval_min)
if r_range_min and r_range_max:
f.write("{0:13s}{1:<s}\n".format("rfilter", r_range_min + "," + r_range_max + "," + r_max_possible))
if q_range_min and q_range_max:
f.write("{0:13s}{1:<s}\n".format("qfilter", q_range_min + "," + q_range_max))
f.close()
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:<s}\n".format("formula", runs_info[_label]["sam_form_used"]))
f.write("{0:13s}{1:<s}\n".format("massdensity", runs_info[_label]["mass_density"]))
f.write("{0:13s}{1:<s}\n".format("radius", runs_info[_label]["radius"]))
f.write("{0:13s}{1:<s}\n".format("packfrac", runs_info[_label]["packing_fraction"]))
f.write("{0:13s}{1:<s}\n".format("geometry", runs_info[_label]["geometry"]))
if None not in runs_info["r_range"]:
f.write("{0:13s}{1:<s}\n".format("rfilter", ",".join(runs_info["r_range"])))
if None not in runs_info["q_range"]:
f.write("{0:13s}{1:<s}\n".format("qfilter", ",".join(runs_info["q_range"])))

def collect_runs_checked(self):
table = self.parent.table
Expand Down
7 changes: 7 additions & 0 deletions tests/test_files/SiO2.redpar
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7ea26bc

Please sign in to comment.