コード例 #1
0
def run(args, out=sys.stdout):
    from mmtbx.building import alternate_conformations
    import iotbx.phil
    cmdline = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil=master_phil,
        float_def="model_error_ml",
        pdb_file_def="file_name")
    params = cmdline.work.extract()
    assert (params.file_name is not None)
    pdb_in = cmdline.get_file(params.file_name)
    hierarchy = pdb_in.file_object.construct_hierarchy()
    xrs = pdb_in.file_object.xray_structure_simple()
    n_modified = alternate_conformations.rejoin_split_single_conformers(
        pdb_hierarchy=hierarchy,
        crystal_symmetry=xrs,
        model_error_ml=params.model_error_ml,
        params=params,
        verbose=True,
        log=out)
    alternate_conformations.finalize_model(
        pdb_hierarchy=hierarchy,
        xray_structure=hierarchy.extract_xray_structure(
            crystal_symmetry=pdb_in.file_object.xray_structure_simple()),
        set_b_iso=True,
        convert_to_isotropic=True)
    if (n_modified == 0):
        print >> out, "No residues modified."
    else:
        open("rejoined.pdb", "w").write(hierarchy.as_pdb_string())
        print >> out, "wrote rejoined.pdb"
コード例 #2
0
 def rejoin(self):
     make_sub_header("Re-joining identical conformers", out=self.out)
     pdb_hierarchy = self.pdb_hierarchy.deep_copy()
     n_modified = alternate_conformations.rejoin_split_single_conformers(
         pdb_hierarchy=pdb_hierarchy,
         crystal_symmetry=self.fmodel.xray_structure,
         model_error_ml=self.fmodel.model_error_ml(),
         params=self.params.merging,
         reset_occupancies=self.params.refinement.
         constrain_correlated_occupancies,
         verbose=self.verbose,
         log=self.out)
     if (n_modified > 0):
         self.pdb_hierarchy = pdb_hierarchy
         xray_structure = self.pdb_hierarchy.extract_xray_structure(
             crystal_symmetry=self.fmodel.xray_structure)
         self.fmodel.update_xray_structure(xray_structure)
         self.map_file = None
     alternate_conformations.finalize_model(
         pdb_hierarchy=self.pdb_hierarchy,
         xray_structure=self.pdb_hierarchy.extract_xray_structure(
             crystal_symmetry=self.fmodel.xray_structure),
         set_b_iso=None,
         convert_to_isotropic=False)
     return (n_modified > 0)
コード例 #3
0
def run (args, out=sys.stdout) :
  from mmtbx.building import alternate_conformations
  import iotbx.phil
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil=master_phil,
    float_def="model_error_ml",
    pdb_file_def="file_name")
  params = cmdline.work.extract()
  assert (params.file_name is not None)
  pdb_in = cmdline.get_file(params.file_name)
  hierarchy = pdb_in.file_object.construct_hierarchy()
  xrs = pdb_in.file_object.xray_structure_simple()
  n_modified = alternate_conformations.rejoin_split_single_conformers(
    pdb_hierarchy=hierarchy,
    crystal_symmetry=xrs,
    model_error_ml=params.model_error_ml,
    params=params,
    verbose=True,
    log=out)
  alternate_conformations.finalize_model(
    pdb_hierarchy=hierarchy,
    xray_structure=hierarchy.extract_xray_structure(
      crystal_symmetry=pdb_in.file_object.xray_structure_simple()),
    set_b_iso=True,
    convert_to_isotropic=True)
  if (n_modified == 0) :
    print >> out, "No residues modified."
  else :
    open("rejoined.pdb", "w").write(hierarchy.as_pdb_string())
    print >> out, "wrote rejoined.pdb"
コード例 #4
0
 def rejoin (self) :
   make_sub_header("Re-joining identical conformers", out=self.out)
   pdb_hierarchy = self.pdb_hierarchy.deep_copy()
   n_modified = alternate_conformations.rejoin_split_single_conformers(
     pdb_hierarchy=pdb_hierarchy,
     crystal_symmetry=self.fmodel.xray_structure,
     model_error_ml=self.fmodel.model_error_ml(),
     params=self.params.merging,
     reset_occupancies=self.params.refinement.constrain_correlated_occupancies,
     verbose=self.verbose,
     log=self.out)
   if (n_modified > 0) :
     self.pdb_hierarchy = pdb_hierarchy
     xray_structure = self.pdb_hierarchy.extract_xray_structure(
       crystal_symmetry=self.fmodel.xray_structure)
     self.fmodel.update_xray_structure(xray_structure)
     self.map_file = None
   alternate_conformations.finalize_model(
     pdb_hierarchy=self.pdb_hierarchy,
     xray_structure=self.pdb_hierarchy.extract_xray_structure(
       crystal_symmetry=self.fmodel.xray_structure),
     set_b_iso=None,
     convert_to_isotropic=False)
   return (n_modified > 0)
コード例 #5
0
def build_cycle(pdb_hierarchy,
                fmodel,
                geometry_restraints_manager,
                params,
                selection=None,
                cif_objects=(),
                nproc=Auto,
                out=sys.stdout,
                verbose=False,
                debug=None,
                i_cycle=0):
    from mmtbx import restraints
    from scitbx.array_family import flex
    t_start = time.time()
    hd_sel = fmodel.xray_structure.hd_selection()
    n_hydrogen = hd_sel.count(True)
    if (n_hydrogen > 0) and (True):  #params.building.delete_hydrogens):
        print("WARNING: %d hydrogen atoms will be removed!" % n_hydrogen,
              file=out)
        non_hd_sel = ~hd_sel
        # XXX it's better to do this in-place for the hierarchy, because calling
        # pdb_hierarchy.select(non_hd_sel) will not remove parent-child
        # relationships involving hydrogens, which causes problems when running
        # the MolProbity validation.
        pdb_hierarchy.remove_hd(reset_i_seq=True)
        xray_structure = fmodel.xray_structure.select(non_hd_sel)
        assert (
            pdb_hierarchy.atoms_size() == xray_structure.scatterers().size())
        fmodel.update_xray_structure(xray_structure)
        geometry_restraints_manager = geometry_restraints_manager.select(
            non_hd_sel)
    pdb_atoms = pdb_hierarchy.atoms()
    segids = pdb_atoms.extract_segid().strip()
    if (not segids.all_eq("")):
        print("WARNING: resetting segids to blank", file=out)
        for i_seq, atom in enumerate(pdb_atoms):
            atom.segid = ""
            sc = fmodel.xray_structure.scatterers()[i_seq]
            sc.label = atom.id_str()
    if isinstance(selection, str):
        sele_cache = pdb_hierarchy.atom_selection_cache()
        selection = sele_cache.selection(selection)
    make_header("Build cycle %d" % (i_cycle + 1), out=out)
    fmodel.info().show_rfactors_targets_scales_overall(out=out)
    if (debug > 0):
        from mmtbx.maps.utils import get_maps_from_fmodel
        from iotbx.map_tools import write_map_coeffs
        two_fofc, fofc = get_maps_from_fmodel(fmodel,
                                              exclude_free_r_reflections=True)
        write_map_coeffs(fwt_coeffs=two_fofc,
                         delfwt_coeffs=fofc,
                         file_name="cycle_%d_start.mtz" % (i_cycle + 1))
    candidate_residues = alt_confs.filter_before_build(
        pdb_hierarchy=pdb_hierarchy,
        fmodel=fmodel,
        geometry_restraints_manager=geometry_restraints_manager,
        selection=selection,
        params=params.prefilter,
        verbose=verbose,
        log=out)
    t1 = time.time()
    print("filtering: %.3fs" % (t1 - t_start), file=out)
    restraints_manager = restraints.manager(
        geometry=geometry_restraints_manager, normalization=True)
    make_sub_header("Finding alternate conformations", out=out)
    building_trials = find_all_alternates(
        residues=candidate_residues,
        pdb_hierarchy=pdb_hierarchy,
        restraints_manager=restraints_manager,
        fmodel=fmodel,
        params=params.residue_fitting,
        nproc=params.nproc,
        verbose=verbose,
        debug=debug,
        log=out).results
    t2 = time.time()
    print("  building: %.3fs" % (t2 - t1), file=out)
    make_sub_header("Scoring and assembling alternates", out=out)
    n_alternates = process_results(pdb_hierarchy=pdb_hierarchy,
                                   fmodel=fmodel,
                                   residues_in=candidate_residues,
                                   building_trials=building_trials,
                                   params=params.residue_fitting,
                                   verbose=verbose,
                                   log=out)
    if (n_alternates > 0):
        print("", file=out)
        print("  %d disordered residues built" % n_alternates, file=out)
        n_split = alt_confs.spread_alternates(
            pdb_hierarchy,
            new_occupancy=params.residue_fitting.expected_occupancy,
            split_all_adjacent=True,
            log=out)
        assert (n_split > 0)
        print("  %d adjacent residues split" % n_split, file=out)
    else:
        print("No alternates built this round.", file=out)
    t3 = time.time()
    print("  assembly: %.3fs" % (t3 - t2), file=out)
    if (not params.cleanup.rsr_after_build):
        if (n_alternates > 0):
            print("Skipping final RSR step (rsr_after_build=False).", file=out)
        else:
            print("No refinement needs to be performed.", file=out)
    else:
        make_sub_header("Real-space refinement", out=out)
        print("", file=out)
        pdb_hierarchy = real_space_refine(pdb_hierarchy=pdb_hierarchy,
                                          fmodel=fmodel,
                                          cif_objects=cif_objects,
                                          params=params,
                                          nproc=params.nproc,
                                          remediate=True,
                                          out=out)
        t4 = time.time()
        print("", file=out)
        print("RSR: %.3fs" % (t4 - t3), file=out)
    fmodel.info().show_targets(out=out, text="Rebuilt model")
    t_end = time.time()
    alt_confs.finalize_model(
        pdb_hierarchy=pdb_hierarchy,
        xray_structure=pdb_hierarchy.extract_xray_structure(
            crystal_symmetry=fmodel.xray_structure),
        set_b_iso=params.cleanup.set_b_iso,
        convert_to_isotropic=params.cleanup.convert_to_isotropic,
        selection="altloc A or altloc B")
    t_end = time.time()
    print("Total runtime for cycle: %.3fs" % (t_end - t_start), file=out)
    return pdb_hierarchy, n_alternates
コード例 #6
0
def build_cycle (pdb_hierarchy,
    fmodel,
    geometry_restraints_manager,
    params,
    selection=None,
    cif_objects=(),
    nproc=Auto,
    out=sys.stdout,
    verbose=False,
    debug=None,
    i_cycle=0) :
  from mmtbx import restraints
  from scitbx.array_family import flex
  t_start = time.time()
  hd_sel = fmodel.xray_structure.hd_selection()
  n_hydrogen = hd_sel.count(True)
  if (n_hydrogen > 0) and (True) : #params.building.delete_hydrogens) :
    print >> out, "WARNING: %d hydrogen atoms will be removed!" % n_hydrogen
    non_hd_sel = ~hd_sel
    # XXX it's better to do this in-place for the hierarchy, because calling
    # pdb_hierarchy.select(non_hd_sel) will not remove parent-child
    # relationships involving hydrogens, which causes problems when running
    # the MolProbity validation.
    pdb_hierarchy.remove_hd(reset_i_seq=True)
    xray_structure = fmodel.xray_structure.select(non_hd_sel)
    assert (pdb_hierarchy.atoms_size() == xray_structure.scatterers().size())
    fmodel.update_xray_structure(xray_structure)
    geometry_restraints_manager = geometry_restraints_manager.select(non_hd_sel)
  pdb_atoms = pdb_hierarchy.atoms()
  segids = pdb_atoms.extract_segid().strip()
  if (not segids.all_eq("")) :
    print >> out, "WARNING: resetting segids to blank"
    for i_seq, atom in enumerate(pdb_atoms) :
      atom.segid = ""
      sc = fmodel.xray_structure.scatterers()[i_seq]
      sc.label = atom.id_str()
  if isinstance(selection, str) :
    sele_cache = pdb_hierarchy.atom_selection_cache()
    selection = sele_cache.selection(selection)
  make_header("Build cycle %d" % (i_cycle+1), out=out)
  fmodel.info().show_rfactors_targets_scales_overall(out=out)
  if (debug > 0) :
    from mmtbx.maps.utils import get_maps_from_fmodel
    from iotbx.map_tools import write_map_coeffs
    two_fofc, fofc = get_maps_from_fmodel(fmodel,
      exclude_free_r_reflections=True)
    write_map_coeffs(
      fwt_coeffs=two_fofc,
      delfwt_coeffs=fofc,
      file_name="cycle_%d_start.mtz" % (i_cycle+1))
  candidate_residues = alt_confs.filter_before_build(
    pdb_hierarchy=pdb_hierarchy,
    fmodel=fmodel,
    geometry_restraints_manager=geometry_restraints_manager,
    selection=selection,
    params=params.prefilter,
    verbose=verbose,
    log=out)
  t1 = time.time()
  print >> out, "filtering: %.3fs" % (t1-t_start)
  restraints_manager = restraints.manager(
    geometry=geometry_restraints_manager,
    normalization=True)
  make_sub_header("Finding alternate conformations", out=out)
  building_trials = find_all_alternates(
    residues=candidate_residues,
    pdb_hierarchy=pdb_hierarchy,
    restraints_manager=restraints_manager,
    fmodel=fmodel,
    params=params.residue_fitting,
    nproc=params.nproc,
    verbose=verbose,
    debug=debug,
    log=out).results
  t2 = time.time()
  print >> out, "  building: %.3fs" % (t2-t1)
  make_sub_header("Scoring and assembling alternates", out=out)
  n_alternates = process_results(
    pdb_hierarchy=pdb_hierarchy,
    fmodel=fmodel,
    residues_in=candidate_residues,
    building_trials=building_trials,
    params=params.residue_fitting,
    verbose=verbose,
    log=out)
  if (n_alternates > 0) :
    print >> out, ""
    print >> out, "  %d disordered residues built" % n_alternates
    n_split = alt_confs.spread_alternates(pdb_hierarchy,
      new_occupancy=params.residue_fitting.expected_occupancy,
      split_all_adjacent=True,
      log=out)
    assert (n_split > 0)
    print >> out, "  %d adjacent residues split" % n_split
  else :
    print >> out, "No alternates built this round."
  t3 = time.time()
  print >> out, "  assembly: %.3fs" % (t3-t2)
  if (not params.cleanup.rsr_after_build) :
    if (n_alternates > 0) :
      print >> out, "Skipping final RSR step (rsr_after_build=False)."
    else :
      print >> out, "No refinement needs to be performed."
  else :
    make_sub_header("Real-space refinement", out=out)
    print >> out, ""
    pdb_hierarchy = real_space_refine(
      pdb_hierarchy=pdb_hierarchy,
      fmodel=fmodel,
      cif_objects=cif_objects,
      params=params,
      nproc=params.nproc,
      remediate=True,
      out=out)
    t4 = time.time()
    print >> out, ""
    print >> out, "RSR: %.3fs" % (t4-t3)
  fmodel.info().show_targets(out=out, text="Rebuilt model")
  t_end = time.time()
  alt_confs.finalize_model(
    pdb_hierarchy=pdb_hierarchy,
    xray_structure=pdb_hierarchy.extract_xray_structure(
      crystal_symmetry=fmodel.xray_structure),
    set_b_iso=params.cleanup.set_b_iso,
    convert_to_isotropic=params.cleanup.convert_to_isotropic,
    selection="altloc A or altloc B")
  t_end = time.time()
  print >> out, "Total runtime for cycle: %.3fs" % (t_end-t_start)
  return pdb_hierarchy, n_alternates