示例#1
0
  def run(self):
    # self.states.add(sites_cart=self.moving_h.atoms().extract_xyz())

    phi_psi_atoms = utils.get_phi_psi_atoms(self.moving_h)

    # here we can start a ccd cycle
    self.n_iter = 0
    rmsd_good = 1000
    previous_rmsd = 1000
    self.early_exit = False
    while (rmsd_good > self.needed_rmsd and
        self.n_iter <= self.max_number_of_iterations and not self.early_exit):
      # print_rama_stats(phi_psi_atoms, r)
      # for phi_psi_pair in phi_psi_atoms[:-1]:

      # check rama again separately before the cycle
      # list_rama_outliers(phi_psi_atoms, r)

      for phi_psi_pair, rama_key in phi_psi_atoms:
        before_rama_score = utils.get_rama_score(phi_psi_pair, self.r, rama_key, round_coords=True)
        rama_score = before_rama_score
        # print "rama score:", rama_score, "->",
        for i, atoms in enumerate(phi_psi_pair):
          # current phi-psi angles:
          # find the optimal angle
          ccd_angle = self._find_angle(atoms[1].xyz, atoms[2].xyz)
          # print "phi_psi_angles", phi_psi_angles
          # rama_score = r.evaluate("general", phi_psi_angles)
          # print "rama_score", rama_score
          angle_modified = self.modify_angle_procedure(ccd_angle)

          phi_psi_angles = utils.get_pair_angles(phi_psi_pair)
          before_rotation_rama_score = utils.get_rama_score(phi_psi_pair, self.r, rama_key, round_coords=True)
          if (ramalyze.evalScore(rama_key, before_rotation_rama_score) == RAMALYZE_OUTLIER):
              # or ramalyze.evalScore(rama_key, before_rotation_rama_score) == RAMALYZE_ALLOWED):
            # assert i == 0
            if i != 0:
              # this is a error, we should spot rama outliers on the first angle
              print "i", i
              print pair_info(phi_psi_pair)
              print "rama_key", rama_key
              print "before_rotation_rama_score", before_rotation_rama_score,
              print ramalyze.evalScore(rama_key, before_rotation_rama_score)
              break

            # correct it to the nearest non-outlier region
            target_phi_psi = utils.find_nearest_non_outlier_region(phi_psi_pair, self.r, rama_key)
            # print "For outlier:", phi_psi_angles, target_phi_psi
            # here we want to correct outlier regardless the target function
            # outcome and proceed to the next phi-psi pair
            now_psi_angle0 = utils.get_dihedral_angle(phi_psi_pair[1])
            utils.rotate_atoms_around_bond(self.moving_h, atoms[1], atoms[2],
                angle=-phi_psi_angles[0]+target_phi_psi[0])
            # now psi angle
            now_psi_angle = utils.get_dihedral_angle(phi_psi_pair[1])

            # print "psi angles:", now_psi_angle0, now_psi_angle
            angles_ok = (approx_equal(now_psi_angle0-now_psi_angle, 0) or
                approx_equal(now_psi_angle0-now_psi_angle, 360) or
                approx_equal(now_psi_angle0-now_psi_angle, -360))

            assert angles_ok
            # approx_equal(now_psi_angle0, now_psi_angle)
            # assert now_psi_angle0 == now_psi_angle
            utils.rotate_atoms_around_bond(self.moving_h, atoms[2], atoms[3],
                angle=-now_psi_angle+target_phi_psi[1])

            approx_equal(utils.get_dihedral_angle(phi_psi_pair[0]), target_phi_psi[0])
            approx_equal(utils.get_dihedral_angle(phi_psi_pair[1]), target_phi_psi[1])
            resulting_rama_ev = utils.rama_evaluate(phi_psi_pair, self.r, rama_key)
            assert resulting_rama_ev == RAMALYZE_FAVORED, resulting_rama_ev
            break # we are done with this phi_psi_pair
          # rotate the whole thing around
          utils.rotate_atoms_around_bond(self.moving_h, atoms[1], atoms[2],
              angle=angle_modified)
          after_rotation_rama_score = utils.get_rama_score(phi_psi_pair, self.r, rama_key, round_coords=True)
          # print "before/after rotation rama:", before_rotation_rama_score, after_rotation_rama_score
          # if before_rotation_rama_score > after_rotation_rama_score:
          if ramalyze.evalScore(rama_key, after_rotation_rama_score) == RAMALYZE_OUTLIER:
            # rotate back!!! / not always
            # print "  rotate back"
            if True: # always
              utils.rotate_atoms_around_bond(self.moving_h, atoms[1], atoms[2],
                  angle=-angle_modified)
          s = utils.get_rama_score(phi_psi_pair, self.r, rama_key,round_coords=True)
          assert utils.rama_score_evaluate(rama_key, s) != RAMALYZE_OUTLIER, s

        # new rama score:
        after_rama_score = utils.get_rama_score(phi_psi_pair, self.r, rama_key)
        if after_rama_score + 1e-7 < before_rama_score:
          pass
          # print "before, after", before_rama_score, after_rama_score
          # STOP()

      rmsd_good = utils.get_rmsd(
          self.fixed_ref_atoms,
          [self.moving_h.atoms()[x].xyz for x in self.moving_ref_atoms_iseqs])
      self.resulting_rmsd = rmsd_good
      # print "n_iter, rmsd:", n_iter, rmsd_good,
      # print get_main_chain_rmsd(moving_h, original_h)

      # self.states.add(sites_cart=self.moving_h.atoms().extract_xyz())
      # if n_iter % 100 == 0:
      #   moving_h.write_pdb_file(file_name="int_%d.pdb" % n_iter)
      self.n_iter += 1
      self.early_exit = previous_rmsd - rmsd_good < self.convergence_diff
      previous_rmsd = rmsd_good
示例#2
0
    def run(self):
        # self.states.add(sites_cart=self.moving_h.atoms().extract_xyz())

        phi_psi_atoms = utils.get_phi_psi_atoms(self.moving_h)

        # here we can start a ccd cycle
        self.n_iter = 0
        rmsd_good = 1000
        previous_rmsd = 1000
        self.early_exit = False
        while (rmsd_good > self.needed_rmsd
               and self.n_iter <= self.max_number_of_iterations
               and not self.early_exit):
            # print_rama_stats(phi_psi_atoms, r)
            # for phi_psi_pair in phi_psi_atoms[:-1]:

            # check rama again separately before the cycle
            # list_rama_outliers(phi_psi_atoms, r)

            for phi_psi_pair, rama_key in phi_psi_atoms:
                before_rama_score = utils.get_rama_score(phi_psi_pair,
                                                         self.r,
                                                         rama_key,
                                                         round_coords=True)
                rama_score = before_rama_score
                # print "rama score:", rama_score, "->",
                for i, atoms in enumerate(phi_psi_pair):
                    # current phi-psi angles:
                    # find the optimal angle
                    ccd_angle = self._find_angle(atoms[1].xyz, atoms[2].xyz)
                    # print "phi_psi_angles", phi_psi_angles
                    # rama_score = r.evaluate("general", phi_psi_angles)
                    # print "rama_score", rama_score
                    angle_modified = self.modify_angle_procedure(ccd_angle)

                    phi_psi_angles = utils.get_pair_angles(phi_psi_pair)
                    before_rotation_rama_score = utils.get_rama_score(
                        phi_psi_pair, self.r, rama_key, round_coords=True)
                    if (ramalyze.evalScore(
                            rama_key,
                            before_rotation_rama_score) == RAMALYZE_OUTLIER):
                        # or ramalyze.evalScore(rama_key, before_rotation_rama_score) == RAMALYZE_ALLOWED):
                        # assert i == 0
                        if i != 0:
                            # this is a error, we should spot rama outliers on the first angle
                            print("i", i)
                            print(pair_info(phi_psi_pair))
                            print("rama_key", rama_key)
                            print("before_rotation_rama_score",
                                  before_rotation_rama_score,
                                  end=' ')
                            print(
                                ramalyze.evalScore(rama_key,
                                                   before_rotation_rama_score))
                            break

                        # correct it to the nearest non-outlier region
                        target_phi_psi = utils.find_nearest_non_outlier_region(
                            phi_psi_pair, self.r, rama_key)
                        # print "For outlier:", phi_psi_angles, target_phi_psi
                        # here we want to correct outlier regardless the target function
                        # outcome and proceed to the next phi-psi pair
                        now_psi_angle0 = utils.get_dihedral_angle(
                            phi_psi_pair[1])
                        utils.rotate_atoms_around_bond(
                            self.moving_h,
                            atoms[1],
                            atoms[2],
                            angle=-phi_psi_angles[0] + target_phi_psi[0])
                        # now psi angle
                        now_psi_angle = utils.get_dihedral_angle(
                            phi_psi_pair[1])

                        # print "psi angles:", now_psi_angle0, now_psi_angle
                        angles_ok = (approx_equal(
                            now_psi_angle0 - now_psi_angle, 0) or approx_equal(
                                now_psi_angle0 - now_psi_angle, 360)
                                     or approx_equal(
                                         now_psi_angle0 - now_psi_angle, -360))

                        assert angles_ok
                        # approx_equal(now_psi_angle0, now_psi_angle)
                        # assert now_psi_angle0 == now_psi_angle
                        utils.rotate_atoms_around_bond(self.moving_h,
                                                       atoms[2],
                                                       atoms[3],
                                                       angle=-now_psi_angle +
                                                       target_phi_psi[1])

                        approx_equal(utils.get_dihedral_angle(phi_psi_pair[0]),
                                     target_phi_psi[0])
                        approx_equal(utils.get_dihedral_angle(phi_psi_pair[1]),
                                     target_phi_psi[1])
                        resulting_rama_ev = utils.rama_evaluate(
                            phi_psi_pair, self.r, rama_key)
                        assert resulting_rama_ev == RAMALYZE_FAVORED, resulting_rama_ev
                        break  # we are done with this phi_psi_pair
                    # rotate the whole thing around
                    utils.rotate_atoms_around_bond(self.moving_h,
                                                   atoms[1],
                                                   atoms[2],
                                                   angle=angle_modified)
                    after_rotation_rama_score = utils.get_rama_score(
                        phi_psi_pair, self.r, rama_key, round_coords=True)
                    # print "before/after rotation rama:", before_rotation_rama_score, after_rotation_rama_score
                    # if before_rotation_rama_score > after_rotation_rama_score:
                    if ramalyze.evalScore(
                            rama_key,
                            after_rotation_rama_score) == RAMALYZE_OUTLIER:
                        # rotate back!!! / not always
                        # print "  rotate back"
                        if True:  # always
                            utils.rotate_atoms_around_bond(
                                self.moving_h,
                                atoms[1],
                                atoms[2],
                                angle=-angle_modified)
                    s = utils.get_rama_score(phi_psi_pair,
                                             self.r,
                                             rama_key,
                                             round_coords=True)
                    assert utils.rama_score_evaluate(rama_key,
                                                     s) != RAMALYZE_OUTLIER, s

                # new rama score:
                after_rama_score = utils.get_rama_score(
                    phi_psi_pair, self.r, rama_key)
                if after_rama_score + 1e-7 < before_rama_score:
                    pass
                    # print "before, after", before_rama_score, after_rama_score
                    # STOP()

            rmsd_good = utils.get_rmsd(self.fixed_ref_atoms, [
                self.moving_h.atoms()[x].xyz
                for x in self.moving_ref_atoms_iseqs
            ])
            self.resulting_rmsd = rmsd_good
            # print "n_iter, rmsd:", n_iter, rmsd_good,
            # print get_main_chain_rmsd(moving_h, original_h)

            # self.states.add(sites_cart=self.moving_h.atoms().extract_xyz())
            # if n_iter % 100 == 0:
            #   moving_h.write_pdb_file(file_name="int_%d.pdb" % n_iter)
            self.n_iter += 1
            self.early_exit = previous_rmsd - rmsd_good < self.convergence_diff
            previous_rmsd = rmsd_good