Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CanonicalSamplingMover.cc
Go to the documentation of this file.
2 // AUTO-REMOVED #include <protocols/simple_moves/sidechain_moves/SidechainMover.hh>
3 // AUTO-REMOVED #include <protocols/simple_moves/sidechain_moves/SidechainMover.fwd.hh>
4 #include <protocols/jd2/util.hh>
5 
7 #include <core/pose/Pose.hh>
8 #include <core/pose/PDBInfo.hh>
12 
13 #include <protocols/loops/Loop.hh>
14 #include <protocols/loops/Loops.hh>
15 
19 #ifdef USEMPI
23 #endif
26 
29 
30 #include <basic/options/option.hh>
31 #include <basic/options/after_opts.hh>
32 #include <basic/options/option_macros.hh>
33 #include <basic/options/keys/mc.OptionKeys.gen.hh>
34 #include <basic/options/keys/out.OptionKeys.gen.hh>
35 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
36 #include <basic/options/keys/loops.OptionKeys.gen.hh>
37 #include <basic/options/keys/canonical_sampling.OptionKeys.gen.hh>
38 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
39 #include <utility/file/file_sys_util.hh>
40 #include <utility/file/PathName.hh>
41 #include <utility/file/gzip_util.hh>
42 
43 // AUTO-REMOVED #include <core/scoring/mm/MMBondAngleResidueTypeParamSet.hh>
45 // AUTO-REMOVED #include <core/scoring/methods/EnergyMethodOptions.hh>
46 #include <core/scoring/rms_util.hh>
51 
52 #include <basic/Tracer.hh>
53 #include <basic/prof.hh>
54 
55 #include <fstream>
56 #include <utility/io/ozstream.hh>
57 #include <utility/io/izstream.hh>
58 #include <ObjexxFCL/format.hh>
59 #include <ObjexxFCL/Fmath.hh>
60 #ifdef USEMPI
61 #include <mpi.h>
62 #endif
63 
64 #ifdef GL_GRAPHICS
66 #endif
67 
68 #include <protocols/jd2/Job.hh>
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
71 
72 //Auto Headers
74 
75 
76 // REQUIRED FOR WINDOWS
77 #ifdef BOINC
78 #include <protocols/boinc/boinc.hh>
79 #endif
80 
81 //moves to src/basic/options_rosetta.py
82 //OPT_1GRP_KEY(Boolean, sampling, no_detailed_balance)
83 //OPT_1GRP_KEY(Integer,sampling,ntrials)
84 //OPT_1GRP_KEY(Real,sampling,mc_kt)
85 //OPT_1GRP_KEY(Integer, sampling, interval_pose_dump)
86 //OPT_1GRP_KEY(Integer, sampling, interval_data_dump)
87 //OPT_1GRP_KEY(Boolean, sampling,output_only_cluster_transitions)
88 //OPT_1GRP_KEY(Real, sampling, transition_threshold )
89 //OPT_2GRP_KEY(File, sampling, out, new_structures )
90 //OPT_1GRP_KEY(Integer, sampling, max_files_per_dir )
91 
92 //debug ramping up temperature to equilibrate structure?
93 //OPT_1GRP_KEY(Boolean, sampling, ramp_temperature)
94 //OPT_1GRP_KEY(Integer, sampling, interval_increment_temp)
95 //OPT_1GRP_KEY(Real, sampling, starting_temp)
96 //OPT_1GRP_KEY(Boolean, sampling, add_constraints)
97 
98 //dump or save part of the structure?
99 //OPT_1GRP_KEY(Boolean, sampling, save_loops_only )
100 //OPT_1GRP_KEY(Boolean, sampling, dump_loops_only )
101 
102 //use xtc format or not? not currently implemented...
103 //OPT_1GRP_KEY(Boolean,sampling,use_xtc_format)
104 
105 namespace protocols{
106 namespace canonical_sampling {
107 
108 static basic::Tracer tr("protocols.canonical_sampling.CanonicalSamplingMover");
109 
111 
113  using namespace protocols::moves;
114  using namespace basic::options;
115  using namespace basic::options::OptionKeys;
116  using namespace core::pack::task;
117 
118  if ( !options_registered_ ) {
119  OPT( mc::known_structures);
120  OPT( out::path::path );
121  OPT(canonical_sampling::sampling::no_detailed_balance);
122  OPT(canonical_sampling::sampling::ntrials);
123  OPT(canonical_sampling::sampling::mc_kt);
124  OPT(canonical_sampling::sampling::interval_pose_dump);
125  OPT(canonical_sampling::sampling::interval_data_dump);
126  OPT(canonical_sampling::sampling::output_only_cluster_transitions);
127  OPT(canonical_sampling::sampling::transition_threshold);
128  OPT(canonical_sampling::out::new_structures);
129  OPT(canonical_sampling::sampling::max_files_per_dir);
130  OPT(canonical_sampling::sampling::save_loops_only);
131  OPT(canonical_sampling::sampling::dump_loops_only);
132  /**
133  NEW_OPT( sampling::ntrials, "number of Monte Carlo trials to run", 1000);
134  NEW_OPT( sampling::no_detailed_balance, "preserve detailed balance", false );
135  NEW_OPT( sampling::mc_kt,"value of kT for Monte Carlo",0.6);
136  NEW_OPT( sampling::interval_pose_dump,"dump a pose out every x steps",1000);
137  NEW_OPT( sampling::interval_data_dump,"dump data out every x steps",100);
138  NEW_OPT( sampling::output_only_cluster_transitions, "output only cluster transitions", false);
139  NEW_OPT( sampling::transition_threshold, "if rmsd to known_structures larger than X, add a new structure to pool", 0.5 );
140  NEW_OPT( sampling::out::new_structures, "write structures above transition_threshold to this file", "discovered_decoys.out" );
141  NEW_OPT( sampling::max_files_per_dir, "distribute traj and transition files into subdirectories with max N entries", 1000 );
142 
143  //
144  //debug ramping up temperature to equilibrate structure?
145  NEW_OPT( sampling::ramp_temperature, "ramp up the temperature and use constraints to equilibrate structure", false);
146  NEW_OPT( sampling::interval_increment_temp, "increment the temperature by 0.1 every x steps", 100000 );
147  NEW_OPT( sampling::starting_temp, "increment the temperature by 0.1 every x steps", 0.1 );
148  NEW_OPT( sampling::add_constraints, "add constraints during equilibration?", false);
149 
150  //dump or save part of the structure?
151  NEW_OPT( sampling::save_loops_only, "save only loop conformation to pool", false );
152  NEW_OPT( sampling::dump_loops_only, "dump only loop conformation in silent-files" , false );
153  NEW_OPT( sampling::use_xtc_format, "should we use xtc (compressed) format for dumping coordinates?", false );
154  **/
155  options_registered_ = true;
156  }
157 
158 
159 
160 }
161 
163  Mover("CanonicalSamplingMover"),
164  mc_(),
165  sfxn_(),
166  randmove_(new protocols::moves::RandomMover()),
167  pool_rms_(),
168  interval_posedump_(100),
170  ntrials_(1000),
171  detailed_balance_(true),
172  MPI_synchronize_pools_(false),
174  save_loops_only_(false),
175  dump_loops_only_(false),
177  boinc_mode_(false)
178 {
180 }
181 
185  int ntrial
186 ):
187  Mover("CanonicalSamplingMover"),
188  mc_(new protocols::moves::MonteCarlo( *sfxn, basic::options::option[ basic::options::OptionKeys::canonical_sampling::sampling::mc_kt ]() ) ),
189  sfxn_(sfxn),
190  randmove_(new protocols::moves::RandomMover()),
191  pool_rms_(ptr),
192  interval_posedump_(1000),
193  interval_transitiondump_(100),
194  ntrials_(ntrial),
195  detailed_balance_(true),
196  MPI_synchronize_pools_(false),
197  use_hierarchical_clustering_(false),
198  save_loops_only_(false),
199  dump_loops_only_(false),
200  output_only_cluster_transition_(false),
201  temperature_( basic::options::option[ basic::options::OptionKeys::canonical_sampling::sampling::mc_kt ]() ),
202  boinc_mode_(false)
203 {
205  runtime_assert( sfxn );
206 }
207 
209  using namespace basic::options;
210  using namespace basic::options::OptionKeys;
211 
212  runtime_assert( options_registered_ );
213 
214  ntrials( option[ basic::options::OptionKeys::canonical_sampling::sampling::ntrials ] );
215  detailed_balance( !option[ basic::options::OptionKeys::canonical_sampling::sampling::no_detailed_balance ] );
216  output_only_cluster_transitions( option[ basic::options::OptionKeys::canonical_sampling::sampling::output_only_cluster_transitions ] );
217  set_interval_pose_dump( option[ basic::options::OptionKeys::canonical_sampling::sampling::interval_pose_dump ] );
218  set_interval_data_dump( option[ basic::options::OptionKeys::canonical_sampling::sampling::interval_data_dump ] );
219  transition_threshold_ = option[ basic::options::OptionKeys::canonical_sampling::sampling::transition_threshold ]();
220  ramp_temperature_ = false;
221  //ramp_temperature_ = option[ canonical_sampling::sampling::ramp_temperature ]();
222  save_loops_only_ = option[ basic::options::OptionKeys::canonical_sampling::sampling::save_loops_only ]();
223  dump_loops_only_ = option[ basic::options::OptionKeys::canonical_sampling::sampling::dump_loops_only ]();
224 
225  //if in boinc mode, you need to alter the outputs
226  if( option[ run::protocol ].user() && option[run::protocol]() == "canonical_sampling") {
227  //assumes this flag is only set when you're using the minirosetta-app
228  boinc_mode_ = true;
229  }
230 }
231 
232 void
235  core::Real probability
236 ) {
237  randmove_->add_mover( m, probability);
238 }
239 
240 //copied from src/apps/pilot/dekim/bbin.cc
243  core::Real a,
244  core::Real x
245  )
246 {
247  using namespace ObjexxFCL;
248  core::Real const halfx = 0.5f * x;
249  return ( ( a >= halfx || a < -halfx ) ? mod( mod( a, x ) + ( x + halfx ), x ) - halfx : a );
250 }
251 
252 
253 
255 
256  std::string ABGEO_assignment = "";
257  for( protocols::loops::Loops::const_iterator itr = loop.begin(); itr != loop.end(); itr++ ) {
258  for( core::Size ii = itr->start(); ii <= itr->stop(); ii++ ){
259  core::Real phi = pose.phi(ii);
260  core::Real psi = pose.psi(ii);
261  core::Real omega = pose.omega(ii);
262  periodic_range( phi , 360.0 ); //does this get applied to phi??
263  periodic_range( psi , 360.0 );
264  periodic_range( omega, 360.0 );
265  std::string position_assignment="";
266  if ( std::abs( omega ) < 90 ) {
267  position_assignment= "O";
268  } else if ( phi >= 0.0 ) {
269  if ( -100 < psi && psi <= 100 ) {
270  position_assignment= "G"; // alpha-L
271  } else {
272  position_assignment= "E"; // E
273  }
274  } else {
275  if ( -125 < psi && psi <= 50 ) {
276  position_assignment= "A"; // helical
277  } else {
278  position_assignment= "B"; // extended
279  }
280  }
281  ABGEO_assignment = ABGEO_assignment + position_assignment;
282  }
283  ABGEO_assignment = ABGEO_assignment + ",";
284  }
285  return ABGEO_assignment;
286 }
287 
289 
291  mc_ = new protocols::moves::MonteCarlo(*sfxn_, temperature);
292  temperature_ = temperature;
293 }
294 
296 
298 
300 
302 
303 
305 
306 void CanonicalSamplingMover::use_MPI_bcast(bool truefalse) {MPI_bcast_ = truefalse;}
307 
309 
310 
312  pool_rms_ = ptr;
313 }
314 
317 }
318 
320  pose.remove_constraints();
321  core::Real const CA_cutoff(9.0);
322  core::Real const cst_tol(0.5);
323  for(unsigned int itr_res_i = 1; itr_res_i <= pose.total_residue(); itr_res_i++){
324  for(unsigned int itr_res_j = 1; itr_res_j <= pose.total_residue(); itr_res_j++){
325  Vector const CA_i( pose.residue( itr_res_i ).xyz(" CA "));
326  Vector const CA_j( pose.residue( itr_res_j ).xyz(" CA "));
327  core::Real const CA_dist = ( CA_i - CA_j ).length();
328  if( CA_dist < CA_cutoff ){
329  pose.add_constraint(
331  core::id::AtomID(pose.residue(itr_res_i).atom_index(" CA "),itr_res_i),
332  core::id::AtomID(pose.residue(itr_res_j).atom_index(" CA "),itr_res_j),
333  new core::scoring::constraints::HarmonicFunc( CA_dist, cst_tol )
334  )
335  );
336  }
337  }
338  }
339 }
340 
341 std::string jobname_dirhash( std::string const& dir_prefix, core::Size nr_dirs ) {
342  //this should split all files over <nr_dirs> directories:
343  // to do this I simply remove the last 5 chars from jobname (which are probably the nstruct _0001)
344  // then I add all ascii values of each character and take it modulo nr_dirs
345 // core::Size sum( 0 );
346 // const char* str = jobname.c_str();
347 // for ( core::Size i=1; i<=jobname.size()-5; i++ ) {
348 // sum+=(int) *(str++);
349 // }
351  utility::file::PathName output_path = basic::options::option[ basic::options::OptionKeys::out::path::path ];
352  std::string dir_name(
353  output_path.name() +"/" +
354  dir_prefix +"/" +
355  ObjexxFCL::lead_zero_string_of( job_id % nr_dirs, 4 ) +"/"
356  );
357  utility::file::create_directory_recursive( dir_name );
358  return dir_name;
359 }
360 
361 
362 /**
363 void CanonicalSamplingMover::dump_xtc_format_decoy(
364  std::ostream& os,
365  core::pose::Pose const& pose,
366  loops::Loops const& loop_to_dump
367  ) {
368 
369 
370 }
371 **/
372 
374  std::ostream& os,
375  core::pose::Pose const& pose,
376  core::Size i_trial,
377  std::string const& jobname,
378  loops::Loops const& loop_to_dump,
379  bool score_only /*default fasle*/
380 ) {
381 
382  //write to silent-struct
383  PROF_START( basic::CANONICALMOVER_WRITE_TO_FILE );
385  if ( score_only && !boinc_mode_ ) {
387  } else {
389  }
390 
391  using namespace ObjexxFCL;
392  //allow two easy obtainable skip intervals: 10 and 100
393  core::Size itrial_100 = i_trial / interval_posedump_ / 100;
394  core::Size rest100 = ( i_trial / interval_posedump_ ) % 100;
395  core::Size rest100_10 = rest100 / 10;
396  core::Size rest100_rest10 = rest100 % 10;
397  core::Size score_dump100 = ( i_trial / interval_transitiondump_ ) % interval_posedump_;
398  std::string score_dump_str("");
399  if ( score_only ) {
400  score_dump_str="."+lead_zero_string_of( score_dump100, 3 );
401  }
402 
403  ///construct NAME_00001.0.0
404  /// NAME_00001.0.1
405  // ...
406  /// NAME_00001.1.0
407  /// for easy extraction of 10th and 100th parts of structures from silent-file
408  /// 10th grep '\..\.0'
409  /// 100th grep '\.0\.0'
410 
411  std::string decoy_tag = jobname + "_"
412  + lead_zero_string_of( itrial_100, 8 ) + "."
413  + lead_zero_string_of( rest100_10, 1 ) + "."
414  + lead_zero_string_of( rest100_rest10, 1)
415  + score_dump_str;
416 
417  if( dump_loops_only_ /* save only loop conformations */
418  && loop_to_dump.num_loop() > 0 ) {
419  // make pose with just loop coordinates
420 
421  for( loops::Loops::const_iterator itr = loop_to_dump.begin(); itr != loop_to_dump.end(); itr++ ) {
422  core::pose::Pose looponly( pose, itr->start(), itr->stop() );
423  ss->fill_struct(looponly, decoy_tag);
424  //looponly.copy_segment(itr->size(),pose,looponly.total_residue()+1,itr->start());
425  }
426 
427  } else {
428  ss->fill_struct(pose, decoy_tag);
429  }
430  ss->add_energy( "itrial", i_trial );
431  if ( i_trial == 0 ) { //first time ?
432  ss->print_header( os );
433  }
435  sfd.write_silent_struct(*ss, os, score_only );
436  PROF_STOP( basic::CANONICALMOVER_WRITE_TO_FILE );
437 }
438 
439 void
441  using namespace ObjexxFCL::fmt;
442  using namespace basic::options;
443  using namespace basic::options::OptionKeys;
444 
445 
446  if ( pose.total_residue() == 0 ) {
447  utility_exit_with_message( "did you forget -in:file:silent ? Need to start CanonicalSamplingMover with a valid pose" );
448  }
449 
450  runtime_assert( pose.total_residue() > 0 );
451 
452  PROF_START( basic::MPICANONICALSAMPLING );
454 
455  runtime_assert( pool_rms_ );
456 
457  // set up loop definition if we're only sampling loop conformations.
458  // even if we're not sampling loop defs, make empty loop definition
459  loops::Loops loops;
460  if( option[basic::options::OptionKeys::loops::loop_file].user() ) {
461  std::string loopfile = option[basic::options::OptionKeys::loops::loop_file]()[1];
462  loops = loops::Loops( loopfile );
463  }
464  //add constraints if specified
465  if( option[ constraints::cst_file ].user() ) {
467  }
468 
469 
470 #ifdef USEMPI
471  int n_nodes;
472  MPI_Comm_size( MPI_COMM_WORLD, ( int* )( &n_nodes ) );
473 
476  mpi_pool_rms->set_discovered_out( (option[ basic::options::OptionKeys::canonical_sampling::out::new_structures ]()).name() );
477  if( mpi_pool_rms ){
478  mpi_pool_rms->set_transition_threshold( transition_threshold_ );
479  //tr.Debug << " set transition threshold to " << transition_threshold_ << std::endl;
480  mpi_pool_rms->set_reserve_size( n_nodes );
481  pool_rms_ = mpi_pool_rms;
482  }else{
483  utility_exit_with_message("cast to MPIBPool_RMSD failed! fatal error!");
484  }
485  }else if( MPI_synchronize_pools_ ){
488  mpi_pool_rms->set_discovered_out( (option[ basic::options::OptionKeys::canonical_sampling::out::new_structures ]()).name() );
489  if( mpi_pool_rms ){
490  mpi_pool_rms->set_transition_threshold( transition_threshold_ );
491  mpi_pool_rms->set_reserve_size( n_nodes );
492  mpi_pool_rms->set_reserve_size( n_nodes );
493  //tr.Debug << " set transition threshold to " << transition_threshold_ << std::endl;
494  pool_rms_ = mpi_pool_rms;
495  }else{
496  utility_exit_with_message("cast to MPIPool_RMSD failed! fatal error!");
497  }
498  } else {
500  mpi_pool_rms->set_discovered_out( (option[ basic::options::OptionKeys::canonical_sampling::out::new_structures ]()).name() );
501  if( mpi_pool_rms ){
502  mpi_pool_rms->set_transition_threshold( transition_threshold_ );
503  mpi_pool_rms->set_reserve_size( n_nodes );
504  mpi_pool_rms->set_reserve_size( n_nodes );
505  tr.Debug << "MPIHPool: set transition threshold to " << transition_threshold_ << std::endl;
506  pool_rms_ = mpi_pool_rms;
507  tr.Debug << "about to begin sampling with MPIHPool " << std::endl;
508  }else{
509  utility_exit_with_message("cast to MPIPool_RMSD failed! fatal error!");
510  }
511  }
512 
513  }
514 #endif
515 
516 
517  //output params
518  int width(10); int precision(6);
519  ///make sure that this job is not repeated again in case of restart --> output to general output file
520  if ( protocols::jd2::JobDistributor::get_instance()->job_outputter() ) {
523  jd->job_outputter()->final_pose( jd->current_job(), pose );
524  }
525 
526  core::Size nr_jobs( protocols::jd2::JobDistributor::get_instance()->total_nr_jobs() );
527  core::Size nr_dirs( nr_jobs / option[ basic::options::OptionKeys::canonical_sampling::sampling::max_files_per_dir ]() + 1 );
528 
529  //exceptional use of ofstream to write directly to directory in MPI mode -- short-cutting the MPI-Filebuffer
530  std::ofstream transition_file;
531  if( !boinc_mode_ ){ //do not output to transition/ directory if in boinc-mode
532  std::string transition_filename( jobname_dirhash( "transitions",nr_dirs ) + jobname + ".transition.dat");
533  transition_file.open( transition_filename.c_str() );
534  }
535  ///taking care that output stream is std::ofstream so that we write directly to File instead of rerouting via MPIFileBuf.
536  /// this would overload MPIFilebuffer since we open a different file for each process...
537  /// keep file open... parallel open/closing is hard on the file-system
538  std::string traj_filename;
539  std::string traj_scorefile;
540 
541  if( !boinc_mode_ ){
542  traj_filename = jobname_dirhash( "trajectories", nr_dirs ) + jobname + ".traj.out";
543  traj_scorefile = jobname_dirhash( "trajectories", nr_dirs ) + jobname + ".traj.sc";
544  } else {
545  traj_filename = jobname + ".traj.out";
546  traj_scorefile = jobname + ".traj.sc"; // this file is actually not needed but included here to prevent seg-faults
547  }
548  std::ofstream traj_file( traj_filename.c_str(), std::ios_base::app );
549  std::ofstream traj_sc( traj_scorefile.c_str(), std::ios_base::app );
550 
551 
552  /**********************************CHECKPOINTING ****************************************************/
553  /** **
554  ** checkpointing is automatically taken care of. if silent-file already exists, **
555  ** then read it in, sets i_trial to whatever you ended on + 1, can get from output silent-file **
556  ** then sets current-pose to whatever the last-pose is in the silent-file **
557  ** if i_trail == ntrial, then start on the next nstruct or the next decoy in the list **
558  ** **/
559 
561  core::Size i_trial=0; //if not overwritten, starts trajectory from beginning
562  if( utility::file::file_exists( traj_filename + ".gz" ) ) {
563  tr << "output file exists and is gzipped... moving on to the next one!" << std::endl;
564  return;
565  }
566  if( utility::file::file_exists( traj_filename ) && utility::file::file_size( traj_filename ) > 0 &&
567  !utility::file::file_exists( traj_filename + ".gz")) {
568  core::io::silent::SilentFileData existing_output;
569  existing_output.set_filename( traj_filename );
570  existing_output.read_file( traj_filename );
571  utility::vector1< std::string > existing_tags;
572  existing_output.read_tags_fast( traj_filename, existing_tags );
573  tr << "number of tags found in " << traj_filename << " is " << existing_tags.size() << std::endl;
574 
575  if( existing_tags.size() > 1 ) {
576  existing_ss = existing_output[ existing_tags[ existing_tags.size() - 1 ] ];
577  tr << "existing output: " << traj_file << " exists, filling pose with last-structure found: " << existing_tags[ existing_tags.size()-1 ] << std::endl;
578  if( existing_ss->has_energy("itrial") ) {
579  i_trial = (core::Size)existing_ss->get_energy("itrial");
580  tr << "last trial recorded: " << i_trial << std::endl;
581  i_trial += 1;
582  } else {
583  tr.Warning << " no last trial found.. cannot restart from last structure" << std::endl;
584  //somehow erase ss data
585  }
586 
587  }
588 
589  }
590 
591  /**********************************CHECKPOINTING ****************************************************/
592 
594  sfd.set_filename( traj_filename );
595 
596  //test-- add ramp up temperature in order to equilibrate structure?
597  //core::Size interval_inc_temp = option[ canonical_sampling::sampling::interval_increment_temp ];
598  //core::Real starting_temp = option[ canonical_sampling::sampling::starting_temp ];
599  //core::Real ending_temp = option[ basic::options::OptionKeys::canonical_sampling::sampling::mc_kt ];
600  //bool constrain_structure = option[ canonical_sampling::sampling::add_constraints ];
601  core::Size interval_inc_temp = 0;
602  core::Real starting_temp = option[ basic::options::OptionKeys::canonical_sampling::sampling::mc_kt ];
603  core::Real ending_temp = option[ basic::options::OptionKeys::canonical_sampling::sampling::mc_kt ];
604  bool constrain_structure = false;
605 
606  if( ramp_temperature_ ){
607  mc_ = new protocols::moves::MonteCarlo( *sfxn_, starting_temp );
608  }else{
609  mc_ = new protocols::moves::MonteCarlo( *sfxn_, ending_temp );
610  }
611 
612  /**
613  if( MPI_synchronize_pools_ && use_hierarchical_clustering ) {
614  core::io::silent::SilentStructOP ss = core::io::silent::SilentStructFactory::get_silent_struct_out();
615  #ifdef USEMPI
616  mc_convergence_checks::MPIHPool_RMSD* hpool_ptr = dynamic_cast<mc_convergence_checks::MPIHPool_RMSD * > (&(*pool_rms_));
617  if( hpool_ptr ) {
618  hpool_ptr->write_headers_to_hierarchy( ss );
619  }
620  #endif
621  }
622  **/
623  if( !boinc_mode_ ) { // prevent all output of transition data (to transitions.dat files) if in boinc-mode
625  transition_file << "I_TRIAL SCORE RG CLUSTER RMS_TO_CLUSTER RMS_TO_START" << std::endl;
626  } else {
627  transition_file << "I_TRIAL STEPS_SINCE_TRANSITON SCORE RG CLUSTER RMS_TO_CLUSTER RMS_TO_START" << std::endl;
628  }
629  }
630 
631  runtime_assert( mc_ ); //are we initialized ?
632  mc_->reset( pose );
633 
634  //setup Rg score calculator
636 
637  //keep a copy of current pose for rms calculations
638  core::pose::Pose init( pose );
639  core::Real rms_to_start;
640 
641  std::string current_cluster_center="";
642  Size current_cluster_first_seen( 0 );
643 
644  if( constrain_structure ){
645  setup_constraints( pose );
646  sfxn_->set_weight( core::scoring::atom_pair_constraint, 1.0 );
647  }
648 
649  //main loop
650  #ifdef BOINC_GRAPHICS
651  boinc::Boinc::attach_graphics_current_pose_observer( pose );
652  #endif
653 
654  #ifdef GL_GRAPHICS
655  protocols::viewer::add_conformation_viewer( pose.conformation(), "canonical_pose");
656  #endif
657  if( existing_ss->nres() > 0 ) {
658  existing_ss->fill_pose( pose );
659  }
660  for ( ; i_trial < ntrials_; i_trial++ ) {
661  core::Real proposal_density_ratio( 1 );
662  //
663  randmove_->apply( pose );
664 
665  //all just to get last_proposal_density_ratio
666  if ( detailed_balance_ ) {
667  proposal_density_ratio = randmove_->last_proposal_density_ratio();
668  }
669 
670  mc_->boltzmann( pose, randmove_->type(), proposal_density_ratio );
671 
672  //test-- add ramp up temperature in order to equilibrate structure?
673  if( ramp_temperature_ &&
674  mc_->temperature() < ending_temp &&
675  ( i_trial % interval_inc_temp ) == 0 ){
676 
677  if( constrain_structure ){
678  setup_constraints( pose );
679  sfxn_->set_weight( core::scoring::atom_pair_constraint, 1.0 );
680  }
681  mc_->set_temperature( mc_->temperature() + 0.1 );
682  }
683  if( ramp_temperature_ &&
684  constrain_structure &&
685  sfxn_->has_nonzero_weight( core::scoring::atom_pair_constraint ) &&
686  (i_trial % (interval_inc_temp/10) == 0)
687  ){
688  sfxn_->set_weight(
690  ( sfxn_->get_weight(core::scoring::atom_pair_constraint) - 0.1 )
691  ); //reduce constraints as simulation progresses
692  if(sfxn_->get_weight( core::scoring::atom_pair_constraint ) < 0.1){
693  sfxn_->set_weight( core::scoring::atom_pair_constraint, 0.0); //because of numeric instability
694  pose.remove_constraints();
695  }
696  }
697  if ( (i_trial % interval_posedump_) == 0 ) {
698  dump_decoy_or_score( traj_file, pose, i_trial, jobname, loops, false /*not just score*/);
699  }
700 
701  if ( (i_trial % interval_transitiondump_) == 0 ) { //output current next cluster
702  std::string cluster_center; core::Real rms_to_cluster;
703  core::pose::Pose looponly;
704  core::Size new_level_start = 0;
706  if( !MPI_synchronize_pools_ ) {
708  utility::vector1< core::Size > address(hpool_ptr->nlevels(), 0 );
709  utility::vector1< core::Real > rms_to_cluster(hpool_ptr->nlevels(), 0.0);
710  if( save_loops_only_ && loops.num_loop() > 0 ) {
711  for( loops::Loops::const_iterator itr = loops.begin(); itr != loops.end(); itr++ ) {
712  looponly = core::pose::Pose( pose, itr->start(), itr->stop() );
713  }
714  hpool_ptr->evaluate( looponly, cluster_center, rms_to_cluster, address );
715  }else {
716  hpool_ptr->evaluate( pose, cluster_center, rms_to_cluster, address );
717  }
719  bool above_threshold = false;
720  for( core::Size ii = 1; ii <= rms_to_cluster.size(); ii++ ) {
721  if( rms_to_cluster[ ii ] > level_n->radius() ) {
722  above_threshold = true;
723  new_level_start = ii;
724  }
725  level_n = (level_n->next_level());
726  }
727 
728  if( above_threshold ){
729  std::string newtag = "new-structure-tag";
730  if( save_loops_only_ && loops.num_loop() > 0 ){
731  hpool_ptr->add_new( looponly, newtag, address, true, new_level_start );
732  } else {
733  hpool_ptr->add_new( pose, newtag, address, true, new_level_start );
734  }
735  }
736  } else { //use hierarchy and use MPI-synching
737 #ifdef USEMPI
739  runtime_assert( hpool_ptr != 0 );
740  if( save_loops_only_ && loops.num_loop() > 0 ){
741  for( loops::Loops::const_iterator itr = loops.begin(); itr != loops.end(); itr++ ) {
742  looponly = core::pose::Pose( pose, itr->start(), itr->stop() );
743  }
744  hpool_ptr->evaluate_and_add( looponly, cluster_center, rms_to_cluster);
745  } else {
746  hpool_ptr->evaluate_and_add( pose, cluster_center, rms_to_cluster );
747  }
748 #endif
749  }
750  } else{ //use MPIPool
751  if( save_loops_only_ && loops.num_loop() > 0 ){
752  for( loops::Loops::const_iterator itr = loops.begin(); itr != loops.end(); itr++ ) {
753  looponly = core::pose::Pose( pose, itr->start(), itr->stop() );
754  }
755  pool_rms_->evaluate_and_add( looponly, cluster_center, rms_to_cluster, transition_threshold_ );
756  } else {
757  pool_rms_->evaluate_and_add( pose, cluster_center, rms_to_cluster, transition_threshold_ );
758  }
759  }
760  //pool_rms_->evaluate( pose, cluster_center, rms_to_cluster);
761  runtime_assert( pose.total_residue() > 0 );
762  dump_decoy_or_score( traj_sc, pose, i_trial, jobname, loops, true /*not just score*/ );
763 
765  PROF_START( basic::MPICANONICALSAMPLING );
766  //evaluates cluster and writes transition
767  rms_to_start = core::scoring::CA_rmsd( init, pose );
768  if( !boinc_mode_ ) {
769  transition_file << i_trial << " "
770  << F(width,precision,mc_->temperature()) << " "
771  << F(width,precision,(*sfxn_)( pose )) << " "
772  << F(width,precision,rge.calculate_rg_score( pose )) << " "
773  << cluster_center << " "
774  << get_ABGEO_string( pose, loops ) << " " //add in on-the-fly ABGEO assignment to save time
775  << F(width,precision,rms_to_cluster) << " "
776  << F(width,precision,rms_to_start) << " "
777  << std::endl;
778  }
779  PROF_STOP( basic::MPICANONICALSAMPLING );
780  } else {// output_only_cluster_transition_
781  //check if transition occurs
782  if ( current_cluster_center.compare("") == 0 ) {
783  //first cluster seen
784  current_cluster_center = cluster_center;
785  } else if (current_cluster_center.compare( cluster_center ) != 0 ) { //new cluster
786  PROF_START( basic::MPICANONICALSAMPLING );
787  rms_to_start = core::scoring::CA_rmsd( init, pose );
788  if( !boinc_mode_ ) {
789  transition_file << i_trial << " "
790  << i_trial-current_cluster_first_seen << " "
791  << F(width,precision,mc_->temperature()) << " "
792  << F(width,precision,(*sfxn_)( pose )) << " "
793  << F(width,precision,rge.calculate_rg_score( pose )) << " "
794  << cluster_center << " "
795  << get_ABGEO_string( pose, loops ) << " " //add in on-the-fly ABGEO assignment to save time
796  << F(width,precision,rms_to_cluster) << " "
797  << F(width,precision,rms_to_start) << " "
798  << std::endl;
799  }
800  current_cluster_center = cluster_center;
801  current_cluster_first_seen = i_trial;
802  PROF_STOP( basic::MPICANONICALSAMPLING );
803  }
804  }
805  } //output occured
806  } //for loop over trials
807  //if using a boinc application, gzip the output
808  if( boinc_mode_ ) {
809  utility::file::gzip( traj_filename, true );
810  utility::file::gzip( traj_scorefile, true );
811  }
812  //DEBUG OUTPUT
813 
814  /**
815 #ifdef USEMPI
816  int rank = 0;
817  MPI_Comm_rank( MPI_COMM_WORLD, (int*) (&rank) );
818  std::ofstream debug_cl_cnters;
819  std::ostringstream q;
820  q << rank;
821  debug_cl_cnters.open((q.str() + ".debug_cl_centers.txt").c_str());
822  for(core::Size itr = 1; itr <= pool_rms_->size(); itr++){
823  std::string tag = pool_rms_->get_tag(itr);
824  debug_cl_cnters << tag << std::endl;
825  }
826 #endif
827  **/
828  //DEBUG OUTPUT
829 
830 } //apply
831 
832 
835  return "CanonicalSamplingMover";
836 }
837 
838 
839 } //moves
840 } //protocols
841