33 #include <basic/options/option_macros.hh>
34 #include <basic/options/keys/in.OptionKeys.gen.hh>
35 #include <basic/options/keys/packing.OptionKeys.gen.hh>
37 #include <basic/Tracer.hh>
46 #include <numeric/random/random.hh>
49 #include <utility/file/file_sys_util.hh>
50 #include <utility/pointer/owning_ptr.hh>
51 #include <utility/tag/Tag.hh>
52 #include <utility/io/ozstream.hh>
53 #include <utility/io/izstream.hh>
59 OPT_2GRP_KEY( File, tempering, temp, file )
60 OPT_2GRP_KEY( Integer, tempering, temp, levels )
61 OPT_2GRP_KEY(
Real, tempering, temp, low )
62 OPT_2GRP_KEY( Real, tempering, temp, high )
63 OPT_2GRP_KEY( RealVector, tempering, temp,
range )
64 OPT_2GRP_KEY( File, tempering, stats, file )
65 OPT_2GRP_KEY( Boolean, tempering, stats, silent )
66 OPT_2GRP_KEY( Boolean, tempering, stats, line_output )
73 static basic::Tracer
tr( "protocols.canonical_sampling.TemperingBase" );
82 NEW_OPT( tempering::temp::file,
"file with temperature definitions for simulated tempering, including weights and counts",
"" );
83 NEW_OPT( tempering::temp::levels,
"how many temp-levels, superseeded by -tempering::temp::file",10 );
85 NEW_OPT( tempering::temp::high,
"min and max temperature, superseeded by -tempering::temperatures or -tempering::temp::range", 3.0 );
86 NEW_OPT( tempering::temp::low,
"min and max temperature, superseeded by -tempering::temperatures or -tempering::temp::range", 0.5 );
88 NEW_OPT( tempering::stats::file,
"filename (postfix) for output of tempering statistics (i.e, counts) <job>_.tempering.stats",
"tempering.stats" );
89 NEW_OPT( tempering::stats::silent,
"write all tempering information as lines into a single file -- similar to silent format",
false );
90 NEW_OPT( tempering::stats::line_output,
"choose line-output as in silent mode, even when using individual files",
false );
92 NEW_OPT( tempering::stride,
"how often should a temperature switch be attempted", 1);
97 namespace canonical_sampling {
101 instance_initialized_( false )
139 return "TemperingBase";
152 bool success(
false );
153 if ( temp_file.size() ) {
155 if ( !success )
tr.Info <<
"cannot read temperatures from file, will initialize from options... " << std::endl;
158 Real temp_low = tag->getOption<
Real >(
"temp_low", 0.6 );
159 Real temp_high = tag->getOption<
Real >(
"temp_high", 3.0 );
160 Size temp_levels = tag->getOption<
Size >(
"temp_levels", 10 );
188 tr.Trace <<
"initialize Tempering Base... " << std::endl;
195 tr.Debug << std::setprecision(2);
198 job_->add_string_real_pair(
"temp_level", current_temp_ );
201 tr.Trace <<
"initialized Tempering Base!!!" << std::endl;
214 if ( std::abs(
temperature() - temp_in ) > 0.01 ) {
215 using namespace ObjexxFCL;
216 utility_exit_with_message(
"inconsistent temperature when trying to restart Tempering temp_in: "
217 +string_of( temp_in )
218 +
" temperature expected at level "+string_of( level )+
" is "+string_of(
temperature() ) );
237 if ( *it > mc_temp )
break;
249 using namespace basic::options;
250 using namespace basic::options::OptionKeys;
251 using namespace core;
254 utility_exit_with_message(
"cannot call TemperingBase::init_from_options() unless TemperingBase::register_options() \
255 on application level before devel::init()" );
258 bool success(
false );
259 if ( option[ tempering::temp::file ].user() ) {
261 if ( !success )
tr.Info <<
"cannot read temperatures from file, will initialize from options... " << std::endl;
264 Real temp_high, temp_low;
269 temp_low=option[ tempering::temp::low ]();
270 temp_high=option[ tempering::temp::high ]();
272 Size const n_levels( option[ tempering::temp::levels ]() );
284 runtime_assert( n_levels >= 2 );
285 tr.Info <<
"initializing temperatures from " << temp_low <<
" to " << temp_high <<
" with " << n_levels <<
" levels using "
287 if (interpolation ==
linear) {
288 Real const temp_step ( (temp_high-temp_low)/(n_levels-1) );
289 for (
Size ct=0; ct<n_levels; ++ct ) {
293 Real next_temp( temp_low );
294 Real temp_factor( pow(temp_high/temp_low, 1/
Real(n_levels-1)) );
295 for (
Size ct=1; ct<n_levels; ++ct ) {
297 next_temp *= temp_factor;
306 utility::io::izstream in( filename );
308 tr.Error <<
"cannot open file " << filename << std::endl;
313 std::istringstream line_stream( line );
317 line_stream >> tag >> n_levels;
319 bool line_format(
false );
320 if ( !line_stream.good() ) {
321 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
322 tr.Error <<
"excpected TEMPERING or TEMPERING_TABLE" << std::endl;
326 if ( tag ==
"TEMPERING" ) {
328 }
else if ( tag ==
"TEMPERING_TABLE" ) {
331 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
332 tr.Error <<
"excpected TEMPERING or TEMPERING_TABLE" << std::endl;
338 for (
Size ct=1; ct <= n_levels; ++ct ) {
342 if ( !line_stream.good() ) {
343 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
344 tr.Error <<
"excpected TEMPERING N t1 t2 ... tN" << std::endl;
351 while ( getline( in, line ) ) {
352 std::istringstream line_stream( line );
355 if ( !line_stream.good() )
tr.Error <<
"format error in temperature file: " << filename <<
" at line " << line << std::endl;
373 file=output_name+
"."+file_in;
377 utility::io::ozstream out( file,
stats_line_output_ ? std::ios::app : std::ios::out );
385 out <<
" " << output_name << std::endl;
387 out << std::setw( 10 );
388 out <<
"TEMPERING_TABLE " <<
n_temp_levels() <<
" " << output_name << std::endl;
408 job_->add_string_real_pair(
"temperature", real_temp );
409 job_->add_string_real_pair(
"temp_level", new_temp );