Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SetReturningPackRotamersMover.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 SetReturningPackRotamersMover.cc
11 /// @brief A pack mover which returns not just the best packer solution, but all nloop solutions.
12 /// @author Ron Jacak
13 
14 // Unit headers
17 
18 // Project headers
23 #include <core/pose/Pose.hh> // need .hh because we create Pose object in apply()
24 
25 #include <ObjexxFCL/format.hh>
26 
27 #include <basic/Tracer.hh>
28 
29 // AUTO-REMOVED #include <basic/options/option.hh>
30 // AUTO-REMOVED #include <basic/options/keys/packing.OptionKeys.gen.hh>
31 
32 #include <utility/exit.hh>
33 #include <utility/vector0.hh>
34 #include <utility/vector1.hh>
35 
36 
37 static basic::Tracer TR("protocols.simple_moves.SetReturningPackRotamersMover");
38 
39 // Utility Headers
40 
41 namespace protocols {
42 namespace simple_moves {
43 
44 using namespace core;
45 using namespace scoring;
46 using namespace pack;
47 
48 
49 // default c'tor
51  protocols::simple_moves::PackRotamersMover()
52 {
53  repacked_poses_.resize( ndruns );
54 }
55 
56 // custom c'tor
58  ScoreFunctionCOP scorefxn,
60  Size ndruns
61 ) :
62  protocols::simple_moves::PackRotamersMover( scorefxn, task, ndruns ),
63  ndruns_(ndruns)
64 {
65  repacked_poses_.resize( ndruns );
66 }
67 
68 
69 //
70 // @begin apply
71 //
72 // @brief
73 // The apply method for SetReturningPackRotamersMover. Assumes that a valid score function and packer task were passed in.
74 // Still makes the best packed pose the returned pose, but also puts all of the repacked poses created in the member variable vector.
75 //
76 void
78 
79  // jec update_residue_neighbors() required to update EnergyGraph (ensures graph_state == GOOD) when calling Interface.cc
81 
82  // guarantee of valid ScoreFunction and PackerTask postponed until now
83  if ( this->score_function() == 0 ) {
84  TR << "undefined ScoreFunction -- creating a default one" << std::endl;
86  }
87 
88  // if present, task_factory_ always overrides/regenerates task_
89  if ( this->task_factory() != 0 ) {
90  this->task( (this->task_factory())->create_task_and_apply_taskoperations( pose ) );
91  } else if ( this->task() == 0 ) {
92  TR << "undefined PackerTask -- creating a default one" << std::endl;
93  this->task( task::TaskFactory::create_packer_task( pose ) );
94  }
95 
96  // in case PackerTask was not generated locally, verify compatibility with pose
97  else runtime_assert( task_is_valid( pose ) );
98 
99  // get rotamers, energies
100  this->setup( pose );
101 
102  core::PackerEnergy best_energy(0.);
103  pose::Pose best_pose;
104  best_pose = pose;
105 
106  // reset the size of ndruns_ to whatever was asked for since this protocols::moves::Mover doesn't query the options system value
107  ndruns_ = repacked_poses_.size();
108 
109  for ( Size run(1); run <= ndruns_; ++run ) {
110  // run SimAnnealer
111  core::PackerEnergy packer_energy( this->run( pose ) );
112  // Real const score( scorefxn_( pose ) ); another option for deciding which is the 'best' result
113  if ( run == 1 || packer_energy < best_energy ) {
114  best_pose = pose;
115  best_energy = packer_energy;
116  }
117  TR << "run " << run << ", packer energy: " << packer_energy << std::endl;
118  repacked_poses_[ run ] = pose;
119 
120  }
121  if ( ndruns_ > 1 )
122  pose = best_pose;
123 }
124 
127  return "SetReturningPackRotamersMover";
128 }
129 
130 
131 //
132 // @begin get_repacked_poses
133 //
134 // @brief
135 // Copies the poses in repacked_poses into the passed in vector reference.
136 //
137 void
139  v = repacked_poses_;
140 }
141 
142 //
143 // @begin output_repacked_poses
144 //
145 // @brief
146 // Writes out all of the poses in the repacked poses vector to PDB files.
147 //
148 void
150 
151  for ( Size ii=1; ii <= repacked_poses_.size(); ++ii ) {
152  // output repacked structure with the vector index in the name
153  std::string filename = filename_prefix + "." + ObjexxFCL::fmt::I( 3, 3, ii ) + ".pdb";
154  repacked_poses_[ ii ].dump_scored_pdb( filename, *(score_function()) );
155  }
156 
157 }
158 
159 
160 } // moves
161 } // protocols
162 
163