def exercise_3(): from mmtbx import masks from cctbx import sgtbx xs = random_structure.xray_structure( space_group_info=sgtbx.space_group_info("P1"), elements=["C"] * 2, unit_cell=(10, 20, 30, 70, 80, 120)) f_calc = xs.structure_factors(d_min=2.0).f_calc() mp = masks.mask_master_params.extract() mm1 = masks.manager(miller_array=f_calc, xray_structure=xs) assert list(xs.scatterers().extract_occupancies()) == [1.0, 1.0] fmasks1 = mm1.shell_f_masks() assert len(fmasks1) == 1 assert flex.mean(flex.abs(fmasks1[0].data())) > 4.0 # xs.set_occupancies(value=0) mp.ignore_zero_occupancy_atoms = False mp.use_asu_masks = False mm2 = masks.manager(miller_array=f_calc, xray_structure=xs, mask_params=mp) assert list(xs.scatterers().extract_occupancies()) == [0.0, 0.0] fmasks1 = mm1.shell_f_masks() assert len(fmasks1) == 1 fmasks2 = mm2.shell_f_masks() assert len(fmasks2) == 1 assert flex.mean( flex.abs(fmasks1[0].data()) ) == \ flex.mean( flex.abs(fmasks2[0].data()) ) # mp.ignore_zero_occupancy_atoms = True mp.use_asu_masks = False mm3 = masks.manager(miller_array=f_calc, xray_structure=xs, mask_params=mp) assert list(xs.scatterers().extract_occupancies()) == [0.0, 0.0] fmasks3 = mm3.shell_f_masks() assert len(fmasks3) == 1 assert approx_equal( flex.abs(fmasks3[0].data()).min_max_mean().as_tuple(), (0.0, 0.0, 0.0))
def exercise_3(): from mmtbx import masks from cctbx import sgtbx xs = random_structure.xray_structure( space_group_info = sgtbx.space_group_info("P1"), elements = ["C"]*2, unit_cell = (10, 20, 30, 70, 80, 120)) f_calc = xs.structure_factors(d_min = 2.0).f_calc() mp = masks.mask_master_params.extract() mm1 = masks.manager(miller_array = f_calc, xray_structure = xs) assert list(xs.scatterers().extract_occupancies()) == [1.0, 1.0] fmasks1 = mm1.shell_f_masks() assert len(fmasks1) == 1 assert flex.mean( flex.abs(fmasks1[0].data()) ) > 4.0 # xs.set_occupancies(value = 0) mp.ignore_zero_occupancy_atoms = False mp.use_asu_masks = False mm2 = masks.manager(miller_array = f_calc, xray_structure = xs, mask_params = mp) assert list(xs.scatterers().extract_occupancies()) == [0.0, 0.0] fmasks1 = mm1.shell_f_masks() assert len(fmasks1) == 1 fmasks2 = mm2.shell_f_masks() assert len(fmasks2)==1 assert flex.mean( flex.abs(fmasks1[0].data()) ) == \ flex.mean( flex.abs(fmasks2[0].data()) ) # mp.ignore_zero_occupancy_atoms = True mp.use_asu_masks = False mm3 = masks.manager(miller_array = f_calc, xray_structure = xs, mask_params = mp) assert list(xs.scatterers().extract_occupancies()) == [0.0, 0.0] fmasks3 = mm3.shell_f_masks() assert len(fmasks3)==1 assert approx_equal( flex.abs(fmasks3[0].data()).min_max_mean().as_tuple(), (0.0, 0.0, 0.0))
def get_f_mask(xrs, ma, step, option=2, r_shrink=None, r_sol=None): # result = ma.deep_copy() sel = ma.d_spacings().data() >= 3 ma = ma.select(sel) # crystal_gridding = maptbx.crystal_gridding( unit_cell=xrs.unit_cell(), space_group_info=xrs.space_group_info(), symmetry_flags=maptbx.use_space_group_symmetry, step=step) n_real = crystal_gridding.n_real() atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs) mask_params = masks.mask_master_params.extract() grid_step_factor = ma.d_min() / step if (r_shrink is not None): mask_params.shrink_truncation_radius = r_shrink if (r_sol is not None): mask_params.solvent_radius = r_sol mask_params.grid_step_factor = grid_step_factor # 1 if (option == 1): asu_mask = ext.atom_mask( unit_cell=xrs.unit_cell(), group=xrs.space_group(), resolution=ma.d_min(), grid_step_factor=grid_step_factor, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius) asu_mask.compute(xrs.sites_frac(), atom_radii) fm_asu = asu_mask.structure_factors(ma.indices()) f_mask = ma.set().array(data=fm_asu) # 2 elif (option == 2): asu_mask = ext.atom_mask( unit_cell=xrs.unit_cell(), space_group=xrs.space_group(), gridding_n_real=n_real, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius) asu_mask.compute(xrs.sites_frac(), atom_radii) fm_asu = asu_mask.structure_factors(ma.indices()) f_mask = ma.set().array(data=fm_asu) # 3 elif (option == 3): mask_p1 = mmtbx.masks.mask_from_xray_structure( xray_structure=xrs, p1=True, for_structure_factors=True, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius, n_real=n_real, in_asu=False).mask_data maptbx.unpad_in_place(map=mask_p1) mask = asu_map_ext.asymmetric_map( xrs.crystal_symmetry().space_group().type(), mask_p1).data() f_mask = ma.structure_factors_from_asu_map(asu_map_data=mask, n_real=n_real) # 4 elif (option == 4): f_mask = masks.bulk_solvent( xray_structure=xrs, ignore_zero_occupancy_atoms=False, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius, ignore_hydrogen_atoms=False, grid_step=step, atom_radii=atom_radii).structure_factors(miller_set=ma) elif (option == 5): o = mmtbx.masks.bulk_solvent( xray_structure=xrs, ignore_zero_occupancy_atoms=False, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius, ignore_hydrogen_atoms=False, gridding_n_real=n_real, atom_radii=atom_radii) assert approx_equal(n_real, o.data.accessor().all()) f_mask = o.structure_factors(ma) elif (option == 6): # XXX No control over n_real, so results with others don't match mask_manager = masks.manager(miller_array=ma, miller_array_twin=None, mask_params=mask_params) f_mask = mask_manager.shell_f_masks(xray_structure=xrs, force_update=True)[0] else: assert 0 # data = flex.complex_double(result.indices().size(), 0) data = data.set_selected(sel, f_mask.data()) result = result.array(data=data) return result
def get_f_mask(xrs, ma, step, option=2): crystal_gridding = maptbx.crystal_gridding( unit_cell=xrs.unit_cell(), space_group_info=xrs.space_group_info(), symmetry_flags=maptbx.use_space_group_symmetry, step=step) n_real = crystal_gridding.n_real() atom_radii = vdw_radii_from_xray_structure(xray_structure=xrs) mask_params = masks.mask_master_params.extract() grid_step_factor = ma.d_min() / step # 1 if (option == 1): asu_mask = ext.atom_mask( unit_cell=xrs.unit_cell(), group=xrs.space_group(), resolution=ma.d_min(), grid_step_factor=grid_step_factor, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius) asu_mask.compute(xrs.sites_frac(), atom_radii) fm_asu = asu_mask.structure_factors(ma.indices()) f_mask = ma.set().array(data=fm_asu) # 2 elif (option == 2): asu_mask = ext.atom_mask( unit_cell=xrs.unit_cell(), space_group=xrs.space_group(), gridding_n_real=n_real, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius) asu_mask.compute(xrs.sites_frac(), atom_radii) fm_asu = asu_mask.structure_factors(ma.indices()) f_mask = ma.set().array(data=fm_asu) # 3 elif (option == 3): mask_params.grid_step_factor = grid_step_factor mask_manager = masks.manager(miller_array=ma, miller_array_twin=None, mask_params=mask_params) f_mask = mask_manager.shell_f_masks(xray_structure=xrs, force_update=True)[0] # 4 elif (option == 4): mask_p1 = mmtbx.masks.mask_from_xray_structure( xray_structure=xrs, p1=True, for_structure_factors=True, n_real=n_real, in_asu=False).mask_data maptbx.unpad_in_place(map=mask_p1) mask = asu_map_ext.asymmetric_map( xrs.crystal_symmetry().space_group().type(), mask_p1).data() f_mask = ma.structure_factors_from_asu_map(asu_map_data=mask, n_real=n_real) elif (option == 5): o = mmtbx.masks.bulk_solvent( xray_structure=xrs, ignore_zero_occupancy_atoms=False, solvent_radius=mask_params.solvent_radius, shrink_truncation_radius=mask_params.shrink_truncation_radius, ignore_hydrogen_atoms=False, gridding_n_real=n_real, atom_radii=atom_radii) f_mask = o.structure_factors(ma) else: assert 0 # return f_mask