示例#1
0
    def test_cell_wrap(self):
        """Test that coordinates are correctly wrapped inside the cell.
        """
        system = System(
            scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
            symbols=["H", "H"],
            cell=[
                [1, 0, 0],
                [0, 1, 0],
                [0, 0, 1]
            ],
            pbc = [True, True, True],
        )

        #orig = np.array([[2, 1.45, -4.8]])
        orig = np.array([[0.5, 0.5, 1.5]])
        scal = system.to_scaled(orig, wrap = True)
        cart = system.to_cartesian(scal)
        self.assertFalse(np.allclose(orig, cart))


        scal2 = system.to_scaled(orig)
        cart2 = system.to_cartesian(scal2, wrap = True)
        self.assertFalse(np.allclose(orig, cart2))

        
        scal3 = system.to_scaled(orig, True)
        cart3 = system.to_cartesian(scal3, wrap = True)
        self.assertFalse(np.allclose(orig, cart3))

        scal4 = system.to_scaled(orig)
        cart4 = system.to_cartesian(scal4)
        self.assertTrue(np.allclose(orig, cart4))
       
        self.assertTrue(np.allclose(cart2, cart3))
示例#2
0
    def test_transformations(self):
        """Test that coordinates are correctly transformed from scaled to
        cartesian and back again.
        """
        system = System(
            scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
            symbols=["H", "H"],
            cell=[[5, 5, 0], [0, -5, -5], [5, 0, 5]],
        )

        orig = np.array([[2, 1.45, -4.8]])
        scal = system.to_scaled(orig)
        cart = system.to_cartesian(scal)
        self.assertTrue(np.allclose(orig, cart))