Пример #1
0
 def test_new(self):
     test_strain = Strain([[0., 0.01, 0.], [0.01, 0.0002, 0.], [0., 0.,
                                                                0.]])
     self.assertArrayAlmostEqual(
         test_strain,
         test_strain.get_deformation_matrix().green_lagrange_strain)
     self.assertRaises(ValueError, Strain,
                       [[0.1, 0.1, 0], [0, 0, 0], [0, 0, 0]])
Пример #2
0
 def test_new(self):
     test_strain = Strain([[0., 0.01, 0.],
                           [0.01, 0.0002, 0.],
                           [0., 0., 0.]])
     self.assertArrayAlmostEqual(
         test_strain,
         test_strain.get_deformation_matrix().green_lagrange_strain)
     self.assertRaises(ValueError, Strain, [[0.1, 0.1, 0],
                                            [0, 0, 0],
                                            [0, 0, 0]])
Пример #3
0
class StrainTest(PymatgenTest):
    def setUp(self):
        self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0],
                                                 [0, 0, 1]])
        self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0],
                                                [0, 0, 1]])

        self.non_ind_str = Strain.from_deformation([[1, 0.02, 0.02], [0, 1, 0],
                                                    [0, 0, 1]])

        with warnings.catch_warnings(record=True):
            warnings.simplefilter("always")
            self.no_dfm = Strain([[0., 0.01, 0.], [0.01, 0.0002, 0.],
                                  [0., 0., 0.]])

    def test_new(self):
        test_strain = Strain([[0., 0.01, 0.], [0.01, 0.0002, 0.], [0., 0.,
                                                                   0.]])
        self.assertArrayAlmostEqual(
            test_strain,
            test_strain.get_deformation_matrix().green_lagrange_strain)
        self.assertRaises(ValueError, Strain,
                          [[0.1, 0.1, 0], [0, 0, 0], [0, 0, 0]])

    def test_from_deformation(self):
        self.assertArrayAlmostEqual(self.norm_str,
                                    [[0.0202, 0, 0], [0, 0, 0], [0, 0, 0]])
        self.assertArrayAlmostEqual(
            self.ind_str, [[0., 0.01, 0.], [0.01, 0.0002, 0.], [0., 0., 0.]])
        self.assertArrayAlmostEqual(
            self.non_ind_str,
            [[0., 0.01, 0.01], [0.01, 0.0002, 0.0002], [0.01, 0.0002, 0.0002]])

    def test_from_index_amount(self):
        # From voigt index
        test = Strain.from_index_amount(2, 0.01)
        should_be = np.zeros((3, 3))
        should_be[2, 2] = 0.01
        self.assertArrayAlmostEqual(test, should_be)
        # from full-tensor index
        test = Strain.from_index_amount((1, 2), 0.01)
        should_be = np.zeros((3, 3))
        should_be[1, 2] = should_be[2, 1] = 0.01
        self.assertArrayAlmostEqual(test, should_be)

    def test_properties(self):
        # deformation matrix
        self.assertArrayAlmostEqual(self.ind_str.get_deformation_matrix(),
                                    [[1, 0.02, 0], [0, 1, 0], [0, 0, 1]])
        symm_dfm = Strain(
            self.no_dfm).get_deformation_matrix(shape="symmetric")
        self.assertArrayAlmostEqual(
            symm_dfm,
            [[0.99995, 0.0099995, 0], [0.0099995, 1.00015, 0], [0, 0, 1]])
        self.assertArrayAlmostEqual(self.no_dfm.get_deformation_matrix(),
                                    [[1, 0.02, 0], [0, 1, 0], [0, 0, 1]])

        # voigt
        self.assertArrayAlmostEqual(self.non_ind_str.voigt,
                                    [0, 0.0002, 0.0002, 0.0004, 0.02, 0.02])

    def test_convert_strain_to_deformation(self):
        strain = Tensor(np.random.random((3, 3))).symmetrized
        while not (np.linalg.eigvals(strain) > 0).all():
            strain = Tensor(np.random.random((3, 3))).symmetrized
        upper = convert_strain_to_deformation(strain, shape="upper")
        symm = convert_strain_to_deformation(strain, shape="symmetric")
        self.assertArrayAlmostEqual(np.triu(upper), upper)
        self.assertTrue(Tensor(symm).is_symmetric())
        for defo in upper, symm:
            self.assertArrayAlmostEqual(defo.green_lagrange_strain, strain)
Пример #4
0
class StrainTest(PymatgenTest):
    def setUp(self):
        self.norm_str = Strain.from_deformation([[1.02, 0, 0],
                                                 [0, 1, 0],
                                                 [0, 0, 1]])
        self.ind_str = Strain.from_deformation([[1, 0.02, 0],
                                                [0, 1, 0],
                                                [0, 0, 1]])

        self.non_ind_str = Strain.from_deformation([[1, 0.02, 0.02],
                                                    [0, 1, 0],
                                                    [0, 0, 1]])

        with warnings.catch_warnings(record=True):
            warnings.simplefilter("always")
            self.no_dfm = Strain([[0., 0.01, 0.],
                                  [0.01, 0.0002, 0.],
                                  [0., 0., 0.]])

    def test_new(self):
        test_strain = Strain([[0., 0.01, 0.],
                              [0.01, 0.0002, 0.],
                              [0., 0., 0.]])
        self.assertArrayAlmostEqual(
            test_strain,
            test_strain.get_deformation_matrix().green_lagrange_strain)
        self.assertRaises(ValueError, Strain, [[0.1, 0.1, 0],
                                               [0, 0, 0],
                                               [0, 0, 0]])

    def test_from_deformation(self):
        self.assertArrayAlmostEqual(self.norm_str,
                                    [[0.0202, 0, 0],
                                     [0, 0, 0],
                                     [0, 0, 0]])
        self.assertArrayAlmostEqual(self.ind_str,
                                    [[0., 0.01, 0.],
                                     [0.01, 0.0002, 0.],
                                     [0., 0., 0.]])
        self.assertArrayAlmostEqual(self.non_ind_str,
                                    [[0., 0.01, 0.01],
                                     [0.01, 0.0002, 0.0002],
                                     [0.01, 0.0002, 0.0002]])

    def test_from_index_amount(self):
        # From voigt index
        test = Strain.from_index_amount(2, 0.01)
        should_be = np.zeros((3, 3))
        should_be[2, 2] = 0.01
        self.assertArrayAlmostEqual(test, should_be)
        # from full-tensor index
        test = Strain.from_index_amount((1, 2), 0.01)
        should_be = np.zeros((3, 3))
        should_be[1, 2] = should_be[2, 1] = 0.01
        self.assertArrayAlmostEqual(test, should_be)

    def test_properties(self):
        # deformation matrix
        self.assertArrayAlmostEqual(self.ind_str.get_deformation_matrix(),
                                    [[1, 0.02, 0],
                                     [0, 1, 0],
                                     [0, 0, 1]])
        symm_dfm = Strain(self.no_dfm).get_deformation_matrix(shape="symmetric")
        self.assertArrayAlmostEqual(symm_dfm, [[0.99995,0.0099995, 0],
                                               [0.0099995,1.00015, 0],
                                               [0, 0, 1]])
        self.assertArrayAlmostEqual(self.no_dfm.get_deformation_matrix(),
                                    [[1, 0.02, 0],
                                     [0, 1, 0],
                                     [0, 0, 1]])

        # voigt
        self.assertArrayAlmostEqual(self.non_ind_str.voigt,
                                    [0, 0.0002, 0.0002, 0.0004, 0.02, 0.02])

    def test_convert_strain_to_deformation(self):
        strain = Tensor(np.random.random((3, 3))).symmetrized
        while not (np.linalg.eigvals(strain) > 0).all():
            strain = Tensor(np.random.random((3, 3))).symmetrized
        upper = convert_strain_to_deformation(strain, shape="upper")
        symm = convert_strain_to_deformation(strain, shape="symmetric")
        self.assertArrayAlmostEqual(np.triu(upper), upper)
        self.assertTrue(Tensor(symm).is_symmetric())
        for defo in upper, symm:
            self.assertArrayAlmostEqual(defo.green_lagrange_strain, strain)