diff --git a/Framework/PythonInterface/plugins/algorithms/Abins.py b/Framework/PythonInterface/plugins/algorithms/Abins.py index e99fa7e64ce91c0464ccf4c1b23f3ca90d61ea92..7ac33ef7cacc0583be33df20b340b5cd336e4bbf 100644 --- a/Framework/PythonInterface/plugins/algorithms/Abins.py +++ b/Framework/PythonInterface/plugins/algorithms/Abins.py @@ -184,7 +184,8 @@ class Abins(PythonAlgorithm): s_calculator = AbinsModules.CalculateS.init(filename=self._phonon_file, temperature=self._temperature, sample_form=self._sample_form, abins_data=dft_data, instrument=self._instrument, - quantum_order_num=self._num_quantum_order_events) + quantum_order_num=self._num_quantum_order_events, + bin_width=self._bin_width) s_data = s_calculator.get_formatted_data() prog_reporter.report("Dynamical structure factors have been determined.") diff --git a/scripts/AbinsModules/CalculateS.py b/scripts/AbinsModules/CalculateS.py index 4bc0cfaf60cc0e3a5466d5ed27c2b30d1d440cdf..35cb2925cff554074bc4fb7c1c1a4edf63004a51 100644 --- a/scripts/AbinsModules/CalculateS.py +++ b/scripts/AbinsModules/CalculateS.py @@ -12,7 +12,7 @@ class CalculateS(object): @staticmethod def init(filename=None, temperature=None, sample_form=None, abins_data=None, instrument=None, - quantum_order_num=None): + quantum_order_num=None, bin_width=1.0): """ :param filename: name of input DFT file (CASTEP: foo.phonon) :param temperature: temperature in K for which calculation of S should be done @@ -20,13 +20,15 @@ class CalculateS(object): :param abins_data: object of type AbinsData with data from phonon file :param instrument: object of type Instrument for which simulation should be performed :param quantum_order_num: number of quantum order events taken into account during the simulation + :param bin_width: width of bins in wavenumber """ if sample_form in AbinsModules.AbinsConstants.ALL_SAMPLE_FORMS: if sample_form == "Powder": return AbinsModules.SPowderSemiEmpiricalCalculator(filename=filename, temperature=temperature, abins_data=abins_data, instrument=instrument, - quantum_order_num=quantum_order_num) + quantum_order_num=quantum_order_num, + bin_width=bin_width) # TODO: implement numerical powder averaging # elif sample == "SingleCrystal": #TODO implement single crystal scenario diff --git a/scripts/AbinsModules/SPowderSemiEmpiricalCalculator.py b/scripts/AbinsModules/SPowderSemiEmpiricalCalculator.py index fd58b3bb10405589b8eeae60431d8bbc5a6c66a8..65902cf4376f74c860e3f533b7048664486cb5d6 100644 --- a/scripts/AbinsModules/SPowderSemiEmpiricalCalculator.py +++ b/scripts/AbinsModules/SPowderSemiEmpiricalCalculator.py @@ -34,7 +34,8 @@ class SPowderSemiEmpiricalCalculator(object): Class for calculating S(Q, omega) """ - def __init__(self, filename=None, temperature=None, abins_data=None, instrument=None, quantum_order_num=None): + def __init__(self, filename=None, temperature=None, abins_data=None, instrument=None, quantum_order_num=None, + bin_width=1.0): """ :param filename: name of input DFT file (CASTEP: foo.phonon) :param temperature: temperature in K for which calculation of S should be done @@ -42,6 +43,7 @@ class SPowderSemiEmpiricalCalculator(object): :param abins_data: object of type AbinsData with data from phonon file :param instrument: name of instrument (str) :param quantum_order_num: number of quantum order events taken into account during the simulation + :param bin_width: bin width used in rebining in wavenumber """ if not isinstance(temperature, (int, float)): raise ValueError("Invalid value of the temperature. Number was expected.") @@ -96,7 +98,8 @@ class SPowderSemiEmpiricalCalculator(object): AbinsModules.AbinsConstants.QUANTUM_ORDER_THREE: self._calculate_order_three, AbinsModules.AbinsConstants.QUANTUM_ORDER_FOUR: self._calculate_order_four} - step = AbinsModules.AbinsParameters.bin_width + step = bin_width + self._bin_width = bin_width start = AbinsModules.AbinsParameters.min_wavenumber + step stop = AbinsModules.AbinsParameters.max_wavenumber + step self._bins = np.arange(start=start, stop=stop, step=step, dtype=AbinsModules.AbinsConstants.FLOAT_TYPE) @@ -505,7 +508,7 @@ class SPowderSemiEmpiricalCalculator(object): rebined_broad_spectrum = self._fix_empty_array() # multiply by k-point weight and scaling constant - factor = self._weight / AbinsModules.AbinsParameters.bin_width + factor = self._weight / self._bin_width rebined_broad_spectrum = rebined_broad_spectrum * factor return local_freq, local_coeff, rebined_broad_spectrum @@ -657,7 +660,8 @@ class SPowderSemiEmpiricalCalculator(object): output_array_x = self._frequencies output_array_y = np.asarray( a=[array_y[inds == i].sum() for i in range(self._freq_size)], - dtype=AbinsModules.AbinsConstants.FLOAT_TYPE) / AbinsModules.AbinsParameters.bin_width + dtype=AbinsModules.AbinsConstants.FLOAT_TYPE) / self._bin_width + return output_array_x, output_array_y diff --git a/scripts/test/AbinsCalculateSPowderTest.py b/scripts/test/AbinsCalculateSPowderTest.py index 5d8e58a61a52f274ce53b035c02e428d7537387a..730af9dbc9c3ee67dabc49e78f78dd1ae58dd808 100644 --- a/scripts/test/AbinsCalculateSPowderTest.py +++ b/scripts/test/AbinsCalculateSPowderTest.py @@ -32,28 +32,24 @@ class AbinsCalculateSPowderTest(unittest.TestCase): # wrong filename with self.assertRaises(ValueError): - AbinsModules.CalculateS.init(filename=1, temperature=self._temperature, sample_form=self._sample_form, abins_data=good_data, instrument=self._instrument, quantum_order_num=self._order_event) # wrong temperature with self.assertRaises(ValueError): - AbinsModules.CalculateS.init(filename=full_path_filename, temperature=-1, sample_form=self._sample_form, abins_data=good_data, instrument=self._instrument, quantum_order_num=self._order_event) # wrong sample with self.assertRaises(ValueError): - - AbinsModules.CalculateS.init(filename=full_path_filename, temperature=self._temperature, sample_form="SOLID", - abins_data=good_data, instrument=self._instrument, + AbinsModules.CalculateS.init(filename=full_path_filename, temperature=self._temperature, + sample_form="SOLID", abins_data=good_data, instrument=self._instrument, quantum_order_num=self._order_event) # wrong abins data: content of abins data instead of object abins_data with self.assertRaises(ValueError): - AbinsModules.CalculateS.init(filename=full_path_filename, temperature=self._temperature, sample_form=self._sample_form, abins_data=good_data.extract(), instrument=self._instrument, quantum_order_num=self._order_event) @@ -75,18 +71,18 @@ class AbinsCalculateSPowderTest(unittest.TestCase): # calculation of powder data good_data = self._get_good_data(filename=name) good_tester = AbinsModules.CalculateS.init( - filename=AbinsModules.AbinsTestHelpers.find_file(filename=name + ".phonon"), - temperature=self._temperature, sample_form=self._sample_form, abins_data=good_data["DFT"], - instrument=self._instrument, quantum_order_num=self._order_event) + filename=AbinsModules.AbinsTestHelpers.find_file(filename=name + ".phonon"), temperature=self._temperature, + sample_form=self._sample_form, abins_data=good_data["DFT"], instrument=self._instrument, + quantum_order_num=self._order_event) calculated_data = good_tester.get_formatted_data() self._check_data(good_data=good_data["S"], data=calculated_data.extract()) # check if loading powder data is correct - new_tester = AbinsModules.CalculateS.init(filename=AbinsModules.AbinsTestHelpers.find_file(filename=name + ".phonon"), - temperature=self._temperature, sample_form=self._sample_form, - abins_data=good_data["DFT"], instrument=self._instrument, - quantum_order_num=self._order_event) + new_tester = AbinsModules.CalculateS.init( + filename=AbinsModules.AbinsTestHelpers.find_file(filename=name + ".phonon"), temperature=self._temperature, + sample_form=self._sample_form, abins_data=good_data["DFT"], instrument=self._instrument, + quantum_order_num=self._order_event) loaded_data = new_tester.load_formatted_data() self._check_data(good_data=good_data["S"], data=loaded_data.extract())