コード例 #1
0
 def data_target_and_grads(self, compute_gradients, x):
     """
 Args:
   compute_gradients: (bool) when True compute gradients
   x: refined parameters
 """
     g = None
     tg = cctbx.maptbx.real_space_refinement_simple.target_and_gradients(
         unit_cell=self.unit_cell,
         density_map=self.map_data,
         sites_cart=self.xray_structure.sites_cart(),
         real_space_gradients_delta=self.real_space_gradients_delta,
         selection=self.selection)
     t = tg.target()
     if compute_gradients:
         if self.refine_sites:
             g = tg.gradients()
         elif self.refine_transformations:
             grad_wrt_xyz = tg.gradients().as_double()
             g = nu.compute_transform_grad(
                 grad_wrt_xyz=grad_wrt_xyz,
                 ncs_restraints_group_list=self.ncs_restraints_group_list,
                 xyz_asu=self.xray_structure.sites_cart(),
                 x=x)
     return t, g
コード例 #2
0
 def data_target_and_grads(self, compute_gradients,x):
   """
   Args:
     compute_gradients: (bool) when True compute gradients
     x: refined parameters
   """
   g = None
   tg = cctbx.maptbx.real_space_refinement_simple.target_and_gradients(
     unit_cell                  = self.unit_cell,
     density_map                = self.map_data,
     sites_cart                 = self.xray_structure.sites_cart(),
     real_space_gradients_delta = self.real_space_gradients_delta,
     selection                  = self.selection)
   t = tg.target()
   if compute_gradients:
     if self.refine_sites:
       g = tg.gradients()
     elif self.refine_transformations:
       grad_wrt_xyz = tg.gradients().as_double()
       g = nu.compute_transform_grad(
         grad_wrt_xyz              = grad_wrt_xyz,
         ncs_restraints_group_list = self.ncs_restraints_group_list,
         xyz_asu                   = self.xray_structure.sites_cart(),
         x                         = x)
   return t, g
コード例 #3
0
 def data_target_and_grads(self, compute_gradients, sites_cart, x):
   g = None
   tgx = self.x_target_functor(compute_gradients=compute_gradients)
   t = tgx.target_work()
   if compute_gradients:
     if self.refine_sites:
       g = flex.vec3_double(
         tgx.gradients_wrt_atomic_parameters(site=True).packed())
     elif self.refine_u_iso:
       g = tgx.gradients_wrt_atomic_parameters(u_iso=True)
     elif self.refine_transformations:
       grad_wrt_xyz = tgx.gradients_wrt_atomic_parameters(site=True).packed()
       g = nu.compute_transform_grad(
         grad_wrt_xyz      = grad_wrt_xyz,
         ncs_restraints_group_list = self.ncs_restraints_group_list,
         xyz_asu           = sites_cart,
         x                 = x)
   return t, g
コード例 #4
0
 def data_target_and_grads(self, compute_gradients, sites_cart, x):
     g = None
     tgx = self.x_target_functor(compute_gradients=compute_gradients)
     t = tgx.target_work()
     if compute_gradients:
         if self.refine_sites:
             g = flex.vec3_double(
                 tgx.gradients_wrt_atomic_parameters(site=True).packed())
         elif self.refine_u_iso:
             g = tgx.gradients_wrt_atomic_parameters(u_iso=True)
         elif self.refine_transformations:
             grad_wrt_xyz = tgx.gradients_wrt_atomic_parameters(
                 site=True).packed()
             g = nu.compute_transform_grad(
                 grad_wrt_xyz=grad_wrt_xyz,
                 ncs_restraints_group_list=self.ncs_restraints_group_list,
                 xyz_asu=sites_cart,
                 x=x)
     return t, g
コード例 #5
0
def restraints_target_and_grads(ncs_restraints_group_list,
                                restraints_manager,
                                xray_structure,
                                grad,
                                x,
                                refine_sites=False,
                                refine_u_iso=False,
                                refine_transformations=False,
                                iso_restraints=None,
                                use_hd=None):
    """
  Args:
    ncs_restraints_group_list: NCS operator list
    restraints_manager: (object)
    xray_structure: (object)
    grad: gradient without restraints
    x: refined parameter
    refine_sites: (bool) indicate refinement type
    refine_u_iso: (bool) indicate refinement type
    refine_transformations: (bool) indicate refinement type
    iso_restraints: (object) iso restraints parameters
    use_hd: (bool) Use hydrogen

  Returns:
    ef_target: (float) restraints target function value
    ef_grad: (flex.double or flex.vec3_double) restraints gradient
  """
    assert [refine_sites, refine_u_iso,
            refine_transformations].count(True) == 1
    ef_grad = None
    ef = None
    if (restraints_manager is not None):
        if (refine_sites):
            ef = restraints_manager.energies_sites(
                sites_cart=xray_structure.sites_cart(), compute_gradients=True)
            ef_grad = ef.gradients
        elif (refine_u_iso):
            ef = restraints_manager.energies_adp_iso(
                xray_structure=xray_structure,
                parameters=iso_restraints,
                use_u_local_only=iso_restraints.use_u_local_only,
                use_hd=use_hd,
                compute_gradients=True)
            ef_grad = ef.gradients
        elif (refine_transformations):
            ef = restraints_manager.energies_sites(
                sites_cart=xray_structure.sites_cart(), compute_gradients=True)
            ef_grad = nu.compute_transform_grad(
                grad_wrt_xyz=ef.gradients.as_double(),
                ncs_restraints_group_list=ncs_restraints_group_list,
                xyz_asu=xray_structure.sites_cart(),
                x=x)
    if (ef is not None): return ef.target, ef_grad
    elif not grad: return 0, 0
    elif isinstance(grad, flex.vec3_double):
        return 0, flex.vec3_double([
            (0, 0, 0),
        ] * len(grad))
    elif isinstance(grad, flex.double):
        return 0, flex.double((0, 0, 0) * (len(grad) // 3))
    else:
        return None, None
コード例 #6
0
def restraints_target_and_grads(
      ncs_restraints_group_list,
      restraints_manager,
      xray_structure,
      grad,
      x,
      refine_sites=False,
      refine_u_iso=False,
      refine_transformations=False,
      iso_restraints=None,
      use_hd=None):
  """
  Args:
    ncs_restraints_group_list: NCS operator list
    restraints_manager: (object)
    xray_structure: (object)
    grad: gradient without restraints
    x: refined parameter
    refine_sites: (bool) indicate refinement type
    refine_u_iso: (bool) indicate refinement type
    refine_transformations: (bool) indicate refinement type
    iso_restraints: (object) iso restraints parameters
    use_hd: (bool) Use hydrogen

  Returns:
    ef_target: (float) restraints target function value
    ef_grad: (flex.double or flex.vec3_double) restraints gradient
  """
  assert [refine_sites, refine_u_iso, refine_transformations].count(True)==1
  ef_grad = None
  ef = None
  if(restraints_manager is not None):
    if(refine_sites):
      ef = restraints_manager.energies_sites(
        sites_cart        = xray_structure.sites_cart(),
        compute_gradients = True)
      ef_grad = ef.gradients
    elif(refine_u_iso):
      ef = restraints_manager.energies_adp_iso(
        xray_structure    = xray_structure,
        parameters        = iso_restraints,
        use_u_local_only  = iso_restraints.use_u_local_only,
        use_hd            = use_hd,
        compute_gradients = True)
      ef_grad = ef.gradients
    elif(refine_transformations):
      ef = restraints_manager.energies_sites(
        sites_cart        = xray_structure.sites_cart(),
        compute_gradients = True)
      ef_grad = nu.compute_transform_grad(
        grad_wrt_xyz      = ef.gradients.as_double(),
        ncs_restraints_group_list = ncs_restraints_group_list,
        xyz_asu           = xray_structure.sites_cart(),
        x                 = x)
  if(ef is not None): return ef.target, ef_grad
  elif not grad: return 0, 0
  elif isinstance(grad,flex.vec3_double):
    return 0, flex.vec3_double([(0,0,0),]*len(grad))
  elif isinstance(grad,flex.double):
    return 0, flex.double((0,0,0)*(len(grad)//3))
  else: return None,None