示例#1
0
    def test_s_data(self):
        abins.parameters.sampling['min_wavenumber'] = 100
        abins.parameters.sampling['max_wavenumber'] = 150

        s_data = abins.SData(temperature=10, sample_form='Powder')
        s_data.set_bin_width(10)
        s_data.set({
            'frequencies': np.linspace(105, 145, 5),
            'atom_1': {
                's': {
                    'order_1': np.array([
                        0.,
                        0.001,
                        1.,
                        1.,
                        0.,
                        0.,
                    ])
                }
            }
        })

        with self.assertRaises(AssertionError):
            with self.assertLogs(logger=self.logger, level='WARNING'):
                s_data.check_thresholds(logger=self.logger)

        abins.parameters.sampling['s_absolute_threshold'] = 0.5
        with self.assertLogs(logger=self.logger, level='WARNING'):
            s_data.check_thresholds(logger=self.logger)
    def _calculate_s_powder_1d(self):
        """
        Calculates 1D S for the powder case.

        :returns: object of type SData with 1D dynamical structure factors for the powder case
        """
        data = self._calculate_s_powder_over_k()

        s_data = abins.SData(temperature=self._temperature,
                             sample_form=self._sample_form,
                             frequencies=self._frequencies,
                             data=data)
        return s_data
    def load_formatted_data(self):
        """
        Loads S from an hdf file.
        :returns: object of type SData.
        """
        data = self._clerk.load(
            list_of_datasets=["data"],
            list_of_attributes=["filename", "order_of_quantum_events"])
        if self._quantum_order_num > data["attributes"][
                "order_of_quantum_events"]:
            raise ValueError(
                "User requested a larger number of quantum events to be included in the simulation "
                "then in the previous calculations. S cannot be loaded from the hdf file."
            )
        if self._quantum_order_num < data["attributes"][
                "order_of_quantum_events"]:

            self._report_progress("""
                         User requested a smaller number of quantum events than in the previous calculations.
                         S Data from hdf file which corresponds only to requested quantum order events will be
                         loaded.""")

            temp_data = {
                "frequencies": data["datasets"]["data"]["frequencies"]
            }

            # load atoms_data
            n_atom = len([
                key for key in data["datasets"]["data"].keys() if "atom" in key
            ])
            for i in range(n_atom):
                temp_data["atom_%s" % i] = {"s": dict()}
                for j in range(FUNDAMENTALS,
                               self._quantum_order_num + S_LAST_INDEX):

                    temp_val = data["datasets"]["data"]["atom_%s" %
                                                        i]["s"]["order_%s" % j]
                    temp_data["atom_%s" % i]["s"].update(
                        {"order_%s" % j: temp_val})

            # reduce the data which is loaded to only this data which is required by the user
            data["datasets"]["data"] = temp_data

        s_data = abins.SData(temperature=self._temperature,
                             sample_form=self._sample_form)
        s_data.set_bin_width(width=self._bin_width)
        s_data.set(items=data["datasets"]["data"])

        return s_data
    def _calculate_s_powder_1d(self):
        """
        Calculates 1D S for the powder case.

        :returns: object of type SData with 1D dynamical structure factors for the powder case
        """
        # calculate data
        data = self._calculate_s_powder_over_k()
        data.update({"frequencies": self._frequencies})

        # put data to SData object
        s_data = abins.SData(temperature=self._temperature,
                             sample_form=self._sample_form)
        s_data.set_bin_width(width=self._bin_width)
        s_data.set(items=data)

        return s_data