Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RigidBodyMoveRotSetOps.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 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/toolbox/RotamerSetOperations/RigidBodyMoveRotSetOps.cc
11 /// @brief classes for rigid body movement during rotamer packing
12 /// @author Florian Richter, floric@u.washington.edu, sep 2009
13 
14 // Unit Headers
16 
17 //Project headers
19 #include <core/graph/Graph.hh>
23 #include <core/pose/Pose.hh>
25 #include <core/scoring/Energies.hh>
27 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
28 #include <basic/Tracer.hh>
29 
30 #include <utility/vector1.hh>
31 
32 
33 namespace protocols {
34 namespace toolbox {
35 namespace rotamer_set_operations {
36 
37 static basic::Tracer tr("protocols.toolbox.RotamerSetOperations.RigidBodyMoveRotSetOps");
38 
39 void
41  core::pose::Pose const & pose,
42  core::scoring::ScoreFunction const & sfxn,
43  core::pack::task::PackerTask const & ptask,
44  core::graph::GraphCOP packer_neighbor_graph,
46 ){
47  using namespace core::pack::rotamer_set;
48 
49  if (rotamer_set.get_n_residue_types() != 1)
50  {
51  tr.Debug << "alter_rotamer_set with multiple rotamer types in source set: " << rotamer_set.get_n_residue_types() << std::endl;
52  }
53 
54  if (ptask.being_designed(rotamer_set.resid()))
55  {
56  tr.Error << "alter_rotamer_set called at designed position: " << rotamer_set.resid() << std::endl;
57  }
58 
59 
60  // Get sequence position for the rotamer set.
61  core::Size sequence_position = rotamer_set.resid();
62 
63  // Generate list of alternate RB confs.
65  get_rigid_body_confs(pose, ptask, sequence_position);
66 
67  tr.Debug << "At seqpos " << sequence_position << " generated " << rigid_body_confs.size() << " alternate rb conformations." << std::endl;
68 
69  if (rigid_body_confs.size() == 0 ) return;
70 
72 
73  // Initialize residuetype
74  core::chemical::ResidueTypeCOP concrete_residue;
75  if( rotamer_set.num_rotamers() != 0 )
76  {
77  concrete_residue = (*rotamer_set.begin())->type();
78  }
79  else
80  {
81  concrete_residue = pose.residue( sequence_position ).type();
82  }
83 
84  for (core::Size i = 1; i <= rigid_body_confs.size(); i++)
85  {
86  runtime_assert( rigid_body_confs[i]->name3() == pose.residue( sequence_position ).name3() );
87  }
88 
89  // Check casting once
90  bool cast_succesful( dynamic_cast< core::pack::rotamer_set::RotamerSet_ * > (& rotamer_set) );
91 
92  //we need a couple of things analogous to RotamerSet_::build_rotamers_for_concrete
93  //some code duplication for now, maybe this can be moved to a common function
94  //1. Regenerate chi sampling information for the rotamer set
95  utility::vector1< utility::vector1< core::Real > > extra_chi_steps( concrete_residue->nchi() );
96  int nneighbs( pose.energies().tenA_neighbor_graph().get_node( sequence_position )->num_neighbors_counting_self() );
97  bool buried( nneighbs >= int(ptask.residue_task( sequence_position ).extrachi_cutoff()) );
98  if( cast_succesful ) {
99  core::pack::rotamer_set::RotamerSet_ & rotset ( static_cast< core::pack::rotamer_set::RotamerSet_ & > (rotamer_set) );
100  for ( Size ii = 1; ii <= concrete_residue->nchi(); ++ii ) {
101  rotset.set_extra_samples( ptask, nneighbs, ii, concrete_residue, extra_chi_steps[ ii ] );
102  }
103  }
104  //RotamerSet_ duplicate lines over
105 
106  // Attempt to create rotamer library for the given type.
109 
110  if(rotlib)
111  {
112  tr.Debug << "At seqpos " << sequence_position << " retrieved rotamer library." << std::endl;
113  }
114  else
115  {
116  tr.Debug << "At seqpos " << sequence_position << " no rotamer library." << std::endl;
117  }
118 
120 
121  for( core::Size i = 1; i <= rigid_body_confs.size(); ++i )
122  {
123  //let's make sure the residue used to create the rotamer
124  //has the same connections as currently in the pose
125  core::conformation::Residue existing_residue( *rigid_body_confs[i] );
126  existing_residue.copy_residue_connections_from( pose.residue( sequence_position ) );
127  utility::vector1< core::conformation::ResidueOP > suggested_rotamers_this_rbconf;
128 
129  // Generate full list of candidate rotamers at the rb conf if a rotamer library is available
130  // otherwise just add the additional rb conf.
131  if( rotlib )
132  {
133  rotlib->fill_rotamer_vector( pose, sfxn, ptask, packer_neighbor_graph, concrete_residue, existing_residue, extra_chi_steps, buried, suggested_rotamers_this_rbconf);
134  }
135  else
136  {
137  //TODO fordas Loop through the initialized rotamer set instead of the pose orientation?
138  core::conformation::ResidueOP currot( new core::conformation::Residue( pose.residue( sequence_position ) ) );
139  currot->orient_onto_residue( existing_residue );
140  suggested_rotamers_this_rbconf.push_back( currot );
141  }
142 
143  // Prune rotamer list with bump check if needed, otherwise add all candidate rotamers
144  for( core::Size j = 1; j<= suggested_rotamers_this_rbconf.size(); ++j )
145  {
146  core::conformation::ResidueOP new_rot = suggested_rotamers_this_rbconf[j];
147 
148  if( ptask.bump_check() && cast_succesful )
149  {
150  core::pack::rotamer_set::RotamerSet_ & rotset ( static_cast< core::pack::rotamer_set::RotamerSet_ & > (rotamer_set) );
151  core::PackerEnergy bumpenergy = rotset.bump_check( new_rot, sfxn, pose, ptask, packer_neighbor_graph );
153  switch ( decision ) {
154  case KEEP_ROTAMER :
155  new_rots.push_back( new_rot );
156  break;
158  runtime_assert ( new_rots.size() > 0 );
159  new_rots[ new_rots.size() ] = new_rot;
160  break;
161  case DELETE_ROTAMER : // do nothing
162  break;
163  }
164  }
165  else
166  {
167  new_rots.push_back( new_rot );
168  }
169  }// loop over suggested rotamers
170  } //loop over rigid body confs
171 
172  //finally, add the new rotamers
173  for( core::Size i = 1; i <= new_rots.size(); ++i)
174  {
175  rotamer_set.add_rotamer( *new_rots[i] );
176  }
177 
178  tr.Debug <<
179  "At seqpos " << sequence_position << " " <<
180  new_rots.size() << " rotamers were added to rotamer set that now contains " <<
181  rotamer_set.num_rotamers() << " rotamers." << std::endl;
182 }
183 
184 
187  core::pose::Pose const & pose,
188  core::pack::task::PackerTaskCOP task, //the_task
189  core::Size residue_index)
190 {
192  pose.residue( residue_index ),
193  get_rigid_body_confs(pose, *task, residue_index) );
194 }
195 
198  core::conformation::Residue const & target_res,
200 {
201  if( alternate_confs.size() > 0 )
202  {
203  runtime_assert( target_res.name3() == alternate_confs[1]->name3() );
204  }
205 
206  Size nbr_atom( target_res.nbr_atom() );
207  core::PointPosition center_pos( target_res.xyz( nbr_atom ) );
208  core::Real max_sq_dist(0.0);
209  for( Size i = 1; i <= alternate_confs.size(); ++i){
210  core::Vector dist_vect( center_pos - alternate_confs[i]->xyz( nbr_atom ) );
211  core::Real sq_dist( dist_vect.length_squared() );
212  if( sq_dist > max_sq_dist ) max_sq_dist = sq_dist;
213  }
214 
215  return std::sqrt( max_sq_dist );
216 }
217 
219  : parent(),
220  seqpos_(seqpos)
221 {
222  rigid_body_confs_.clear();
223 }
224 
226  : parent( other ),
227  seqpos_(other.seqpos_),
228  rigid_body_confs_(other.rigid_body_confs_)
229 {}
230 
233  return new RigidBodyMoveRSO( *this );
234 }
235 
238  core::pose::Pose const & /*pose*/,
239  core::pack::task::PackerTask const & /*ptask*/,
240  core::Size residue_index)
241 {
242  runtime_assert(residue_index == seqpos_);
243 
244  return rigid_body_confs_;
245 }
246 
247 void
250 {
251  rigid_body_confs_ = rigid_body_confs;
252 }
253 
254 } //namespace protocols
255 } //namespace toolbox
256 } //namespace rotamer_set_operations
257 
258