def __init__(self, map_data, xray_structure, ncs_restraints_group_list, real_space_gradients_delta, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, data_weight=None, refine_sites=False, refine_transformations=False): adopt_init_args(self, locals()) self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=self.xray_structure.sites_cart().size()) self.extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=ncs_restraints_group_list, refine_selection=self.refine_selection) self.unit_cell = self.xray_structure.unit_cell() # get selection to refine asu_size = xray_structure.scatterers().size() if refine_sites: # Use all atoms to refine self.selection = flex.bool(asu_size, refine_selection) elif refine_transformations: # use only NCS related atoms (Without the Master NCS copy) self.selection = nu.get_ncs_related_selection( ncs_restraints_group_list=ncs_restraints_group_list, asu_size=asu_size)
def __init__(self, fmodel, ncs_restraints_group_list, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, data_weight=None, refine_sites=False, refine_u_iso=False, refine_transformations=False, iso_restraints=None, use_hd=False): adopt_init_args(self, locals()) asu_size = self.fmodel.xray_structure.sites_cart().size() self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=asu_size) self.extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=ncs_restraints_group_list, refine_selection=self.refine_selection) self.fmodel.xray_structure.scatterers().flags_set_grads(state=False) self.x_target_functor = self.fmodel.target_functor() self.xray_structure = self.fmodel.xray_structure if self.refine_sites: xray.set_scatterer_grad_flags( scatterers=self.fmodel.xray_structure.scatterers(), site=True) elif self.refine_u_iso: xray.set_scatterer_grad_flags( scatterers=self.fmodel.xray_structure.scatterers(), u_iso=True) elif self.refine_transformations: xray.set_scatterer_grad_flags( scatterers=self.fmodel.xray_structure.scatterers(), site=True)
def __init__( self, map_data, xray_structure, ncs_restraints_group_list, real_space_gradients_delta, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, data_weight=None, refine_sites=False, refine_transformations=False): adopt_init_args(self, locals()) self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=self.xray_structure.sites_cart().size()) self.extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=ncs_restraints_group_list, refine_selection=self.refine_selection) self.unit_cell = self.xray_structure.unit_cell() # get selection to refine asu_size = xray_structure.scatterers().size() if refine_sites: # Use all atoms to refine self.selection = flex.bool(asu_size, refine_selection) elif refine_transformations: # use only NCS related atoms (Without the Master NCS copy) self.selection = nu.get_ncs_related_selection( ncs_restraints_group_list=ncs_restraints_group_list, asu_size=asu_size)
def __init__(self, xray_structure, ncs_restraints_group_list, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, refine_sites=False, refine_transformations=False): adopt_init_args(self, locals()) self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=self.xray_structure.sites_cart().size()) self.extended_ncs_selection = ncs_restraints_group_list.get_extended_ncs_selection( refine_selection=self.refine_selection) self.unit_cell = self.xray_structure.unit_cell()
def __init__( self, xray_structure, ncs_restraints_group_list, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, refine_sites=False, refine_transformations=False): adopt_init_args(self, locals()) self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=self.xray_structure.sites_cart().size()) self.extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=ncs_restraints_group_list, refine_selection=self.refine_selection) self.unit_cell = self.xray_structure.unit_cell()
def __init__(self, map_data, xray_structure, ncs_restraints_group_list, real_space_gradients_delta, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, data_weight=None, refine_sites=False): adopt_init_args(self, locals()) self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=self.xray_structure.sites_cart().size()) self.extended_ncs_selection = ncs_restraints_group_list.get_extended_ncs_selection( refine_selection=self.refine_selection) self.unit_cell = self.xray_structure.unit_cell() # get selection to refine asu_size = xray_structure.scatterers().size() self.selection = flex.bool(asu_size, refine_selection)
def test_grads_one_ncs_to_asu(self): # No more NAGs in NCS selection # print sys._getframe().f_code.co_name pdb_inp = iotbx.pdb.input(lines=test_pdb_1, source_info=None) p = ncs.input.get_default_params() p.ncs_search.exclude_selection = None ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy(), params=p.ncs_search) pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_1) ph = pdb_inp.construct_hierarchy() xrs = pdb_inp.xray_structure_simple() # nrgl = ncs_inp.get_ncs_restraints_group_list() asu_length = ncs_inp.truncated_hierarchy.atoms_size() # refine_selection = nu.get_refine_selection(number_of_atoms=asu_length) extended_ncs_selection = nrgl.get_extended_ncs_selection( refine_selection=refine_selection) # self.assertEqual(asu_length, ph.atoms_size()) self.assertEqual(asu_length, 18) # xrs_one_ncs_copy = xrs.select(extended_ncs_selection) master_grad = xrs_one_ncs_copy.extract_u_iso_or_u_equiv() # g = grads_one_ncs_to_asu(ncs_restraints_group_list=nrgl, total_asu_length=asu_length, extended_ncs_selection=extended_ncs_selection, master_grad=master_grad) # self.assertEqual(g.size(), 18) masters = [[0, 1, 12], [2, 3, 13]] copies = [[[4, 5, 14], [8, 9, 16]], [[6, 7, 15], [10, 11, 17]]] for m, cs in zip(masters, copies): ml = list(g.select(flex.size_t(m))) for c in cs: cl = list(g.select(flex.size_t(c))) self.assertEqual(ml, cl)
def test_grads_one_ncs_to_asu(self): # No more NAGs in NCS selection # print sys._getframe().f_code.co_name pdb_inp = iotbx.pdb.input(lines=test_pdb_1,source_info=None) ncs_inp = ncs.input(hierarchy=pdb_inp.construct_hierarchy(), exclude_selection=None) pdb_inp = iotbx.pdb.input(source_info=None, lines=test_pdb_1) ph = pdb_inp.construct_hierarchy() xrs = pdb_inp.xray_structure_simple() # nrgl = ncs_inp.get_ncs_restraints_group_list() asu_length = ncs_inp.total_asu_length # refine_selection = nu.get_refine_selection(number_of_atoms=asu_length) extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=nrgl, refine_selection=refine_selection) # self.assertEqual(asu_length, ph.atoms_size()) self.assertEqual(asu_length, 18) # xrs_one_ncs_copy = xrs.select(extended_ncs_selection) master_grad = xrs_one_ncs_copy.extract_u_iso_or_u_equiv() # g = grads_one_ncs_to_asu( ncs_restraints_group_list=nrgl, total_asu_length=asu_length, extended_ncs_selection=extended_ncs_selection, master_grad=master_grad) # self.assertEqual(g.size(),18) masters = [[0,1,12],[2, 3, 13]] copies = [[[4, 5, 14],[8, 9, 16]],[[6, 7, 15],[10, 11, 17]]] for m,cs in zip(masters,copies): ml = list(g.select(flex.size_t(m))) for c in cs: cl = list(g.select(flex.size_t(c))) self.assertEqual(ml,cl)
def __init__( self, fmodel, ncs_restraints_group_list, refine_selection=None, use_ncs_constraints=True, restraints_manager=None, data_weight=None, refine_sites=False, refine_u_iso=False, refine_transformations=False, iso_restraints = None, use_hd = False): adopt_init_args(self, locals()) asu_size = self.fmodel.xray_structure.sites_cart().size() self.refine_selection = nu.get_refine_selection( refine_selection=self.refine_selection, number_of_atoms=asu_size) self.extended_ncs_selection = nu.get_extended_ncs_selection( ncs_restraints_group_list=ncs_restraints_group_list, refine_selection=self.refine_selection) self.fmodel.xray_structure.scatterers().flags_set_grads(state=False) self.x_target_functor = self.fmodel.target_functor() self.xray_structure = self.fmodel.xray_structure if self.refine_sites: xray.set_scatterer_grad_flags( scatterers = self.fmodel.xray_structure.scatterers(), site = True) elif self.refine_u_iso: xray.set_scatterer_grad_flags( scatterers = self.fmodel.xray_structure.scatterers(), u_iso = True) elif self.refine_transformations: xray.set_scatterer_grad_flags( scatterers = self.fmodel.xray_structure.scatterers(), site = True)
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