def run(args): map_fname = args[0] af = any_file(map_fname) assert af.file_type == "ccp4_map" ccp4_map = af.file_content print("origin:", ccp4_map.origin) # see how access this info in cctbx_project/iotbx/ccp4_map/__init__.py: def show_summary print("summary:", ccp4_map.show_summary()) xc = yc = zc = 1 # real coordinates # fractional coordinates xf, yf, zf = ccp4_map.unit_cell().fractionalize([xc, yc, zc]) print("map value:", ccp4_map.map_data().eight_point_interpolation([xf, yf, zf])) shifted_map_data = shift_origin_if_needed(ccp4_map.map_data()).map_data print("map value on shifted map:", shifted_map_data.eight_point_interpolation([xf, yf, zf])) print("shifted origin:", shifted_map_data.origin()) # This does not work for non 0-based (non-shifted) map print("map value at closes grid point:", shifted_map_data.value_at_closest_grid_point([xf, yf, zf])) cs = ccp4_map.crystal_symmetry() # writing shifted map iotbx.mrcfile.write_ccp4_map(file_name="shifted_map.map", unit_cell=cs.unit_cell(), space_group=cs.space_group(), map_data=shifted_map_data, labels=flex.std_string([""]))
def _shift_origin(self): sites_cart = None if (self.xray_structure is not None): sites_cart = self.xray_structure.sites_cart() soin = maptbx.shift_origin_if_needed( map_data=self.map_data, sites_cart=sites_cart, crystal_symmetry=self.crystal_symmetry) self.map_data = soin.map_data if (self.xray_structure is not None): self.xray_structure.set_sites_cart(soin.sites_cart) self.pdb_hierarchy.atoms().set_xyz(soin.sites_cart) if (self.half_map_data_1 is not None): soin = maptbx.shift_origin_if_needed(map_data=self.half_map_data_1, sites_cart=None, crystal_symmetry=None) self.half_map_data_1 = soin.map_data soin = maptbx.shift_origin_if_needed(map_data=self.half_map_data_2, sites_cart=None, crystal_symmetry=None) self.half_map_data_2 = soin.map_data
def run(args, log=sys.stdout): print >> log, "-" * 79 print >> log, legend print >> log, "-" * 79 inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) params = inputs.params.extract() # model broadcast(m="Input PDB:", log=log) file_names = inputs.pdb_file_names if (len(file_names) != 1): raise Sorry("PDB file has to given.") pi = iotbx.pdb.input(file_name=file_names[0]) h = pi.construct_hierarchy() xrs = pi.xray_structure_simple(crystal_symmetry=inputs.crystal_symmetry) xrs.scattering_type_registry(table=params.scattering_table) xrs.show_summary(f=log, prefix=" ") # map broadcast(m="Input map:", log=log) if (inputs.ccp4_map is None): raise Sorry("Map file has to given.") inputs.ccp4_map.show_summary(prefix=" ") map_data = inputs.ccp4_map.map_data() # shift origin if needed soin = maptbx.shift_origin_if_needed( map_data=map_data, sites_cart=xrs.sites_cart(), crystal_symmetry=xrs.crystal_symmetry()) map_data = soin.map_data xrs.set_sites_cart(soin.sites_cart) # estimate resolution d_min = params.resolution if (d_min is None): raise Sorry("Map resolution must be given.") print >> log, " d_min: %6.4f" % d_min # result_obj = compdiff(map_data_obs=map_data, xrs=xrs, d_min=d_min, vector_map=False) write_ccp4_map(map_data=result_obj.map_result, unit_cell=xrs.unit_cell(), space_group=xrs.space_group(), file_name="map_model_difference_1.ccp4") # result_obj = compdiff(map_data_obs=map_data, xrs=xrs, d_min=d_min, vector_map=True) write_ccp4_map(map_data=result_obj.map_result, unit_cell=xrs.unit_cell(), space_group=xrs.space_group(), file_name="map_model_difference_2.ccp4")
def run(args): map_fname = args[0] af = any_file(map_fname) assert af.file_type == "ccp4_map" ccp4_map = af.file_content print("origin:", ccp4_map.origin) # see how access this info in cctbx_project/iotbx/ccp4_map/__init__.py: def show_summary print("summary:", ccp4_map.show_summary()) xc = yc = zc = 1 # real coordinates # fractional coordinates xf, yf, zf = ccp4_map.unit_cell().fractionalize([xc, yc, zc]) print("map value:", ccp4_map.map_data().eight_point_interpolation([xf, yf, zf])) shifted_map_data = shift_origin_if_needed(ccp4_map.map_data()).map_data print("map value on shifted map:", shifted_map_data.eight_point_interpolation([xf, yf, zf])) print("shifted origin:", shifted_map_data.origin())
def __init__( self, # I suggest we use map_input with symmetries here instead of # raw map_data and call something like mtriage.py:check_and_set_crystal_symmetry # to set CS consistently for maps and model. # Especially because DataManager is supposed to provide these # map_input objects. # consider reusing/replacing crystal.select_crystal_symmetry() # Warning! Model and all map_data are being changed in place. # This warning should remain here map_data=None, # whole_map_input would be a better name? map_data_1=None, # half_map_input_1 would be a better name? map_data_2=None, # half_map_input_2 would be a better name? model=None, # where this CS is supposed to come from? After agreing on picking # CS here, the only thing it could be useful - to pass CS # obtained from command-line args or from parameters. Consider # renaming parameter accordingly. crystal_symmetry=None, box=True, ignore_symmetry_conflicts=False): # # We should be able to work without symmetry at all. Why not just box # model? assert [model, crystal_symmetry].count(None) != 2 if (crystal_symmetry is None and model is not None): crystal_symmetry = model.crystal_symmetry() if ([model, crystal_symmetry].count(None) == 0): if ignore_symmetry_conflicts: # Take crystal_symmetry if necessary if not (model.crystal_symmetry().is_similar_symmetry( crystal_symmetry)): model = mmtbx.model.manager( model_input=model.get_hierarchy().as_pdb_input(), crystal_symmetry=crystal_symmetry) else: assert model.crystal_symmetry().is_similar_symmetry( crystal_symmetry) if (not [map_data_1, map_data_2].count(None) in [0, 2]): raise Sorry("None or two half-maps are required.") # # Suggest to get rid of self._model, self._map_data etc to make crystal # clear that they are changed in place. Therefore getter functions # at the bottom are useless and confusing. self._map_data = map_data self._half_map_data_1 = map_data_1 self._half_map_data_2 = map_data_2 self._model = model self._crystal_symmetry = crystal_symmetry # # I don't see any connection between _counts, map_histograms and main # purpose of this class (actually, it is function written using class syntax) # - shifting origins, cutting boxes, figuring out crystal symmetries. # This can be easily done just before calling this and totally separate. # I suggest to remove it from here ---> self._counts = get_map_counts(map_data=self._map_data, crystal_symmetry=crystal_symmetry) self._map_histograms = get_map_histograms(data=self._map_data, n_slots=20, data_1=self._half_map_data_1, data_2=self._half_map_data_2) # <---- End of removing suggestion. # Shift origin sites_cart = None if (self._model is not None): sites_cart = self._model.get_sites_cart() self.soin = maptbx.shift_origin_if_needed( map_data=self._map_data, sites_cart=sites_cart, crystal_symmetry=crystal_symmetry) self._original_origin_cart = self.soin.original_origin_cart self._original_origin_grid_units = self.soin.original_origin_grid_units self.box = None self._map_data = self.soin.map_data if (self._model is not None): self._model.set_sites_cart(sites_cart=self.soin.sites_cart) if (self._half_map_data_1 is not None): self._half_map_data_1 = maptbx.shift_origin_if_needed( map_data=self._half_map_data_1, sites_cart=None, crystal_symmetry=None).map_data self._half_map_data_2 = maptbx.shift_origin_if_needed( map_data=self._half_map_data_2, sites_cart=None, crystal_symmetry=None).map_data # Box if (self._model is not None and box): xrs = self._model.get_xray_structure() if (self._half_map_data_1 is not None): self._half_map_data_1 = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._half_map_data_1, box_cushion=5.0).map_box self._half_map_data_2 = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._half_map_data_2, box_cushion=5.0).map_box self.box = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._map_data, box_cushion=5.0) # This should be changed to call model.set_shift_manager(shift_manager=box) # For now just call _model.unset_restraints_manager() afterwards. self._model.set_xray_structure( xray_structure=self.box.xray_structure_box) self._crystal_symmetry = self._model.crystal_symmetry() self._map_data = self.box.map_box
def __init__(self, pdb_hierarchy, xray_structure, fmodel, distance_cutoff=4.0, collect_all=True, molprobity_map_params=None): validation.__init__(self) from mmtbx.real_space_correlation import extract_map_stats_for_single_atoms from cctbx import adptbx from scitbx.matrix import col self.n_bad = 0 self.n_heavy = 0 pdb_atoms = pdb_hierarchy.atoms() if (len(pdb_atoms) > 1): assert (not pdb_atoms.extract_i_seq().all_eq(0)) unit_cell = xray_structure.unit_cell() pair_asu_table = xray_structure.pair_asu_table( distance_cutoff=distance_cutoff) asu_mappings = pair_asu_table.asu_mappings() asu_table = pair_asu_table.table() u_isos = xray_structure.extract_u_iso_or_u_equiv() occupancies = xray_structure.scatterers().extract_occupancies() sites_frac = xray_structure.sites_frac() sel_cache = pdb_hierarchy.atom_selection_cache() water_sel = sel_cache.selection("water") if (molprobity_map_params is not None): # assume parameters have been validated (symmetry of pdb and map matches) two_fofc_map = None fc_map = None d_min = None crystal_gridding = None # read two_fofc_map if (molprobity_map_params.map_file_name is not None): f = any_file(molprobity_map_params.map_file_name) two_fofc_map = f.file_object.map_data() d_min = molprobity_map_params.d_min crystal_gridding = maptbx.crystal_gridding( f.file_object.unit_cell(), space_group_info=space_group_info( f.file_object.space_group_number), pre_determined_n_real=f.file_object.unit_cell_grid) pdb_atoms = pdb_hierarchy.atoms() xray_structure = pdb_hierarchy.extract_xray_structure( crystal_symmetry=f.crystal_symmetry()) unit_cell = xray_structure.unit_cell() # check for origin shift # --------------------------------------------------------------------- soin = maptbx.shift_origin_if_needed( map_data=two_fofc_map, sites_cart=xray_structure.sites_cart(), crystal_symmetry=xray_structure.crystal_symmetry()) two_fofc_map = soin.map_data xray_structure.set_sites_cart(soin.sites_cart) # --------------------------------------------------------------------- pair_asu_table = xray_structure.pair_asu_table( distance_cutoff=distance_cutoff) asu_mappings = pair_asu_table.asu_mappings() asu_table = pair_asu_table.table() u_isos = xray_structure.extract_u_iso_or_u_equiv() occupancies = xray_structure.scatterers().extract_occupancies() sites_frac = xray_structure.sites_frac() sel_cache = pdb_hierarchy.atom_selection_cache() water_sel = sel_cache.selection("water") elif (molprobity_map_params.map_coefficients_file_name is not None): f = any_file(molprobity_map_params.map_coefficients_file_name) fourier_coefficients = f.file_server.get_miller_array( molprobity_map_params.map_coefficients_label) crystal_symmetry = fourier_coefficients.crystal_symmetry() d_min = fourier_coefficients.d_min() crystal_gridding = maptbx.crystal_gridding( crystal_symmetry.unit_cell(), d_min, resolution_factor=0.25, space_group_info=crystal_symmetry.space_group_info()) two_fofc_map = miller.fft_map( crystal_gridding=crystal_gridding, fourier_coefficients=fourier_coefficients).apply_sigma_scaling().\ real_map_unpadded() # calculate fc_map assert ((d_min is not None) and (crystal_gridding is not None)) f_calc = xray_structure.structure_factors(d_min=d_min).f_calc() fc_map = miller.fft_map(crystal_gridding=crystal_gridding, fourier_coefficients=f_calc) fc_map = fc_map.apply_sigma_scaling().real_map_unpadded() map_stats = extract_map_stats_for_single_atoms( pdb_atoms=pdb_atoms, xray_structure=xray_structure, fmodel=None, selection=water_sel, fc_map=fc_map, two_fofc_map=two_fofc_map) else: map_stats = extract_map_stats_for_single_atoms( pdb_atoms=pdb_atoms, xray_structure=xray_structure, fmodel=fmodel, selection=water_sel) waters = [] for i_seq, atom in enumerate(pdb_atoms): if (water_sel[i_seq]): rt_mx_i_inv = asu_mappings.get_rt_mx(i_seq, 0).inverse() self.n_total += 1 asu_dict = asu_table[i_seq] nearest_atom = nearest_contact = None for j_seq, j_sym_groups in asu_dict.items(): atom_j = pdb_atoms[j_seq] site_j = sites_frac[j_seq] # Filter out hydrogens if atom_j.element.upper().strip() in ["H", "D"]: continue for j_sym_group in j_sym_groups: rt_mx = rt_mx_i_inv.multiply( asu_mappings.get_rt_mx(j_seq, j_sym_group[0])) site_ji = rt_mx * site_j site_ji_cart = xray_structure.unit_cell( ).orthogonalize(site_ji) vec_i = col(atom.xyz) vec_ji = col(site_ji_cart) dxyz = abs(vec_i - vec_ji) if (nearest_contact is None) or (dxyz < nearest_contact): nearest_contact = dxyz nearest_atom = atom_info(pdb_atom=atom_j, symop=rt_mx) w = water(pdb_atom=atom, b_iso=adptbx.u_as_b(u_isos[i_seq]), occupancy=occupancies[i_seq], nearest_contact=nearest_contact, nearest_atom=nearest_atom, score=map_stats.two_fofc_ccs[i_seq], fmodel=map_stats.fmodel_values[i_seq], two_fofc=map_stats.two_fofc_values[i_seq], fofc=map_stats.fofc_values[i_seq], anom=map_stats.anom_values[i_seq], n_hbonds=None) # TODO if (w.is_bad_water()): w.outlier = True self.n_bad += 1 elif (w.is_heavy_atom()): w.outlier = True self.n_heavy += 1 if (w.outlier) or (collect_all): self.results.append(w) self.n_outliers = len(self.results)
def run(args, log=None, ccp4_map=None, return_as_miller_arrays=False, nohl=False, return_f_obs=False, space_group_number=None, out=sys.stdout): if log is None: log = out inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) got_map = False if ccp4_map: got_map = True broadcast(m="Parameters:", log=log) inputs.params.show(prefix=" ", out=out) params = inputs.params.extract() if (ccp4_map is None and inputs.ccp4_map is not None): broadcast(m="Processing input CCP4 map file: %s" % inputs.ccp4_map_file_name, log=log) ccp4_map = inputs.ccp4_map ccp4_map.show_summary(prefix=" ", out=out) got_map = True if (not got_map): raise Sorry("Map file is needed.") # m = ccp4_map if (m.space_group_number > 1): raise Sorry("Input map space group: %d. Must be P1." % m.space_group_number) broadcast(m="Input map information:", log=log) print("m.all() :", m.data.all(), file=out) print("m.focus() :", m.data.focus(), file=out) print("m.origin():", m.data.origin(), file=out) print("m.nd() :", m.data.nd(), file=out) print("m.size() :", m.data.size(), file=out) print("m.focus_size_1d():", m.data.focus_size_1d(), file=out) print("m.is_0_based() :", m.data.is_0_based(), file=out) print("map: min/max/mean:", flex.min(m.data), flex.max(m.data), flex.mean(m.data), file=out) print("unit cell:", m.unit_cell_parameters, file=out) # if not space_group_number: space_group_number = 1 if space_group_number <= 1: symmetry_flags = None else: symmetry_flags = maptbx.use_space_group_symmetry, #cs = crystal.symmetry(m.unit_cell_parameters, space_group_number) # this will not work if m.unit_cell_grid != m.data.all() # Instead use ccp4 map crystal_symmetry and classify according to the case cs = m.crystal_symmetry() if m.unit_cell_grid == m.data.all(): print("\nOne unit cell of data is present in map", file=out) else: if params.keep_origin: print("\nNOTE: This map does not have exactly one unit cell of data, so \n"+\ "keep_origin is not available\n", file=out) print( "--> Setting keep_origin=False and creating a new cell and gridding.\n", file=out) params.keep_origin = False print("Moving origin of input map to (0,0,0)", file=out) print("New cell will be: (%.3f, %.3f, %.3f, %.1f, %.1f, %.1f) A " % (cs.unit_cell().parameters()), file=out) print("New unit cell grid will be: (%s, %s, %s) " % (m.data.all()), file=out) map_data = m.data # Get origin in grid units and new position of origin in grid units original_origin = map_data.origin() print("\nInput map has origin at grid point (%s,%s,%s)" % (tuple(original_origin)), file=out) if params.output_origin_grid_units is not None: params.keep_origin = False new_origin = tuple(params.output_origin_grid_units) print("User-specified origin at grid point (%s,%s,%s)" % (tuple(params.output_origin_grid_units)), file=out) if tuple(params.output_origin_grid_units) == tuple(original_origin): print("This is the same as the input origin. No origin shift.", file=out) elif params.keep_origin: new_origin = original_origin print("Keeping origin at grid point (%s,%s,%s)" % (tuple(original_origin)), file=out) else: new_origin = ( 0, 0, 0, ) print("New origin at grid point (%s,%s,%s)" % (tuple(( 0, 0, 0, ))), file=out) # shift_cart is shift away from (0,0,0) if new_origin != ( 0, 0, 0, ): shift_cart = get_shift_cart(map_data=map_data, crystal_symmetry=cs, origin=new_origin) else: shift_cart = ( 0, 0, 0, ) map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data # generate complete set of Miller indices up to given high resolution d_min n_real = map_data.focus() crystal_gridding = maptbx.crystal_gridding( unit_cell=cs.unit_cell(), space_group_info=cs.space_group_info(), symmetry_flags=symmetry_flags, pre_determined_n_real=n_real) # d_min = params.d_min if (d_min is None and not params.box): d_min = maptbx.d_min_from_map( map_data=map_data, unit_cell=cs.unit_cell(), resolution_factor=params.resolution_factor) print("\nResolution of map coefficients using "+\ "resolution_factor of %.2f: %.1f A\n" %(params.resolution_factor,d_min), file=out) if (d_min is None): # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2 f_obs_cmpl = miller.structure_factor_box_from_map( map=map_data.as_double(), crystal_symmetry=cs, include_000=True) else: complete_set = miller.build_set(crystal_symmetry=cs, anomalous_flag=False, d_min=d_min) try: f_obs_cmpl = complete_set.structure_factors_from_map( map=map_data.as_double(), use_scale=True, anomalous_flag=False, use_sg=False) except Exception as e: if (str(e) == "cctbx Error: Miller index not in structure factor map."): msg = "Too high resolution requested. Try running with larger d_min." raise Sorry(msg) else: raise Sorry(str(e)) if params.scale_max is not None: f_obs_cmpl = f_obs_cmpl.apply_scaling(target_max=params.scale_max) from scitbx.matrix import col if col(shift_cart) != col(( 0, 0, 0, )): print("Output origin is at: (%.3f, %.3f, %.3f) A " % (tuple(-col(shift_cart))), file=out) f_obs_cmpl = f_obs_cmpl.translational_shift( cs.unit_cell().fractionalize(-col(shift_cart)), deg=False) else: print("Output origin is at (0.000, 0.000, 0.000) A", file=out) if nohl and return_as_miller_arrays and not return_f_obs: return f_obs_cmpl mtz_dataset = f_obs_cmpl.as_mtz_dataset(column_root_label="F") f_obs = abs(f_obs_cmpl) f_obs.set_sigmas(sigmas=flex.double(f_obs_cmpl.data().size(), 1)) if nohl and return_as_miller_arrays and return_f_obs: return f_obs mtz_dataset.add_miller_array(miller_array=f_obs, column_root_label="F-obs") mtz_dataset.add_miller_array(miller_array=f_obs.generate_r_free_flags(), column_root_label="R-free-flags") if not nohl: # convert phases into HL coefficeints broadcast(m="Convert phases into HL coefficients:", log=log) hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=params.b_blur) cc = get_cc(f=f_obs_cmpl, hl=hl) print("cc:", cc, file=out) if (abs(1. - cc) > 1.e-3): print( "Supplied b_blur is not good. Attempting to find optimal b_blur.", file=out) cc_best = 999. b_blur_best = params.b_blur for b_blur in range(1, 100): hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=b_blur) cc = get_cc(f=f_obs_cmpl, hl=hl) if (cc < cc_best): cc_best = cc b_blur_best = b_blur if (abs(1. - cc) < 1.e-3): b_blur_best = b_blur break hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=b_blur_best) print("cc:", get_cc(f=f_obs_cmpl, hl=hl), file=out) print("b_blur_best:", b_blur_best, file=out) mtz_dataset.add_miller_array(miller_array=hl, column_root_label="HL") else: hl = None if return_as_miller_arrays: if return_f_obs: return f_obs, hl else: return f_obs_cmpl, hl else: # write output MTZ file with all the data broadcast(m="Writing output MTZ file:", log=log) print(" file name:", params.output_file_name, file=log) mtz_object = mtz_dataset.mtz_object() mtz_object.write(file_name=params.output_file_name)
def __init__(self, map_data = None, map_data_1 = None, map_data_2 = None, model = None, crystal_symmetry = None, box = True): # assert [model, crystal_symmetry].count(None) != 2 if(crystal_symmetry is None and model is not None): crystal_symmetry = model.crystal_symmetry() if([model, crystal_symmetry].count(None)==0): assert model.crystal_symmetry().is_similar_symmetry(crystal_symmetry) if(not [map_data_1, map_data_2].count(None) in [0,2]): raise Sorry("None or two half-maps are required.") # self._map_data = map_data self._half_map_data_1 = map_data_1 self._half_map_data_2 = map_data_2 self._model = model self._crystal_symmetry = crystal_symmetry # self._counts = get_map_counts( map_data = self._map_data, crystal_symmetry = crystal_symmetry) self._map_histograms = get_map_histograms( data = self._map_data, n_slots = 20, data_1 = self._half_map_data_1, data_2 = self._half_map_data_2) # Shift origin sites_cart = None if(self._model is not None): sites_cart = self._model.get_sites_cart() soin = maptbx.shift_origin_if_needed( map_data = self._map_data, sites_cart = sites_cart, crystal_symmetry = crystal_symmetry) self._map_data = soin.map_data if(self._model is not None): self._model.set_sites_cart(sites_cart = soin.sites_cart) if(self._half_map_data_1 is not None): self._half_map_data_1 = maptbx.shift_origin_if_needed( map_data = self._half_map_data_1, sites_cart = None, crystal_symmetry = None).map_data self._half_map_data_2 = maptbx.shift_origin_if_needed( map_data = self._half_map_data_2, sites_cart = None, crystal_symmetry = None).map_data # Box if(self._model is not None and box): xrs = self._model.get_xray_structure() if(self._half_map_data_1 is not None): self._half_map_data_1 = mmtbx.utils.extract_box_around_model_and_map( xray_structure = xrs, map_data = self._half_map_data_1, box_cushion = 5.0).map_box self._half_map_data_2 = mmtbx.utils.extract_box_around_model_and_map( xray_structure = xrs, map_data = self._half_map_data_2, box_cushion = 5.0).map_box box = mmtbx.utils.extract_box_around_model_and_map( xray_structure = xrs, map_data = self._map_data, box_cushion = 5.0) self._model.set_xray_structure(xray_structure = box.xray_structure_box) self._crystal_symmetry = self._model.crystal_symmetry() self._map_data = box.map_box
def run(self): xrs = self.pdb_hierarchy.extract_xray_structure( crystal_symmetry=self.crystal_symmetry) xrs.scattering_type_registry(table=self.params.scattering_table) soin = maptbx.shift_origin_if_needed( map_data=self.map_data, sites_cart=xrs.sites_cart(), crystal_symmetry=self.crystal_symmetry) map_data = soin.map_data xrs.set_sites_cart(soin.sites_cart) self.five_cc_result = mmtbx.maps.correlation.five_cc( map=map_data, xray_structure=xrs, d_min=self.params.resolution, compute_cc_mask=self.params.compute_cc_mask, compute_cc_volume=self.params.compute_cc_volume, compute_cc_peaks=self.params.compute_cc_peaks) # Atom radius self.atom_radius = mtriage.get_atom_radius( xray_structure=xrs, d_min=self.params.resolution, map_data=map_data, crystal_symmetry=self.crystal_symmetry, radius=self.params.atom_radius) # Model-map FSC if (self.params.compute_fsc): mtriage_params = mtriage.master_params().extract() mtriage_params.scattering_table = self.params.scattering_table mtriage_params.compute_d_model = False mtriage_params.compute_d99 = False mtriage_params.radius_smooth = self.atom_radius self.fsc = mtriage.mtriage( map_data=self.map_data, pdb_hierarchy=self.pdb_hierarchy, crystal_symmetry=self.crystal_symmetry, params=mtriage_params).run().get_results().fsc_curve_model.fsc # cc_calculator = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel( xray_structure=xrs, map_data=map_data, d_min=self.params.resolution) # def get_common_data(atoms, atom_radius): sel = atoms.extract_i_seq() return group_args(b_iso_mean=flex.mean(atoms.extract_b()), occ_mean=flex.mean(atoms.extract_occ()), n_atoms=atoms.size(), cc=cc_calculator.cc(selection=sel, atom_radius=atom_radius), xyz_mean=atoms.extract_xyz().mean()) # CC per chain if (self.params.compute_cc_per_chain): for chain in self.pdb_hierarchy.chains(): cd = get_common_data(atoms=chain.atoms(), atom_radius=self.atom_radius) self.cc_per_chain.append( group_args(chain_id=chain.id, b_iso_mean=cd.b_iso_mean, occ_mean=cd.occ_mean, n_atoms=cd.n_atoms, cc=cd.cc)) # CC per residue if (self.params.compute_cc_per_residue): for rg in self.pdb_hierarchy.residue_groups(): for conformer in rg.conformers(): for residue in conformer.residues(): cd = get_common_data(atoms=residue.atoms(), atom_radius=self.atom_radius) self.cc_per_residue.append( group_args( chain_id=rg.parent().id, resname=residue.resname, resseq=residue.resseq, icode=residue.icode, b_iso_mean=cd.b_iso_mean, occ_mean=cd.occ_mean, n_atoms=cd.n_atoms, cc=cd.cc, xyz_mean=cd.xyz_mean, residue=residue)) # for compatibility with GUI
def run(args, log=None, ccp4_map=None, return_as_miller_arrays=False, nohl=False, return_f_obs=False, space_group_number=None, out=sys.stdout): if log is None: log = out inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) got_map = False if ccp4_map: got_map = True broadcast(m="Parameters:", log=log) inputs.params.show(prefix=" ", out=out) params = inputs.params.extract() if (ccp4_map is None and inputs.ccp4_map is not None): broadcast(m="Processing input CCP4 map file: %s" % inputs.ccp4_map_file_name, log=log) ccp4_map = inputs.ccp4_map ccp4_map.show_summary(prefix=" ", out=out) got_map = True if (not got_map): raise Sorry("Map file is needed.") # m = ccp4_map if (m.space_group_number > 1): raise Sorry("Input map space group: %d. Must be P1." % m.space_group_number) broadcast(m="Input map information:", log=log) print >> out, "m.all() :", m.data.all() print >> out, "m.focus() :", m.data.focus() print >> out, "m.origin():", m.data.origin() print >> out, "m.nd() :", m.data.nd() print >> out, "m.size() :", m.data.size() print >> out, "m.focus_size_1d():", m.data.focus_size_1d() print >> out, "m.is_0_based() :", m.data.is_0_based() print >> out, "map: min/max/mean:", flex.min(m.data), flex.max( m.data), flex.mean(m.data) print >> out, "unit cell:", m.unit_cell_parameters # if not space_group_number: space_group_number = 1 if space_group_number <= 1: symmetry_flags = None else: symmetry_flags = maptbx.use_space_group_symmetry, cs = crystal.symmetry(m.unit_cell_parameters, space_group_number) map_data = m.data # Get origin in grid units and new position of origin in grid units original_origin = map_data.origin() print >> out, "Input map has origin at grid point (%s,%s,%s)" % ( tuple(original_origin)) if params.output_origin_grid_units is not None: params.keep_origin = False new_origin = tuple(params.output_origin_grid_units) print >> out, "User-specified origin at grid point (%s,%s,%s)" % ( tuple(params.output_origin_grid_units)) if tuple(params.output_origin_grid_units) == tuple(original_origin): print >> out, "This is the same as the input origin. No origin shift." elif params.keep_origin: new_origin = original_origin print >> out, "Keeping origin at grid point (%s,%s,%s)" % ( tuple(original_origin)) else: new_origin = ( 0, 0, 0, ) print >> out, "New origin at grid point (%s,%s,%s)" % (tuple(( 0, 0, 0, ))) # shift_cart is shift away from (0,0,0) if new_origin != ( 0, 0, 0, ): shift_cart = get_shift_cart(map_data=map_data, crystal_symmetry=cs, origin=new_origin) else: shift_cart = ( 0, 0, 0, ) map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data # generate complete set of Miller indices up to given high resolution d_min n_real = map_data.focus() crystal_gridding = maptbx.crystal_gridding( unit_cell=cs.unit_cell(), space_group_info=cs.space_group_info(), symmetry_flags=symmetry_flags, pre_determined_n_real=n_real) # d_min = params.d_min if (d_min is None and not params.box): d_min = maptbx.d_min_from_map(map_data=map_data, unit_cell=cs.unit_cell()) if (d_min is None): # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2 f_obs_cmpl = miller.structure_factor_box_from_map( map=map_data.as_double(), crystal_symmetry=cs, include_000=True) else: complete_set = miller.build_set(crystal_symmetry=cs, anomalous_flag=False, d_min=d_min) try: f_obs_cmpl = complete_set.structure_factors_from_map( map=map_data.as_double(), use_scale=True, anomalous_flag=False, use_sg=False) except Exception, e: if (str(e) == "cctbx Error: Miller index not in structure factor map."): msg = "Too high resolution requested. Try running with larger d_min." raise Sorry(msg) else: raise Sorry(str(e))
def run(self): xrs = self.pdb_hierarchy.extract_xray_structure( crystal_symmetry=self.crystal_symmetry) xrs.scattering_type_registry(table = self.params.scattering_table) soin = maptbx.shift_origin_if_needed( map_data = self.map_data, sites_cart = xrs.sites_cart(), crystal_symmetry = self.crystal_symmetry) map_data = soin.map_data xrs.set_sites_cart(soin.sites_cart) self.five_cc = mmtbx.maps.correlation.five_cc( map = map_data, xray_structure = xrs, keep_map_calc = self.params.keep_map_calc, d_min = self.params.resolution, compute_cc_mask = self.params.compute.cc_mask, compute_cc_volume = self.params.compute.cc_volume, compute_cc_peaks = self.params.compute.cc_peaks, compute_cc_box = self.params.compute.cc_box, compute_cc_image = self.params.compute.cc_image) # Atom radius self.atom_radius = mtriage.get_atom_radius( xray_structure = xrs, resolution = self.params.resolution, radius = self.params.atom_radius) # cc_calculator = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel( xray_structure = xrs, map_data = map_data, d_min = self.params.resolution) # def get_common_data(atoms, atom_radius): sel = atoms.extract_i_seq() cc = cc_calculator.cc(selection = sel, atom_radius = atom_radius) return group_args( b_iso_mean = flex.mean(atoms.extract_b()), occ_mean = flex.mean(atoms.extract_occ()), n_atoms = atoms.size(), cc = cc, xyz_mean = atoms.extract_xyz().mean()) # CC per chain if(self.params.compute.cc_per_chain): for chain in self.pdb_hierarchy.chains(): cd = get_common_data(atoms=chain.atoms(), atom_radius=self.atom_radius) self.cc_per_chain.append(group_args( chain_id = chain.id, b_iso_mean = cd.b_iso_mean, occ_mean = cd.occ_mean, n_atoms = cd.n_atoms, cc = cd.cc)) # CC per residue if(self.params.compute.cc_per_residue): for rg in self.pdb_hierarchy.residue_groups(): for conformer in rg.conformers(): for residue in conformer.residues(): cd = get_common_data( atoms = residue.atoms(), atom_radius = self.atom_radius) self.cc_per_residue.append(group_args( chain_id = rg.parent().id, resname = residue.resname, resseq = residue.resseq, icode = residue.icode, b_iso_mean = cd.b_iso_mean, occ_mean = cd.occ_mean, n_atoms = cd.n_atoms, cc = cd.cc, xyz_mean = cd.xyz_mean)) # Side chain sel_mc_str = "protein and (name C or name N or name CA or name O or name CB)" asc = self.pdb_hierarchy.atom_selection_cache() sel_mc = asc.selection(sel_mc_str) sel_sc = ~sel_mc if(sel_mc.count(True)>0): self.cc_main_chain = get_common_data( atoms = self.pdb_hierarchy.select(sel_mc).atoms(), atom_radius = self.atom_radius) if(sel_sc.count(True)>0): self.cc_side_chain = get_common_data( atoms = self.pdb_hierarchy.select(sel_sc).atoms(), atom_radius = self.atom_radius)
def run(args, log=sys.stdout): print >> log, "-" * 79 print >> log, legend print >> log, "-" * 79 inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) params = inputs.params.extract() # estimate resolution d_min = params.resolution broadcast(m="Map resolution:", log=log) if (d_min is None): raise Sorry("Resolution is required.") print >> log, " d_min: %6.4f" % d_min # model broadcast(m="Input PDB:", log=log) file_names = inputs.pdb_file_names if (len(file_names) != 1): raise Sorry("PDB file has to given.") if (inputs.crystal_symmetry is None): raise Sorry("No crystal symmetry defined.") pdb_inp = iotbx.pdb.input(file_name=file_names[0]) model = mmtbx.model.manager(model_input=pdb_inp, crystal_symmetry=inputs.crystal_symmetry, build_grm=True) if model.get_number_of_models() > 1: raise Sorry("Only one model allowed.") model.setup_scattering_dictionaries( scattering_table=params.scattering_table) model.get_xray_structure().show_summary(f=log, prefix=" ") broadcast(m="Input map:", log=log) if (inputs.ccp4_map is None): raise Sorry("Map file has to given.") inputs.ccp4_map.show_summary(prefix=" ") map_data = inputs.ccp4_map.map_data() print >> log, " Actual map (min,max,mean):", \ map_data.as_1d().min_max_mean().as_tuple() make_sub_header("Histogram of map values", out=log) md = map_data.as_1d() show_histogram(data=md, n_slots=10, data_min=flex.min(md), data_max=flex.max(md), log=log) # shift origin if needed soin = maptbx.shift_origin_if_needed( map_data=map_data, sites_cart=model.get_sites_cart(), crystal_symmetry=model.crystal_symmetry()) map_data = soin.map_data model.set_sites_cart(soin.sites_cart, update_grm=True) #### # Compute and show all stats #### broadcast(m="Model statistics:", log=log) make_sub_header("Overall", out=log) info = mmtbx.model.statistics.info(model=model) info.geometry.show() # XXX - these are not available anymore due to refactoring # make_sub_header("Histogram of devations from ideal bonds", out=log) # show_histogram(data=ms.bond_deltas, n_slots=10, data_min=0, data_max=0.2, # log=log) # # # make_sub_header("Histogram of devations from ideal angles", out=log) # show_histogram(data=ms.angle_deltas, n_slots=10, data_min=0, data_max=30., # log=log) # # # make_sub_header("Histogram of non-bonded distances", out=log) # show_histogram(data=ms.nonbonded_distances, n_slots=10, data_min=0, # data_max=5., log=log) # make_sub_header("Histogram of ADPs", out=log) info.adp.show(log=log) # bs = xrs.extract_u_iso_or_u_equiv()*adptbx.u_as_b(1.) # show_histogram(data=bs, n_slots=10, data_min=flex.min(bs), # data_max=flex.max(bs), log=log) # # Compute CC broadcast(m="Map-model CC (overall):", log=log) five_cc_result = mmtbx.maps.correlation.five_cc( map=map_data, xray_structure=model.get_xray_structure(), d_min=d_min) atom_radius = five_cc_result.atom_radius if atom_radius is None: atom_radius = five_cc_result._atom_radius() print >> log, " CC_mask : %6.4f" % five_cc_result.result.cc_mask print >> log, " CC_volume: %6.4f" % five_cc_result.result.cc_volume print >> log, " CC_peaks : %6.4f" % five_cc_result.result.cc_peaks # Compute FSC(map, model) broadcast(m="Model-map FSC:", log=log) fsc = mmtbx.maps.correlation.fsc_model_vs_map( xray_structure=model.get_xray_structure(), map=map_data, atom_radius=atom_radius, d_min=d_min) fsc.show(prefix=" ") # Local CC cc_calculator = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel( xray_structure=model.get_xray_structure(), map_data=map_data, d_min=d_min) broadcast(m="Map-model CC (local):", log=log) # per residue print >> log, "Per residue:" residue_results = list() ph = model.get_hierarchy() xrs = model.get_xray_structure() for rg in ph.residue_groups(): cc = cc_calculator.cc(selection=rg.atoms().extract_i_seq()) chain_id = rg.parent().id print >> log, " chain id: %s resid %s: %6.4f" % (chain_id, rg.resid(), cc) # per chain print >> log, "Per chain:" for chain in ph.chains(): print >> log, " chain %s: %6.4f" % ( chain.id, cc_calculator.cc(selection=chain.atoms().extract_i_seq())) # per residue detailed counts print >> log, "Per residue (histogram):" crystal_gridding = maptbx.crystal_gridding( unit_cell=xrs.unit_cell(), space_group_info=xrs.space_group_info(), pre_determined_n_real=map_data.accessor().all()) f_calc = xrs.structure_factors(d_min=d_min).f_calc() fft_map = miller.fft_map(crystal_gridding=crystal_gridding, fourier_coefficients=f_calc) fft_map.apply_sigma_scaling() map_model = fft_map.real_map_unpadded() sites_cart = xrs.sites_cart() cc_per_residue = flex.double() for rg in ph.residue_groups(): cc = mmtbx.maps.correlation.from_map_map_atoms( map_1=map_data, map_2=map_model, sites_cart=sites_cart.select(rg.atoms().extract_i_seq()), unit_cell=xrs.unit_cell(), radius=2.) cc_per_residue.append(cc) show_histogram(data=cc_per_residue, n_slots=10, data_min=-1., data_max=1.0, log=log)
def run(args, log=None, ccp4_map=None, return_as_miller_arrays=False, nohl=False, return_f_obs=False, space_group_number=None, out=sys.stdout): if log is None: log = out inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) got_map = False if ccp4_map: got_map = True broadcast(m="Parameters:", log=log) inputs.params.show(prefix=" ", out=out) params = inputs.params.extract() if (ccp4_map is None and inputs.ccp4_map is not None): broadcast(m="Processing input CCP4 map file: %s" % inputs.ccp4_map_file_name, log=log) ccp4_map = inputs.ccp4_map ccp4_map.show_summary(prefix=" ", out=out) got_map = True if (not got_map): raise Sorry("Map file is needed.") # m = ccp4_map if (m.unit_cell_crystal_symmetry().space_group_number() > 1): raise Sorry("Input map space group: %d. Must be P1." % m.unit_cell_crystal_symmetry().space_group_number()) broadcast(m="Input map information:", log=log) print("m.all() :", m.map_data().all(), file=out) print("m.focus() :", m.map_data().focus(), file=out) print("m.origin():", m.map_data().origin(), file=out) print("m.nd() :", m.map_data().nd(), file=out) print("m.size() :", m.map_data().size(), file=out) print("m.focus_size_1d():", m.map_data().focus_size_1d(), file=out) print("m.is_0_based() :", m.map_data().is_0_based(), file=out) print("map: min/max/mean:", flex.min(m.map_data()), flex.max(m.map_data()), flex.mean(m.map_data()), file=out) print("unit cell:", m.unit_cell().parameters(), file=out) # # Instead use ccp4 map crystal_symmetry and classify according to the case cs = m.crystal_symmetry() if m.unit_cell_grid == m.map_data().all(): print("\nOne unit cell of data is present in map", file=out) else: if params.keep_origin: print("\nNOTE: This map does not have exactly one unit cell of data, so \n"+\ "keep_origin is not available\n", file=out) print( "--> Setting keep_origin=False and creating a new cell and gridding.\n", file=out) params.keep_origin = False print("Moving origin of input map to (0,0,0)", file=out) print("New cell will be: (%.3f, %.3f, %.3f, %.1f, %.1f, %.1f) A " % (cs.unit_cell().parameters()), file=out) print("New unit cell grid will be: (%s, %s, %s) " % (m.map_data().all()), file=out) map_data = m.map_data() # Get origin in grid units and new position of origin in grid units original_origin = map_data.origin() print("\nInput map has origin at grid point (%s,%s,%s)" % (tuple(original_origin)), file=out) if params.output_origin_grid_units is not None: params.keep_origin = False new_origin = tuple(params.output_origin_grid_units) print("User-specified origin at grid point (%s,%s,%s)" % (tuple(params.output_origin_grid_units)), file=out) if tuple(params.output_origin_grid_units) == tuple(original_origin): print("This is the same as the input origin. No origin shift.", file=out) elif params.keep_origin: new_origin = original_origin print("Keeping origin at grid point (%s,%s,%s)" % (tuple(original_origin)), file=out) else: new_origin = ( 0, 0, 0, ) print("New origin at grid point (%s,%s,%s)" % (tuple(( 0, 0, 0, ))), file=out) # shift_cart is shift away from (0,0,0) if new_origin != ( 0, 0, 0, ): shift_cart = get_shift_cart(map_data=map_data, crystal_symmetry=cs, origin=new_origin) else: shift_cart = ( 0, 0, 0, ) d_min = params.d_min box = params.box resolution_factor = params.resolution_factor # Shift the map data if necessary map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data f_obs_cmpl = calculate_inverse_fft( map_data=map_data, crystal_symmetry=cs, d_min=params.d_min, box=params.box, resolution_factor=params.resolution_factor, out=out) if params.scale_max is not None: f_obs_cmpl = f_obs_cmpl.apply_scaling(target_max=params.scale_max) from scitbx.matrix import col if col(shift_cart) != col(( 0, 0, 0, )): print("Output origin is at: (%.3f, %.3f, %.3f) A " % (tuple(-col(shift_cart))), file=out) f_obs_cmpl = f_obs_cmpl.translational_shift( cs.unit_cell().fractionalize(-col(shift_cart)), deg=False) else: print("Output origin is at (0.000, 0.000, 0.000) A", file=out) if nohl and return_as_miller_arrays and not return_f_obs: return f_obs_cmpl mtz_dataset = f_obs_cmpl.as_mtz_dataset(column_root_label="F") f_obs = abs(f_obs_cmpl) f_obs.set_sigmas(sigmas=flex.double(f_obs_cmpl.data().size(), 1)) if nohl and return_as_miller_arrays and return_f_obs: return f_obs mtz_dataset.add_miller_array(miller_array=f_obs, column_root_label="F-obs") mtz_dataset.add_miller_array(miller_array=f_obs.generate_r_free_flags(), column_root_label="R-free-flags") if not nohl and params.k_blur is not None and params.b_blur is None: # convert phases into HL coefficeints broadcast(m="Convert phases into HL coefficients:", log=log) hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=params.b_blur) cc = get_cc(f=f_obs_cmpl, hl=hl) print("cc:", cc, file=out) if (abs(1. - cc) > 1.e-3): print( "Supplied b_blur is not good. Attempting to find optimal b_blur.", file=out) cc_best = 999. b_blur_best = params.b_blur for b_blur in range(1, 100): hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=b_blur) cc = get_cc(f=f_obs_cmpl, hl=hl) if (cc < cc_best): cc_best = cc b_blur_best = b_blur if (abs(1. - cc) < 1.e-3): b_blur_best = b_blur break hl = get_hl(f_obs_cmpl=f_obs_cmpl, k_blur=params.k_blur, b_blur=b_blur_best) print("cc:", get_cc(f=f_obs_cmpl, hl=hl), file=out) print("b_blur_best:", b_blur_best, file=out) mtz_dataset.add_miller_array(miller_array=hl, column_root_label="HL") else: hl = None if return_as_miller_arrays: if return_f_obs: return f_obs, hl else: return f_obs_cmpl, hl else: # write output MTZ file with all the data broadcast(m="Writing output MTZ file:", log=log) print(" file name:", params.output_file_name, file=log) mtz_object = mtz_dataset.mtz_object() mtz_object.write(file_name=params.output_file_name)
def __init__(self, map_inp, map_inp_1=None, map_inp_2=None, pdb_inp=None, box=True): # if (not [map_inp_1, map_inp_2].count(None) in [0, 2]): raise Sorry("None or two half-maps are required.") # self._map_data = None self._half_map_data_1 = None self._half_map_data_2 = None self._model = None # if (pdb_inp is not None): self._model = mmtbx.model.manager(model_input=pdb_inp, log=null_out()) check_and_set_crystal_symmetry( models=[self._model], map_inps=[map_inp, map_inp_1, map_inp_2]) self._map_data = map_inp.map_data() self._counts = get_map_counts( map_data=self._map_data, crystal_symmetry=map_inp.crystal_symmetry()) if (map_inp_1 is not None): self._half_map_data_1 = map_inp_1.map_data() if (map_inp_2 is not None): self._half_map_data_2 = map_inp_2.map_data() self._map_histograms = get_map_histograms(data=self._map_data, n_slots=20, data_1=self._half_map_data_1, data_2=self._half_map_data_2) # Shift origin sites_cart = None if (self._model is not None): sites_cart = self._model.get_sites_cart() soin = maptbx.shift_origin_if_needed( map_data=self._map_data, sites_cart=sites_cart, crystal_symmetry=self._model.crystal_symmetry()) self._map_data = soin.map_data if (self._model is not None): self._model.set_sites_cart(sites_cart=soin.sites_cart) if (self._half_map_data_1 is not None): self._half_map_data_1 = maptbx.shift_origin_if_needed( map_data=self._half_map_data_1, sites_cart=None, crystal_symmetry=None).map_data self._half_map_data_2 = maptbx.shift_origin_if_needed( map_data=self._half_map_data_2, sites_cart=None, crystal_symmetry=None).map_data # Box if (self._model is not None and box): xrs = self._model.get_xray_structure() if (self._half_map_data_1 is not None): self._half_map_data_1 = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._half_map_data_1, box_cushion=5.0).map_box self._half_map_data_2 = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._half_map_data_2, box_cushion=5.0).map_box box = mmtbx.utils.extract_box_around_model_and_map( xray_structure=xrs, map_data=self._map_data, box_cushion=5.0) self._model.set_xray_structure( xray_structure=box.xray_structure_box) self._map_data = box.map_box
def run(args, log=sys.stdout): print >> log, "-" * 79 print >> log, legend print >> log, "-" * 79 inputs = mmtbx.utils.process_command_line_args( args=args, master_params=master_params()) params = inputs.params.extract() # estimate resolution d_min = params.resolution broadcast(m="Map resolution:", log=log) if (d_min is None): raise Sorry("Resolution is required.") print >> log, " d_min: %6.4f" % d_min # model broadcast(m="Input PDB:", log=log) file_names = inputs.pdb_file_names if (len(file_names) != 1): raise Sorry("PDB file has to given.") if (inputs.crystal_symmetry is None): raise Sorry("No crystal symmetry defined.") processed_pdb_file = monomer_library.pdb_interpretation.process( mon_lib_srv=monomer_library.server.server(), ener_lib=monomer_library.server.ener_lib(), file_name=file_names[0], crystal_symmetry=inputs.crystal_symmetry, force_symmetry=True, log=None) ph = processed_pdb_file.all_chain_proxies.pdb_hierarchy if (len(ph.models()) > 1): raise Sorry("Only one model allowed.") xrs = processed_pdb_file.xray_structure() xrs.scattering_type_registry(table=params.scattering_table) xrs.show_summary(f=log, prefix=" ") # restraints sctr_keys = xrs.scattering_type_registry().type_count_dict().keys() has_hd = "H" in sctr_keys or "D" in sctr_keys geometry = processed_pdb_file.geometry_restraints_manager( show_energies=False, assume_hydrogens_all_missing=not has_hd, plain_pairs_radius=5.0) # map broadcast(m="Input map:", log=log) if (inputs.ccp4_map is None): raise Sorry("Map file has to given.") inputs.ccp4_map.show_summary(prefix=" ") map_data = inputs.ccp4_map.map_data() print >> log, " Actual map (min,max,mean):", \ map_data.as_1d().min_max_mean().as_tuple() make_sub_header("Histogram of map values", out=log) md = map_data.as_1d() show_histogram(data=md, n_slots=10, data_min=flex.min(md), data_max=flex.max(md), log=log) # shift origin if needed soin = maptbx.shift_origin_if_needed( map_data=map_data, sites_cart=xrs.sites_cart(), crystal_symmetry=xrs.crystal_symmetry()) map_data = soin.map_data xrs.set_sites_cart(soin.sites_cart) #### # Compute and show all stats #### broadcast(m="Model statistics:", log=log) make_sub_header("Overall", out=log) ms = model_statistics.geometry(pdb_hierarchy=ph, restraints_manager=geometry, molprobity_scores=True) ms.show() make_sub_header("Histogram of devations from ideal bonds", out=log) show_histogram(data=ms.bond_deltas, n_slots=10, data_min=0, data_max=0.2, log=log) # make_sub_header("Histogram of devations from ideal angles", out=log) show_histogram(data=ms.angle_deltas, n_slots=10, data_min=0, data_max=30., log=log) # make_sub_header("Histogram of non-bonded distances", out=log) show_histogram(data=ms.nonbonded_distances, n_slots=10, data_min=0, data_max=5., log=log) # make_sub_header("Histogram of ADPs", out=log) bs = xrs.extract_u_iso_or_u_equiv() * adptbx.u_as_b(1.) show_histogram(data=bs, n_slots=10, data_min=flex.min(bs), data_max=flex.max(bs), log=log) # # Compute CC broadcast(m="Map-model CC (overall):", log=log) five_cc_result = mmtbx.maps.correlation.five_cc(map=map_data, xray_structure=xrs, d_min=d_min) print >> log, " CC_mask : %6.4f" % five_cc_result.cc_mask print >> log, " CC_volume: %6.4f" % five_cc_result.cc_volume print >> log, " CC_peaks : %6.4f" % five_cc_result.cc_peaks # Compute FSC(map, model) broadcast(m="Model-map FSC:", log=log) fsc = mmtbx.maps.correlation.fsc_model_vs_map( xray_structure=xrs, map=map_data, atom_radius=five_cc_result.atom_radius, d_min=d_min) fsc.show(prefix=" ") # Local CC cc_calculator = mmtbx.maps.correlation.from_map_and_xray_structure_or_fmodel( xray_structure=xrs, map_data=map_data, d_min=d_min) broadcast(m="Map-model CC (local):", log=log) # per residue print >> log, "Per residue:" residue_results = list() for rg in ph.residue_groups(): cc = cc_calculator.cc(selection=rg.atoms().extract_i_seq()) chain_id = rg.parent().id print >> log, " chain id: %s resid %s: %6.4f" % (chain_id, rg.resid(), cc) # per chain print >> log, "Per chain:" for chain in ph.chains(): print >> log, " chain %s: %6.4f" % ( chain.id, cc_calculator.cc(selection=chain.atoms().extract_i_seq())) # per residue detailed counts print >> log, "Per residue (histogram):" crystal_gridding = maptbx.crystal_gridding( unit_cell=xrs.unit_cell(), space_group_info=xrs.space_group_info(), pre_determined_n_real=map_data.accessor().all()) f_calc = xrs.structure_factors(d_min=d_min).f_calc() fft_map = miller.fft_map(crystal_gridding=crystal_gridding, fourier_coefficients=f_calc) fft_map.apply_sigma_scaling() map_model = fft_map.real_map_unpadded() sites_cart = xrs.sites_cart() cc_per_residue = flex.double() for rg in ph.residue_groups(): cc = mmtbx.maps.correlation.from_map_map_atoms( map_1=map_data, map_2=map_model, sites_cart=sites_cart.select(rg.atoms().extract_i_seq()), unit_cell=xrs.unit_cell(), radius=2.) cc_per_residue.append(cc) show_histogram(data=cc_per_residue, n_slots=10, data_min=-1., data_max=1.0, log=log)
def __init__(self, map_data, crystal_symmetry, half_map_data_1=None, half_map_data_2=None, pdb_hierarchy=None): self._map_data = map_data self._crystal_symmetry = crystal_symmetry self._half_map_data_1 = half_map_data_1 self._half_map_data_2 = half_map_data_2 self._pdb_hierarchy = pdb_hierarchy self._xray_structure = None # self._validate() self._counts = get_map_counts( map_data = self._map_data, crystal_symmetry = self._crystal_symmetry) self._map_histograms = get_map_histograms( data = self._map_data, n_slots = 20, data_1 = self._half_map_data_1, data_2 = self._half_map_data_2) # Shift origin if needed sites_cart = None if(pdb_hierarchy is not None): sites_cart = self._pdb_hierarchy.atoms().extract_xyz() soin = maptbx.shift_origin_if_needed( map_data = self._map_data, sites_cart = sites_cart, crystal_symmetry = self._crystal_symmetry) self._map_data = soin.map_data if(pdb_hierarchy is not None): self._pdb_hierarchy.atoms().set_xyz(soin.sites_cart) if(self._half_map_data_1 is not None): self._half_map_data_1 = maptbx.shift_origin_if_needed( map_data = self._half_map_data_1, sites_cart = None, crystal_symmetry = None).map_data self._half_map_data_2 = maptbx.shift_origin_if_needed( map_data = self._half_map_data_2, sites_cart = None, crystal_symmetry = None).map_data # Box if(self._pdb_hierarchy is not None): self._xray_structure = self._pdb_hierarchy.extract_xray_structure( crystal_symmetry = self._crystal_symmetry) if(self._half_map_data_1 is not None): self._half_map_data_1 = mmtbx.utils.extract_box_around_model_and_map( xray_structure = self._xray_structure, map_data = self._half_map_data_1, box_cushion = 5.0).map_box self._half_map_data_2 = mmtbx.utils.extract_box_around_model_and_map( xray_structure = self._xray_structure, map_data = self._half_map_data_2, box_cushion = 5.0).map_box box = mmtbx.utils.extract_box_around_model_and_map( xray_structure = self._xray_structure, map_data = self._map_data, box_cushion = 5.0) self._pdb_hierarchy.adopt_xray_structure(box.xray_structure_box) self._map_data = box.map_box self._xray_structure = box.xray_structure_box self._crystal_symmetry = self._xray_structure.crystal_symmetry()