Ejemplo n.º 1
0
    def run(self):
        hierarchy = self.model.get_hierarchy()
        map_data, grid_unit_cell = None, None
        # sanity check for map and model
        if self.map_inp is not None:
            base = map_and_model.input(map_manager=self.map_inp,
                                       model=self.model,
                                       crystal_symmetry=self.cs_consensus,
                                       box=False)

            hierarchy = base.model().get_hierarchy()
            map_data = base.map_data()
            grid_unit_cell = self.map_inp.grid_unit_cell()

        hierarchy.atoms().reset_i_seq()

        self.ringer_result = iterate_over_residues(
            pdb_hierarchy=hierarchy,
            map_coeffs=self.miller_array,
            map_data=map_data,
            unit_cell=grid_unit_cell,
            params=self.params,
            log=self.out).results

        if (self.params.output_base is not None):
            plots_dir = self.params.output_base + "_plots"
        else:
            plots_dir = 'emringer_plots'

        import matplotlib
        matplotlib.use("Agg")
        self.scoring_result = em_scoring.main(
            file_name=self.params.output_base,
            ringer_result=self.ringer_result,
            out_dir=plots_dir,
            sampling_angle=self.params.sampling_angle,
            quiet=self.params.quiet,
            out=self.out)

        rolling_window_threshold = self.params.rolling_window_threshold
        self.rolling_result = em_rolling.main(
            ringer_results=self.ringer_result,
            dir_name=plots_dir,
            threshold=rolling_window_threshold,  #scoring.optimal_threshold,
            graph=False,
            save=not self.params.quiet,
            out=self.out)
Ejemplo n.º 2
0
def run(args, out=None, verbose=True, plots_dir=None):
    t0 = time.time()
    if (out is None): out = sys.stdout
    import iotbx.phil
    cmdline = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil=master_phil,
        pdb_file_def="model",
        reflection_file_def="map_coeffs",
        map_file_def="map_file",
        usage_string="""\
phenix.emringer model.pdb map.mrc [cif_file ...] [options]

%s
""" % __doc__)
    params = cmdline.work.extract()
    validate_params(params)
    pdb_in = cmdline.get_file(params.model)
    pdb_in.check_file_type("pdb")

    pdb_inp = iotbx.pdb.input(file_name=params.model)
    model = mmtbx.model.manager(model_input=pdb_inp)
    crystal_symmetry_model = model.crystal_symmetry()
    if crystal_symmetry_model is not None:
        crystal_symmetry_model.show_summary()

    hierarchy = model.get_hierarchy()
    map_coeffs = map_inp = None
    map_data, unit_cell = None, None
    if (params.map_coeffs is not None):
        mtz_in = cmdline.get_file(params.map_coeffs)
        mtz_in.check_file_type("hkl")
        best_guess = None
        best_labels = []
        all_labels = []
        for array in mtz_in.file_server.miller_arrays:
            if (array.info().label_string() == params.map_label):
                map_coeffs = array
                break
            elif (params.map_label is None):
                if (array.is_complex_array()):
                    labels = array.info().label_string()
                    all_labels.append(labels)
                    if (labels.startswith("2FOFCWT")
                            or labels.startswith("2mFoDFc")
                            or labels.startswith("FWT")):
                        best_guess = array
                        best_labels.append(labels)
        if (map_coeffs is None):
            if (len(all_labels) == 0):
                raise Sorry(
                    "No valid (pre-weighted) map coefficients found in file.")
            elif (best_guess is None):
                raise Sorry(
                    "Couldn't automatically determine appropriate map labels. "
                    + "Choices:\n  %s" % "  \n".join(all_labels))
            elif (len(best_labels) > 1):
                raise Sorry(
                    "Multiple appropriate map coefficients found in file. " +
                    "Choices:\n  %s" % "\n  ".join(best_labels))
            map_coeffs = best_guess
            print("  Guessing %s for input map coefficients" % best_labels[0],
                  file=out)
    else:
        ccp4_map_in = cmdline.get_file(params.map_file)
        ccp4_map_in.check_file_type("ccp4_map")
        map_inp = ccp4_map_in.file_object
        cs_consensus = mmtbx.utils.check_and_set_crystal_symmetry(
            models=[model], map_inps=[map_inp])
        base = map_and_model.input(map_data=map_inp.map_data(),
                                   model=model,
                                   box=False)
        hierarchy = base.model().get_hierarchy()
        map_data = base.map_data()
        unit_cell = map_inp.grid_unit_cell()

    hierarchy.atoms().reset_i_seq()

    make_header("Iterating over residues", out=out)
    t1 = time.time()
    from mmtbx.ringer import iterate_over_residues
    results = iterate_over_residues(pdb_hierarchy=hierarchy,
                                    map_coeffs=map_coeffs,
                                    map_data=map_data,
                                    unit_cell=unit_cell,
                                    params=params,
                                    log=out).results
    t2 = time.time()
    if (verbose):
        print("Time excluding I/O: %8.1fs" % (t2 - t1), file=out)
        print("Overall runtime:    %8.1fs" % (t2 - t0), file=out)
    if (params.output_base is None):
        pdb_base = os.path.basename(params.model)
        params.output_base = os.path.splitext(pdb_base)[0] + "_emringer"
    easy_pickle.dump("%s.pkl" % params.output_base, results)
    print("Wrote %s.pkl" % params.output_base, file=out)
    csv = "\n".join([r.format_csv() for r in results])
    open("%s.csv" % params.output_base, "w").write(csv)
    print("Wrote %s.csv" % params.output_base, file=out)
    if (plots_dir is None):
        plots_dir = params.output_base + "_plots"
    if (not os.path.isdir(plots_dir)):
        os.makedirs(plots_dir)
    from mmtbx.ringer import em_rolling
    from mmtbx.ringer import em_scoring
    import matplotlib
    matplotlib.use("Agg")
    make_header("Scoring results", out=out)
    scoring = em_scoring.main(file_name=params.output_base,
                              ringer_result=results,
                              out_dir=plots_dir,
                              sampling_angle=params.sampling_angle,
                              quiet=False,
                              out=out)
    make_header("Inspecting chains", out=out)
    rolling_window_threshold = params.rolling_window_threshold
    rolling = em_rolling.main(
        ringer_results=results,
        dir_name=plots_dir,
        threshold=rolling_window_threshold,  #scoring.optimal_threshold,
        graph=False,
        save=True,
        out=out)
    scoring.show_summary(out=out)
    print("\nReferences:", file=out)

    references = """\
  Barad BA, Echols N, Wang RYR, Cheng YC, DiMaio F, Adams PD, Fraser JS. (2015)
  Side-chain-directed model and map validation for 3D Electron Cryomicroscopy.
  Nature Methods, in press.

  Lang PT, Ng HL, Fraser JS, Corn JE, Echols N, Sales M, Holton JM, Alber T.
  Automated electron-density sampling reveals widespread conformational
  polymorphism in proteins. Protein Sci. 2010 Jul;19(7):1420-31. PubMed PMID:
  20499387"""
    print(references, file=out)
    if (params.show_gui):
        run_app(results)
    else:
        return (results, scoring, rolling)
Ejemplo n.º 3
0
def run (args, out=None, verbose=True, plots_dir=None) :
  t0 = time.time()
  if (out is None) : out = sys.stdout
  import iotbx.phil
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil=master_phil,
    pdb_file_def="model",
    reflection_file_def="map_coeffs",
    map_file_def="map_file",
    usage_string="""\
phenix.emringer model.pdb map.mrc [cif_file ...] [options]

%s
""" % __doc__)
  params = cmdline.work.extract()
  validate_params(params)
  pdb_in = cmdline.get_file(params.model)
  pdb_in.check_file_type("pdb")
  hierarchy = pdb_in.file_object.construct_hierarchy()
  hierarchy.atoms().reset_i_seq()
  map_coeffs = ccp4_map = None
  if (params.map_coeffs is not None) :
    mtz_in = cmdline.get_file(params.map_coeffs)
    mtz_in.check_file_type("hkl")
    best_guess = None
    best_labels = []
    all_labels = []
    for array in mtz_in.file_server.miller_arrays :
      if (array.info().label_string() == params.map_label) :
        map_coeffs = array
        break
      elif (params.map_label is None) :
        if (array.is_complex_array()) :
          labels = array.info().label_string()
          all_labels.append(labels)
          if (labels.startswith("2FOFCWT") or labels.startswith("2mFoDFc") or
              labels.startswith("FWT")) :
            best_guess = array
            best_labels.append(labels)
    if (map_coeffs is None) :
      if (len(all_labels) == 0) :
        raise Sorry("No valid (pre-weighted) map coefficients found in file.")
      elif (best_guess is None) :
        raise Sorry("Couldn't automatically determine appropriate map labels. "+
          "Choices:\n  %s" % "  \n".join(all_labels))
      elif (len(best_labels) > 1) :
        raise Sorry("Multiple appropriate map coefficients found in file. "+
          "Choices:\n  %s" % "\n  ".join(best_labels))
      map_coeffs = best_guess
      print >> out, "  Guessing %s for input map coefficients" % best_labels[0]
  else :
    ccp4_map_in = cmdline.get_file(params.map_file)
    ccp4_map_in.check_file_type("ccp4_map")
    ccp4_map = ccp4_map_in.file_object
  make_header("Iterating over residues", out=out)
  t1 = time.time()
  from mmtbx.ringer import iterate_over_residues
  results = iterate_over_residues(
    pdb_hierarchy=hierarchy,
    map_coeffs=map_coeffs,
    ccp4_map=ccp4_map,
    params=params,
    log=out).results
  t2 = time.time()
  if (verbose) :
    print >> out, "Time excluding I/O: %8.1fs" % (t2 - t1)
    print >> out, "Overall runtime:    %8.1fs" % (t2 - t0)
  if (params.output_base is None) :
    pdb_base = os.path.basename(params.model)
    params.output_base = os.path.splitext(pdb_base)[0] + "_emringer"
  easy_pickle.dump("%s.pkl" % params.output_base, results)
  print >> out, "Wrote %s.pkl" % params.output_base
  csv = "\n".join([ r.format_csv() for r in results ])
  open("%s.csv" % params.output_base, "w").write(csv)
  print >> out, "Wrote %s.csv" % params.output_base
  if (plots_dir is None) :
    plots_dir = params.output_base + "_plots"
  if (not os.path.isdir(plots_dir)) :
    os.makedirs(plots_dir)
  from mmtbx.ringer import em_rolling
  from mmtbx.ringer import em_scoring
  import matplotlib
  matplotlib.use("Agg")
  make_header("Scoring results", out=out)
  scoring = em_scoring.main(
    file_name=params.output_base,
    ringer_result=results,
    out_dir=plots_dir,
    sampling_angle=params.sampling_angle,
    quiet=False,
    out=out)
  make_header("Inspecting chains", out=out)
  rolling_window_threshold = params.rolling_window_threshold
  rolling = em_rolling.main(
    ringer_results=results,
    dir_name=plots_dir,
    threshold=rolling_window_threshold, #scoring.optimal_threshold,
    graph=False,
    save=True,
    out=out)
  scoring.show_summary(out=out)
  print >> out, "\nReferences:"
  print >> out, """\
  Barad BA, Echols N, Wang RYR, Cheng YC, DiMaio F, Adams PD, Fraser JS. (2015)
  Side-chain-directed model and map validation for 3D Electron Cryomicroscopy.
  Nature Methods, in press.

  Lang PT, Ng HL, Fraser JS, Corn JE, Echols N, Sales M, Holton JM, Alber T.
  Automated electron-density sampling reveals widespread conformational
  polymorphism in proteins. Protein Sci. 2010 Jul;19(7):1420-31. PubMed PMID:
  20499387"""
  if (params.show_gui) :
    run_app(results)
  else :
    return (results, scoring, rolling)