Exemplo n.º 1
0
def get_res_nums_around(pdb_hierarchy, center_resnum_list, n_following, n_previous,
    include_intermediate=False, avoid_ss_annot=None):
  """
  Warning, this function most likely won't work properly with insertion codes
  """
  working_ss_annot = None
  if avoid_ss_annot is not None:
    working_ss_annot = avoid_ss_annot.deep_copy()
    working_ss_annot.remove_empty_annotations(
        hierarchy=pdb_hierarchy)
  residue_list = list(
      pdb_hierarchy.only_model().only_chain().only_conformer().residues())
  center_index = []
  for i in range(len(residue_list)):
    if residue_list[i].resseq in center_resnum_list:
      center_index.append(i)
      # break
  if not include_intermediate:
    # return residue_list[max(0,center_index-n_previous)].resseq, \
    #     residue_list[min(len(residue_list)-1,center_index+n_following)].resseq
    print "center_index, resnum list", center_index, center_resnum_list
    # assert len(center_index) == len(center_resnum_list)
    start_res_num = residue_list[max(0,center_index[0]-n_previous)].resseq_as_int()
    end_res_num = residue_list[min(len(residue_list)-1,center_index[-1]+n_following)].resseq_as_int()
    srn, ern = get_loop_borders(pdb_hierarchy, center_resnum_list, working_ss_annot)
    print "start_res_num, end_res_num", start_res_num, end_res_num
    print "srn, ern", srn, ern
    # srn, ern = -9999, 9999999
    # So now we have borders of the loop: srn, ern, center_resnum,
    # n_following, n_previous.
    # We combine the above knowledge to adjust the borders keeping the same
    # loop size
    # adjst beginning
    if srn > start_res_num:
      end_res_num += srn - start_res_num
      start_res_num = srn
    # adjust end
    if ern < end_res_num:
      start_res_num = max(start_res_num - (end_res_num-ern), srn)
      end_res_num = ern

    f_start_res_num = start_res_num
    f_end_res_num = end_res_num
    print "srn, ern", srn, ern
    print "f_start_res_num, f_end_res_num", f_start_res_num, f_end_res_num
    if f_end_res_num == hy36decode(4, center_resnum_list[-1]):
      f_end_res_num += 1
    if f_start_res_num == hy36decode(4,center_resnum_list[0]):
      f_start_res_num -= 1
    print "after f_start_res_num, f_end_res_num", f_start_res_num, f_end_res_num
    return hy36encode(4, f_start_res_num), hy36encode(4, f_end_res_num)
  else:
    res = []
    for i in range(max(0,center_index[0]-n_previous),
        min(len(residue_list)-1,center_index[-1]+n_following+1)):
      res.append(residue_list[i].resseq)
    return res
Exemplo n.º 2
0
 def create_atom(xyz, peak, serial):
   rg = iotbx.pdb.hierarchy.residue_group(resseq=hy36encode(4, serial))
   ag = iotbx.pdb.hierarchy.atom_group(resname="UNK")
   rg.append_atom_group(ag)
   a = iotbx.pdb.hierarchy.atom()
   ag.append_atom(a)
   a.name = " UNK"
   a.element = "X"
   a.xyz = xyz
   a.b = peak
   a.occ = 1.
   a.serial = serial
   return rg
Exemplo n.º 3
0
def get_fixed_moving_parts(pdb_hierarchy, out_res_num_list, n_following, n_previous,
    ss_annotation=None, direction_forward=True, log=None):
  # limitation: only one  chain in pdb_hierarchy!!!
  if log is None:
    log = StringIO()
  original_pdb_h = pdb_hierarchy.deep_copy()
  # print >> log, "  out_res_num, n_following, n_previous", out_res_num_list, n_following, n_previous
  start_res_num, end_res_num = get_res_nums_around(pdb_hierarchy, out_res_num_list,
      n_following, n_previous, include_intermediate=False, avoid_ss_annot=ss_annotation)
  print >> log, "  start_res_num, end_res_num", start_res_num, end_res_num
  xrs = original_pdb_h.extract_xray_structure()
  truncate_to_poly_gly(pdb_hierarchy, start_res_num, end_res_num)
  cache = pdb_hierarchy.atom_selection_cache()
  # print "POSSIBLE ERROR:", "selectioin:", "(name N or name CA or name C or name O) and resid %s through %s" % (
  #         start_res_num, end_res_num)
  m_selection = cache.iselection(
      "(name N or name CA or name C or name O) and resid %s through %s" % (
          start_res_num, end_res_num))
  # Somewhere here would be the place to tweak n_following, n_previous to
  # exclude SS parts. It would be nice to increase n_prev in case
  # we need to cut on n_following etc.
  # If no ss_annotation is provided, don't filter.
  contains_ss_element = False
  if ss_annotation is not None:
    ss_selection_str = ss_annotation.overall_selection()
    ss_selection = cache.iselection(ss_selection_str)
    intersect = flex.size_t(sorted(list(set(ss_selection) & set(m_selection))))
    if intersect.size() > 0:
      intersect_h = pdb_hierarchy.select(intersect)
      print >> log, "Hitting SS element"
      print >> log, intersect_h.as_pdb_string()
      contains_ss_element = False
      assert intersect_h.atoms_size() > 0, "Wrong atom count in SS intersection"
      # assert 0, "hitting SS element!"


  moving_h = pdb_hierarchy.select(m_selection)
  moving_h.reset_atom_i_seqs()
  # print dir(moving_h)
  # STOP()
  m_cache = moving_h.atom_selection_cache()
  # print "len inp h atoms", pdb_hierarchy.atoms_size()
  # print "len moving_h atoms", moving_h.atoms_size()
  # here we need N, CA, C atoms from the end_res_num residue
  eff_end_resnum = end_res_num
  if not direction_forward:
    eff_end_resnum = start_res_num
  sel = m_cache.selection("resid %s" % end_res_num)
  int_eff_resnum = hy36decode(4,eff_end_resnum)
  while len(moving_h.select(sel).atoms()) == 0:
    if direction_forward:
      int_eff_resnum -= 1
    else:
      int_eff_resnum += 1
    sel = m_cache.selection("resid %d" % int_eff_resnum)
  eff_end_resnum = hy36encode(4, int_eff_resnum)

  anchor_present = True
  moving_ref_atoms_iseqs = []
  fixed_ref_atoms = []
  # print "fixed_ref_atoms:"
  base_sel = "resid %s and name " % eff_end_resnum
  for ssel in ["N", "CA", "C"]:
    sel = m_cache.selection(base_sel+ssel)
    atoms = moving_h.select(sel).atoms()
    if atoms.size() > 0:
      moving_ref_atoms_iseqs.append(atoms[0].i_seq)
      fixed_ref_atoms.append(atoms[0].detached_copy())
    else:
      anchor_present = False
    # print "  ", atoms[0].id_str()
  print "anchor_present", anchor_present
  return (moving_h, moving_ref_atoms_iseqs, fixed_ref_atoms, m_selection,
      contains_ss_element, anchor_present)