def tst_twin_completion(): uc = uctbx.unit_cell("40,40,70,90,90,90") xs = crystal.symmetry(unit_cell=uc, space_group="P1") miller_set = miller.build_set(crystal_symmetry=xs, anomalous_flag=False, d_min=3.0).map_to_asu() select = flex.bool(miller_set.indices().size(), True) select[300] = False miller_set_mod = miller_set.select(select) # make sure we threw away a reflection assert not miller_set_mod.indices().all_eq(miller_set.indices()) checker = xray.twin_completion(miller_set_mod.indices(), xs.space_group(), False, [0, 1, 0, 1, 0, 0, 0, 0, -1]) new_hkl = checker.twin_complete() miller_set_mod = miller_set_mod.customized_copy(indices=new_hkl) miller_set_mod = miller_set_mod.map_to_asu() a, b = miller_set_mod.common_sets(miller_set) assert a.indices().size() == miller_set_mod.indices().size() assert a.indices().size() == miller_set.indices().size() assert miller_set_mod.is_unique_set_under_symmetry() checker = xray.twin_completion(miller_set.indices(), xs.space_group(), False, [0, 1, 0, 1, 0, 0, 0, 0, -1]) basic_flags = miller_set.generate_r_free_flags_basic() lattice_flags = miller_set.generate_r_free_flags_on_lattice_symmetry() assert not checker.check_free_flags( basic_flags.data()) # this should give False assert checker.check_free_flags( lattice_flags.data()) # this should give True selection_array = checker.get_free_model_selection(lattice_flags.indices(), lattice_flags.data()) assert selection_array.all_eq(lattice_flags.data())
def tst_twin_completion(): uc = uctbx.unit_cell( "40,40,70,90,90,90" ) xs = crystal.symmetry( unit_cell=uc, space_group="P1" ) miller_set = miller.build_set( crystal_symmetry=xs, anomalous_flag=False, d_min=3.0 ).map_to_asu() select = flex.bool( miller_set.indices().size(), True ) select[300]=False miller_set_mod = miller_set.select( select ) # make sure we threw away a reflection assert not miller_set_mod.indices().all_eq( miller_set.indices() ) checker = xray.twin_completion( miller_set_mod.indices(), xs.space_group(), False, [0,1,0,1,0,0,0,0,-1] ) new_hkl = checker.twin_complete() miller_set_mod = miller_set_mod.customized_copy( indices=new_hkl) miller_set_mod = miller_set_mod.map_to_asu() a,b = miller_set_mod.common_sets( miller_set ) assert a.indices().size() == miller_set_mod.indices().size() assert a.indices().size() == miller_set.indices().size() assert miller_set_mod.is_unique_set_under_symmetry() checker = xray.twin_completion( miller_set.indices(), xs.space_group(), False, [0,1,0,1,0,0,0,0,-1] ) basic_flags = miller_set.generate_r_free_flags_basic() lattice_flags = miller_set.generate_r_free_flags_on_lattice_symmetry() assert not checker.check_free_flags( basic_flags.data() ) # this should give False assert checker.check_free_flags( lattice_flags.data() ) # this should give True selection_array = checker.get_free_model_selection( lattice_flags.indices(), lattice_flags.data() ) assert selection_array.all_eq( lattice_flags.data() )
def __init__(self): self.structure = xray.structure( crystal_symmetry=crystal.symmetry( unit_cell=(7.6338, 7.6338, 9.8699, 90, 90, 120), space_group_symbol='hall: P 3 -2c'), scatterers=flex.xray_scatterer(( xray.scatterer( #0 label='LI', site=(0.032717, 0.241544, 0.254924), u=(0.000544, 0.000667, 0.000160, 0.000326, 0.000072, -0.000030)), xray.scatterer( #1 label='NA', site=(0.033809, 0.553123, 0.484646), u=(0.000554, 0.000731, 0.000174, 0.000212, 0.000032, -0.000015)), xray.scatterer( #2 label='S1', site=(0.000000, 0.000000, -0.005908), u=(0.000370, 0.000370, 0.000081, 0.000185, 0.000000, 0.000000)), xray.scatterer( #3 label='S2', site=(0.333333, 0.666667, 0.211587), u=(0.000244, 0.000244, 0.000148, 0.000122, 0.000000, 0.000000)), xray.scatterer( #4 label='S3', site=(0.666667, 0.333333, 0.250044), u=(0.000349, 0.000349, 0.000094, 0.000174, 0.000000, 0.000000)), xray.scatterer( #5 label='O1', site=(0.000000, -0.000000, 0.154207), u=(0.000360, 0.000360, 0.000149, 0.000180, 0.000000, 0.000000), occupancy=0.999000), xray.scatterer( #6 label='O2', site=(0.333333, 0.666667, 0.340665), u=(0.000613, 0.000613, 0.000128, 0.000306, 0.000000, 0.000000)), xray.scatterer( #7 label='O3', site=(0.666667, 0.333333, 0.112766), u=(0.000724, 0.000724, 0.000118, 0.000362, 0.000000, 0.000000)), xray.scatterer( #8 label='O4', site=(0.225316, 0.110088, -0.035765), u=(0.000477, 0.000529, 0.000213, 0.000230, 0.000067, -0.000013)), xray.scatterer( #9 label='O5', site=(0.221269, 0.442916, 0.153185), u=(0.000767, 0.000286, 0.000278, 0.000210, 0.000016, -0.000082)), xray.scatterer( #10 label='O6', site=(0.487243, 0.169031, 0.321690), u=(0.000566, 0.000582, 0.000354, 0.000007, 0.000022, 0.000146)) ))) self.twin_laws = (sgtbx.rot_mx((0,1,0,1,0,0,0,0,-1)),) self.twin_fractions = flex.double((flex.random_double(),)) self.scale_factor = 0.05 + 10 * flex.random_double() self.crystal_symmetry = self.structure.crystal_symmetry() mi = self.crystal_symmetry.build_miller_set(anomalous_flag=False, d_min=0.5) fo_sq = mi.structure_factors_from_scatterers( self.structure, algorithm="direct").f_calc().norm() fo_sq = fo_sq.customized_copy( data=fo_sq.data()*self.scale_factor, sigmas=flex.double(fo_sq.size(), 1)) twin_completion = xray.twin_completion( mi.indices(), mi.space_group(), mi.anomalous_flag(), self.twin_laws[0].as_double()) sigmas = flex.double(fo_sq.size(), 1) from cctbx import miller twin_complete_set = miller.set( crystal_symmetry=self.crystal_symmetry, indices=twin_completion.twin_complete(), anomalous_flag=mi.anomalous_flag()).map_to_asu() detwinner = xray.hemihedral_detwinner( hkl_obs=fo_sq.indices(), hkl_calc=twin_complete_set.indices(), space_group=mi.space_group(), anomalous_flag=mi.anomalous_flag(), twin_law=self.twin_laws[0].as_double()) twinned_i, twinned_s = detwinner.twin_with_twin_fraction( fo_sq.data(), sigmas, twin_fraction=self.twin_fractions[0]) self.fo_sq = fo_sq.customized_copy(data=twinned_i, sigmas=twinned_s)