Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerBoltzCalculator.cc
Go to the documentation of this file.
1 
2 /// @file protocols/toolbox/PoseMetricCalculators/RotamerBoltzCalculator.cc
3 /// @brief Calculates Rotamer occupancy of each rotameric state in a given set of residues.
4 /// @author Hetu Kamisetty
6 #include <utility/stream_util.hh>
7 #include <basic/MetricValue.hh>
8 #include <basic/Tracer.hh>
9 #include <basic/prof.hh>
11 // AUTO-REMOVED #include <core/conformation/Residue.hh>
12 #include <core/graph/Graph.hh>
20 #include <core/pose/Pose.hh>
21 #include <core/types.hh>
22 // AUTO-REMOVED #include <protocols/rosetta_scripts/util.hh>
27 
28 #include <utility/string_util.hh>
29 #include <utility/vector0.hh>
30 #include <utility/vector1.hh>
31 #include <cmath>
32 #include <boost/foreach.hpp>
33 
34 //Auto Headers
36 #define foreach BOOST_FOREACH
37 namespace protocols{
38 namespace toolbox {
39 namespace pose_metric_calculators {
41  //pose_ = pose;
43  //mm_ = new core::kinematics::MoveMap;
44  temperature(temp);
45  rb_jump_ = 1;
46  repacking_radius(repack_rad);
47 
48  }
49 
52  for(Size i=1;i<pose.total_residue(); i++){
53  allboltz.push_back(computeBoltzWeight(pose, i));
54  }
55  all_boltz_ = allboltz;
56  return allboltz;
57  }
59  core::pack::task::PackerTaskOP task = init_task(pose,resi);
60  protocols::simple_moves::MinMoverOP mm = init_minmover(pose, resi, true, task);
61  return computeBoltzWeight(pose, resi, mm, task);//assume unbound
62  }
64  ///user doesn't have movemap, so can't initialize min_mover himself right now.
65 
66  //core::pose::Pose& pose = pose();
67  //std::cout<<" in rotamer boltz calculator with resi "<<resi<<std::endl;
68  using namespace protocols::moves;
69  using namespace core::pack::rotamer_set;
70  using namespace core::pack::task;
71  using namespace core::conformation;
73  task->set_bump_check(false);
74  pmover.task(task);
75  pmover.call_setup(pose);
77  //std::cout<<" in rotamer boltz done with call_setup "<<resi<<std::endl;
78  pmover.apply(pose);//what happens if setup and apply are called with different poses?
79  min_mover->apply( pose );
80  core::pose::Pose const const_min_pose( pose );
81  core::Real const init_score( stf.compute( const_min_pose ) );
82 
83  RotamerSetsCOP rotsets = pmover.rotamer_sets();
84  Size moltenResid = rotsets->resid_2_moltenres(resi);
86  utility::vector0<int> rot_to_pack;
87 
88 
89  /*
90  std::cout<<" num rotamers acc to rotsets "<<rotsets->nrotamers_for_moltenres(moltenResid)<<std::endl;
91  std::cout<<" num rotamers acc to this "<<rotset_->num_rotamers()<<std::endl;
92  RotamerSetCOP rset = rotsets->rotamer_set_for_residue(resi);
93  for(Size i=1;i<=rotset_->num_rotamers(); i++){
94  ResidueCOP r = rotset_->rotamer(i);
95  //std::cout<<i<<"th rotamer acc to this "<<r->type()<<std::endl;
96  utility::vector1<core::Real> chi = r->chi();
97  for(Size j=1;j<=chi.size(); j++){
98  std::cout<<j<<"th chi acc to "<<i<<"th rotamer is "<<chi.at(j)<<std::endl;
99  }
100  }
101  for(Size i=1;i<=rset->num_rotamers(); i++){
102  ResidueCOP r = rset->rotamer(i);
103  utility::vector1<core::Real> chi = r->chi();
104  for(Size j=1;j<=chi.size(); j++){
105  std::cout<<j<<"th chi acc to "<<i<<"th rotamer is "<<chi.at(j)<<std::endl;
106  }
107  }
108  */
109 
110  for(Size i=1;i<rotset_->num_rotamers(); i++){
111  core::pose::Pose pose = const_min_pose;
112  PROF_START(basic::TEST3);
113  rot_to_pack = init_rot_to_pack(rotsets, moltenResid, i);
114  pmover.apply_to_rotpack(pose, rot_to_pack);
115  min_mover->apply( pose );
116  PROF_STOP(basic::TEST3);
117  core::Real const score( stf.compute( pose ) );
118  scores.push_back( score );
119  }
120  return computeBoltzSum(init_score, scores);
121  //gives rot_to_pack where entry is rotameric id into rotamersets
122  }
123  /*RotamerBoltzCalculator::RotamerBoltzCalculator(Pose& pose, utility::vector0<int> moltres_to_pack, utility::vector0<int> rotid_in_moltres, core::Real temp){//gives rotamer id into rotamerset for each position of interest.
124  }
125  */
126 
128  using namespace core::pack::task;
129  using namespace core::pack::rotamer_set;
130  using namespace core::conformation;
131 
132  Residue const & res = pose.residue( resi );
133  RotamerSetFactory rsf;
134  rotset_ = rsf.create_rotamer_set( res );
135  rotset_->set_resid( resi );
136 
139  PackerTaskOP ptask( tf->create_task_and_apply_taskoperations( pose ) );
140  ResidueLevelTask & restask( ptask->nonconst_residue_task( resi ) );
141  restask.restrict_to_repacking();///hmk: what is this doing?
142  core::graph::GraphOP packer_graph = new core::graph::Graph( pose.total_residue() );
143  ptask->set_bump_check(false);
144  rotset_->build_rotamers( pose, *scorefxn_, *ptask, packer_graph, false );
145 
146  /// des_around will mark all residues around resi for design, the rest for packing.
148  des_around->design_shell( repacking_radius() );
149  des_around->include_residue( resi );
150  tf->push_back( des_around );
151  PackerTaskOP task = tf->create_task_and_apply_taskoperations( pose );
152  return task;
153  }
155  using namespace core::conformation;
156 
158 
159  mm->set_bb( false );
160  if( unbound ) // the complex was split, don't minimize rb dof
161  mm->set_jump( false );
162  else // minimize rb if bound
163  mm->set_jump( (int)(rb_jump()), true );
164  for( core::Size i=1; i<=pose.total_residue(); ++i ){
165  if( task->being_designed( i ) ){
166  task->nonconst_residue_task( i ).restrict_to_repacking(); // mark all des around to repacking only
167  mm->set_chi( i, true );
168  }
169  else{
170  task->nonconst_residue_task( i ).prevent_repacking(); /// mark all non-desaround positions for no repacking
171  //task->nonconst_residue_task( i ).restrict_to_repacking();
172  mm->set_chi( i, false );
173  }
174  }
175  //task->nonconst_residue_task( resi ).prevent_repacking();
176 
178  min_mover->score_function( scorefxn() );
179  min_mover->movemap( mm );
180  min_mover->min_options()->min_type( "dfpmin_armijo_nonmonotone" );
181  return min_mover;
182  }
183 
184 
186  core::Real boltz_sum ( 0.0 );
187  foreach( core::Real const score, scores )
188  boltz_sum += exp(( init_score - score )/temperature());
189 
190  return( 1/boltz_sum );
191  }
192 
193  void RotamerBoltzCalculator::lookup( std::string const & key, basic::MetricValueBase * valptr ) const{
194  if ( key == "boltz" ) {
195  basic::check_cast( valptr, &all_boltz_, "boltz expects to return a util:vector1<real>" );
196  (static_cast<basic::MetricValue<utility::vector1< core::Real > > *>(valptr))->set( all_boltz_ );
197 
198  } else {
199  basic::Error() << "This Calculator cannot compute metric " << key << std::endl;
200  utility_exit();
201  }
202 
203  }
205  if ( key == "boltz" ) {
206  return utility::to_string(all_boltz_);
207  }
208  else{
209  return "error";
210  }
211  }
213 
214  core::pose::Pose cpose = this_pose;
215  computeAllBoltz(cpose);
216  }
218  utility::vector0 < int > rot_to_pack;
219  rot_to_pack.reserve( rotamer_sets->nrotamers() );
220  ///for ( Size rot = 1; rot <= num_rots_to_pack(); ++rot ) {
221  for ( Size rot = 1; rot <= rotamer_sets->nrotamers(); ++rot ) {
222  core::Size this_moltenres = rotamer_sets->moltenres_for_rotamer(rot);
223  core::Size this_rotid = rotamer_sets->rotid_on_moltenresidue(rot);
224  if(this_moltenres ==moltenres && !(this_rotid==rot_to_fix)){
225  continue;
226  }else{
227  rot_to_pack.push_back( rot );
228  }
229  }
230  return rot_to_pack;
231  }
232 
233 
234 }//pose_metrics
235 }//toolbox
236 }//protocols