Esempio n. 1
0
    def test_center_of_coordinates_shift(self):
        """
    test shifting translation to and from the center of coordinates of the
    master ncs copy
    """
        # print sys._getframe().f_code.co_name

        xrs = self.pdb_inp.xray_structure_simple()
        nrg = self.ncs_restraints_group_list

        shifts = nu.get_ncs_groups_centers(xray_structure=xrs,
                                           ncs_restraints_group_list=nrg)

        xyz = self.pdb_inp.atoms().extract_xyz()
        center_of_coor = (flex.vec3_double([xyz.sum()]) *
                          (1 / xyz.size())).round(8)
        # test shifts
        t1 = shifts[0].round(8)
        t2 = shifts[1].round(8)
        d1 = flex.sqrt((center_of_coor - t1).dot()).min_max_mean().as_tuple()
        d2 = flex.sqrt((center_of_coor - t2).dot()).min_max_mean().as_tuple()
        assert (d1 == d2) and (d1 == (0, 0, 0))

        # test shift to center
        new_nrg = nu.shift_translation_to_center(shifts=shifts,
                                                 ncs_restraints_group_list=nrg)
        expected = (-4.62169, -5.42257, 5.288)
        assert (new_nrg[0].copies[0].t.round(5)).elems == expected
        # back to original coordinates system
        old_nrg = nu.shift_translation_back_to_place(
            shifts=shifts, ncs_restraints_group_list=new_nrg)
        expected = (old_nrg[0].copies[0].t.round(5)).elems
        result = (nrg[0].copies[0].t.round(5)).elems
        assert result == expected
Esempio n. 2
0
  def test_center_of_coordinates_shift(self):
    """
    test shifting translation to and from the center of coordinates of the
    master ncs copy
    """
    # print sys._getframe().f_code.co_name

    xrs = self.pdb_inp.xray_structure_simple()
    nrg = self.ncs_restraints_group_list

    shifts = nu.get_ncs_groups_centers(
      xray_structure = xrs,
      ncs_restraints_group_list=nrg)

    xyz = self.pdb_inp.atoms().extract_xyz()
    center_of_coor = (flex.vec3_double([xyz.sum()]) * (1/xyz.size())).round(8)
    # test shifts
    t1 = shifts[0].round(8)
    t2 = shifts[1].round(8)
    d1 = flex.sqrt((center_of_coor-t1).dot()).min_max_mean().as_tuple()
    d2 = flex.sqrt((center_of_coor-t2).dot()).min_max_mean().as_tuple()
    assert (d1 == d2) and (d1 == (0,0,0))

    # test shift to center
    new_nrg = nu.shift_translation_to_center(
      shifts = shifts,
      ncs_restraints_group_list=nrg)
    expected = (-4.62169, -5.42257, 5.288)
    assert (new_nrg[0].copies[0].t.round(5)).elems == expected
    # back to original coordinates system
    old_nrg = nu.shift_translation_back_to_place(
      shifts=shifts,
      ncs_restraints_group_list=new_nrg)
    expected = (old_nrg[0].copies[0].t.round(5)).elems
    result = (nrg[0].copies[0].t.round(5)).elems
    assert result == expected
Esempio n. 3
0
 def __init__(self,
              ncs_restraints_group_list,
              target_and_grads_object,
              xray_structure,
              refine_selection=None,
              finite_grad_differences_test=False,
              finite_grad_difference_val=0,
              max_iterations=35,
              refine_sites=False,
              refine_u_iso=False,
              refine_transformations=False):
     """
 NCS constrained ADP and coordinates refinement. Also refines NCS operators.
 """
     adopt_init_args(self,
                     args=locals(),
                     exclude=['ncs_restraints_group_list'])
     self.refine_selection = nu.get_refine_selection(
         refine_selection=self.refine_selection,
         number_of_atoms=self.xray_structure.sites_cart().size())
     self.use_ncs_constraints = target_and_grads_object.use_ncs_constraints
     self.ncs_restraints_group_list = nu.ncs_restraints_group_list_copy(
         ncs_restraints_group_list)
     self.ncs_groups_coordinates_centers = []
     self.extended_ncs_selection = nu.get_extended_ncs_selection(
         ncs_restraints_group_list=self.ncs_restraints_group_list,
         refine_selection=self.refine_selection)
     assert [
         self.refine_sites, self.refine_u_iso, self.refine_transformations
     ].count(True) == 1
     self.total_asu_length = len(xray_structure.sites_cart())
     traditional_convergence_test_eps = 1.0e-6
     if self.use_ncs_constraints:
         xray_structure_one_ncs_copy = xray_structure.select(
             self.extended_ncs_selection)
     else:
         xray_structure_one_ncs_copy = xray_structure.select(
             self.refine_selection)
     if self.refine_sites:
         self.x = xray_structure_one_ncs_copy.sites_cart().as_double()
     elif self.refine_u_iso:
         assert xray_structure_one_ncs_copy.scatterers().size() == \
           xray_structure_one_ncs_copy.use_u_iso().count(True)
         self.x = xray_structure_one_ncs_copy.extract_u_iso_or_u_equiv()
     elif self.refine_transformations:
         # move refinable parameters to coordinate center
         self.ncs_groups_coordinates_centers = nu.get_ncs_groups_centers(
             xray_structure=self.xray_structure,
             ncs_restraints_group_list=self.ncs_restraints_group_list)
         self.ncs_restraints_group_list = nu.shift_translation_to_center(
             shifts=self.ncs_groups_coordinates_centers,
             ncs_restraints_group_list=self.ncs_restraints_group_list)
         self.x = nu.concatenate_rot_tran(
             ncs_restraints_group_list=self.ncs_restraints_group_list)
     minimizer = scitbx.lbfgs.run(
         target_evaluator=self,
         termination_params=scitbx.lbfgs.termination_parameters(
             max_iterations=max_iterations,
             traditional_convergence_test_eps=
             traditional_convergence_test_eps),
         exception_handling_params=scitbx.lbfgs.
         exception_handling_parameters(
             ignore_line_search_failed_rounding_errors=True,
             ignore_line_search_failed_step_at_lower_bound=True,
             ignore_line_search_failed_maxfev=True))
     # change transforms to the original coordinate system
     if self.refine_transformations:
         self.ncs_restraints_group_list = nu.shift_translation_back_to_place(
             shifts=self.ncs_groups_coordinates_centers,
             ncs_restraints_group_list=self.ncs_restraints_group_list)
     if (getattr(self.target_and_grads_object, "finalize", None)):
         self.target_and_grads_object.finalize()
     # pass the refined ncs_restraints_group_list to original object
     for g1, g2 in zip(ncs_restraints_group_list,
                       self.ncs_restraints_group_list):
         for tr1, tr2 in zip(g1.copies, g2.copies):
             tr1.r = tr2.r
             tr1.t = tr2.t
 def __init__(self,
       ncs_restraints_group_list,
       target_and_grads_object,
       xray_structure,
       refine_selection             = None,
       finite_grad_differences_test = False,
       finite_grad_difference_val   = 0,
       max_iterations               = 35,
       refine_sites                 = False,
       refine_u_iso                 = False,
       refine_transformations       = False):
   """
   NCS constrained ADP and coordinates refinement. Also refines NCS operators.
   """
   adopt_init_args(self, args=locals(),exclude=['ncs_restraints_group_list'])
   self.refine_selection = nu.get_refine_selection(
     refine_selection=self.refine_selection,
     number_of_atoms=self.xray_structure.sites_cart().size())
   self.use_ncs_constraints = target_and_grads_object.use_ncs_constraints
   self.ncs_restraints_group_list = nu.ncs_restraints_group_list_copy(
     ncs_restraints_group_list)
   self.ncs_groups_coordinates_centers = []
   self.extended_ncs_selection = nu.get_extended_ncs_selection(
     ncs_restraints_group_list=self.ncs_restraints_group_list,
     refine_selection=self.refine_selection)
   assert [self.refine_sites,
           self.refine_u_iso, self.refine_transformations].count(True) == 1
   self.total_asu_length = len(xray_structure.sites_cart())
   traditional_convergence_test_eps = 1.0e-6
   if self.use_ncs_constraints:
     xray_structure_one_ncs_copy = xray_structure.select(
       self.extended_ncs_selection)
   else:
     xray_structure_one_ncs_copy = xray_structure.select(self.refine_selection)
   if self.refine_sites:
     self.x = xray_structure_one_ncs_copy.sites_cart().as_double()
   elif self.refine_u_iso:
     assert xray_structure_one_ncs_copy.scatterers().size() == \
       xray_structure_one_ncs_copy.use_u_iso().count(True)
     self.x = xray_structure_one_ncs_copy.extract_u_iso_or_u_equiv()
   elif self.refine_transformations:
     # move refinable parameters to coordinate center
     self.ncs_groups_coordinates_centers = nu.get_ncs_groups_centers(
       xray_structure=self.xray_structure,
       ncs_restraints_group_list=self.ncs_restraints_group_list)
     self.ncs_restraints_group_list = nu.shift_translation_to_center(
       shifts = self.ncs_groups_coordinates_centers,
       ncs_restraints_group_list = self.ncs_restraints_group_list)
     self.x = nu.concatenate_rot_tran(
       ncs_restraints_group_list=self.ncs_restraints_group_list)
   minimizer = scitbx.lbfgs.run(
     target_evaluator=self,
     termination_params=scitbx.lbfgs.termination_parameters(
       max_iterations=max_iterations,
       traditional_convergence_test_eps=traditional_convergence_test_eps),
     exception_handling_params=scitbx.lbfgs.exception_handling_parameters(
       ignore_line_search_failed_rounding_errors=True,
       ignore_line_search_failed_step_at_lower_bound=True,
       ignore_line_search_failed_maxfev=True))
   # change transforms to the original coordinate system
   if self.refine_transformations:
     self.ncs_restraints_group_list = nu.shift_translation_back_to_place(
         shifts = self.ncs_groups_coordinates_centers,
         ncs_restraints_group_list = self.ncs_restraints_group_list)
   if(getattr(self.target_and_grads_object, "finalize", None)):
     self.target_and_grads_object.finalize()
   # pass the refined ncs_restraints_group_list to original object
   for g1,g2 in zip(ncs_restraints_group_list,self.ncs_restraints_group_list):
     for tr1,tr2 in zip(g1.copies,g2.copies):
       tr1.r = tr2.r
       tr1.t = tr2.t