def test_update_rot_tran(self): """ Verify correct conversion from angles and translation to rotation matrices and translations """ # print sys._getframe().f_code.co_name x = flex.double([ -0.40177529, 1.20019851, 2.64221706, 0.5, -0.5, 0.0, 2.24044161, 1.57079633, 0.0, 0.0, 0.0, 0.0]) self.tr_obj1 = nu.update_rot_tran( x=x,transforms_obj=self.tr_obj1) rot_results, tran_results = nu.get_rotation_translation_as_list( transforms_obj=self.tr_obj1) rot_expected = [self.rotation1, self.rotation2] tran_expected = [self.translation1,self.translation2] assert approx_equal(tran_results,tran_expected,1.0e-4) assert approx_equal(rot_results,rot_expected,1.0e-4)
def test_update_rot_tran(self): """ Verify correct conversion from angles and translation to rotation matrices and translations """ # print sys._getframe().f_code.co_name x = flex.double([ -0.40177529, 1.20019851, 2.64221706, 0.5, -0.5, 0.0, 2.24044161, 1.57079633, 0.0, 0.0, 0.0, 0.0 ]) self.tr_obj1 = nu.update_rot_tran(x=x, transforms_obj=self.tr_obj1) rot_results, tran_results = nu.get_rotation_translation_as_list( transforms_obj=self.tr_obj1) rot_expected = [self.rotation1, self.rotation2] tran_expected = [self.translation1, self.translation2] assert approx_equal(tran_results, tran_expected, 1.0e-4) assert approx_equal(rot_results, rot_expected, 1.0e-4)
def run(prefix="tst", d_min=1.0): """ NCS constraints: xyz, adp, and operators. """ pdb_file_name_answer = "%s_answer.pdb"%prefix of=open(pdb_file_name_answer, "w") print >> of, pdb_str_answer of.close() # pdb_file_name_poor = "%s_poor.pdb"%prefix of=open(pdb_file_name_poor, "w") print >> of, pdb_str_poor of.close() # pdb_inp_answer = iotbx.pdb.input(file_name=pdb_file_name_answer) ph_answer = pdb_inp_answer.construct_hierarchy() ph_answer.atoms().reset_i_seq() xrs_answer = pdb_inp_answer.xray_structure_simple() # pdb_inp_poor = iotbx.pdb.input(file_name=pdb_file_name_poor) ph_poor = pdb_inp_poor.construct_hierarchy() ph_poor_obj = iotbx.pdb.input(source_info=None, lines=pdb_str_poor2) ph_poor.atoms().reset_i_seq() xrs_poor = pdb_inp_poor.xray_structure_simple() # ppf = mmtbx.utils.process_pdb_file_srv(log=False).process_pdb_files( raw_records=pdb_str_poor.splitlines())[0] mmtbx.utils.assert_xray_structures_equal( x1=ppf.xray_structure(show_summary = False), x2=xrs_poor) restraints_manager = mmtbx.restraints.manager( geometry = ppf.geometry_restraints_manager(show_energies = False), normalization = True) # fc = xrs_answer.structure_factors(d_min=d_min).f_calc() fft_map = fc.fft_map(resolution_factor = 0.25) fft_map.apply_sigma_scaling() map_data = fft_map.real_map_unpadded() # ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy = ph_answer, add_identity=True) ncs_obj_poor.write_pdb_file(file_name="asu.pdb", crystal_symmetry=xrs_poor.crystal_symmetry(), mode="asu") rm = ncs_obj_poor.back_rotation_matrices tv = ncs_obj_poor.back_translation_vectors ir = [rm[0]] it = [tv[0]] # create transformation object transforms_obj = ncs.input( hierarchy = ph_poor_obj.construct_hierarchy(), rotations=rm, translations=tv) x = nu.concatenate_rot_tran(transforms_obj=transforms_obj) x = nu.shake_transformations( x = x, shake_angles_sigma=1*math.pi/180, shake_translation_sigma=0.1) transforms_obj = nu.update_rot_tran(x=x, transforms_obj=transforms_obj) rm,tv = nu.get_rotation_translation_as_list(transforms_obj=transforms_obj) # just to see how result of shaking looks like rm_ = ir+rm tv_ = it+tv ncs_obj_poor.back_rotation_matrices=rm_ ncs_obj_poor.back_translation_vectors=tv_ ncs_obj_poor.update_sites_cart( sites_cart_master_ncs_copy=ncs_obj_poor.ph_first_chain.atoms().extract_xyz()) ncs_obj_poor.write_pdb_file(file_name="asu2.pdb", crystal_symmetry=xrs_poor.crystal_symmetry(), mode="asu") transforms_obj = nu.update_transforms(transforms_obj,rm,tv) ncs_restraints_group_list = transforms_obj.get_ncs_restraints_group_list() refine_selection = flex.size_t(xrange(transforms_obj.total_asu_length)) for i in xrange(5): data_weight = 1 tfg_obj = mmtbx.refinement.minimization_ncs_constraints.\ target_function_and_grads_real_space( map_data = map_data, xray_structure = xrs_poor, ncs_restraints_group_list = ncs_restraints_group_list, refine_selection = refine_selection, real_space_gradients_delta = d_min/4, restraints_manager = restraints_manager, data_weight = data_weight, refine_sites = True) minimized = mmtbx.refinement.minimization_ncs_constraints.lbfgs( target_and_grads_object = tfg_obj, xray_structure = xrs_poor, ncs_restraints_group_list = ncs_restraints_group_list, refine_selection = refine_selection, finite_grad_differences_test = False, max_iterations = 60, refine_sites = True) xrs_poor = tfg_obj.xray_structure ph_poor.adopt_xray_structure(tfg_obj.xray_structure) # ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy = ph_poor, add_identity=False) rm,tv = nu.get_rotation_translation_as_list( ncs_restraints_group_list= ncs_restraints_group_list) # ph_poor.write_pdb_file(file_name="refined.pdb")
def run(prefix="tst", d_min=1.0): """ NCS constraints: xyz, adp, and operators. """ pdb_file_name_answer = "%s_answer.pdb"%prefix of=open(pdb_file_name_answer, "w") print >> of, pdb_str_answer of.close() # pdb_file_name_poor = "%s_poor.pdb"%prefix of=open(pdb_file_name_poor, "w") print >> of, pdb_str_poor of.close() # pdb_inp_answer = iotbx.pdb.input(file_name=pdb_file_name_answer) ph_answer = pdb_inp_answer.construct_hierarchy() ph_answer.atoms().reset_i_seq() xrs_answer = pdb_inp_answer.xray_structure_simple() # pdb_inp_poor = iotbx.pdb.input(file_name=pdb_file_name_poor) ph_poor = pdb_inp_poor.construct_hierarchy() ph_poor_obj = iotbx.pdb.hierarchy.input(pdb_string=pdb_str_poor2) ph_poor.atoms().reset_i_seq() xrs_poor = pdb_inp_poor.xray_structure_simple() # ppf = mmtbx.utils.process_pdb_file_srv(log=False).process_pdb_files( raw_records=pdb_str_poor.splitlines())[0] mmtbx.utils.assert_xray_structures_equal( x1=ppf.xray_structure(show_summary = False), x2=xrs_poor) restraints_manager = mmtbx.restraints.manager( geometry = ppf.geometry_restraints_manager(show_energies = False), normalization = True) # fc = xrs_answer.structure_factors(d_min=d_min).f_calc() fft_map = fc.fft_map(resolution_factor = 0.25) fft_map.apply_sigma_scaling() map_data = fft_map.real_map_unpadded() # ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy = ph_answer, add_identity=True) ncs_obj_poor.write_pdb_file(file_name="asu.pdb", crystal_symmetry=xrs_poor.crystal_symmetry(), mode="asu") rm = ncs_obj_poor.back_rotation_matrices tv = ncs_obj_poor.back_translation_vectors ir = [rm[0]] it = [tv[0]] # create transformation object transforms_obj = ncs.input( pdb_hierarchy_inp = ph_poor_obj, rotations=rm, translations=tv) x = nu.concatenate_rot_tran(transforms_obj=transforms_obj) x = nu.shake_transformations( x = x, shake_angles_sigma=1*math.pi/180, shake_translation_sigma=0.1) transforms_obj = nu.update_rot_tran(x=x, transforms_obj=transforms_obj) rm,tv = nu.get_rotation_translation_as_list(transforms_obj=transforms_obj) # just to see how result of shaking looks like rm_ = ir+rm tv_ = it+tv ncs_obj_poor.back_rotation_matrices=rm_ ncs_obj_poor.back_translation_vectors=tv_ ncs_obj_poor.update_sites_cart( sites_cart_master_ncs_copy=ncs_obj_poor.ph_first_chain.atoms().extract_xyz()) ncs_obj_poor.write_pdb_file(file_name="asu2.pdb", crystal_symmetry=xrs_poor.crystal_symmetry(), mode="asu") transforms_obj = nu.update_transforms(transforms_obj,rm,tv) ncs_restraints_group_list = transforms_obj.get_ncs_restraints_group_list() refine_selection = flex.size_t(xrange(transforms_obj.total_asu_length)) for i in xrange(5): data_weight = 1 for action in [[False, True], [True, False]]: refine_sites, refine_transformations = action tfg_obj = mmtbx.refinement.minimization_ncs_constraints.\ target_function_and_grads_real_space( map_data = map_data, xray_structure = xrs_poor, ncs_restraints_group_list = ncs_restraints_group_list, refine_selection = refine_selection, real_space_gradients_delta = d_min/4, restraints_manager = restraints_manager, data_weight = data_weight, refine_sites = refine_sites, refine_transformations = refine_transformations) minimized = mmtbx.refinement.minimization_ncs_constraints.lbfgs( target_and_grads_object = tfg_obj, xray_structure = xrs_poor, ncs_restraints_group_list = ncs_restraints_group_list, refine_selection = refine_selection, finite_grad_differences_test = False, max_iterations = 60, refine_sites = refine_sites, refine_transformations = refine_transformations) xrs_poor = tfg_obj.xray_structure ph_poor.adopt_xray_structure(tfg_obj.xray_structure) # ncs_obj_poor = mmtbx.ncs.asu_ncs_converter(pdb_hierarchy = ph_poor, add_identity=False) rm,tv = nu.get_rotation_translation_as_list( ncs_restraints_group_list= ncs_restraints_group_list) # ph_poor.write_pdb_file(file_name="refined.pdb")