31 #include <basic/Tracer.hh>
32 #include <basic/MemTracer.hh>
37 #include <utility/exit.hh>
38 #include <utility/excn/Exceptions.hh>
39 #include <utility/file/file_sys_util.hh>
41 #include <utility/io/ozstream.hh>
42 #include <utility/io/izstream.hh>
43 #include <ObjexxFCL/format.hh>
45 #include <basic/options/option.hh>
46 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
47 #include <basic/options/keys/run.OptionKeys.gen.hh>
52 static basic::Tracer
tr(
"protocols.jd2.Archive");
55 #include <basic/options/option_macros.hh>
56 #include <basic/prof.hh>
58 #include <utility/vector1.hh>
59 #include <boost/algorithm/string/erase.hpp>
71 using namespace basic::options;
72 using namespace basic::options::OptionKeys;
77 NEW_OPT( iterative::pool_size,
"number of structures maintained in pool", 500 );
97 max_nstruct_( option[ iterative::pool_size ]() ),
98 accepts_since_last_batch_( 0 ),
100 proposed_since_last_batch_( 0 ),
107 if ( ( option[ run::test_cycles ]() || option[ run::dry_run ]() ) && !option[ run::memory_test_cycles ]() ) {
157 tr.Trace <<
"ArchiveBase::init_from_decoy_set" << std::endl;
159 Batch init_batch( 0 );
160 using namespace core::io::silent;
161 using namespace core::chemical;
170 pss->fill_struct( pose, tag );
171 centroid_sfd.add_structure( pss );
178 using namespace core;
179 using namespace io::silent;
181 tr.Debug <<
"read structures returned for " << batch.
batch() << std::endl;
183 Size accepted_ct( 0 );
186 it->set_decoy_tag( batch.
batch()+
"_"+ObjexxFCL::lead_zero_string_of( ++ct, 6 ) );
193 accepted_ct += accept ? 1 : 0;
196 mem_tr <<
" ArchiveBase::read_structures now: " <<
decoys().size() <<
" decoys "<< std::endl;
198 tr.Debug <<
"...done reading --- " << accepted_ct <<
" structures were accepted into the archive" << std::endl;
199 tr.Trace <<
"now there are " <<
decoys().size() <<
" decoys in archive " << std::endl;
208 decoys_.insert( iss, new_decoy );
217 std::string const backup_filename ( dirname +
"/decoys.out.backup" );
218 std::string const tmp_filename ( dirname +
"/tmp_decoys.out" );
219 using namespace core::io::silent;
224 utility::file::create_directory( dirname );
229 utility::io::ozstream output( tmp_filename );
232 for ( SilentStructs::const_iterator it =
decoys_.begin(); it !=
decoys_.end(); ++it ) {
235 sfd.write_silent_struct( **it, output );
242 rename( filename.c_str(), backup_filename.c_str() );
244 rename( tmp_filename.c_str(), filename.c_str() );
246 utility::io::ozstream status( dirname+
"/STATUS" );
247 basic::show_time(
tr,
"save "+
name()+
" status");
254 bool b_have_restored(
false );
255 using namespace core::io::silent;
256 mem_tr <<
"ArchiveBase::restore_from_file..." << std::endl;
260 if ( !sfd.
read_file( filename ) )
throw ( utility::excn::EXCN_BadInput(
"problem reading silent file"+filename ) );
265 mem_tr <<
"ArchiveBase::restored " <<
decoys_.size() <<
" decoys" << std::endl;
266 utility::io::izstream status( dirname+
"/STATUS" );
267 if ( status.good() ) {
269 b_have_restored =
true;
271 tr.Info <<
name() <<
": no archive status found... " << std::endl;
274 mem_tr <<
"ArchiveBase::restored_from_file" << std::endl;
275 return b_have_restored;
284 runtime_assert( tag ==
"acceptance_history:" );
287 while ( tag !=
"END_AH" ) {
288 runtime_assert( tag ==
"AH:" );
290 std::istringstream line_stream( line );
291 typedef std::istream_iterator< AcceptHistoryQueue::value_type > istream_iterator;
292 std::copy( istream_iterator( line_stream ), istream_iterator(), std::back_inserter(
acceptance_history_ ) );
295 mem_tr <<
"ArchiveBase::restored_status" << std::endl;
299 using namespace ObjexxFCL::fmt;
300 os <<
"total_accepts accepts_during_stage total_proposed proposed_during_stage\n"
304 Size const cols( 50 );
308 if ( ct <= 1 ) { os <<
"\nAH: "; ct = cols; }
310 os <<
"\nEND_AH" << std::endl;
314 using namespace core::io::silent;
316 tr.Debug <<
"generate batch number " << ct_batches_ << std::endl;
317 if ( ct_batches_ <= 3 ||
decoys().
size()==0 ) {
322 utility::io::ozstream flags( batch.
flag_file() );
323 if ( ct_batches_ == 1 && make_mistake_ ) flags <<
"-abinitio::sskip_stages 1 2" << std::endl;
324 flags <<
"-abinitio::skip_convergence_check" << std::endl;
332 make_mistake_ =
false;
337 std::copy(
decoys().begin(),
decoys().
end(), std::back_inserter( start_decoys ) );
339 Batch& batch(
manager().start_new_batch( start_decoys ) );
341 utility::io::ozstream broker( batch.
broker_file() );
342 broker <<
"USE_INPUT_POSE\n\nCLAIMER StartStructClaimer\nEND_CLAIMER\n" << std::endl;
351 runtime_assert( cen_score_ );
352 (*cen_score_)( pose );
359 make_mistake_( true )
361 using namespace basic::options;
362 using namespace basic::options::OptionKeys;
363 using namespace core::scoring;
369 out <<
"nr_batches_generated: "<<
ct_batches_ << std::endl;
382 decoys().push_back( decoy );