Пример #1
0
    def test_good_case(self):

        # hypothetical data for two atoms
        good_powder = {"a_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03],
                                               [0.01, 0.02, 0.03]],

                                               [[0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03]]])},

                       "b_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03]],

                                                [[0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03]]])}}
        good_tester = PowderData(num_atoms=2)
        good_tester.set(items=good_powder)

        extracted_data = good_tester.extract()
        for key in good_powder:
            for k_point in good_powder[key]:
                self.assertEqual(True, np.allclose(good_powder[key][k_point], extracted_data[key][k_point]))
Пример #2
0
    def test_good_case(self):

        # hypothetical data for two atoms
        good_powder = {"a_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03],
                                               [0.01, 0.02, 0.03]],

                                               [[0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03],
                                                [0.01, 0.02, 0.03]]])},

                       "b_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03]],

                                                [[0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03],
                                                 [0.01, 0.02, 0.03]]])}}
        good_tester = PowderData(num_atoms=2)
        good_tester.set(items=good_powder)

        extracted_data = good_tester.extract()
        for key in good_powder:
            for k_point in good_powder[key]:
                self.assertEqual(True, np.allclose(good_powder[key][k_point], extracted_data[key][k_point]))
Пример #3
0
    def test_set(self):

        poor_tester = PowderData(num_atoms=2)

        # wrong items: list instead of numpy array
        bad_items = {
            "a_tensors": [[0.002, 0.001]],
            "b_tensors": [[0.002, 0.001]]
        }
        with self.assertRaises(ValueError):
            poor_tester.set(items=bad_items)

        # wrong size of items: data only for one atom ; should be for two atoms
        bad_items = {
            "a_tensors": {
                "0":
                np.asarray([[[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
                             [0.01, 0.02, 0.03]]])
            },
            "b_tensors": {
                "0":
                np.asarray([[[0.01, 0.02, 0.03], [0.01, 0.02, 0.03],
                             [0.01, 0.02, 0.03]]])
            }
        }
        with self.assertRaises(ValueError):
            poor_tester.set(items=bad_items)
Пример #4
0
    def test_set(self):

        poor_tester = PowderData(num_atoms=2)

        # wrong items: list instead of numpy array
        bad_items = {"a_tensors": [[0.002, 0.001]], "b_tensors": [[0.002, 0.001]]}
        with self.assertRaises(ValueError):
            poor_tester.set(items=bad_items)

        # wrong size of items: data only for one atom ; should be for two atoms
        bad_items = {"a_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03], [0.01, 0.02, 0.03], [0.01, 0.02, 0.03]]])},
                     "b_tensors": {"0": np.asarray([[[0.01, 0.02, 0.03], [0.01, 0.02, 0.03], [0.01, 0.02, 0.03]]])}}
        with self.assertRaises(ValueError):
            poor_tester.set(items=bad_items)