def run(args, log=sys.stdout): if (len(args) == 0): print >> log, legend defaults(log=log) return # parsed = defaults(log=log) processed_args = mmtbx.utils.process_command_line_args( args=args, log=sys.stdout, master_params=parsed) params = processed_args.params.extract() reflection_files = processed_args.reflection_files if (len(reflection_files) == 0): if (params.hkl_file is None): raise Sorry("No reflection file found.") else: hkl_in = file_reader.any_file(params.hkl_file, force_type="hkl") hkl_in.assert_file_type("hkl") reflection_files = [hkl_in.file_object] crystal_symmetry = processed_args.crystal_symmetry if (crystal_symmetry is None): if (params.space_group is not None) and (params.unit_cell is not None): from cctbx import crystal crystal_symmetry = crystal.symmetry( space_group_info=params.space_group, unit_cell=params.unit_cell) else: raise Sorry("No crystal symmetry found.") if (len(processed_args.pdb_file_names) == 0): if (params.pdb_file is None): raise Sorry("No model file found.") else: pdb_file_names = [params.pdb_file] else: pdb_file_names = processed_args.pdb_file_names # rfs = reflection_file_utils.reflection_file_server( crystal_symmetry=crystal_symmetry, force_symmetry=True, reflection_files=reflection_files, err=StringIO()) parameters = mmtbx.utils.data_and_flags_master_params().extract() parameters.labels = params.f_obs_label parameters.r_free_flags.label = params.r_free_flags_label determine_data_and_flags_result = mmtbx.utils.determine_data_and_flags( reflection_file_server=rfs, parameters=parameters, keep_going=True, log=StringIO()) f_obs = determine_data_and_flags_result.f_obs print "Input data:" print " Iobs or Fobs:", f_obs.info().labels r_free_flags = determine_data_and_flags_result.r_free_flags print " Free-R flags:", r_free_flags.info().labels # parameters = mmtbx.utils.experimental_phases_params.extract() parameters.labels = params.hendrickson_lattman_coefficients_label experimental_phases_result = mmtbx.utils.determine_experimental_phases( reflection_file_server=rfs, parameters=parameters, log=StringIO(), parameter_scope="", working_point_group=None, symmetry_safety_check=True, ignore_all_zeros=True) if (experimental_phases_result is not None): print " HL coefficients:", experimental_phases_result.info().labels experimental_phases = extract_experimental_phases( experimental_phases=experimental_phases_result, f_obs=f_obs) # if (r_free_flags is None): r_free_flags = f_obs.array(data=flex.bool(f_obs.data().size(), False)) # pdb_inp = mmtbx.utils.pdb_inp_from_multiple_files(pdb_file_names, log=sys.stdout) model = mmtbx.model.manager(model_input=pdb_inp, process_input=False, crystal_symmetry=crystal_symmetry, log=sys.stdout) if (model.get_number_of_models() > 1): #XXX support multi-models raise Sorry("Multiple model file not supported in this tool.") # XXX Twining not supported xray_structure = model.get_xray_structure() if (not xray_structure.unit_cell().is_similar_to(f_obs.unit_cell())): raise Sorry( "The unit cells in the model and reflections files are not " + "isomorphous.") print "Input model:" print " number of atoms:", xray_structure.scatterers().size() fmodel = mmtbx.f_model.manager(xray_structure=xray_structure, r_free_flags=r_free_flags, f_obs=f_obs, abcd=experimental_phases) fmodel.update_all_scales( update_f_part1=True, remove_outliers=params.remove_f_obs_outliers, bulk_solvent_and_scaling=params.bulk_solvent_and_scaling) print "Overall statistics:" fmodel.info().show_all() # print "Output data:" if (params.output_file_name is not None): output_file_name = params.output_file_name else: pdb_file_bn = os.path.basename(pdb_file_names[0]) hkl_file_bn = os.path.basename(reflection_files[0].file_name()) try: pdb_file_prefix = pdb_file_bn[:pdb_file_bn.index(".")] except ValueError: pdb_file_prefix = pdb_file_bn try: hkl_file_prefix = hkl_file_bn[:hkl_file_bn.index(".")] except ValueError: hkl_file_prefix = hkl_file_bn output_file_name = "%s_%s.mtz" % (pdb_file_prefix, hkl_file_prefix) print " file name:", output_file_name print " to see the contnt of %s:" % output_file_name print " phenix.mtz.dump %s" % output_file_name out = open(output_file_name, "w") fmodel.export(out=out) out.close() print "All done." return output_file_name
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)