def test_fit_rot_trans_no_options(fit_universe): test_u = fit_universe[0] ref_u = fit_universe[1] ref_com = ref_u.atoms.center(None) ref_u.trajectory.ts.positions -= ref_com R = rotation_matrix(np.pi / 3, [1, 0, 0])[:3, :3] ref_u.trajectory.ts.positions = np.dot(ref_u.trajectory.ts.positions, R) ref_u.trajectory.ts.positions += ref_com fit_rot_trans(test_u, ref_u)(test_u.trajectory.ts) assert_array_almost_equal(test_u.trajectory.ts.positions, ref_u.trajectory.ts.positions, decimal=3)
def test_fit_rot_trans_plane(fit_universe, plane): # the reference is rotated in the x axis so removing the translations and rotations # in the yz plane should return the same as the fitting without specifying a plane test_u = fit_universe[0] ref_u = fit_universe[1] ref_com = ref_u.atoms.center(None) mobile_com = test_u.atoms.center(None) axes = {'yz': 0, 'xz': 1, 'xy': 2} idx = axes[plane] rotaxis = np.asarray([0, 0, 0]) rotaxis[idx] = 1 ref_u.trajectory.ts.positions -= ref_com R = rotation_matrix(np.pi / 3, rotaxis)[:3, :3] ref_u.trajectory.ts.positions = np.dot(ref_u.trajectory.ts.positions, R) ref_com[idx] = mobile_com[idx] ref_u.trajectory.ts.positions += ref_com fit_rot_trans(test_u, ref_u, plane=plane)(test_u.trajectory.ts) assert_array_almost_equal(test_u.trajectory.ts.positions[:, idx], ref_u.trajectory.ts.positions[:, idx], decimal=3)
def test_fit_rot_trans_bad_plane(fit_universe, plane): test_u = fit_universe[0] ref_u = fit_universe[1] with pytest.raises(ValueError): fit_rot_trans(test_u, ref_u, plane=plane)(test_u.trajectory.ts)
def test_fit_rot_trans_bad_weights(fit_universe, weights): test_u = fit_universe[0] ref_u = fit_universe[1] bad_weights = weights with pytest.raises(ValueError): fit_rot_trans(test_u, ref_u, weights=bad_weights)(test_u.trajectory.ts)
def test_fit_rot_trans_shorter_universe(fit_universe): ref_u = fit_universe[1] bad_u = fit_universe[0].atoms[0:5] test_u = bad_u with pytest.raises(ValueError): fit_rot_trans(test_u, ref_u)(test_u.trajectory.ts)
def test_fit_rot_trans_bad_universe(fit_universe, universe): test_u = fit_universe[0] ref_u = universe with pytest.raises(AttributeError): fit_rot_trans(test_u, ref_u)(test_u.trajectory.ts)