Ejemplo n.º 1
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
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]
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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.default_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,
        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 = ss_manager.selection_cache.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:
      rama_score = get_rama_score(phi_psi_pair, self.r, rama_key)
      if rama_evaluate(phi_psi_pair, self.r, rama_key) == ramalyze.RAMALYZE_OUTLIER:
        n_outliers += 1
      else:
        reg = gather_ss_stats.helix_sheet_rama_region(phi_psi_pair)
        if (reg == 1 and not helix) or (reg == 2 and helix):
          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_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]
Ejemplo n.º 7
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