def exercise_core(n=10, verbose=0): from libtbx.test_utils import approx_equal import random # make two random sets of sites please c = euler_angles_as_matrix([random.uniform(0, 360) for i in xrange(3)]) set_1 = flex.vec3_double(flex.random_double(n * 3) * 10 - 2) set_2 = flex.vec3_double(flex.random_double(n * 3) * 10 - 2) set_3 = tuple(c) * set_2 set_a = set_1.concatenate(set_2) set_b = set_1.concatenate(set_3) tmp = find_domain(set_a, set_b, initial_rms=0.02, match_radius=0.03, minimum_size=1) if verbose: tmp.show() assert len(tmp.matches) == 2 assert approx_equal(tmp.matches[0][3], 0, eps=1e-5) assert approx_equal(tmp.matches[0][4], n, eps=1e-5)
def exercise_planarity(): weights = flex.double([1,2,3,4]) for points,norm in [([(1,1,0), (-1,-1,0), (-1,1,0), (1,-1,0)], (0,0,1)), ([(0,1,1), (0,-1,-1), (0,-1,1), (0,1,-1)], (1,0,0)), ([(1,0,1), (-1,0,-1), (-1,0,1), (1,0,-1)], (0,1,0)), ([(1,1,-1), (-1,-1,1), (-1,1,-1), (1,-1,1)], (0,1,1))]: norm = col(norm) norm /= abs(norm) for i_trial in xrange(5): for i_pert in xrange(5): if (i_trial == 0 and i_pert == 0): sites = [col(v) for v in points] rot_norm = norm else: shift = col([random.uniform(-10,10) for i in xrange(3)]) rot = sqr(euler_angles_as_matrix( [random.uniform(0,360) for i in xrange(3)])) rot_norm = rot * norm if (i_pert == 0): sites = [rot*col(v)+shift for v in points] else: sites = [] for v in points: f = 0.1 pert = col([(random.random()-0.5)*f for i in xrange(3)]) sites.append(rot*col(v)+shift+pert) pl = geometry_restraints.planarity(sites=sites, weights=weights) n = col(pl.normal()) gradients_analytical = pl.gradients() if (i_pert == 0): assert abs(abs(n.dot(rot_norm))-1) < 1.e-5 assert approx_equal(pl.residual(), 0) for grad in gradients_analytical: assert approx_equal(grad, [0,0,0]) assert approx_equal(pl.residual(), pl.lambda_min()) residual_obj = residual_functor( restraint_type=geometry_restraints.planarity, weights=weights) gradients_finite = finite_differences(sites, residual_obj) assert approx_equal(gradients_finite, gradients_analytical)
def random_rotation(): import random from scitbx.math import euler_angles_as_matrix return euler_angles_as_matrix([random.uniform(0,360) for i in xrange(3)])
def random_rotation(): return euler_angles_as_matrix([random.uniform(0,360) for i in xrange(3)])
def random_rotation(angle_min=0, angle_max=360): import random from scitbx.math import euler_angles_as_matrix return euler_angles_as_matrix( [random.uniform(angle_min,angle_max) for i in xrange(3)])
def random_rotation(angle_min=0, angle_max=360): angles = [random.uniform(angle_min, angle_max) for i in range(3)] print("Rotation: ", angles) return euler_angles_as_matrix(angles, deg=True)
def random_rotation(): return euler_angles_as_matrix([random.uniform(0, 360) for i in range(3)])
def random_rotation(): import random from scitbx.math import euler_angles_as_matrix return euler_angles_as_matrix([random.uniform(0, 360) for i in xrange(3)])