Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RemodelAccumulator.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/forge/remodel/RemodelLoopMover.cc
11 /// @brief Loop modeling protocol based on routines from Remodel and EpiGraft
12 /// packages in Rosetta++.
13 /// @author Possu Huang (possu@u.washington.edu)
14 
15 // unit headers
18 
19 // package headers
20 
21 // project headers
22 #include <basic/Tracer.hh>
24 #include <basic/options/keys/remodel.OptionKeys.gen.hh>
25 #include <basic/options/keys/cluster.OptionKeys.gen.hh>
26 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
29 #include <basic/options/option.hh>
30 #include <fstream>
31 #include <sys/stat.h>
32 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
33 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
35 // AUTO-REMOVED #include <protocols/forge/build/BuildInstruction.hh> // REQUIRED FOR WINDOWS
36 
37 #include <utility/vector1.hh>
38 
39 //Auto Headers
41 
42 
43 // numeric headers
44 
45 // boost headers
46 
47 // C++ headers
48 //#include <string>
49 
50 
51 namespace protocols {
52 namespace forge {
53 namespace remodel{
54 
55 // Tracer instance for this file
56 // Named after the original location of this code
57 static basic::Tracer TR( "protocols.forge.remodel.RemodelAccumulator" );
58 
59 // RNG
60 //static numeric::random::RandomGenerator RG( 9788221 ); // magic number, don't change
61 
62 
63 /// @brief default constructor
65  cluster_switch_ = basic::options::option[basic::options::OptionKeys::remodel::use_clusters];
66 }
67 
68 /// @brief value constructor
70  //check clustering info
71  cluster_switch_ = basic::options::option[basic::options::OptionKeys::remodel::use_clusters];
72 
73  //remodel_data_ = remodeldata;
74  working_model_ = working_model;
75 
76 }
77 
78 /// @brief copy constructor
79 
80 /// @brief default destructor
82 
83 /// @brief clone this object
85  return new RemodelAccumulator( *this );
86 }
87 
88 
89 /// @brief create this type of object
91  return new RemodelAccumulator();
92 }
93 
95  using namespace core::scoring;
96  using namespace protocols::simple_filters;
97  using namespace basic::options;
98 
99 //make the object's own collection of poses
100  core::pose::PoseOP pose_pt = new core::pose::Pose( pose );
101 
103  sfxn_ = score12;
104 
105  ScoreTypeFilter const pose_total_score( score12, total_score, 100 );
106  core::Real score(pose_total_score.compute( *pose_pt ));
107  pose_store_.insert(std::pair<core::Real, core::pose::PoseOP>(score, pose_pt));
108  keep_top_pose( basic::options::option[basic::options::OptionKeys::remodel::save_top] );
109 
110  if (cluster_switch_){
111  if (option[OptionKeys::remodel::cluster_on_entire_pose]){
112  cluster_pose();
113  } else { //default uses only loops -- otherwise large structures averages out changes
114  cluster_loop();
115  }
116 
117  cluster_->sort_each_group_by_energy();
118  cluster_->sort_groups_by_energy();
119 
120  // take the lowest energy in clusters and refine it.
121  //std::vector< core::pose::Pose > results = cluster_->get_pose_list();
122  }
123 
124 }
125 
128  return "RemodelAccumulator";
129 }
130 
131 
132 
134 {
135  // TR << "sorted size " << pose_store_.size() << std::endl;
136  if ( pose_store_.size() > num_to_keep ) {
137  std::multimap<core::Real, core::pose::PoseOP>::iterator worst_structure = --pose_store_.end();
138  //delete (*worst_structure).second; // deletes Pose allocated on heap
139  pose_store_.erase( worst_structure );
140  // TR << "sorted size " << pose_store_.size() << std::endl;
141 
142  }
143 }
144 
145 std::vector<core::pose::PoseOP> RemodelAccumulator::contents_in_pose_store(){
146  std::vector<core::pose::PoseOP> dummy_return;
147  for (std::multimap<core::Real, core::pose::PoseOP>::iterator it= pose_store_.begin(), end = pose_store_.end(); it != end; it++){
148  dummy_return.push_back(it->second);
149  }
150  return dummy_return;
151 }
152 
153 
155 
156  std::ofstream cpfile;
157  cpfile.open("checkpoint.txt", std::ios::trunc);
158  cpfile << progress_point << std::endl;
159  cpfile.close();
160 
161  core::Size num_report = basic::options::option[basic::options::OptionKeys::remodel::save_top];
162 
163  core::Size filecount = 1;
164  for (std::multimap<core::Real, core::pose::PoseOP>::iterator it= pose_store_.begin(), end = pose_store_.end(); it != end; it++){
165  if (filecount <= num_report){
166  std::stringstream sstream;
167  std::string num(ObjexxFCL::lead_zero_string_of(filecount,3));
168  sstream << "ck_" << num << ".pdb";
169 
170  it->second->dump_pdb(sstream.str());
171  }
172  filecount++;
173  }
174 }
175 
176 
177 
178 
179 
181 {
182  using namespace core::scoring;
183  using namespace core::scoring::constraints;
185  using namespace protocols::simple_filters;
186  using namespace basic::options;
187 
188  //if reading checkpoint, make sure there's no info stored
189  pose_store_.clear();
190  core::Size num_report = basic::options::option[basic::options::OptionKeys::remodel::save_top];
191  for (core::Size i = 1; i<= num_report; i++){
192  std::string number(ObjexxFCL::lead_zero_string_of(i, 3));
193 
194  //std::string filename = flags.prefix + "_" + number + ".pdb";
195  std::string filename = "ck_" + number + ".pdb";
196  std::cout << "checking checkpointed file: " << filename << std::endl;
197  struct stat stFileInfo;
198  bool boolReturn;
199  int intStat;
200 
201  intStat = stat(filename.c_str(), &stFileInfo);
202  if (intStat == 0){
203  //file exists
204  boolReturn = true;
205  } else {
206  boolReturn = false;
207  continue;
208  }
209 
210  if (boolReturn == true){
211  core::pose::Pose dummyPose;
212  core::import_pose::pose_from_pdb( dummyPose, filename.c_str(),false); //fullatom, ideal, readAllChain
213 
214  //RemodelDesignMover designMover(remodel_data_, working_model_);
215  //designMover.set_state("stage");
216  //designMover.apply(dummyPose);
217 
218  //special case for repeat proteins. they need to carry constraints
219  //from the start. Build constraints are set in RemodelLoopMover, a bit
220  //different from everything else
221 
222  if (option[ OptionKeys::remodel::repeat_structure].user()){
223  if (option[ OptionKeys::constraints::cst_file ].user()){
225  repeat_constraint->apply( dummyPose );
226  }
227 
228  // ResidueTypeLinkingConstraints
229  Size repeat_number = basic::options::option[ OptionKeys::remodel::repeat_structure];
230  Size count=0;
231  Real bonus = 10;
232  Size segment_length = (dummyPose.n_residue())/repeat_number;
233  for (Size rep = 1; rep < repeat_number; rep++ ){ // from 1 since first segment don't need self-linking
234  for (Size res = 1; res <= segment_length; res++){
235  dummyPose.add_constraint( new ResidueTypeLinkingConstraint(dummyPose, res, res+(segment_length*rep), bonus));
236  count++;
237  }
238  }
239  std::cout << "linking " << count << " residue pairs" << std::endl;
240  }
241 
242  if (option[OptionKeys::remodel::RemodelLoopMover::cyclic_peptide].user()){ //all processes/constraints has to be applied to checkpointed files
244  }
245 
246  this->apply(dummyPose);
247 
249  sfxn_ = score12;
250 
251  ScoreTypeFilter const pose_total_score( score12, total_score, 100 );
252  core::Real score(pose_total_score.compute( dummyPose ));
253 
254 
255  std::cout << "checkpointed_pose " << filename << " score = " << score << std::endl;
256  }
257  }
258  int ck=0;
259  std::ifstream trajCount("checkpoint.txt");
260  trajCount >> ck;
261 
262  std::cout << "checkpoint at " << ck << std::endl;
263 
264  return ck;
265 }
266 
267 
268 
269 
270 
271 
273  runtime_assert(cluster_switch_);
275  run_cluster();
276 }
277 
279  runtime_assert(cluster_switch_);
281  //debug
282 TR << "loops to build " << working_model_.loops << std::endl;
283  run_cluster();
284 }
285 
287 
288  runtime_assert(cluster_switch_);
289 
290 //set cluster size from command line
291  core::Real radius = basic::options::option[basic::options::OptionKeys::remodel::cluster_radius];
292 
293 
294  cluster_->set_score_function( sfxn_ );
295  cluster_->set_cluster_radius( radius );
296 
297  for ( std::multimap<core::Real, core::pose::PoseOP>::iterator it = pose_store_.begin(), end = pose_store_.end(); it != end ; it++){
298  cluster_->apply((*(*it).second));
299  }
300 
301  cluster_->do_clustering(basic::options::option[basic::options::OptionKeys::cluster::max_total_cluster]());
302  cluster_->do_redistribution();
303 
304 }
305 
307  return cluster_switch_;
308 }
309 
310 std::vector<core::pose::PoseOP> RemodelAccumulator::clustered_top_poses(core::Size count){
311  runtime_assert(cluster_switch_);
312  return cluster_->return_top_poses_in_clusters(count);
313 }
314 
316  cluster_->limit_groupsize( (int)num_top ); // keep only cluster center and best energy
317 }
318 
319 std::vector<core::pose::PoseOP> RemodelAccumulator::clustered_best_poses(){
320  runtime_assert(cluster_switch_);
321  return cluster_->return_lowest_poses_in_clusters();
322 }
323 
324 
325 
326 
327 } // remodel
328 } // forge
329 } // protocol