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]
Example #2
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 #3
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 #5
0
def exercise_favored_regions():
    assert ramalyze.get_favored_regions(0) == [(-99, 119), (-63, -43),
                                               (53, 43)]
Example #6
0
def exercise_favored_regions():
  assert ramalyze.get_favored_regions(0) == [(-99, 119), (-63, -43), (53, 43)]
Example #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