35 #include <basic/options/option_macros.hh>
36 #include <basic/options/keys/in.OptionKeys.gen.hh>
37 #include <basic/options/keys/packing.OptionKeys.gen.hh>
39 #include <basic/Tracer.hh>
48 #include <numeric/random/random.hh>
51 #include <utility/file/file_sys_util.hh>
52 #include <utility/pointer/owning_ptr.hh>
53 #include <utility/tag/Tag.hh>
54 #include <utility/io/ozstream.hh>
55 #include <utility/io/izstream.hh>
61 OPT_2GRP_KEY( Integer, tempering, reweight, stride )
62 OPT_2GRP_KEY( Boolean, tempering, temp, jump )
63 OPT_2GRP_KEY(
Real, tempering, temp, offset )
69 static basic::Tracer
tr( "protocols.canonical_sampling.SimulatedTempering" );
70 static numeric::
random::RandomGenerator
RG(6127547);
80 NEW_OPT( tempering::temp::offset,
"offset for score (effectively scales all weights)", 40 );
81 NEW_OPT( tempering::reweight::stride,
"every X trials update the weights distribution - 0 for no reweighting", 0 );
82 NEW_OPT( tempering::temp::jump,
"if true we can jump to any temperature instead of +/- 1 level",
false );
87 namespace canonical_sampling {
102 return "SimulatedTempering";
137 tr.Debug << std::setprecision(2);
188 new_temp=
RG.random_range( 1, nlevels );
190 Real const r1(
RG.uniform() );
197 if ( new_temp > nlevels ) new_temp = nlevels;
198 if ( new_temp < 1 ) new_temp = 1;
204 Real const temp_ratio =
206 if (
RG.uniform() < std::min( 1.0, prefac*std::exp(-(score+
score_offset_)*temp_ratio) )) {
209 tr.Debug <<
"set new temperature to level " << new_temp <<
" T=" << real_temp << std::endl;
226 return "SimulatedTempering";
264 using namespace basic::options;
265 using namespace basic::options::OptionKeys;
266 using namespace core;
267 tr.Debug <<
"initialize from options..." << std::endl;
278 utility::io::izstream in( filename );
280 tr.Error <<
"cannot open file " << filename << std::endl;
285 std::istringstream line_stream( line );
291 bool line_format(
false );
292 if ( !line_stream.good() ) {
293 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
294 tr.Error <<
"excpected TEMPERING or TEMPERING_TABLE" << std::endl;
298 if ( tag ==
"TEMPERING" ) {
300 }
else if ( tag ==
"TEMPERING_TABLE" ) {
303 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
304 tr.Error <<
"excpected TEMPERING or TEMPERING_TABLE" << std::endl;
308 Real temp, weight, count, wcount;
310 for (
Size ct=1; ct <= n_levels; ++ct ) {
311 line_stream >> temp >> weight >> wcount >> count;
312 temperatures.push_back( temp );
317 if ( !line_stream.good() ) {
318 tr.Error <<
"format not recognized in temperature file: " << filename <<
" at line " << line << std::endl;
319 tr.Error <<
"excpected TEMPERING N t1 w1 c1 t2 w2 c2 ... tN wN cN" << std::endl;
326 while ( getline( in, line ) ) {
327 std::istringstream line_stream( line );
328 Real temp, weight, wcount;
330 if ( !line_stream.good() )
tr.Error <<
"format error in temperature file: " << filename <<
" at line " << line << std::endl;
331 line_stream >> weight;
332 if ( !line_stream.good() ) {
333 tr.Warning <<
"no weights in temperature file: " << filename <<
" initialize with 1.0" << std::endl;
336 line_stream >> wcount;
337 if ( !line_stream.good() ) {
340 temperatures.push_back( temp );
355 file=output_name+
"."+file_in;
359 utility::io::ozstream out( file,
stats_line_output() ? std::ios::app : std::ios::out );
367 out <<
" " << output_name << std::endl;
369 out << std::setw( 10 );