def test_ortho_PBC(self): from MDAnalysis.core.distances import applyPBC U = MDAnalysis.Universe(PSF, DCD) atoms = U.atoms.coordinates() box1 = np.array([2.5, 2.5, 3.5], dtype=np.float32) box2 = np.array([2.5, 2.5, 3.5, 90., 90., 90.], dtype=np.float32) cyth1 = applyPBC(atoms, box1) cyth2 = applyPBC(atoms, box2) reference = atoms - np.floor(atoms / box1) * box1 assert_almost_equal(cyth1, reference, self.prec, err_msg="Ortho applyPBC #1 failed comparison with np") assert_almost_equal(cyth2, reference, self.prec, err_msg="Ortho applyPBC #2 failed comparison with np")
def test_tric_PBC(self): from MDAnalysis.core.distances import applyPBC U = MDAnalysis.Universe(TRIC) atoms = U.atoms.coordinates() box1 = U.dimensions box2 = MDAnalysis.coordinates.core.triclinic_vectors(box1) print box2 print box2.shape def numpy_PBC(coords, box): coords -= np.array([box[2] * val for val in np.floor(coords[:, 2] / box[2][2])]) coords -= np.array([box[1] * val for val in np.floor(coords[:, 1] / box[1][1])]) coords -= np.array([box[0] * val for val in np.floor(coords[:, 0] / box[0][0])]) return coords cyth1 = applyPBC(atoms, box1) cyth2 = applyPBC(atoms, box2) reference = numpy_PBC(atoms, box2) assert_almost_equal(cyth1, reference, self.prec, err_msg="Triclinic applyPBC failed comparison with np") assert_almost_equal(cyth2, reference, self.prec, err_msg="Trlclinic applyPBC failed comparison with np")