Example #1
0
    def __call__(self, hsh_tuple):
        temp_annot = iotbx.pdb.secondary_structure.annotation(
            helices=hsh_tuple[0], sheets=hsh_tuple[1])
        helix = len(hsh_tuple[0]) > 0
        # print temp_annot.as_pdb_str().replace('\n',' '),
        ss_params = mmtbx.secondary_structure.manager.get_default_ss_params()
        ss_params.secondary_structure.enabled = True
        ss_params.secondary_structure.protein.remove_outliers = False
        ss_params.secondary_structure.protein.helix = []
        ss_params.secondary_structure.protein.sheet = []
        ss_params.secondary_structure.nucleic_acid.enabled = False
        ss_m_log = StringIO()

        ss_manager = mmtbx.secondary_structure.manager(
            pdb_hierarchy=self.pdb_h,
            atom_selection_cache=self.asc,
            sec_str_from_pdb_file=temp_annot,
            params=ss_params.secondary_structure,
            show_summary_on=False,
            log=ss_m_log)
        h_bond_proxies, hb_angles = ss_manager.create_protein_hbond_proxies(
            log=ss_m_log)

        cutoff_bad = self.bad_hbond_cutoff
        cutoff_mediocre = self.mediocre_hbond_cutoff
        n_hbonds = 0
        n_bad_hbonds = 0
        n_mediocre_hbonds = 0
        hb_lens = []
        for hb_p in h_bond_proxies:
            # print dir(hb_p)
            n_hbonds += 1
            hb_len = self.atoms[hb_p.i_seqs[0]].distance(
                self.atoms[hb_p.i_seqs[1]])
            hb_lens.append(hb_len)
            if hb_len > cutoff_bad:
                n_bad_hbonds += 1
            elif hb_len > cutoff_mediocre:
                n_mediocre_hbonds += 1

        # Ramachandran outliers and wrong areas
        sele = self.asc.selection(temp_annot.as_atom_selections()[0])
        ss_h = self.pdb_h.select(sele)
        phi_psi_atoms = get_phi_psi_atoms(ss_h)

        n_outliers = 0
        n_wrong_region = 0
        for phi_psi_pair, rama_key in phi_psi_atoms:
            phi, psi = get_pair_angles(phi_psi_pair)
            r_eval = self.r.evaluate_angles(rama_key, phi, psi)
            if r_eval == ramalyze.RAMALYZE_OUTLIER:
                n_outliers += 1
            else:
                reg = pp2_helix_sheet_rama_region(phi, psi, self.pp2m)
                if (helix and reg != 'A') or (not helix and reg != 'B'):
                    n_wrong_region += 1
                    # print "  Wrong region:", phi_psi_pair[0][2].id_str(), reg, helix
        del ss_manager
        del ss_params
        return n_hbonds, n_bad_hbonds, n_mediocre_hbonds, hb_lens, n_outliers, n_wrong_region
def get_starting_conformations(moving_h, cutoff=50, log=null_out):
  """
  modify only ramachandran outliers.
  """
  variants = []
  r = ramachandran_eval.RamachandranEval()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  for phi_psi_pair, rama_key in phi_psi_atoms:
    if (utils.rama_evaluate(phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER):
      variants.append(ramalyze.get_favored_regions(rama_key))
    else:
      variants.append([(None, None)])
  result = []
  print >> log, "variants", variants
  if variants.count([(None, None)]) == len(variants):
    print "Nothing to CCD"
    return result
  all_angles_combination = list(itertools.product(*variants))
  i = 0
  for comb in all_angles_combination:
    print >> log, "Model %d, angles:" % i, comb
    if is_not_none_combination(comb):
      result.append(set_rama_angles(moving_h, list(comb)))
    i += 1
  return result[:cutoff]
def set_rama_angles(moving_h, angles):
  """
  angles = [(phi, psi), (phi, psi), ... (phi, psi)]
  phi or psi == None means we don't change this angle
  returns deep-copied hierarchy with new angles. Change occurs from first to
  last angle so starting point would be in the same place.
  This function should produce up to all possible favored conformations.
  This function doesn't change moving_h

  """
  # print "angles", angles
  # STOP()
  result_h = moving_h.deep_copy()
  result_h.reset_atom_i_seqs()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  assert len(phi_psi_atoms) == len(angles)
  for ps_atoms, target_angle_pair in zip(phi_psi_atoms, angles):
    phi_psi_pair = ps_atoms[0]
    phi_psi_angles = utils.get_pair_angles(phi_psi_pair)
    # phi
    if target_angle_pair[0] is not None:
      utils.rotate_atoms_around_bond(
          result_h,
          phi_psi_pair[0][1],
          phi_psi_pair[0][2],
          angle=-phi_psi_angles[0]+target_angle_pair[0])
    # psi
    if target_angle_pair[1] is not None:
      utils.rotate_atoms_around_bond(
          result_h,
          phi_psi_pair[1][1],
          phi_psi_pair[1][2],
          angle=-phi_psi_angles[1]+target_angle_pair[1])
  return result_h
Example #4
0
def get_starting_conformations(moving_h, cutoff=50, log=null_out()):
  """
  modify only ramachandran outliers.
  """
  variants = []
  r = rama_eval()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  for phi_psi_pair, rama_key in phi_psi_atoms:
    if (utils.rama_evaluate(phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER):
      vs = get_sampled_rama_favored_angles(rama_key, r)
      # print len(vs)
      # print vs
      # STOP()
      variants.append(vs)
      # variants.append(ramalyze.get_favored_regions(rama_key))
    else:
      variants.append([(None, None)])
  result = []
  print >> log, "variants", variants
  if variants.count([(None, None)]) == len(variants):
    print "Nothing to CCD"
    return result
  all_angles_combination = list(itertools.product(*variants))
  i = 0
  n_added = 0
  n_all_combination = len(all_angles_combination)
  i_max = min(cutoff, n_all_combination)
  while n_added < i_max:
    comb = all_angles_combination[i]
    if is_not_none_combination(comb):
      result.append(set_rama_angles(moving_h, list(comb)))
      print >> log, "Model %d, angles:" % i, comb
      n_added += 1
    i += 1
  return result
Example #5
0
def get_all_starting_conformations(moving_h, change_radius, cutoff=50, log=null_out()):
  variants = []
  r = rama_eval()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  n_rama = len(phi_psi_atoms)
  change_angles = range((n_rama)//2-change_radius, (n_rama)//2+change_radius+1)
  # print "  change_angles", change_angles
  for i, (phi_psi_pair, rama_key) in enumerate(phi_psi_atoms):
    if i in change_angles or (utils.rama_evaluate(phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER):
      if utils.rama_evaluate(phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER:
        vs = get_sampled_rama_favored_angles(rama_key, r)
      else:
        vs = ramalyze.get_favored_regions(rama_key)
      variants.append(vs)
      # variants.append(ramalyze.get_favored_regions(rama_key))
    else:
      variants.append([(None, None)])
  print >> log, "variants", variants
  all_angles_combination = list(itertools.product(*variants))
  result = []
  i = 0
  n_added = 0
  n_all_combination = len(all_angles_combination)
  i_max = min(cutoff, n_all_combination)
  while n_added < i_max:
    comb = all_angles_combination[i]
    if is_not_none_combination(comb):
      result.append(set_rama_angles(moving_h, list(comb)))
      print >> log, "Model %d, angles:" % i, comb
      n_added += 1
    i += 1
  # STOP()
  return result
Example #6
0
def set_rama_angles(moving_h, angles):
  """
  angles = [(phi, psi), (phi, psi), ... (phi, psi)]
  phi or psi == None means we don't change this angle
  returns deep-copied hierarchy with new angles. Change occurs from first to
  last angle so starting point would be in the same place.
  This function should produce up to all possible favored conformations.
  This function doesn't change moving_h
  """
  # print "angles", angles
  # STOP()
  result_h = moving_h.deep_copy()
  result_h.reset_atom_i_seqs()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  assert len(phi_psi_atoms) == len(angles)
  for ps_atoms, target_angle_pair in zip(phi_psi_atoms, angles):
    phi_psi_pair = ps_atoms[0]
    phi_psi_angles = utils.get_pair_angles(phi_psi_pair)
    # phi
    if target_angle_pair[0] is not None:
      utils.rotate_atoms_around_bond(
          result_h,
          phi_psi_pair[0][1],
          phi_psi_pair[0][2],
          angle=-phi_psi_angles[0]+target_angle_pair[0])
    # psi
    if target_angle_pair[1] is not None:
      utils.rotate_atoms_around_bond(
          result_h,
          phi_psi_pair[1][1],
          phi_psi_pair[1][2],
          angle=-phi_psi_angles[1]+target_angle_pair[1])
  return result_h
Example #7
0
def get_all_starting_conformations(moving_h,
                                   change_radius,
                                   n_outliers,
                                   direction_forward=True,
                                   cutoff=50,
                                   change_all=True,
                                   log=null_out(),
                                   check_omega=False):
    if log is None:
        log = StringIO()
    variants = []
    result = []
    r = rama_eval()
    phi_psi_atoms = utils.get_phi_psi_atoms(moving_h, omega=True)
    # print "N residue groups in h", [x.resseq for x in moving_h.residue_groups()]
    if len(phi_psi_atoms) == 0:
        print >> log, "Strange input to starting conformations!!!"
        return result
    n_rama = len(phi_psi_atoms)
    # print "n_rama", n_rama
    change_angles = [None]
    if change_all:
        change_angles = range(
            (n_rama) // 2 - change_radius - n_outliers // 2,
            (n_rama) // 2 + change_radius + 1 + n_outliers // 2)
        # if change_angles[0] < 0:
        #   change_angles = range(change_angles[-1]-change_angles[0])
    has_twisted = False
    if check_omega:
        omegas = [x[2] for x in phi_psi_atoms]
        for o in omegas:
            if o is not None and abs(abs(o) - 180) > 30:
                has_twisted = True
    print >> log, "n_outliers", n_outliers
    for i, (phi_psi_pair, rama_key, omega) in enumerate(phi_psi_atoms):
        angle_is_outlier = utils.rama_evaluate(
            phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER
        twisted = omega is not None and ((abs(abs(omega) - 180) > 30)
                                         and check_omega)
        print >> log, "in cycle, N, outlier?, change?, twisted?", i, angle_is_outlier, i in change_angles, twisted
        if angle_is_outlier and n_outliers < 3:
            vs = get_sampled_rama_favored_angles(rama_key, r)
        elif (i in change_angles) or angle_is_outlier or has_twisted:
            # vs = get_sampled_rama_favored_angles(rama_key, r)
            vs = ramalyze.get_favored_regions(rama_key)
        else:
            vs = [(None, None)]
        variants.append(vs)
    print >> log, "variants", variants
    all_angles_combination = list(itertools.product(*variants))
    # filter none combinations
    # print "len(all_angles_combination)", len(all_angles_combination)
    all_angles_combination_f = []
    for comb in all_angles_combination:
        if is_not_none_combination(comb):
            all_angles_combination_f.append(comb)
    print >> log, "len(all_angles_combination_f)", len(
        all_angles_combination_f)
    return all_angles_combination_f
def get_all_starting_conformations(moving_h, change_radius, cutoff=50, log=null_out):
  variants = []
  r = ramachandran_eval.RamachandranEval()
  phi_psi_atoms = utils.get_phi_psi_atoms(moving_h)
  n_rama = len(phi_psi_atoms)
  change_angles = range((n_rama)//2-change_radius, (n_rama)//2+change_radius+1)
  # print "  change_angles", change_angles
  for i, (phi_psi_pair, rama_key) in enumerate(phi_psi_atoms):
    if i in change_angles or (utils.rama_evaluate(phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER):
      variants.append(ramalyze.get_favored_regions(rama_key))
    else:
      variants.append([(None, None)])
  print >> log, "variants", variants
  all_angles_combination = list(itertools.product(*variants))
  result = []
  i = 0
  for comb in all_angles_combination:
    if is_not_none_combination(comb):
      result.append(set_rama_angles(moving_h, list(comb)))
      print >> log, "Model %d, angles:" % i, comb
      i += 1
  # STOP()
  return result[:cutoff]
Example #9
0
def set_rama_angles(moving_h,
                    angles,
                    direction_forward=True,
                    check_omega=False):
    """
  angles = [(phi, psi), (phi, psi), ... (phi, psi)]
  phi or psi == None means we don't change this angle
  returns deep-copied hierarchy with new angles. Change occurs from first to
  last angle so starting point would be in the same place.
  This function should produce up to all possible favored conformations.
  This function doesn't change moving_h
  direction_forward==True - set from beginning to end - the end residue moves
  direction_forward==False - set from end to beginning, the first residue moves
  """
    # print "angles", angles
    # STOP()
    result_h = moving_h.deep_copy()
    result_h.reset_atom_i_seqs()
    fixed_omega = False
    phi_psi_atoms = utils.get_phi_psi_atoms(moving_h, omega=True)
    assert len(phi_psi_atoms) == len(angles), "%d != %d" % (len(phi_psi_atoms),
                                                            len(angles))
    if not direction_forward:
        phi_psi_atoms.reverse()
        angles.reverse()
    for ps_atoms, target_angle_pair in zip(phi_psi_atoms, angles):
        phi_psi_pair = ps_atoms[0]
        # print "phi_psi_pair", phi_psi_pair
        omega = ps_atoms[2]
        phi_psi_angles = utils.get_pair_angles(phi_psi_pair)
        # print "ps_atoms, target_angle_pair", phi_psi_angles, target_angle_pair
        # phi
        if target_angle_pair[0] is not None and phi_psi_angles[0] is not None:
            rotation_angle = -phi_psi_angles[0] + target_angle_pair[0]
            # print "rot angle", rotation_angle
            # if not direction_forward:
            #   rotation_angle = -rotation_angle
            utils.rotate_atoms_around_bond(result_h,
                                           phi_psi_pair[0][1],
                                           phi_psi_pair[0][2],
                                           angle=rotation_angle,
                                           direction_forward=direction_forward)
        # psi
        if target_angle_pair[1] is not None and phi_psi_angles[1] is not None:
            rotation_angle = -phi_psi_angles[1] + target_angle_pair[1]
            # print "rot angle", rotation_angle
            # if not direction_forward:
            #   rotation_angle = -rotation_angle
            utils.rotate_atoms_around_bond(result_h,
                                           phi_psi_pair[1][1],
                                           phi_psi_pair[1][2],
                                           angle=rotation_angle,
                                           direction_forward=direction_forward)
        # omega
        if omega is not None and abs(abs(omega) - 180) > 10 and check_omega:
            rotation_angle = -omega + 180
            # print "Omega rotation:", omega, rotation_angle
            utils.rotate_atoms_around_bond(result_h,
                                           phi_psi_pair[0][0],
                                           phi_psi_pair[0][1],
                                           angle=rotation_angle,
                                           direction_forward=direction_forward)
            fixed_omega = True
    # print utils.list_rama_outliers_h(result_h)
    # result_h.write_pdb_file(file_name="variant_%s.pdb" % direction_forward)
    # STOP()
    return result_h, fixed_omega
Example #10
0
def get_all_starting_conformations(moving_h,
                                   change_radius,
                                   include_allowed,
                                   n_outliers,
                                   direction_forward=True,
                                   cutoff=50,
                                   change_all=True,
                                   log=null_out(),
                                   check_omega=False):
    if log is None:
        log = StringIO()
    variants = []
    result = []
    r = rama_eval()
    phi_psi_atoms = utils.get_phi_psi_atoms(moving_h, omega=True)
    # print "N residue groups in h", [x.resseq for x in moving_h.residue_groups()]
    if len(phi_psi_atoms) == 0:
        print("Strange input to starting conformations!!!", file=log)
        return result
    n_rama = len(phi_psi_atoms)
    # print "n_rama", n_rama
    change_angles = [None]
    if change_all:
        change_angles = range(
            (n_rama) // 2 - change_radius - n_outliers // 2,
            (n_rama) // 2 + change_radius + 1 + n_outliers // 2)
        # if change_angles[0] < 0:
        #   change_angles = range(change_angles[-1]-change_angles[0])
    has_twisted = False
    if check_omega:
        omegas = [x[2] for x in phi_psi_atoms]
        for o in omegas:
            if o is not None and abs(abs(o) - 180) > 30:
                has_twisted = True
    print("n_outliers", n_outliers, file=log)
    for i, (phi_psi_pair, rama_key, omega) in enumerate(phi_psi_atoms):
        angle_is_outlier = utils.rama_evaluate(
            phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_OUTLIER
        angle_is_outlier = angle_is_outlier or (
            include_allowed and utils.rama_evaluate(
                phi_psi_pair, r, rama_key) == ramalyze.RAMALYZE_ALLOWED)
        twisted = omega is not None and ((abs(abs(omega) - 180) > 30)
                                         and check_omega)
        print("in cycle, N, outlier?, change?, twisted?",
              i,
              angle_is_outlier,
              i in change_angles,
              twisted,
              file=log)
        if angle_is_outlier and n_outliers < 3:
            vs = get_sampled_rama_favored_angles(rama_key, r)
        elif (i in change_angles) or angle_is_outlier or has_twisted:
            # vs = get_sampled_rama_favored_angles(rama_key, r)
            vs = ramalyze.get_favored_regions(rama_key)
        else:
            vs = [(None, None)]
        variants.append(vs)
    print("variants", variants, file=log)

    # Filtering them, since could be
    # [len(x) for x in variants] = [129, 129, 4, 129, 129]
    # resulting in 1107691524 all_angles_combination
    n_comb = numpy.prod([len(x) for x in variants])
    if n_comb > cutoff:
        # still aiming for ~1000
        n_in_each = int(1000**(1 / len(variants)))
        variants = [
            random.sample(x, n_in_each) if len(x) > n_in_each else x
            for x in variants
        ]
    all_angles_combination = list(itertools.product(*variants))
    # filter none combinations
    # print "len(all_angles_combination)", len(all_angles_combination)
    all_angles_combination_f = []
    for comb in all_angles_combination:
        if is_not_none_combination(comb):
            all_angles_combination_f.append(comb)
    print("len(all_angles_combination_f)",
          len(all_angles_combination_f),
          file=log)
    return all_angles_combination_f