def rigid_bond_deviation(self): if (self.n_rigid_bond_proxies is not None): rigid_bond_deltas = adp_restraints.rigid_bond_deltas( sites_cart=self.sites_cart, u_cart=self.u_cart, proxies=self.rigid_bond_proxies) r_sq = rigid_bond_deltas * rigid_bond_deltas r_ave = math.sqrt(flex.mean_default(r_sq, 0)) r_max = math.sqrt(flex.max_default(r_sq, 0)) r_min = math.sqrt(flex.min_default(r_sq, 0)) return r_min, r_max, r_ave
def exercise_rigid_bond(): i_seqs = (1,2) weight = 1 p = adp_restraints.rigid_bond_proxy(i_seqs=i_seqs,weight=weight) assert p.i_seqs == i_seqs assert p.weight == weight sites = ((1,2,3),(2,3,4)) u_cart = ((1,2,3,4,5,6), (3,4,5,6,7,8)) expected_gradients = ((-4, -4, -4, -8, -8, -8), (4, 4, 4, 8, 8, 8)) r = adp_restraints.rigid_bond(sites=sites, u_cart=u_cart, weight=weight) assert r.weight == weight assert approx_equal(r.delta_z(), -6) assert approx_equal(r.residual(), 36) assert approx_equal(r.gradients(), expected_gradients) sites_cart = flex.vec3_double(((1,2,3),(2,5,4),(3,4,5))) u_cart = flex.sym_mat3_double(((1,2,3,4,5,6), (2,3,3,5,7,7), (3,4,5,3,7,8))) r = adp_restraints.rigid_bond( adp_restraint_params(sites_cart=sites_cart, u_cart=u_cart), proxy=p) assert approx_equal(r.weight, weight) unit_cell = uctbx.unit_cell([15,25,30,90,90,90]) sites_frac = unit_cell.fractionalize(sites_cart=sites_cart) u_star = flex.sym_mat3_double([ adptbx.u_cart_as_u_star(unit_cell, u_cart_i) for u_cart_i in u_cart]) pair = adp_restraints.rigid_bond_pair(sites_frac[1], sites_frac[2], u_star[1], u_star[2], unit_cell) assert approx_equal(pair.delta_z(), abs(r.delta_z())) assert approx_equal(pair.z_12(), r.z_12()) assert approx_equal(pair.z_21(), r.z_21()) # gradients_aniso_cart = flex.sym_mat3_double(sites_cart.size(), (0,0,0,0,0,0)) gradients_iso = flex.double(sites_cart.size(), 0) proxies = adp_restraints.shared_rigid_bond_proxy([p,p]) params = adp_restraint_params(sites_cart=sites_cart, u_cart=u_cart) residuals = adp_restraints.rigid_bond_residuals(params, proxies=proxies) assert approx_equal(residuals, (r.residual(),r.residual())) deltas = adp_restraints.rigid_bond_deltas(params, proxies=proxies) assert approx_equal(deltas, (r.delta_z(),r.delta_z())) residual_sum = adp_restraints.rigid_bond_residual_sum( params=params, proxies=proxies, gradients_aniso_cart=gradients_aniso_cart) assert approx_equal(residual_sum, 2 * r.residual()) for g,e in zip(gradients_aniso_cart[1:3], r.gradients()): assert approx_equal(g, matrix.col(e)*2) fd_grads_aniso, fd_grads_iso = finite_difference_gradients( restraint_type=adp_restraints.rigid_bond, proxy=p, sites_cart=sites_cart, u_cart=u_cart) for g,e in zip(gradients_aniso_cart, fd_grads_aniso): assert approx_equal(g, matrix.col(e)*2) # # check frame invariance of residual # u_cart_1 = matrix.sym(sym_mat3=(0.1,0.2,0.05,0.03,0.02,0.01)) u_cart_2 = matrix.sym(sym_mat3=(0.21,0.32,0.11,0.02,0.02,0.07)) u_cart = (u_cart_1.as_sym_mat3(),u_cart_2.as_sym_mat3()) site_cart_1 = matrix.col((1,2,3)) site_cart_2 = matrix.col((3,1,4.2)) sites = (tuple(site_cart_1),tuple(site_cart_2)) a = adp_restraints.rigid_bond(sites=sites, u_cart=u_cart, weight=1) expected_residual = a.residual() gen = flex.mersenne_twister() for i in range(20): R = matrix.rec(gen.random_double_r3_rotation_matrix(),(3,3)) u_cart_1_rot = R * u_cart_1 * R.transpose() u_cart_2_rot = R * u_cart_2 * R.transpose() u_cart = (u_cart_1_rot.as_sym_mat3(),u_cart_2_rot.as_sym_mat3()) site_cart_1_rot = R * site_cart_1 site_cart_2_rot = R * site_cart_2 sites = (tuple(site_cart_1_rot),tuple(site_cart_2_rot)) a = adp_restraints.rigid_bond( sites=sites, u_cart=u_cart, weight=1) assert approx_equal(a.residual(), expected_residual)