def test_transforms(self): from MDAnalysis.lib.distances import transform_StoR, transform_RtoS # To check the cython coordinate transform, the same operation is done in numpy # Is a matrix multiplication of Coords x Box = NewCoords, so can use np.dot # Test transformation R_mol1 = transform_StoR(self.S_mol1, self.box) R_np1 = np.dot(self.S_mol1, self.box) # Test transformation when given box in different form R_mol2 = transform_StoR(self.S_mol2, self.boxV) R_np2 = np.dot(self.S_mol2, self.box) assert_almost_equal(R_mol1, R_np1, self.prec, err_msg="StoR transform failed with box") assert_almost_equal(R_mol2, R_np2, self.prec, err_msg="StoR transform failed with boxV") # Round trip test S_test1 = transform_RtoS(R_mol1, self.boxV) # boxV here althought initial transform with box S_test2 = transform_RtoS(R_mol2, self.box) # and vice versa, should still work assert_almost_equal(S_test1, self.S_mol1, self.prec, err_msg="Round trip failed in transform") assert_almost_equal(S_test2, self.S_mol2, self.prec, err_msg="Round trip failed in transform")
def test_transforms(self): from MDAnalysis.lib.distances import transform_StoR, transform_RtoS # To check the cython coordinate transform, the same operation is done in numpy # Is a matrix multiplication of Coords x Box = NewCoords, so can use np.dot # Test transformation R_mol1 = transform_StoR(self.S_mol1, self.box) R_np1 = np.dot(self.S_mol1, self.box) # Test transformation when given box in different form R_mol2 = transform_StoR(self.S_mol2, self.boxV) R_np2 = np.dot(self.S_mol2, self.box) assert_almost_equal(R_mol1, R_np1, self.prec, err_msg="StoR transform failed with box") assert_almost_equal(R_mol2, R_np2, self.prec, err_msg="StoR transform failed with boxV") # Round trip test S_test1 = transform_RtoS( R_mol1, self.boxV) # boxV here althought initial transform with box S_test2 = transform_RtoS(R_mol2, self.box) # and vice versa, should still work assert_almost_equal(S_test1, self.S_mol1, self.prec, err_msg="Round trip failed in transform") assert_almost_equal(S_test2, self.S_mol2, self.prec, err_msg="Round trip failed in transform")
def assert_in_box(positions, box): """Asserts that all `positions` are strictly within the primary periodic image as defined by `box` """ relpos = transform_RtoS(positions, box) assert np.all((relpos >= 0.0) & (relpos < 1.0))