Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopHashRelaxProtocol.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/loops/LoopHashSampler.cc
11 /// @brief
12 /// @author Mike Tyka
13 
19 
20 #include <core/pose/util.hh>
21 #include <core/pose/Pose.hh>
22 #include <basic/Tracer.hh>
27 #include <core/scoring/rms_util.hh>
29 #include <utility/string_util.hh>
31 //#include <protocols/match/Hit.fwd.hh>
32 #include <protocols/moves/Mover.hh>
33 #include <utility/exit.hh>
34 #include <utility/fixedsizearray1.hh>
35 #include <utility/pointer/owning_ptr.hh>
37 
44 #include <protocols/loops/Loops.hh>
45 
46 #include <numeric/geometry/hashing/SixDHasher.hh>
47 #include <numeric/random/random.hh>
48 
49 // C++ headers
50 //#include <cstdlib>
51 
52 #include <iostream>
53 #include <string>
54 #include <cstdio>
55 
56 // option key includes
57 #include <basic/options/keys/in.OptionKeys.gen.hh>
58 #include <basic/options/keys/out.OptionKeys.gen.hh>
59 #include <basic/options/keys/lh.OptionKeys.gen.hh>
60 #include <basic/options/keys/relax.OptionKeys.gen.hh>
61 
65 #include <utility/vector1.hh>
66 #include <utility/excn/EXCN_Base.hh>
67 
68 #include <basic/options/option.hh>
69 #include <basic/options/keys/lh.OptionKeys.gen.hh>
70 
71 #include <utility/vector1.hh>
72 
73 
74 // C++ headers
75 //#include <cstdlib>
76 #include <iostream>
77 #include <string>
78 #if defined(WIN32) || defined(__CYGWIN__)
79  #include <ctime>
80 #endif
81 
82 
83 
84 
85 static basic::Tracer TR("LocalHashRelaxProtocol");
86 static numeric::random::RandomGenerator RG(7590021); // <- Magic number, do not change it (and dont try and use it anywhere else)
87 
88 
89 namespace protocols {
90 namespace loophash {
91 
93 {
94  std::cout << "HERE!" << std::endl;
95 }
96 
97 void
99  using namespace basic::options;
100  using namespace basic::options::OptionKeys;
101  using namespace core::scoring;
102 
103  core::Size skim_size = 2;
104 
105  if( !library_ ) std::cout << std::string( "FATAL ERROR: Libary not loaded ") ;
106 
107  //core::Real mpi_metropolis_temp_ = option[ lh::mpi_metropolis_temp ]();
108 
109  LocalInserter_SimpleMinOP simple_inserter( new LocalInserter_SimpleMin() );
110  LoopHashSampler lsampler( library_, simple_inserter );
111  lsampler.set_min_bbrms( option[ lh::min_bbrms ]() );
112  lsampler.set_max_bbrms( option[ lh::max_bbrms ]() );
113  lsampler.set_min_rms( option[ lh::min_rms ]() );
114  lsampler.set_max_rms( option[ lh::max_rms ]() );
115  lsampler.set_max_struct( skim_size );
116 
117  core::pose::Pose native_pose;
118  if( option[ in::file::native ].user() ){
119  core::import_pose::pose_from_pdb( native_pose, option[ in::file::native ]() );
120  } else {
121  native_pose = pose; // jsut make a copy of the current pose - rmses will be relative to starts
122  }
123 
124  // Set up contraints
125  ScoreFunctionOP fascorefxn = getScoreFunction();
126 
127  // convert pose to centroid pose:
128  if( !pose.is_fullatom() ){
130  }
131 
132 
133  // See if a loopfile was defined - if so restrict sampling to those loops
134 // protocols::loops::Loops loops(true);
135 // utility::vector1< core::Size > selection;
136 // loops.get_residues( selection );
137 // TR << "Userdefined Loopregions: " << loops.size() << std::endl;
138 // TR << loops << std::endl;
139 // TR << "Residues: ";
140 // for( core::Size i=1; i <= selection.size(); ++i) TR << selection[i] << " ";
141 // TR << std::endl;
142 
143  //read_coord_cst(); //include this function later !
144 
145  //core::Size total_starttime = time(NULL);
146 
147  static int casecount = 0;
148  core::pose::Pose opose = pose;
149  std::vector< core::io::silent::SilentStructOP > lib_structs;
150 
151  TR.Info << "Loophash apply function ! " << std::endl;
152 
153  //protocols::relax::FastRelax *qrelax = new protocols::relax::FastRelax( fascorefxn, 1 );
154  protocols::relax::FastRelax *relax = new protocols::relax::FastRelax( fascorefxn, option[ OptionKeys::relax::sequence_file ]() );
155 
156  // convert pose to centroid pose:
159 
160  // Generate alternate structures
161  core::Size starttime2 = time(NULL);
162  core::Size sampler_chunk_size = 1;
163  core::Size start_res;
164  core::Size stop_res;
165  do {
166  start_res = std::max( core::Size(2), core::Size(rand()%(pose.total_residue() - sampler_chunk_size - 2 )) );
167  stop_res = std::min( core::Size(pose.total_residue()), core::Size(start_res + sampler_chunk_size - 1 ) );
168 
169  // If a loopfile was given choose your insertion site from there
170  // TR.Info << "Selection size: " << selection.size() << std::endl;
171  // if( selection.size() > 0 ){
172  // utility::vector1< core::Size > temp_selection = selection;
173  // std::random_shuffle( temp_selection.begin(), temp_selection.end());
174  // start_res = std::max( core::Size(2), core::Size( temp_selection[1] ) );
175  // stop_res = std::min( core::Size(pose.total_residue()), core::Size(start_res + sampler_chunk_size - 1) );
176  // TR.Info << "SubselectionSample: " << start_res << " - " << stop_res << std::endl;
177  // }
178 
179  lsampler.set_start_res( start_res );
180  lsampler.set_stop_res( stop_res );
181  lsampler.build_structures( pose, lib_structs );
182  core::Size endtime2 = time(NULL);
183  //core::Size loophash_time = endtime2 - starttime2;
184  TR.Info << "FOUND (" << start_res << " to " << stop_res << "): "
185  << lib_structs.size() << " states in time: "
186  << endtime2 - starttime2 << " s " << std::endl;
187 
188  // try again if we have failed to find structures << danger this is totally an infinte loop here
189 
190  } while ( lib_structs.size() == 0 );
191 
192  // choose up to "skim_size" of them
193  std::random_shuffle( lib_structs.begin(), lib_structs.end());
194  std::vector< core::io::silent::SilentStructOP > select_lib_structs;
195  for( core::Size k=0;k< std::min(skim_size, lib_structs.size() ) ;k++){
196  select_lib_structs.push_back( lib_structs[k] );
197  }
198 
199  core::Real bestcenscore = MAXIMAL_FLOAT;
200  //core::Size bestcenindex = 0;
201  for( core::Size h = 0; h < select_lib_structs.size(); h++){
202  core::pose::Pose rpose;
203  select_lib_structs[h]->fill_pose( rpose );
204 
205  //rpose.dump_pdb("struct_" + string_of(h) + ".pdb" );
206 
207  core::Real refrms = 0;
208  core::Real rms_factor = 10.0;
209  core::Real decoy_score = select_lib_structs[h]->get_energy("lh_censcore") + refrms * rms_factor;
210 
211  select_lib_structs[h]->add_energy( "refrms", refrms, 1.0 );
212  select_lib_structs[h]->add_energy( "comb_score", decoy_score, 1.0 );
213  TR.Info << "refrms: " << refrms << " Energy: " << decoy_score << std::endl;
214  if( decoy_score < bestcenscore ){
215  bestcenscore = decoy_score;
216  //bestcenindex = h; // set but never used ~Labonte
217  }
218  }
219  TR.Info << "Best:" << " Energy: " << bestcenscore << std::endl;
220 
221  /// For fullatom goodness, continue
222  core::Size starttime = time(NULL);
223  relax->batch_apply( select_lib_structs );
224  core::Size endtime = time(NULL);
225  //core::Size batchrelax_time = endtime - starttime;
226  TR.Info << "Batchrelax time: " << endtime - starttime << " for " << select_lib_structs.size() << " structures " << std::endl;
227 
228  core::Real bestscore = MAXIMAL_FLOAT;
229  //core::Size bestindex = 0;
230  core::pose::Pose relax_winner;
231  for( core::Size h = 0; h < select_lib_structs.size(); h++){
232  TR.Info << "DOING: " << h << " / " << select_lib_structs.size() << std::endl;
233  core::pose::Pose rpose;
234 
235  select_lib_structs[h]->fill_pose( rpose );
236 
237  //core::Real score = CA_rmsd( native_pose, rpose );
238  core::Real score = (*fascorefxn)(rpose);
239  TR.Info << "score: " << h << " " << score << std::endl;
240 
241  select_lib_structs[h]->add_energy("lh_score_new", score );
242 
243  if( score < bestscore ){
244  bestscore = score;
245  //bestindex = h; // set but never used ~Labonte
246  relax_winner = rpose;
247  }
248  }
249  casecount++;
250 
251 
252  std::cout << "SETTING Relax winner" << std::endl;
253  pose = relax_winner;
254 
255  }
256 
257 
258 
259 void
261 {
262 }
263 
265  return new LoopHashRelaxProtocol( *this );
266  }
267 
269  return new LoopHashRelaxProtocol( library_ );
270 }
271 
272 } // namespace loops
273 } // namespace protocols
274 
275 
276 
277