Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SwitchResidueTypeSet.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 sw=2 noet:
3 //
4 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file core/util/SwitchResidueTypeSet.cc
10 /// @brief Functions for switching the residue type set of a pose
11 /// @author P. Douglas Renfrew (renfrew@nyu.edu)
12 
13 // Unit Headers
15 
16 // Project Headers
20 
21 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
24 
25 #include <core/pose/Pose.hh>
26 
29 #include <core/scoring/Energies.hh>
30 
32 
35 
37 
38 // Basic Headers
39 #include <basic/Tracer.hh>
40 
41 // Option Headers
42 #include <basic/options/option.hh>
43 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
44 #include <basic/options/keys/run.OptionKeys.gen.hh>
45 
46 #include <utility/vector1.hh>
47 
48 //Auto Headers
50 #include <core/kinematics/Jump.hh>
51 
52 
53 
54 
55 namespace core {
56 namespace util {
57 
58 static basic::Tracer TR("core.util.switchresiduetypeset");
59 
60 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 ///@details the function allows a pose to use a different residue_type_set to represent all its residues,
62 ///such as from fullatom residues to centroid residues, or vice versa. During the switch, corresponding atoms
63 ///will be copied. Redundant atoms will be removed (in case from fullatom to centroid) and missing atoms will be
64 ///built by ideal geometry (in the case from centroid to fullatom).
65 void
67  core::pose::Pose & pose,
68  std::string const & type_set_name,
69  bool allow_sloppy_match
70  )
71 {
72  using namespace core::chemical;
73  using namespace core::conformation;
74  using namespace std;
75  using utility::vector1;
76 
77  //SML 04/06/09
78  //Energies object is not properly "aware" of typeset changes, and can attempt to score your pose with an incompatible
79  //scorefunction if you go FA->CEN (or vice versa) and access the Energies without rescoring.
80  //So, we'll eject the Energies to be safe!
81  pose.energies().clear();
82 
83 
84  // retrieve proper residue_type_set
85  core::chemical::ResidueTypeSetCAP target_residue_type_set( core::chemical::ChemicalManager::get_instance()->residue_type_set( type_set_name ) );
86  // loop each position and find new type that matches from the new type set
87  for ( core::Size i=1; i<= pose.total_residue(); ++i ) {
88  core::conformation::Residue const & rsd( pose.residue(i) );
89  // in future we may have a conformation using mixed type set, so check this by residue
90  std::string const & current_type_set_name ( rsd.type().residue_type_set().name() ); // database_directory() );
91  if ( current_type_set_name == type_set_name ) {
92  TR.Warning << "core::util::switch_to_residue_type_set: residue " << i << " already in " << type_set_name
93  << " residue_type_set" << std::endl;
94  continue;
95  }
96 
97  // get all residue types with same AA
98 
99  core::conformation::ResidueOP new_rsd( 0 );
100  if( ( rsd.aa() == aa_unk ) || ( rsd.name().substr(0,5) == "HIS_D" ) ){
101  // ligand or metal ions are all defined as "UNK" AA, so check a rsdtype with same name
102  // for HIS_D tautomer, we want to keep its tautomer state
103  core::chemical::ResidueTypeCOPs const & rsd_types( target_residue_type_set->name3_map( rsd.name3() ) );
104  for (core::Size j=1; j<=rsd_types.size(); ++j ) {
105  core::chemical::ResidueType const & new_rsd_type( *rsd_types[j] );
106  if ( rsd.type().name() == new_rsd_type.name() ) {
107  new_rsd = core::conformation::ResidueFactory::create_residue( new_rsd_type, rsd, pose.conformation() );
108  break;
109  }
110  }
111  } else {
112  // for a normal AA/DNA/RNA residue, now look for a rsdtype with same variants
113  core::chemical::ResidueTypeCOPs const & rsd_types( target_residue_type_set->name3_map( rsd.name().substr(0,3) ) );
114  for ( core::Size j=1; j<= rsd_types.size(); ++j ) {
115  core::chemical::ResidueType const & new_rsd_type( *rsd_types[j] );
116  if ( rsd.type().variants_match( new_rsd_type ) ) {
117  new_rsd = core::conformation::ResidueFactory::create_residue( new_rsd_type, rsd, pose.conformation() );
118  break;
119  }
120  }
121  if ( allow_sloppy_match ){
122  if ( ! new_rsd ) {
123  TR.Warning << "Did not find perfect match for residue: " << rsd.name()
124  << "at position " << i << ". Trying to find acceptable match. " << std::endl;
125  for ( core::Size j=1; j<= rsd_types.size(); ++j ) {
126  core::chemical::ResidueType const & new_rsd_type( *rsd_types[j] );
127  if ( rsd.type().name3() == new_rsd_type.name3() ) {
128  new_rsd = core::conformation::ResidueFactory::create_residue( new_rsd_type, rsd, pose.conformation() );
129  break;
130  }
131  }
132  if ( new_rsd ) {
133  TR.Warning << "Found an acceptable match: " << rsd.type().name() << " --> " << new_rsd->name() << std::endl;
134  }
135  }
136  }
137  }
138 
139  if ( ! new_rsd ) {
140  std::cerr << pose.sequence() << std::endl;
141  std::cerr << "can not find a residue type that matches the residue " << rsd.name()
142  << "at position " << i << std::endl;
143  utility_exit_with_message( "core::util::switch_to_residue_type_set fails\n" );
144  }
145  // switch to corresponding residue type in the new set.
146  if ( !rsd.is_protein() ) {
147  // rethink this logic, phil
148  TR.Debug << "trying to preserve existing coords for non-protein residue: " << rsd.seqpos() << ' ' << rsd.name() << std::endl;
150  }
151  pose.replace_residue( i, *new_rsd, false );
152  }
153 
154  // After a CEN->FA transition, rebuild the disulfides
155  if(pose.is_fullatom() && basic::options::option[ basic::options::OptionKeys::run::rebuild_disulf ]() ) {
158 
159  if( disulfides.size() > 0 ) {
160  // Setup Packer & Minimizer
162  task->initialize_from_command_line().or_include_current( true );
163  task->restrict_to_repacking();
164 
166  mm->set_bb( false );
167 
168  // Set up each residue individually
169  for( core::Size i(1); i <= pose.total_residue(); ++i )
170  {
171  core::conformation::Residue const& res(pose.residue(i));
172  if( !res.is_protein() )
173  continue;
174 
175  // Determine if i is part of disulfides
176  bool is_disulf = false;
177  for(vector1<pair<core::Size, core::Size> >::const_iterator
178  disulf(disulfides.begin()), end_disulf(disulfides.end());
179  disulf != end_disulf; ++disulf)
180  {
181  if( i == disulf->first || i == disulf->second ) {
182  is_disulf = true;
183  break;
184  }
185  }
186 
187  if( is_disulf ) {
188  // repack & minimize disulfides
189  mm->set_chi(i, true);
190  } else {
191  // Other residues are unchanged
192  task->nonconst_residue_task(i).prevent_repacking();
193  }
194  }
195 
196  // Rebuild disulfides
197  core::util:: rebuild_disulfide(pose, disulfides, task, NULL, mm, NULL);
198  }
199  }
200 }
201 
202 
203 } // util
204 } // core