예제 #1
0
    def test_scale(self):
        """
        Test if scaling is correct.
        @return:
        """
        wrk_ref = Abins(AbInitioProgram=self._ab_initio_program,
                        VibrationalOrPhononFile=self._squaricn + ".phonon",
                        TemperatureInKelvin=self._temperature,
                        SampleForm=self._sample_form,
                        Instrument=self._instrument_name,
                        Atoms=self._atoms,
                        Scale=self._scale,
                        SumContributions=self._sum_contributions,
                        QuantumOrderEventsNumber=self._quantum_order_events_number,
                        ScaleByCrossSection=self._cross_section_factor,
                        OutputWorkspace=self._squaricn + "_ref")

        wrk = Abins(AbInitioProgram=self._ab_initio_program,
                    VibrationalOrPhononFile=self._squaricn + ".phonon",
                    TemperatureInKelvin=self._temperature,
                    SampleForm=self._sample_form,
                    Instrument=self._instrument_name,
                    Atoms=self._atoms,
                    SumContributions=self._sum_contributions,
                    QuantumOrderEventsNumber=self._quantum_order_events_number,
                    Scale=10,
                    ScaleByCrossSection=self._cross_section_factor,
                    OutputWorkspace="squaricn_scale")

        ref = Scale(wrk_ref, Factor=10)

        (result, messages) = CompareWorkspaces(wrk, ref, Tolerance=self._tolerance)
        self.assertEqual(result, True)
예제 #2
0
    def case_restart_diff_t(self):
        """
        The considered testing scenario looks as follows. First the user performs the simulation for T=10K (first run).
        Then the user changes T to 20K (second run). For T=20K  S has to be recalculated. After that the user performs
        simulation with the same parameters as for the initial simulation, e.g., T=10K (third run). In the third run all
        required data will be read from hdf file. It is checked if workspace for the initial run and the third run is
        the same (should be the same).
        """
        temperature_for_test = self._temperature + 10  # 20K
        wrk_name = self._system_name

        # T = 10 K
        Abins(AbInitioProgram=self._ab_initio_program,
              VibrationalOrPhononFile=self._system_name + self._extension[self._ab_initio_program],
              TemperatureInKelvin=self._temperature, SampleForm=self._sample_form, Instrument=self._instrument_name,
              BinWidthInWavenumber=self._bin_width, Atoms=self._atoms, SumContributions=self._sum_contributions,
              Scale=self._scale, QuantumOrderEventsNumber=str(self._quantum_order_event),
              ScaleByCrossSection=self._cross_section_factor, OutputWorkspace=wrk_name + "init")

        # T = 20 K
        Abins(AbInitioProgram=self._ab_initio_program,
              VibrationalOrPhononFile=self._system_name + self._extension[self._ab_initio_program],
              TemperatureInKelvin=temperature_for_test, SampleForm=self._sample_form, Instrument=self._instrument_name,
              BinWidthInWavenumber=self._bin_width,
              Atoms=self._atoms, SumContributions=self._sum_contributions, Scale=self._scale,
              QuantumOrderEventsNumber=str(self._quantum_order_event), ScaleByCrossSection=self._cross_section_factor,
              OutputWorkspace=wrk_name + "_mod")

        # T = 10 K
        Abins(AbInitioProgram=self._ab_initio_program,
              VibrationalOrPhononFile=self._system_name + self._extension[self._ab_initio_program],
              TemperatureInKelvin=self._temperature, SampleForm=self._sample_form, Instrument=self._instrument_name,
              BinWidthInWavenumber=self._bin_width, Atoms=self._atoms, SumContributions=self._sum_contributions,
              Scale=self._scale, QuantumOrderEventsNumber=str(self._quantum_order_event),
              ScaleByCrossSection=self._cross_section_factor, OutputWorkspace=self._output_name)
예제 #3
0
    def test_exp(self):
        """
        Tests if experimental data is loaded correctly.
        @return:
        """
        Abins(AbInitioProgram=self._ab_initio_program,
              VibrationalOrPhononFile="benzene_Abins.phonon",
              ExperimentalFile="benzene_Abins.dat",
              TemperatureInKelvin=self._temperature,
              SampleForm=self._sample_form,
              Instrument=self._instrument_name,
              Atoms=self._atoms,
              Scale=self._scale,
              SumContributions=self._sum_contributions,
              QuantumOrderEventsNumber=self._quantum_order_events_number,
              ScaleByCrossSection=self._cross_section_factor,
              OutputWorkspace="benzene_exp")

        # load experimental data
        Load(Filename="benzene.dat", OutputWorkspace="benzene_only_exp")

        (result,
         messages) = CompareWorkspaces(Workspace1=mtd["experimental_wrk"],
                                       Workspace2=mtd["benzene_only_exp"],
                                       CheckAxes=False,
                                       Tolerance=self._tolerance)
        self.assertEqual(result, True)
예제 #4
0
 def case_from_scratch(self):
     """
     User performs calculation from scratch (not loaded from hdf file). All data is calculated.
     """
     Abins(DFTprogram=self._dft_program, PhononFile=self._system_name + self._extension[self._dft_program],
           Temperature=self._temperature, SampleForm=self._sample_form, Instrument=self._instrument_name,
           Atoms=self._atoms, SumContributions=self._sum_contributions,
           QuantumOrderEventsNumber=str(self._quantum_order_event), Scale=self._scale,
           ScaleByCrossSection=self._cross_section_factor, OutputWorkspace=self._output_name)
    def test_good_case(self):

        good_names = [self._wrk_name, self._wrk_name + "_Si", self._wrk_name + "_Si_total"]
        Abins(PhononFile=self._Si2 + ".phonon", OutputWorkspace=self._wrk_name)
        names = mtd.getObjectNames()
        # Builtin cmp has been removed in Python 3
        def _cmp(a, b):
            return (a > b) - (a < b)
        self.assertAlmostEqual(0, _cmp(good_names, names))
예제 #6
0
    def test_partial(self):
        # By default workspaces for all atoms should be created. Test this default behaviour.

        experimental_file = ""

        wrk_ref = Abins(AbInitioProgram=self._ab_initio_program,
                        VibrationalOrPhononFile=self._squaricn + ".phonon",
                        ExperimentalFile=experimental_file,
                        TemperatureInKelvin=self._temperature,
                        SampleForm=self._sample_form,
                        Instrument=self._instrument_name,
                        Atoms=self._atoms,
                        Scale=self._scale,
                        SumContributions=self._sum_contributions,
                        QuantumOrderEventsNumber=self._quantum_order_events_number,
                        ScaleByCrossSection=self._cross_section_factor,
                        OutputWorkspace=self._squaricn + "_ref")

        wks_all_atoms_explicitly = Abins(VibrationalOrPhononFile=self._squaricn + ".phonon",
                                         Atoms="H, C, O",
                                         SumContributions=self._sum_contributions,
                                         QuantumOrderEventsNumber=self._quantum_order_events_number,
                                         OutputWorkspace="explicit")

        wks_all_atoms_default = Abins(VibrationalOrPhononFile=self._squaricn + ".phonon",
                                      SumContributions=self._sum_contributions,
                                      QuantumOrderEventsNumber=self._quantum_order_events_number,
                                      OutputWorkspace="default")

        # Python 3 has no guarantee of dict order so the workspaces in the group may be in
        # a different order on Python 3
        self.assertEqual(wks_all_atoms_explicitly.size(), wks_all_atoms_default.size())
        explicit_names = wks_all_atoms_explicitly.getNames()
        for i in range(len(explicit_names)):
            explicit_name = explicit_names[i]
            default_name = "default" + explicit_name[8:]
            (result, messages) = CompareWorkspaces(explicit_name, default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)

        self.assertEqual(wrk_ref.size(), wks_all_atoms_default.size())
        ref_names = wrk_ref.getNames()
        for i in range(len(ref_names)):
            ref_name = ref_names[i]
            default_name = "default" + ref_name[len(self._squaricn + "_ref"):]
            (result, messages) = CompareWorkspaces(ref_name, default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)
예제 #7
0
    def test_partial_by_number(self):
        """Simulated INS spectrum can also be resolved by numbered atoms. Check consistency with element totals"""

        wrk_ref = Abins(AbInitioProgram=self._ab_initio_program,
                        VibrationalOrPhononFile=self._squaricn + ".phonon",
                        Atoms=self._atoms,
                        QuantumOrderEventsNumber=self._quantum_order_events_number,
                        ScaleByCrossSection=self._cross_section_factor,
                        OutputWorkspace=self._squaricn + "_ref")

        numbered_workspace_name = "numbered"
        h_indices = ("1", "2", "3", "4")
        wks_numbered_atoms = Abins(VibrationalOrPhononFile=self._squaricn + ".phonon",
                                   Atoms=", ".join([AbinsConstants.ATOM_PREFIX + s for s in h_indices]),
                                   SumContributions=self._sum_contributions,
                                   QuantumOrderEventsNumber=self._quantum_order_events_number,
                                   ScaleByCrossSection=self._cross_section_factor,
                                   OutputWorkspace=numbered_workspace_name)

        wrk_ref_names = list(wrk_ref.getNames())
        wrk_h_total = wrk_ref[wrk_ref_names.index(self._squaricn + "_ref_H_total")]

        wks_numbered_atom_names = list(wks_numbered_atoms.getNames())
        wrk_atom_totals = [wks_numbered_atoms[wks_numbered_atom_names.index(name)]
                           for name in
                           ['_'.join((numbered_workspace_name, AbinsConstants.ATOM_PREFIX, s, 'total')) for s in h_indices]]

        assert_array_almost_equal(wrk_h_total.extractX(), wrk_atom_totals[0].extractX())

        assert_array_almost_equal(wrk_h_total.extractY(),
                                  sum((wrk.extractY() for wrk in wrk_atom_totals)))
예제 #8
0
 def test_lagrange_exists(self):
     Abins(AbInitioProgram=self._ab_initio_program,
           VibrationalOrPhononFile=(self._squaricn + ".phonon"),
           TemperatureInKelvin=self._temperature,
           SampleForm=self._sample_form,
           Instrument="Lagrange",
           Setting="Cu(331) (Lagrange)",
           Atoms=self._atoms,
           Scale=self._scale,
           SumContributions=self._sum_contributions,
           QuantumOrderEventsNumber=self._quantum_order_events_number,
           ScaleByCrossSection=self._cross_section_factor,
           OutputWorkspace="squaricn-lagrange")
예제 #9
0
 def case_restart_diff_order(self, order=None):
     """
     The considered testing scenario looks as follows. First calculations are performed for
     self._quantum_order_event. Then calculations are performed for order (different quantum order event). In case
     order >  self._quantum_order_event then S should be calculated. Otherwise, it will be loaded from an hdf file.
     :param order: number of quantum order event for which restart should be done.
     """
     self.case_from_scratch()
     DeleteWorkspace(self._output_name)
     Abins(DFTprogram=self._dft_program, PhononFile=self._system_name + self._extension[self._dft_program],
           Temperature=self._temperature, SampleForm=self._sample_form, Instrument=self._instrument_name,
           Atoms=self._atoms, SumContributions=self._sum_contributions, Scale=self._scale,
           QuantumOrderEventsNumber=str(order), ScaleByCrossSection=self._cross_section_factor,
           OutputWorkspace=self._output_name)
예제 #10
0
    def test_partial_by_element(self):
        """Check results of INS spectrum resolved by elements: default should match explicit list of elements"""

        experimental_file = ""

        wrk_ref = Abins(
            AbInitioProgram=self._ab_initio_program,
            VibrationalOrPhononFile=self._squaricn + ".phonon",
            ExperimentalFile=experimental_file,
            TemperatureInKelvin=self._temperature,
            SampleForm=self._sample_form,
            Instrument=self._instrument_name,
            Atoms=self._atoms,
            Scale=self._scale,
            SumContributions=self._sum_contributions,
            QuantumOrderEventsNumber=self._quantum_order_events_number,
            ScaleByCrossSection=self._cross_section_factor,
            OutputWorkspace=self._squaricn + "_ref")

        wks_all_atoms_explicitly = Abins(
            VibrationalOrPhononFile=self._squaricn + ".phonon",
            Atoms="H, C, O",
            SumContributions=self._sum_contributions,
            QuantumOrderEventsNumber=self._quantum_order_events_number,
            OutputWorkspace="explicit")

        wks_all_atoms_default = Abins(
            VibrationalOrPhononFile=self._squaricn + ".phonon",
            SumContributions=self._sum_contributions,
            QuantumOrderEventsNumber=self._quantum_order_events_number,
            OutputWorkspace="default")

        # Python 3 has no guarantee of dict order so the workspaces in the group may be in
        # a different order on Python 3
        self.assertEqual(wks_all_atoms_explicitly.size(),
                         wks_all_atoms_default.size())
        explicit_names = wks_all_atoms_explicitly.getNames()
        for i in range(len(explicit_names)):
            explicit_name = explicit_names[i]
            default_name = "default" + explicit_name[8:]
            (result, messages) = CompareWorkspaces(explicit_name,
                                                   default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)

        self.assertEqual(wrk_ref.size(), wks_all_atoms_default.size())
        ref_names = wrk_ref.getNames()
        for i in range(len(ref_names)):
            ref_name = ref_names[i]
            default_name = "default" + ref_name[len(self._squaricn + "_ref"):]
            (result, messages) = CompareWorkspaces(ref_name,
                                                   default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)
예제 #11
0
    def test_partial(self):
        # By default workspaces for all atoms should be created. Test this default behaviour.

        experimental_file = ""

        wrk_ref = Abins(DFTprogram=self._dft_program,
                        PhononFile=self._squaricn + ".phonon",
                        ExperimentalFile=experimental_file,
                        Temperature=self._temperature,
                        SampleForm=self._sample_form,
                        Instrument=self._instrument_name,
                        Atoms=self._atoms,
                        Scale=self._scale,
                        SumContributions=self._sum_contributions,
                        QuantumOrderEventsNumber=self._quantum_order_events_number,
                        ScaleByCrossSection=self._cross_section_factor,
                        OutputWorkspace=self._squaricn + "_ref")

        wks_all_atoms_explicitly = Abins(PhononFile=self._squaricn + ".phonon",
                                         Atoms="H, C, O",
                                         SumContributions=self._sum_contributions,
                                         QuantumOrderEventsNumber=self._quantum_order_events_number,
                                         OutputWorkspace="explicit")

        wks_all_atoms_default = Abins(PhononFile=self._squaricn + ".phonon",
                                      SumContributions=self._sum_contributions,
                                      QuantumOrderEventsNumber=self._quantum_order_events_number,
                                      OutputWorkspace="default")

        # Python 3 has no guarantee of dict order so the workspaces in the group may be in
        # a different order on Python 3
        self.assertEqual(wks_all_atoms_explicitly.size(), wks_all_atoms_default.size())
        explicit_names = wks_all_atoms_explicitly.getNames()
        for i in range(len(explicit_names)):
            explicit_name = explicit_names[i]
            default_name = "default" + explicit_name[8:]
            (result, messages) = CompareWorkspaces(explicit_name, default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)

        self.assertEqual(wrk_ref.size(), wks_all_atoms_default.size())
        ref_names = wrk_ref.getNames()
        for i in range(len(ref_names)):
            ref_name = ref_names[i]
            default_name = "default" + ref_name[len(self._squaricn + "_ref"):]
            (result, messages) = CompareWorkspaces(ref_name, default_name,
                                                   Tolerance=self._tolerance)
            self.assertEqual(result, True)