Exemple #1
0
def exercise_isotropic_adp():
  i_seqs = (0,)
  weight = 2
  u_cart = ((1,2,3,5,2,8),)
  u_iso = (0,)
  use_u_aniso = (True,)
  p = adp_restraints.isotropic_adp_proxy(
    i_seqs=i_seqs,
    weight=weight)
  assert p.i_seqs == i_seqs
  assert approx_equal(p.weight, weight)
  i = adp_restraints.isotropic_adp(u_cart=u_cart[0], weight=weight)
  expected_deltas = (-1, 0, 1, 5, 2, 8)
  expected_gradients = (-4, 0, 4, 40, 16, 64)
  assert approx_equal(i.weight, weight)
  assert approx_equal(i.deltas(), expected_deltas)
  assert approx_equal(i.rms_deltas(), 4.5704364002673632)
  assert approx_equal(i.residual(), 376.0)
  assert approx_equal(i.gradients(), expected_gradients)
  gradients_aniso_cart = flex.sym_mat3_double(1, (0,0,0,0,0,0))
  gradients_iso = flex.double(1,0)
  proxies = adp_restraints.shared_isotropic_adp_proxy([p,p])
  u_cart = flex.sym_mat3_double(u_cart)
  u_iso = flex.double(u_iso)
  use_u_aniso = flex.bool(use_u_aniso)
  params = adp_restraint_params(u_cart=u_cart, u_iso=u_iso, use_u_aniso=use_u_aniso)
  residuals = adp_restraints.isotropic_adp_residuals(params, proxies=proxies)
  assert approx_equal(residuals, (i.residual(),i.residual()))
  deltas_rms = adp_restraints.isotropic_adp_deltas_rms(params, proxies=proxies)
  assert approx_equal(deltas_rms, (i.rms_deltas(),i.rms_deltas()))
  residual_sum = adp_restraints.isotropic_adp_residual_sum(
    params,
    proxies=proxies,
    gradients_aniso_cart=gradients_aniso_cart
  )
  assert approx_equal(residual_sum, 752.0)
  fd_grads_aniso, fd_grads_iso = finite_difference_gradients(
    restraint_type=adp_restraints.isotropic_adp,
    proxy=p,
    u_cart=u_cart,
    u_iso=u_iso,
    use_u_aniso=use_u_aniso
  )
  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 = matrix.sym(sym_mat3=(0.1,0.2,0.05,0.03,0.02,0.01))
  a = adp_restraints.isotropic_adp(
    u_cart=u_cart.as_sym_mat3(), 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_rot = R * u_cart * R.transpose()
    a = adp_restraints.isotropic_adp(
      u_cart=u_cart_rot.as_sym_mat3(), weight=1)
    assert approx_equal(a.residual(), expected_residual)
Exemple #2
0
def exercise_isotropic_adp():
  i_seqs = (0,)
  weight = 2
  u_cart = ((1,2,3,5,2,8),)
  u_iso = (0,)
  use_u_aniso = (True,)
  p = adp_restraints.isotropic_adp_proxy(
    i_seqs=i_seqs,
    weight=weight)
  assert p.i_seqs == i_seqs
  assert approx_equal(p.weight, weight)
  i = adp_restraints.isotropic_adp(u_cart=u_cart[0], weight=weight)
  expected_deltas = (-1, 0, 1, 5, 2, 8)
  expected_gradients = (-4, 0, 4, 40, 16, 64)
  assert approx_equal(i.weight, weight)
  assert approx_equal(i.deltas(), expected_deltas)
  assert approx_equal(i.rms_deltas(), 4.5704364002673632)
  assert approx_equal(i.residual(), 376.0)
  assert approx_equal(i.gradients(), expected_gradients)
  gradients_aniso_cart = flex.sym_mat3_double(1, (0,0,0,0,0,0))
  gradients_iso = flex.double(1,0)
  proxies = adp_restraints.shared_isotropic_adp_proxy([p,p])
  u_cart = flex.sym_mat3_double(u_cart)
  u_iso = flex.double(u_iso)
  use_u_aniso = flex.bool(use_u_aniso)
  params = adp_restraint_params(u_cart=u_cart, u_iso=u_iso, use_u_aniso=use_u_aniso)
  residuals = adp_restraints.isotropic_adp_residuals(params, proxies=proxies)
  assert approx_equal(residuals, (i.residual(),i.residual()))
  deltas_rms = adp_restraints.isotropic_adp_deltas_rms(params, proxies=proxies)
  assert approx_equal(deltas_rms, (i.rms_deltas(),i.rms_deltas()))
  residual_sum = adp_restraints.isotropic_adp_residual_sum(
    params,
    proxies=proxies,
    gradients_aniso_cart=gradients_aniso_cart
  )
  assert approx_equal(residual_sum, 752.0)
  fd_grads_aniso, fd_grads_iso = finite_difference_gradients(
    restraint_type=adp_restraints.isotropic_adp,
    proxy=p,
    u_cart=u_cart,
    u_iso=u_iso,
    use_u_aniso=use_u_aniso
  )
  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 = matrix.sym(sym_mat3=(0.1,0.2,0.05,0.03,0.02,0.01))
  a = adp_restraints.isotropic_adp(
    u_cart=u_cart.as_sym_mat3(), 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_rot = R * u_cart * R.transpose()
    a = adp_restraints.isotropic_adp(
      u_cart=u_cart_rot.as_sym_mat3(), weight=1)
    assert approx_equal(a.residual(), expected_residual)
Exemple #3
0
 def __init__(self,
              u_cart,
              u_iso=None,
              use_u_aniso=None,
              sites_cart=None,
              adp_similarity_proxies=None,
              rigid_bond_proxies=None,
              isotropic_adp_proxies=None,
              compute_gradients=True,
              gradients_aniso_cart=None,
              gradients_iso=None,
              disable_asu_cache=False,
              normalization=False):
     adopt_init_args(self, locals())
     self.number_of_restraints = 0
     self.residual_sum = 0
     self.normalization_factor = None
     if (adp_similarity_proxies is not None):
         assert u_iso is not None and use_u_aniso is not None
     if (rigid_bond_proxies is not None): assert sites_cart is not None
     if (sites_cart is not None): assert sites_cart.size() == u_cart.size()
     if (u_iso is not None): assert u_iso.size() == u_cart.size()
     if (use_u_aniso is not None):
         assert use_u_aniso.size() == u_cart.size()
     if (compute_gradients):
         if (self.gradients_aniso_cart is None):
             self.gradients_aniso_cart = flex.sym_mat3_double(
                 sites_cart.size(), [0, 0, 0, 0, 0, 0])
         else:
             assert self.gradients_aniso_cart.size() == sites_cart.size()
         if (u_iso is not None and self.gradients_iso is None):
             self.gradients_iso = flex.double(sites_cart.size(), 0)
         elif (u_iso is not None):
             assert self.gradients_iso.size() == sites_cart.size()
     if (adp_similarity_proxies is None):
         self.n_adp_similarity_proxies = None
         self.adp_similarity_residual_sum = 0
     else:
         self.n_adp_similarity_proxies = len(adp_similarity_proxies)
         self.adp_similarity_residual_sum = adp_restraints.adp_similarity_residual_sum(
             u_cart=u_cart,
             u_iso=u_iso,
             use_u_aniso=use_u_aniso,
             proxies=adp_similarity_proxies,
             gradients_aniso_cart=self.gradients_aniso_cart,
             gradients_iso=self.gradients_iso)
         self.number_of_restraints += 6 * self.n_adp_similarity_proxies
         self.residual_sum += self.adp_similarity_residual_sum
     if (rigid_bond_proxies is None):
         self.n_rigid_bond_proxies = None
         self.rigid_bond_residual_sum = 0
     else:
         self.n_rigid_bond_proxies = len(rigid_bond_proxies)
         self.rigid_bond_residual_sum = adp_restraints.rigid_bond_residual_sum(
             sites_cart=sites_cart,
             u_cart=u_cart,
             proxies=rigid_bond_proxies,
             gradients_aniso_cart=self.gradients_aniso_cart)
         self.number_of_restraints += self.n_rigid_bond_proxies
         self.residual_sum += self.rigid_bond_residual_sum
     if (isotropic_adp_proxies is None):
         self.n_isotropic_adp_proxies = None
         self.isotropic_adp_residual_sum = 0
     else:
         self.n_isotropic_adp_proxies = len(isotropic_adp_proxies)
         self.isotropic_adp_residual_sum = adp_restraints.isotropic_adp_residual_sum(
             u_cart=u_cart,
             proxies=isotropic_adp_proxies,
             gradients_aniso_cart=self.gradients_aniso_cart)
         self.number_of_restraints += self.n_isotropic_adp_proxies
         self.residual_sum += self.isotropic_adp_residual_sum
     self.finalize_target_and_gradients()
Exemple #4
0
 def __init__(self, u_cart,
                    u_iso=None,
                    use_u_aniso=None,
                    sites_cart=None,
                    adp_similarity_proxies=None,
                    rigid_bond_proxies=None,
                    isotropic_adp_proxies=None,
                    compute_gradients=True,
                    gradients_aniso_cart=None,
                    gradients_iso=None,
                    disable_asu_cache=False,
                    normalization=False):
   adopt_init_args(self, locals())
   self.number_of_restraints = 0
   self.residual_sum = 0
   self.normalization_factor = None
   if (adp_similarity_proxies is not None):
     assert u_iso is not None and use_u_aniso is not None
   if (rigid_bond_proxies is not None): assert sites_cart is not None
   if (sites_cart is not None): assert sites_cart.size() == u_cart.size()
   if (u_iso is not None): assert u_iso.size() == u_cart.size()
   if (use_u_aniso is not None): assert use_u_aniso.size() == u_cart.size()
   if (compute_gradients):
     if (self.gradients_aniso_cart is None):
       self.gradients_aniso_cart = flex.sym_mat3_double(
         sites_cart.size(), [0,0,0,0,0,0])
     else:
       assert self.gradients_aniso_cart.size() == sites_cart.size()
     if (u_iso is not None and self.gradients_iso is None):
       self.gradients_iso = flex.double(sites_cart.size(), 0)
     elif (u_iso is not None):
       assert self.gradients_iso.size() == sites_cart.size()
   if (adp_similarity_proxies is None):
     self.n_adp_similarity_proxies = None
     self.adp_similarity_residual_sum = 0
   else:
     self.n_adp_similarity_proxies = len(adp_similarity_proxies)
     self.adp_similarity_residual_sum = adp_restraints.adp_similarity_residual_sum(
       u_cart=u_cart,
       u_iso=u_iso,
       use_u_aniso=use_u_aniso,
       proxies=adp_similarity_proxies,
       gradients_aniso_cart=self.gradients_aniso_cart,
       gradients_iso=self.gradients_iso)
     self.number_of_restraints += 6 * self.n_adp_similarity_proxies
     self.residual_sum += self.adp_similarity_residual_sum
   if (rigid_bond_proxies is None):
     self.n_rigid_bond_proxies = None
     self.rigid_bond_residual_sum = 0
   else:
     self.n_rigid_bond_proxies = len(rigid_bond_proxies)
     self.rigid_bond_residual_sum = adp_restraints.rigid_bond_residual_sum(
       sites_cart=sites_cart,
       u_cart=u_cart,
       proxies=rigid_bond_proxies,
       gradients_aniso_cart=self.gradients_aniso_cart)
     self.number_of_restraints += self.n_rigid_bond_proxies
     self.residual_sum += self.rigid_bond_residual_sum
   if (isotropic_adp_proxies is None):
     self.n_isotropic_adp_proxies = None
     self.isotropic_adp_residual_sum = 0
   else:
     self.n_isotropic_adp_proxies = len(isotropic_adp_proxies)
     self.isotropic_adp_residual_sum = adp_restraints.isotropic_adp_residual_sum(
       u_cart=u_cart,
       proxies=isotropic_adp_proxies,
       gradients_aniso_cart=self.gradients_aniso_cart)
     self.number_of_restraints += self.n_isotropic_adp_proxies
     self.residual_sum += self.isotropic_adp_residual_sum
   self.finalize_target_and_gradients()