def test_nrg_selection(self): """ test that a atom selection propagates correctly to ncs_restraints_group_list """ # print sys._getframe().f_code.co_name nrg = self.ncs_restraints_group_list m1 = list(nrg[0].master_iselection) c1 = list(nrg[0].copies[0].iselection) c2 = list(nrg[0].copies[1].iselection) assert len(m1) == len(c1) assert m1 == [0, 1, 2, 3, 4, 5, 6] assert c1 == [7, 8, 9, 10, 11, 12, 13] assert c2 == [14, 15, 16, 17, 18, 19, 20] selection1 = flex.size_t([0,1,5,3,100,101]) selection2 = flex.size_t([0,1,5,3,7,8,9,12,100,101]) selection3 = flex.size_t([0,1,5,3,7,8,9,12,14,15,19,17,100,101]) new_nrg = nu.ncs_groups_selection( ncs_restraints_group_list=nrg, selection=selection1) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) assert mt == [] assert c1t == [] # atoms selected in both master and copies new_nrg = nu.ncs_groups_selection( ncs_restraints_group_list=nrg, selection=selection2) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) assert mt == [] assert c1t == [] new_nrg = nu.ncs_groups_selection( ncs_restraints_group_list=nrg, selection=selection3) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) c2t = list(new_nrg[0].copies[1].iselection) assert mt == [0, 1, 5] assert c1t == [7, 8, 12] assert c2t == [14, 15, 19]
def test_nrg_selection(self): """ test that a atom selection propagates correctly to ncs_restraints_group_list """ # print sys._getframe().f_code.co_name nrg = self.ncs_restraints_group_list m1 = list(nrg[0].master_iselection) c1 = list(nrg[0].copies[0].iselection) c2 = list(nrg[0].copies[1].iselection) assert len(m1) == len(c1) assert m1 == [0, 1, 2, 3, 4, 5, 6] assert c1 == [7, 8, 9, 10, 11, 12, 13] assert c2 == [14, 15, 16, 17, 18, 19, 20] selection1 = flex.size_t([0, 1, 5, 3, 100, 101]) selection2 = flex.size_t([0, 1, 5, 3, 7, 8, 9, 12, 100, 101]) selection3 = flex.size_t( [0, 1, 5, 3, 7, 8, 9, 12, 14, 15, 19, 17, 100, 101]) new_nrg = nu.ncs_groups_selection(ncs_restraints_group_list=nrg, selection=selection1) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) assert mt == [] assert c1t == [] # atoms selected in both master and copies new_nrg = nu.ncs_groups_selection(ncs_restraints_group_list=nrg, selection=selection2) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) assert mt == [] assert c1t == [] new_nrg = nu.ncs_groups_selection(ncs_restraints_group_list=nrg, selection=selection3) # only atoms in master are selected mt = list(new_nrg[0].master_iselection) c1t = list(new_nrg[0].copies[0].iselection) c2t = list(new_nrg[0].copies[1].iselection) assert mt == [0, 1, 5] assert c1t == [7, 8, 12] assert c2t == [14, 15, 19]
def refine(self, selection, optimize_weight = True, start_trial_weight_value = 50, selection_buffer_radius=5, box_cushion=2, rms_bonds_limit = 0.03, rms_angles_limit = 3.0): if(self.ncs_groups is None): # no NCS constraints sites_cart_moving = self.sites_cart selection_within = self.xray_structure.selection_within( radius = selection_buffer_radius, selection = selection) sel = selection.select(selection_within) iselection = flex.size_t() for i, state in enumerate(selection): if state: iselection.append(i) box = utils.extract_box_around_model_and_map( xray_structure = self.xray_structure, map_data = self.target_map, selection = selection_within, box_cushion = box_cushion) new_unit_cell = box.xray_structure_box.unit_cell() geo_box = self.geometry_restraints_manager.select(box.selection) geo_box = geo_box.discard_symmetry(new_unit_cell=new_unit_cell) geo_box.remove_reference_coordinate_restraints_in_place() # disaster happens otherwise map_box = box.map_box sites_cart_box = box.xray_structure_box.sites_cart() rsr_simple_refiner = simple( target_map = map_box, selection = sel, real_space_gradients_delta = self.real_space_gradients_delta, max_iterations = self.max_iterations, geometry_restraints_manager = geo_box) real_space_result = refinery( refiner = rsr_simple_refiner, xray_structure = box.xray_structure_box, optimize_weight = optimize_weight, start_trial_weight_value = start_trial_weight_value, rms_bonds_limit = rms_bonds_limit, rms_angles_limit = rms_angles_limit) self.weight_optimal = real_space_result.weight_final sites_cart_box_refined = real_space_result.sites_cart_result sites_cart_box_refined_shifted_back = \ sites_cart_box_refined + box.shift_to_map_boxed_sites_back sites_cart_refined = sites_cart_box_refined_shifted_back.select(sel) sites_cart_moving = sites_cart_moving.set_selected( iselection, sites_cart_refined) self.xray_structure.set_sites_cart(sites_cart_moving) self.sites_cart = self.xray_structure.sites_cart() else: # NCS constraints are present # select on xrs, grm, ncs_groups grm = self.geometry_restraints_manager.select(selection) xrs = self.xray_structure.select(selection) sel = flex.bool(xrs.scatterers().size(), True) size = self.xray_structure.scatterers().size() ncs_groups_ = ncs_utils.ncs_groups_selection( ncs_restraints_group_list = self.ncs_groups, selection = selection) # rsr_simple_refiner = simple( target_map = self.target_map, selection = sel, real_space_gradients_delta = self.real_space_gradients_delta, max_iterations = self.max_iterations, geometry_restraints_manager = grm, ncs_groups = ncs_groups_) real_space_result = refinery( refiner = rsr_simple_refiner, xray_structure = xrs, optimize_weight = optimize_weight, start_trial_weight_value = start_trial_weight_value, rms_bonds_limit = rms_bonds_limit, rms_angles_limit = rms_angles_limit) self.weight_optimal = real_space_result.weight_final
def refine(self, selection, optimize_weight=True, start_trial_weight_value=50, selection_buffer_radius=5, box_cushion=2, rms_bonds_limit=0.03, rms_angles_limit=3.0): if (self.ncs_groups is None): # no NCS constraints sites_cart_moving = self.sites_cart selection_within = self.xray_structure.selection_within( radius=selection_buffer_radius, selection=selection) sel = selection.select(selection_within) iselection = flex.size_t() for i, state in enumerate(selection): if state: iselection.append(i) box = utils.extract_box_around_model_and_map( xray_structure=self.xray_structure, map_data=self.target_map, selection=selection_within, box_cushion=box_cushion) new_unit_cell = box.xray_structure_box.unit_cell() geo_box = self.geometry_restraints_manager.select(box.selection) geo_box = geo_box.discard_symmetry(new_unit_cell=new_unit_cell) geo_box.remove_reference_coordinate_restraints_in_place( ) # disaster happens otherwise map_box = box.map_box sites_cart_box = box.xray_structure_box.sites_cart() rsr_simple_refiner = simple( target_map=map_box, selection=sel, real_space_gradients_delta=self.real_space_gradients_delta, max_iterations=self.max_iterations, geometry_restraints_manager=geo_box, gradients_method=self.gradients_method) real_space_result = refinery( refiner=rsr_simple_refiner, xray_structure=box.xray_structure_box, optimize_weight=optimize_weight, start_trial_weight_value=start_trial_weight_value, rms_bonds_limit=rms_bonds_limit, rms_angles_limit=rms_angles_limit) self.weight_optimal = real_space_result.weight_final sites_cart_box_refined = real_space_result.sites_cart_result shift_back = [-box.shift_cart[i] for i in xrange(3)] sites_cart_box_refined_shifted_back = \ sites_cart_box_refined + shift_back # Sure + not - ? sites_cart_refined = sites_cart_box_refined_shifted_back.select( sel) sites_cart_moving = sites_cart_moving.set_selected( iselection, sites_cart_refined) self.xray_structure.set_sites_cart(sites_cart_moving) self.sites_cart = self.xray_structure.sites_cart() else: # NCS constraints are present # select on xrs, grm, ncs_groups grm = self.geometry_restraints_manager.select(selection) xrs = self.xray_structure.select(selection) sel = flex.bool(xrs.scatterers().size(), True) size = self.xray_structure.scatterers().size() ncs_groups_ = ncs_utils.ncs_groups_selection( ncs_restraints_group_list=self.ncs_groups, selection=selection) # rsr_simple_refiner = simple( target_map=self.target_map, selection=sel, real_space_gradients_delta=self.real_space_gradients_delta, max_iterations=self.max_iterations, geometry_restraints_manager=grm, ncs_groups=ncs_groups_) real_space_result = refinery( refiner=rsr_simple_refiner, xray_structure=xrs, optimize_weight=optimize_weight, start_trial_weight_value=start_trial_weight_value, rms_bonds_limit=rms_bonds_limit, rms_angles_limit=rms_angles_limit) self.weight_optimal = real_space_result.weight_final