def write_pdb_file(self, prefix):
    from iotbx.pdb.misc_records_output import link_record_output
    link_records = link_record_output(self.processed_pdb_file.all_chain_proxies)
    broadcast(m=prefix, log = self.log)
    self.pdb_hierarchy.adopt_xray_structure(self.xray_structure)
    ofn = self.params.output_file_name_prefix
    directory = self.params.directory
    suffix = "_" + self._pdb_suffix  + ".pdb"
    if(ofn is None):
      pfn = os.path.basename(self.pdb_file_names[0])
      ind = max(0,pfn.rfind("."))
      ofn = pfn+suffix if ind==0 else pfn[:ind]+suffix
    else: ofn = self.params.output_file_name_prefix+".pdb"
    if (self.use_directory_prefix) and (directory is not None) :
      ofn = os.path.join(directory, ofn)
    print >> self.log, "  output file name:", ofn
    print >> self.log, self.min_max_mean_shift()

    print >> self.log, self.min_max_mean_shift()
    cs = None
    if self.output_crystal_symmetry:
      cs = self.xray_structure.crystal_symmetry()
    write_whole_pdb_file(
        file_name=ofn,
        processed_pdb_file=self.processed_pdb_file,
        pdb_hierarchy=self.pdb_hierarchy,
        crystal_symmetry=cs,
        link_records=link_records,
      )
    if(self.states_collector):
      self.states_collector.write(
        file_name=ofn[:].replace(".pdb","_all_states.pdb"))
    self.output_file_name = os.path.abspath(ofn)
    def write(self, pdb_output_file_name="", crystal_symmetry=None):
        """ (string) -> text file
    Writes the modified protein, with the added chains, obtained by the
    BIOMT/MTRIX reconstruction, to a text file in a pdb format.
    self.assembled_multimer is the modified pdb object with the added chains

    Argumets:
    pdb_output_file_name -- string. 'name.pdb'
    if no pdn_output_file_name is given pdb_output_file_name=file_name

    >>> v = multimer('name.pdb','ba')
    >>> v.write('new_name.pdb')
    Write a file 'new_name.pdb' to the current directory
    >>> v.write(v.pdb_input_file_name)
    Write a file 'copy_name.pdb' to the current directory
    """
        input_file_name = os.path.basename(self.pdb_input_file_name)
        if pdb_output_file_name == "":
            pdb_output_file_name = input_file_name
        # Avoid writing over the original file
        if pdb_output_file_name == input_file_name:
            # if file name of output is the same as the input, add 'copy_' in front of the name
            self.pdb_output_file_name = self.transform_type + "_" + input_file_name
        else:
            self.pdb_output_file_name = pdb_output_file_name
        # we need to add crystal symmetry to the new file since it is
        # sometimes needed when calculating the R-work factor (r_factor_calc.py)
        if not crystal_symmetry and os.path.isfile(self.pdb_input_file_name):
            crystal_symmetry = crystal_symmetry_from_any.extract_from(self.pdb_input_file_name)
        # using the function to write whole pdb file
        pdb.write_whole_pdb_file(
            file_name=self.pdb_output_file_name,
            pdb_hierarchy=self.assembled_multimer,
            crystal_symmetry=crystal_symmetry,
        )
Пример #3
0
def run(args):
  if len(args) == 0:
    show_usage()
    return
  inp_fn = args[0]
  pdb_input = iotbx.pdb.input(
      file_name=inp_fn,
      source_info=None,
      raise_sorry_if_format_error=True)
  pdb_h = pdb_input.construct_hierarchy(sort_atoms=True)

  out_fn_prefix = inp_fn
  if inp_fn.endswith(".pdb") or inp_fn.endswith(".cif"):
    out_fn_prefix = inp_fn[:-4]
  out_fn = out_fn_prefix + "_sorted.pdb"

  if hasattr(pdb_input, "extract_secondary_structure"):
    ss_annotation = pdb_input.extract_secondary_structure()
    write_whole_pdb_file(
        file_name=out_fn,
        output_file=None,
        processed_pdb_file=None,
        pdb_hierarchy=pdb_h,
        crystal_symmetry=pdb_input.crystal_symmetry(),
        ss_annotation=ss_annotation,
        atoms_reset_serial_first_value=None,
        link_records=None)
  else:
    # This was a mmcif file, so outputting mmcif
    pdb_h.write_mmcif_file(
        file_name = out_fn,
        crystal_symmetry=pdb_input.crystal_symmetry(),
    )
Пример #4
0
  def write_pdb_file(self, prefix):
    from iotbx.pdb.misc_records_output import link_record_output
    link_records = link_record_output(self.processed_pdb_file.all_chain_proxies)
    broadcast(m=prefix, log = self.log)
    self.pdb_hierarchy.adopt_xray_structure(self.xray_structure)
    ofn = self.params.output_file_name_prefix
    directory = self.params.directory
    suffix = "_" + self._pdb_suffix  + ".pdb"
    if(ofn is None):
      pfn = os.path.basename(self.pdb_file_names[0])
      ind = max(0,pfn.rfind("."))
      ofn = pfn+suffix if ind==0 else pfn[:ind]+suffix
    else: ofn = self.params.output_file_name_prefix+".pdb"
    if (self.use_directory_prefix) and (directory is not None) :
      ofn = os.path.join(directory, ofn)
    print >> self.log, "  output file name:", ofn
    print >> self.log, self.min_max_mean_shift()

    print >> self.log, self.min_max_mean_shift()
    cs = None
    if self.output_crystal_symmetry:
      cs = self.xray_structure.crystal_symmetry()
    write_whole_pdb_file(
        file_name=ofn,
        processed_pdb_file=self.processed_pdb_file,
        pdb_hierarchy=self.pdb_hierarchy,
        crystal_symmetry=cs,
        link_records=link_records,
      )
    if(self.states_collector):
      self.states_collector.write(
        file_name=ofn[:].replace(".pdb","_all_states.pdb"))
    self.output_file_name = os.path.abspath(ofn)
def run(args, command_name=libtbx.env.dispatcher_name):
    parser = argparse.ArgumentParser(
        prog=command_name,
        usage='%s pdb_file "atom_selection" [...]' % command_name)
    parser.add_argument("file_name",
                        nargs=1,
                        help="File name of the model file")
    parser.add_argument(
        "inselections",
        help="Atom selection strings",
        nargs='+',
    )
    parser.add_argument("--write-pdb-file",
                        action="store",
                        help="write selected atoms to new PDB file",
                        default=None)
    parser.add_argument(
        "--cryst1-replacement-buffer-layer",
        action="store",
        type=float,
        help="replace CRYST1 with pseudo unit cell covering the selected"
        " atoms plus a surrounding buffer layer",
        default=None)
    co = parser.parse_args(args)
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    processed_pdb_file = pdb_interpretation.process(mon_lib_srv=mon_lib_srv,
                                                    ener_lib=ener_lib,
                                                    file_name=co.file_name[0],
                                                    log=sys.stdout)
    print
    acp = processed_pdb_file.all_chain_proxies

    selection_cache = acp.pdb_hierarchy.atom_selection_cache()
    atoms = acp.pdb_atoms
    all_bsel = flex.bool(atoms.size(), False)
    for selection_string in co.inselections:
        print selection_string
        isel = acp.iselection(string=selection_string, cache=selection_cache)
        all_bsel.set_selected(isel, True)
        if (not co.write_pdb_file):
            print "  %d atom%s selected" % plural_s(isel.size())
            for atom in atoms.select(isel):
                print "    %s" % atom.format_atom_record()
    print
    if (co.write_pdb_file):
        print "Writing file:", show_string(co.write_pdb_file)
        sel_hierarchy = acp.pdb_hierarchy.select(all_bsel)
        if (co.cryst1_replacement_buffer_layer is None):
            crystal_symmetry = acp.special_position_settings
        else:
            import cctbx.crystal
            crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry(
                sites_cart=sel_hierarchy.atoms().extract_xyz(),
                buffer_layer=co.cryst1_replacement_buffer_layer)
        write_whole_pdb_file(file_name=co.write_pdb_file,
                             processed_pdb_file=processed_pdb_file,
                             pdb_hierarchy=sel_hierarchy,
                             crystal_symmetry=crystal_symmetry)
        print
Пример #6
0
def run(args, out=sys.stdout, replace_stderr=True):
  log = mmtbx.utils.set_log(args, out=out, replace_stderr=replace_stderr)
  broadcast(m="phenix.pdbtools tools for PDB model manipulations.", log=log)
  if(len(args)==0):
    master_params().show(out = log)
    return None
  inputs = get_inputs(args=args, log=log, master_params=master_params())
  ### get i/o file names
  ofn = inputs.params.output.file_name
  output_format = inputs.params.output.format
  ifn = inputs.pdb_file_names
  if(ofn is None):
    if output_format == "pdb": ext = "pdb"
    elif output_format == "mmcif": ext = "cif"
    if(len(ifn)==1): ofn = os.path.basename(ifn[0]) + "_modified."+ext
    elif(len(ifn)>1): ofn = os.path.basename(ifn[0]) + "_et_al_modified"+ext
    else:
      pdbout = os.path.basename(inputs.pdb_file_names[0])
      ofn = pdbout+"_modified."+ext
  # Show parameters
  broadcast(m="Complete set of parameters", log=log)
  master_params().format(inputs.params).show(out = log)
  print >> log
  # Run calcs
  broadcast(m="Performing manipulations", log=log)
  task_obj = mmtbx.pdbtools.modify(
    xray_structure = inputs.xray_structure,
    params         = inputs.params.modify,
    pdb_hierarchy  = inputs.pdb_hierarchy,
    log            = log)
  results = task_obj.get_results()
  #
  broadcast(m="Writing output model", log=log)
  print >> log, "Output model file name: ", ofn
  if(inputs.fake_crystal_symmetry):
    crystal_symmetry = None
  else:
    crystal_symmetry = results.crystal_symmetry
  if output_format == "pdb":
    write_whole_pdb_file(
      file_name        = ofn,
      pdb_hierarchy    = results.pdb_hierarchy,
      ss_annotation    = inputs.pdb_inp.extract_secondary_structure(),
      crystal_symmetry = crystal_symmetry,
      append_end       = True,
      atoms_reset_serial_first_value = 1)
  elif output_format =="mmcif":
    write_whole_cif_file(
      file_name        = ofn,
      pdb_hierarchy    = results.pdb_hierarchy,
      ss_annotation    = inputs.pdb_inp.extract_secondary_structure(),
      crystal_symmetry = crystal_symmetry)
  broadcast(m="All done.", log=log)
  return None
Пример #7
0
def run(args):
  log = sys.stdout
  if len(args) == 0:
    format_usage_message(log)
    return
  inputs = mmtbx.utils.process_command_line_args(args=args,
      master_params=master_params())
  work_params = inputs.params.extract()
  inputs.params.show(prefix=" ", out=log)
  pdb_file_names = list(inputs.pdb_file_names)
  if work_params.file_name is not None:
    pdb_file_names += work_params.file_name
  if len(pdb_file_names) == 0:
    raise Sorry("No PDB file specified")
  work_params.model_idealization.enabled=True
  # work_params.model_idealization.file_name_before_regularization="before.pdb"

  pdb_combined = iotbx.pdb.combine_unique_pdb_files(file_names=pdb_file_names)
  pdb_input = iotbx.pdb.input(source_info=None,
    lines=flex.std_string(pdb_combined.raw_records))
  pdb_h = pdb_input.construct_hierarchy()
  # couple checks if combined pdb_h is ok
  o_c = pdb_h.overall_counts()
  o_c.raise_duplicate_atom_labels_if_necessary()
  o_c.raise_residue_groups_with_multiple_resnames_using_same_altloc_if_necessary()
  o_c.raise_chains_with_mix_of_proper_and_improper_alt_conf_if_necessary()
  o_c.raise_improper_alt_conf_if_necessary()

  ann = ioss.annotation.from_phil(
      phil_helices=work_params.secondary_structure.protein.helix,
      phil_sheets=work_params.secondary_structure.protein.sheet,
      pdb_hierarchy=pdb_h)
  if ann.get_n_helices() + ann.get_n_sheets() == 0:
    ann = pdb_input.extract_secondary_structure()
  if ann is None or ann.get_n_helices() + ann.get_n_sheets() == 0:
    raise Sorry("No secondary structure annotations found.")
  ssb.substitute_ss(
      real_h=pdb_h,
      xray_structure=pdb_input.xray_structure_simple(),
      ss_annotation=ann,
      params=work_params.model_idealization,
      cif_objects=inputs.cif_objects,
      verbose=True,
      log=log,
      )
  # Write resulting pdb file.
  write_whole_pdb_file(
      file_name="%s_idealized.pdb" % os.path.basename(pdb_file_names[0]),
      pdb_hierarchy=pdb_h,
      crystal_symmetry=pdb_input.crystal_symmetry(),
      ss_annotation=ann)
  print >> log, "All done."
Пример #8
0
 def shift_and_write_result(self, hierarchy, fname_suffix, grm=None):
   cs_to_write = self.cs if self.shift_vector is None else None
   pdb_h_shifted = hierarchy.deep_copy()
   pdb_h_shifted.reset_atom_i_seqs()
   if self.shift_vector is not None:
     atoms = pdb_h_shifted.atoms()
     sites_cart = atoms.extract_xyz()
     atoms.set_xyz(new_xyz=sites_cart-self.shift_vector)
   write_whole_pdb_file(
       file_name="%s_%s_nosh.pdb" % (self.params.output_prefix, fname_suffix),
       pdb_hierarchy=hierarchy,
       crystal_symmetry=self.cs,
       ss_annotation=self.ann)
   write_whole_pdb_file(
       file_name="%s_%s.pdb" % (self.params.output_prefix, fname_suffix),
       pdb_hierarchy=pdb_h_shifted,
       crystal_symmetry=cs_to_write,
       ss_annotation=self.original_ann)
Пример #9
0
def run(args):
  if len(args) == 0:
    show_usage()
    return
  inp_fn = args[0]
  import time
  t0=time.time()
  pdb_input = iotbx.pdb.input(
      file_name=inp_fn,
      source_info=None,
      raise_sorry_if_format_error=True)
  t0=time.time()
  pdb_h = pdb_input.construct_hierarchy()
  info = pdb_h.flip_symmetric_amino_acids()
  print info

  out_fn_prefix = inp_fn
  if inp_fn.endswith(".pdb") or inp_fn.endswith(".cif"):
    out_fn_prefix = inp_fn[:-4]
  out_fn = out_fn_prefix + "_iupac.pdb"

  if hasattr(pdb_input, "extract_secondary_structure"):
    ss_annotation = pdb_input.extract_secondary_structure()
    write_whole_pdb_file(
        file_name=out_fn,
        output_file=None,
        processed_pdb_file=None,
        pdb_hierarchy=pdb_h,
        crystal_symmetry=pdb_input.crystal_symmetry(),
        ss_annotation=ss_annotation,
        atoms_reset_serial_first_value=None,
        link_records=None)
  else:
    # This was a mmcif file, so outputting mmcif
    pdb_h.write_mmcif_file(
        file_name = out_fn,
        crystal_symmetry=pdb_input.crystal_symmetry(),
    )
Пример #10
0
  def write(self,pdb_output_file_name='',crystal_symmetry=None):
    ''' (string) -> text file
    Writes the modified protein, with the added chains, obtained by the
    BIOMT/MTRIX reconstruction, to a text file in a pdb format.
    self.assembled_multimer is the modified pdb object with the added chains

    Argumets:
    pdb_output_file_name -- string. 'name.pdb'
    if no pdn_output_file_name is given pdb_output_file_name=file_name

    >>> v = multimer('name.pdb','ba')
    >>> v.write('new_name.pdb')
    Write a file 'new_name.pdb' to the current directory
    >>> v.write(v.pdb_input_file_name)
    Write a file 'copy_name.pdb' to the current directory
    '''
    input_file_name = os.path.basename(self.pdb_input_file_name)
    if pdb_output_file_name == '':
      pdb_output_file_name = input_file_name
    # Avoid writing over the original file
    if pdb_output_file_name == input_file_name:
      # if file name of output is the same as the input, add 'copy_' in front of the name
      self.pdb_output_file_name = self.transform_type + '_' + input_file_name
    else:
      self.pdb_output_file_name = pdb_output_file_name
    # we need to add crystal symmetry to the new file since it is
    # sometimes needed when calculating the R-work factor (r_factor_calc.py)
    if not crystal_symmetry and os.path.isfile(self.pdb_input_file_name):
      crystal_symmetry = crystal_symmetry_from_any.extract_from(
        self.pdb_input_file_name)
    # using the function to write whole pdb file
    pdb.write_whole_pdb_file(
        file_name=self.pdb_output_file_name,
        pdb_hierarchy=self.assembled_multimer,
        crystal_symmetry=crystal_symmetry,
        ss_annotation=self.new_annotation)
Пример #11
0
def run(args, command_name=libtbx.env.dispatcher_name):
  if (len(args) == 0): args = ["--help"]
  command_line = (option_parser(
    usage='%s pdb_file "atom_selection" [...]' % command_name)
    .option(None, "--write_pdb_file",
      action="store",
      type="string",
      default=None,
      help="write selected atoms to new PDB file",
      metavar="FILE")
    .option(None, "--cryst1_replacement_buffer_layer",
      action="store",
      type="float",
      default=None,
      help="replace CRYST1 with pseudo unit cell covering the selected"
        " atoms plus a surrounding buffer layer",
      metavar="WIDTH")
  ).process(args=args, min_nargs=2)
  co = command_line.options
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    file_name=command_line.args[0],
    log=sys.stdout)
  print
  acp = processed_pdb_file.all_chain_proxies

  hierarchy=acp.pdb_hierarchy
  asc=hierarchy.atom_selection_cache()
  sel=asc.selection(string = "chain 'A' and resid 1 through 8 and icode ' '")
  h1=hierarchy.select(sel)  # keep original hierarchy too
  print h1.as_pdb_string()


  selection_cache = acp.pdb_hierarchy.atom_selection_cache()
  atoms = acp.pdb_atoms
  all_bsel = flex.bool(atoms.size(), False)
  for selection_string in command_line.args[1:]:
    print selection_string
    isel = acp.iselection(string=selection_string, cache=selection_cache)
    all_bsel.set_selected(isel, True)
    if (not co.write_pdb_file):
      print "  %d atom%s selected" % plural_s(isel.size())
      for atom in atoms.select(isel):
        print "    %s" % atom.format_atom_record()
  print
  if (co.write_pdb_file):
    print "Writing file:", show_string(co.write_pdb_file)
    sel_hierarchy = acp.pdb_hierarchy.select(all_bsel)
    if (co.cryst1_replacement_buffer_layer is None):
      crystal_symmetry = acp.special_position_settings
    else:
      import cctbx.crystal
      crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry(
        sites_cart=sel_hierarchy.atoms().extract_xyz(),
        buffer_layer=co.cryst1_replacement_buffer_layer)
    write_whole_pdb_file(
        file_name=co.write_pdb_file,
        processed_pdb_file=processed_pdb_file,
        pdb_hierarchy=sel_hierarchy,
        crystal_symmetry=crystal_symmetry)
    print
Пример #12
0
  def __init__(self,
               pdb_input,
               cif_objects=None,
               params=None,
               log=sys.stdout,
               verbose=True):
    t_0 = time()
    self.pdb_input = pdb_input
    self.cif_objects = cif_objects
    self.params = params
    self.log = log
    self.verbose = verbose

    self.rmsd_from_start = None
    self.init_model_statistics = None
    self.after_ss_idealization = None
    self.after_loop_idealization = None
    self.after_rotamer_fixing = None
    self.final_model_statistics = None
    self.reference_map = None

    self.whole_grm = None
    self.master_grm = None
    self.working_grm = None

    self.mon_lib_srv = None
    self.ener_lib = None
    self.rotamer_manager = None
    self.rama_manager = rama_eval()

    self.original_hierarchy = None # original pdb_h, without any processing
    self.original_boxed_hierarchy = None # original and boxed (if needed)
    self.whole_pdb_h = None # boxed with processing (AC trimming, H trimming,...)
    self.master_pdb_h = None # master copy in case of NCS
    self.working_pdb_h = None # one to use for fixing (master_pdb_h or working_pdb_h)

    # various checks, shifts, trims
    self.cs = self.pdb_input.crystal_symmetry()
    # check self.cs (copy-paste from secondary_sturcure_restraints)
    corrupted_cs = False
    if self.cs is not None:
      if [self.cs.unit_cell(), self.cs.space_group()].count(None) > 0:
        corrupted_cs = True
        self.cs = None
      elif self.cs.unit_cell().volume() < 10:
        corrupted_cs = True
        self.cs = None

    self.original_hierarchy = self.pdb_input.construct_hierarchy()
    # couple checks if pdb_h is ok
    o_c = self.original_hierarchy.overall_counts()
    o_c.raise_duplicate_atom_labels_if_necessary()
    o_c.raise_residue_groups_with_multiple_resnames_using_same_altloc_if_necessary()
    o_c.raise_chains_with_mix_of_proper_and_improper_alt_conf_if_necessary()
    o_c.raise_improper_alt_conf_if_necessary()
    if len(self.original_hierarchy.models()) > 1:
      raise Sorry("Multi model files are not supported")
    ca_only_present = False
    for c in self.original_hierarchy.only_model().chains():
      if c.is_ca_only():
        ca_only_present = True
    if ca_only_present:
      raise Sorry("Don't support models with chains containing only CA atoms.")

    self.original_boxed_hierarchy = self.original_hierarchy.deep_copy()
    self.original_boxed_hierarchy.reset_atom_i_seqs()
    self.shift_vector = None
    if self.cs is None:
      if corrupted_cs:
        print >> self.log, "Symmetry information is corrupted, "
      else:
        print >> self.log, "Symmetry information was not found, "
      print >> self.log, "putting molecule in P1 box."
      self.log.flush()
      from cctbx import uctbx
      atoms = self.original_boxed_hierarchy.atoms()
      box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
        sites_cart=atoms.extract_xyz(),
        buffer_layer=3)
      atoms.set_xyz(new_xyz=box.sites_cart)
      self.cs = box.crystal_symmetry()
      self.shift_vector = box.shift_vector

    # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_h.pdb")
    if self.shift_vector is not None:
      write_whole_pdb_file(
          file_name="%s_boxed.pdb" % self.params.output_prefix,
          pdb_hierarchy=self.original_boxed_hierarchy,
          crystal_symmetry=self.cs,
          ss_annotation=self.pdb_input.extract_secondary_structure())

    asc = self.original_boxed_hierarchy.atom_selection_cache()
    if self.params.trim_alternative_conformations:
      sel = asc.selection("altloc ' '")
      self.whole_pdb_h = self.original_boxed_hierarchy.select(sel).deep_copy()
      print >> self.log, "Atoms in original/working model: %d/%d" % (
          self.original_boxed_hierarchy.atoms_size(), self.whole_pdb_h.atoms_size())
    else:
      self.whole_pdb_h = self.original_boxed_hierarchy.deep_copy()
      # self.whole_pdb_h.reset_atom_i_seqs()
    # Trimming hydrogens
    # Many intermediate variables are needed due to strange behavior of
    # selections described in
    # iotbx/pdb/tst_hierarchy.py:exercise_selection_and_deep_copy()
    asc2 = self.whole_pdb_h.atom_selection_cache()
    h_sel = asc2.selection("not (element H or element D)")
    temp_h = self.whole_pdb_h.select(h_sel)
    self.whole_pdb_h = temp_h.deep_copy()
    self.whole_pdb_h.reset_atom_i_seqs()
    self.init_model_statistics = geometry_no_grm(
        pdb_hierarchy=iotbx.pdb.input(
          source_info=None,
          lines=self.whole_pdb_h.as_pdb_string()).construct_hierarchy(),
        molprobity_scores=True)
    self.time_for_init = time()-t_0
Пример #13
0
  def __init__(self,
               model, # shifted, with shift_manager
               map_data = None, # shifted map_data
               params=None,
               log=sys.stdout,
               verbose=True):
    t_0 = time()
    self.model = model
    # self.cif_objects = cif_objects
    self.params = params
    self.log = log
    self.verbose = verbose

    # self.shift_manager = self.model.get_shift_manager()

    self.rmsd_from_start = None
    self.init_model_statistics = None
    self.init_gm_model_statistics = None
    self.after_ss_idealization = None
    self.after_loop_idealization = None
    self.after_rotamer_fixing = None
    self.final_model_statistics = None
    self.user_supplied_map = map_data
    self.reference_map = None # Whole map for all NCS copies
    self.master_map = None # Map for only one NCS copy, or == reference_map if no NCS
    self.init_ref_map = None # separate map for initial GM. Should be tighter than the 2 above

    self.whole_grm = None
    self.master_grm = None
    self.working_grm = None

    params_line = grand_master_phil_str
    params = iotbx.phil.parse(
        input_string=params_line, process_includes=True).extract()
    params.pdb_interpretation.clash_guard.nonbonded_distance_threshold=None
    params.pdb_interpretation.peptide_link.ramachandran_restraints = True
    params.pdb_interpretation.peptide_link.oldfield.weight_scale=3
    params.pdb_interpretation.peptide_link.oldfield.plot_cutoff=0.03
    params.pdb_interpretation.peptide_link.apply_peptide_plane = True
    if self.params.loop_idealization.make_all_trans:
      params.pdb_interpretation.peptide_link.apply_all_trans = True
    params.pdb_interpretation.nonbonded_weight = 10000
    params.pdb_interpretation.c_beta_restraints=True
    params.pdb_interpretation.max_reasonable_bond_distance = None
    params.pdb_interpretation.ncs_search.enabled = True
    params.pdb_interpretation.ncs_search.chain_max_rmsd=4.0
    params.pdb_interpretation.ncs_search.chain_similarity_threshold=0.99
    params.pdb_interpretation.ncs_search.residue_match_radius=999.0
    params.pdb_interpretation.restraints_library.rdl = True
    params.pdb_interpretation.secondary_structure = self.params.secondary_structure
    self.model.set_pdb_interpretation_params(params)


    self.original_hierarchy = self.model.get_hierarchy().deep_copy() # original pdb_h, without any processing
    self.original_boxed_hierarchy = None # original and boxed (if needed)

    self.filtered_ncs_restr_group_list = []

    self.init_ss_annotation = self.model.get_ss_annotation()

    # various checks, shifts, trims
    self.cs = self.original_cs = self.model.crystal_symmetry()
    if self.model.get_shift_manager() is not None:
      self.cs = self.model.get_shift_manager().box_crystal_symmetry

    # check self.cs (copy-paste from secondary_sturcure_restraints)
    corrupted_cs = False
    if self.cs is not None:
      if [self.cs.unit_cell(), self.cs.space_group()].count(None) > 0:
        corrupted_cs = True
        self.cs = None
      elif self.cs.unit_cell().volume() < 10:
        corrupted_cs = True
        self.cs = None

    # couple checks if pdb_h is ok
    o_c = self.original_hierarchy.overall_counts()
    o_c.raise_duplicate_atom_labels_if_necessary()
    o_c.raise_residue_groups_with_multiple_resnames_using_same_altloc_if_necessary()
    o_c.raise_chains_with_mix_of_proper_and_improper_alt_conf_if_necessary()
    o_c.raise_improper_alt_conf_if_necessary()
    if len(self.original_hierarchy.models()) > 1:
      raise Sorry("Multi model files are not supported")
    ca_only_present = False
    for c in self.original_hierarchy.only_model().chains():
      if c.is_ca_only():
        ca_only_present = True
    if ca_only_present:
      raise Sorry("Don't support models with chains containing only CA atoms.")

    self.original_boxed_hierarchy = self.model.get_hierarchy().deep_copy()
    self.shift_vector = None
    if self.cs is None:
      assert self.model.get_shift_manager() is None
      # should it happen here?
      if corrupted_cs:
        print >> self.log, "Symmetry information is corrupted, "
      else:
        print >> self.log, "Symmetry information was not found, "
      print >> self.log, "putting molecule in P1 box."
      self.log.flush()
      from cctbx import uctbx
      box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
        sites_cart=self.model.get_sites_cart(),
        buffer_layer=3)
      self.model.set_sites_cart(sites_cart=box.sites_cart)
      self.original_boxed_hierarchy = self.model.get_hierarchy().deep_copy()
      self.cs = box.crystal_symmetry()
      self.model.set_crystal_symmetry(self.cs)
      self.shift_vector = box.shift_vector

    if self.shift_vector is not None and self.params.debug:
      write_whole_pdb_file(
          file_name="%s_boxed.pdb" % self.params.output_prefix,
          pdb_hierarchy=self.model.get_hierarchy(),
          crystal_symmetry=self.model.crystal_symmetry(),
          ss_annotation=self.init_ss_annotation)

    if self.params.trim_alternative_conformations:
      self.model.remove_alternative_conformations(always_keep_one_conformer=True)

    self.model = self.model.remove_hydrogens()

    self.time_for_init = time()-t_0
Пример #14
0
def run(args, command_name=libtbx.env.dispatcher_name):
    if (len(args) == 0): args = ["--help"]
    command_line = (option_parser(
        usage='%s pdb_file "atom_selection" [...]' % command_name).option(
            None,
            "--write_pdb_file",
            action="store",
            type="string",
            default=None,
            help="write selected atoms to new PDB file",
            metavar="FILE"
        ).option(
            None,
            "--cryst1_replacement_buffer_layer",
            action="store",
            type="float",
            default=None,
            help="replace CRYST1 with pseudo unit cell covering the selected"
            " atoms plus a surrounding buffer layer",
            metavar="WIDTH")).process(args=args, min_nargs=2)
    co = command_line.options
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=command_line.args[0],
        log=sys.stdout)
    print
    acp = processed_pdb_file.all_chain_proxies

    hierarchy = acp.pdb_hierarchy
    asc = hierarchy.atom_selection_cache()
    sel = asc.selection(string="chain 'A' and resid 1 through 8 and icode ' '")
    h1 = hierarchy.select(sel)  # keep original hierarchy too
    print h1.as_pdb_string()

    selection_cache = acp.pdb_hierarchy.atom_selection_cache()
    atoms = acp.pdb_atoms
    all_bsel = flex.bool(atoms.size(), False)
    for selection_string in command_line.args[1:]:
        print selection_string
        isel = acp.iselection(string=selection_string, cache=selection_cache)
        all_bsel.set_selected(isel, True)
        if (not co.write_pdb_file):
            print "  %d atom%s selected" % plural_s(isel.size())
            for atom in atoms.select(isel):
                print "    %s" % atom.format_atom_record()
    print
    if (co.write_pdb_file):
        print "Writing file:", show_string(co.write_pdb_file)
        sel_hierarchy = acp.pdb_hierarchy.select(all_bsel)
        if (co.cryst1_replacement_buffer_layer is None):
            crystal_symmetry = acp.special_position_settings
        else:
            import cctbx.crystal
            crystal_symmetry = cctbx.crystal.non_crystallographic_symmetry(
                sites_cart=sel_hierarchy.atoms().extract_xyz(),
                buffer_layer=co.cryst1_replacement_buffer_layer)
        write_whole_pdb_file(file_name=co.write_pdb_file,
                             processed_pdb_file=processed_pdb_file,
                             pdb_hierarchy=sel_hierarchy,
                             crystal_symmetry=crystal_symmetry)
        print