예제 #1
0
    def test_box_vectors(self):
        """Test the getter and setter for box_vectors"""
        topology = Topology()
        good_box_vectors = unit.Quantity(np.array([10, 20, 30]), unit.angstrom)
        bad_box_vectors = np.array([10, 20, 30
                                    ])  # They're bad because they're unitless
        assert topology.box_vectors is None

        with self.assertRaises(ValueError) as context:
            topology.box_vectors = bad_box_vectors
        assert topology.box_vectors is None

        topology.box_vectors = good_box_vectors
        assert (topology.box_vectors == good_box_vectors).all()
예제 #2
0
    def test_box_vectors(self):
        """Test the getter and setter for box_vectors"""
        topology = Topology()
        good_box_vectors = unit.Quantity(np.eye(3) * 20 * unit.angstrom)
        one_dim_vectors = unit.Quantity(np.ones(3) * 20 * unit.angstrom)
        bad_shape_vectors = unit.Quantity(np.ones(2) * 20 * unit.angstrom)
        bad_units_vectors = unit.Quantity(np.ones(3) * 20 * unit.year)
        unitless_vectors = np.array([10, 20, 30])
        assert topology.box_vectors is None

        for bad_vectors in [
                bad_shape_vectors,
                bad_units_vectors,
                unitless_vectors,
        ]:
            with self.assertRaises(InvalidBoxVectorsError):
                topology.box_vectors = bad_vectors
            assert topology.box_vectors is None

        for good_vectors in [good_box_vectors, one_dim_vectors]:
            topology.box_vectors = good_vectors
            assert (topology.box_vectors == good_vectors * np.eye(3)).all()