def get_resnums_of_chain_rama_outliers(self, pdb_hierarchy): phi_psi_atoms = utils.get_phi_psi_atoms(pdb_hierarchy, omega=True) # pdb_hierarchy.write_pdb_file(file_name="phi_psi_atoms.pdb") # print "len phi psi atoms", len(phi_psi_atoms) result = [] rama_results = [] ranges_for_idealization = [] # print >> self.log, "rama outliers for input hierarchy:" list_of_reference_exclusion = [] outp = utils.list_rama_outliers_h(pdb_hierarchy, self.r) print >> self.log, outp for phi_psi_pair, rama_key, omega in phi_psi_atoms: if phi_psi_pair[0] is not None and phi_psi_pair[1] is not None: # print "resseq:", phi_psi_pair[0][2].parent().parent().resseq ev = utils.rama_evaluate(phi_psi_pair, self.r, rama_key) # print " ev", ev rama_results.append(ev) # print phi_psi_pair[0][0].id_str() resnum = phi_psi_pair[0][2].parent().parent().resseq if ev == ramalyze.RAMALYZE_OUTLIER: result.append(resnum) if omega is not None and abs(abs(omega)-180) > 30: print >> self.log, "Spotted twisted/cis peptide:", resnum, omega result.append(resnum) # STOP() return result
def get_resnums_of_chain_rama_outliers(self, pdb_hierarchy): phi_psi_atoms = utils.get_phi_psi_atoms(pdb_hierarchy) # print "len phi psi atoms", len(phi_psi_atoms) result = [] rama_results = [] ranges_for_idealization = [] # print >> self.log, "rama outliers for input hierarchy:" list_of_reference_exclusion = [] outp = utils.list_rama_outliers_h(pdb_hierarchy, self.r) print >>self.log, outp for phi_psi_pair, rama_key in phi_psi_atoms: # print "resseq:", phi_psi_pair[0][2].parent().parent().resseq ev = utils.rama_evaluate(phi_psi_pair, self.r, rama_key) # print " ev", ev rama_results.append(ev) if ev == ramalyze.RAMALYZE_OUTLIER: resnum = phi_psi_pair[0][2].parent().parent().resseq result.append(resnum) return result
def get_resnums_of_chain_rama_outliers(self, pdb_hierarchy): phi_psi_atoms = utils.get_phi_psi_atoms(pdb_hierarchy) # print "len phi psi atoms", len(phi_psi_atoms) result = [] rama_results = [] ranges_for_idealization = [] # print >> self.log, "rama outliers for input hierarchy:" list_of_reference_exclusion = [] outp = utils.list_rama_outliers_h(pdb_hierarchy, self.r) print >> self.log, outp for phi_psi_pair, rama_key in phi_psi_atoms: # print "resseq:", phi_psi_pair[0][2].parent().parent().resseq ev = utils.rama_evaluate(phi_psi_pair, self.r, rama_key) # print " ev", ev rama_results.append(ev) if ev == ramalyze.RAMALYZE_OUTLIER: resnum = phi_psi_pair[0][2].parent().parent().resseq result.append(resnum) return result
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
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
def run(self, direction_forward=True, save_states=False, avoid_allowed_region=False): if save_states: self.states = mmtbx.utils.states(pdb_hierarchy=self.moving_h) self.states.add(sites_cart=self.moving_h.atoms().extract_xyz()) phi_psi_atoms = utils.get_phi_psi_atoms(self.moving_h) if not direction_forward: phi_psi_atoms.reverse() # here we can start a ccd cycle self.n_iter = 0 rmsd_good = 1000 previous_rmsd = 1000 self.early_exit = False # self.moving_h.write_pdb_file(file_name="start_ccd.pdb") 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 if atoms is None: continue if direction_forward: ccd_angle = self._find_angle(atoms[1].xyz, atoms[2].xyz) else: ccd_angle = self._find_angle(atoms[2].xyz, atoms[1].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(ccd_angle) # angle_modified = ccd_angle # print (" ccd_angle", ccd_angle, angle_modified) # angle_modified = - angle_modified phi_psi_angles = utils.get_pair_angles(phi_psi_pair) # print "phi_psi_angles", phi_psi_angles 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 (avoid_allowed_region and 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], direction_forward=direction_forward) # 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, eps=1e-4, out=null_out()) or approx_equal(now_psi_angle0 - now_psi_angle, 360, eps=1e-4, out=null_out()) or approx_equal(now_psi_angle0 - now_psi_angle, -360, eps=1e-4, out=null_out())) if not angles_ok: approx_equal(now_psi_angle0 - now_psi_angle, 0, eps=1e-4) approx_equal(now_psi_angle0 - now_psi_angle, 360, eps=1e-4) approx_equal(now_psi_angle0 - now_psi_angle, -360, eps=1e-4) 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], direction_forward=direction_forward) # 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) # print "evaluation:", resulting_rama_ev, RAMALYZE_FAVORED 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, direction_forward=direction_forward) 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: eval_score_after_rotation = ramalyze.evalScore( rama_key, after_rotation_rama_score) if eval_score_after_rotation == RAMALYZE_OUTLIER or \ eval_score_after_rotation == RAMALYZE_ALLOWED: # 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, direction_forward=direction_forward) 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 if avoid_allowed_region: assert utils.rama_score_evaluate( rama_key, s) != RAMALYZE_ALLOWED, "%s, %s" % ( s, after_rotation_rama_score) # 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_xyz_fixed(self.fixed_ref_atoms, [ self.moving_h.atoms()[x] for x in self.moving_ref_atoms_iseqs ]) self.resulting_rmsd = rmsd_good # print "n_iter, rmsd:", self.n_iter, rmsd_good # print get_main_chain_rmsd(moving_h, original_h) if save_states: 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 = abs(previous_rmsd - rmsd_good) < self.convergence_diff # if self.early_exit: # print " Early exit:", self.early_exit, previous_rmsd - rmsd_good previous_rmsd = rmsd_good