18 #include <basic/TracerToFile.hh>
28 #include <basic/options/option.hh>
29 #include <utility/basic_sys_util.hh>
30 #include <utility/excn/Exceptions.hh>
31 #include <utility/io/izstream.hh>
32 #include <basic/Tracer.hh>
33 #include <basic/prof.hh>
197 #ifndef WIN_PYROSETTA
198 #include <platform/types.hh>
202 #include <mach-o/dyld.h>
206 #include <basic/options/keys/in.OptionKeys.gen.hh>
211 using basic::Warning;
214 #if (defined WIN32) && (!defined WIN_PYROSETTA)
216 #include <wincrypt.h>
226 #include <basic/options/keys/out.OptionKeys.gen.hh>
227 #include <basic/options/keys/run.OptionKeys.gen.hh>
228 #include <basic/options/keys/corrections.OptionKeys.gen.hh>
229 #include <basic/options/keys/score.OptionKeys.gen.hh>
230 #include <basic/options/keys/OptionKeys.hh>
233 #include <basic/resource_manager/ResourceLoaderRegistrator.hh>
240 #include <basic/resource_manager/ResourceOptionsRegistrator.hh>
250 #include <basic/options/keys/LoopModel.OptionKeys.gen.hh>
256 #include <utility/vector0.hh>
257 #include <utility/vector1.hh>
275 using namespace scoring::methods;
405 using namespace scoring::constraints;
426 using namespace core::io::silent;
436 using namespace core::sequence;
443 using namespace pack::task::operation;
492 using basic::resource_manager::ResourceLoaderRegistrator;
499 using basic::resource_manager::ResourceOptionsRegistrator;
508 static basic::Tracer
TR(
"core.init");
511 using namespace basic::options;
512 using namespace basic::options::OptionKeys;
516 init_mpi(
int argc,
char * argv []) {
517 int already_initialized( 0 );
518 MPI_Initialized( & already_initialized );
519 if ( already_initialized == 0 ) MPI_Init(&argc, &argv);
530 std::cerr <<
"Initializing options.... ok " << std::endl;std::cerr.flush();
534 initialize().load( argc, argv,
false );
536 std::cerr <<
"Loaded options.... ok " << std::endl;std::cerr.flush();
540 std::cerr <<
"Processed options.... ok " << std::endl; std::cerr.flush();
544 OptionCollection::set_show_accessed_options_flag( option[ out::show_accessed_options ].value() );
550 basic::TracerOptions & TO( basic::Tracer::tracer_options() );
552 if( option[ out::mute ].active() ) TO.muted = option[ out::mute ]();
554 if( option[ out::unmute ].active() ) TO.unmuted = option[ out::unmute ]();
555 if( option[ out::level ].active() ) TO.level = option[ out::level ]();
556 if( option[ out::levels ].active() ) TO.levels = option[ out::levels ]();
557 if( option[ out::chname ].active() ) TO.print_channel_name = option[ out::chname ]();
558 if( option[ out::chtimestamp ].active() ) TO.timestamp = option[ out::chtimestamp ]();
561 utility::add_exit_callback(basic::Tracer::flush_all_tracers);
568 if( option[corrections::correct]) {
570 if ( ! option[ corrections::score::no_his_his_pairE ].user() ) {
571 option[corrections::score::no_his_his_pairE].value(
true );
578 if ( ! option[ corrections::score::p_aa_pp_nogridshift ].user() ) {
579 option[corrections::score::p_aa_pp_nogridshift].value(
true );
583 if ( ! option[ corrections::score::rama_not_squared ].user() ) {
584 option[corrections::score::rama_not_squared].value(
true );
586 if ( ! option[ corrections::score::rama_map ].user() ) {
587 option[ corrections::score::rama_map ].value(
"scoring/score_functions/rama/Rama09_noEH_kernel25_it08.dat");
590 if ( ! option[ corrections::score::dun02_file ].user() ) {
591 option[corrections::score::dun02_file].value(
"rotamer/bbdep02.May.sortlib-correct.12.2010" );
595 if ( ! option[ corrections::chemical::icoor_05_2009 ].user() ) {
596 option[corrections::chemical::icoor_05_2009].value(
true );
598 if ( ! option[ score::hbond_params ].user() ) {
599 option[score::hbond_params].value(
"correct_params" );
602 if ( ! option[ corrections::score::ch_o_bond_potential ].user() ) {
603 option[ corrections::score::ch_o_bond_potential ].value(
"scoring/score_functions/carbon_hbond/ch_o_bond_potential_near_min_yf.dat");
610 if( option[ run::version ]() ) {
617 if( option[ in::path::path ].user() ){
618 utility::io::izstream::set_alternative_search_paths(
619 option[ in::path::path ]());
630 if(option[LoopModel::input_pdb].user())
631 error_messages.push_back(
"-LoopModel:input_pdb is no longer used. Please use -s to input pdb files.");
634 if(error_messages.size() > 0)
637 for(error_it = error_messages.begin();error_it != error_messages.end();++error_it)
639 TR.Fatal <<
"ERROR: You have specified one or more deprecated flags:" <<std::endl;
640 TR.Fatal << *error_it <<std::endl;
651 for (
int i=0; i< argc; ++i ) {
652 TR <<
' ' << argv[i];
663 bool const_seed =
false;
664 bool use_time_as_seed =
false;
665 if( option[ run::constant_seed ].active() ) const_seed = option[ run::constant_seed ]();
666 if( option[ run::jran ].active() ) seed = option[ run::jran ]();
667 if( option[ run::seed_offset ].active() ) seed_offset = option[ run::seed_offset ]();
668 if( option[ run::use_time_as_seed ].active() ) use_time_as_seed = option[ run::use_time_as_seed ]();
671 if( option[ out::mpi_tracer_to_file ].user() ){
673 MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank );
675 std::stringstream outfilename;
676 outfilename << option[ out::mpi_tracer_to_file ]() <<
"_" << mpi_rank;
677 basic::otstreamOP redirect_tracer =
new basic::TracerToFile( outfilename.str() );
678 basic::Tracer::set_ios_hook( redirect_tracer, basic::Tracer::AllChannels,
false );
679 basic::Tracer::super_mute(
true );
685 std::string random_device_name( option[ run::rng_seed_device ]() );
690 real_seed = seed + seed_offset;
695 MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank );
699 T(
"core.init") <<
"Constant seed mode, seed=" << seed <<
" seed_offset=" << seed_offset
700 <<
" real_seed=" << real_seed << std::endl;
703 #if (defined WIN32) && (!defined WIN_PYROSETTA)
704 bool const on_windows_platform =
true;
706 bool const on_windows_platform =
false;
709 std::ifstream random_device( random_device_name.c_str(), std::ios::in | std::ios::binary );
710 if ( ( random_device.fail() && !on_windows_platform ) || use_time_as_seed ) {
711 if ( !use_time_as_seed ) {
713 T(
"core.init") <<
"NOTICE: rng device failure, using time as seed" << std::endl;
715 random_device.close();
725 real_seed = 1000*seed + seed_offset;
734 MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank );
736 MPI_Bcast( &real_seed, 1, MPI_INT, 0, MPI_COMM_WORLD );
741 T(
"core.init") <<
"'Time' seed mode, seed=" << seed <<
" seed_offset=" << seed_offset
742 <<
" real_seed=" << real_seed << std::endl;
745 uint32_t unsigned_32bit_seed;
747 #if (defined WIN32) && (!defined WIN_PYROSETTA)
749 random_device_name =
"CryptGenRandom";
753 key_container_name <<
"arzetta-" << GetCurrentProcessId() <<
"-" << GetCurrentThreadId();
756 HCRYPTPROV hCryptProv = 0;
758 if ( !CryptAcquireContext( &hCryptProv, key_container_name.str().c_str(), NULL, PROV_RSA_AES, CRYPT_NEWKEYSET ) ) {
759 TR.Fatal <<
"FATAL: CryptAcquireContext unable to acquire cryptographic provider!" << std::endl;
760 TR.Fatal << std::hex << GetLastError() << std::endl;
766 if ( !CryptGenRandom( hCryptProv, 4, pbData ) ) {
767 TR.Fatal <<
"FATAL: Unable to obtain random number seed using CryptGenRandom!" << std::endl;
768 TR.Fatal << std::hex << GetLastError() << std::endl;
773 unsigned_32bit_seed = pbData[ 0 ] + ( pbData[ 1 ] << 8 ) + ( pbData[ 2 ] << 16 ) + ( pbData[ 3 ] << 24 );
776 if ( !CryptReleaseContext( hCryptProv, 0 ) ) {
777 TR.Fatal <<
"FATAL: CryptReleaseContext failed to release cryptographic provider!" << std::endl;
778 TR.Fatal << std::hex << GetLastError() << std::endl;
783 if ( !CryptAcquireContext( &hCryptProv, key_container_name.str().c_str(), NULL, PROV_RSA_AES, CRYPT_DELETEKEYSET ) ) {
784 TR.Fatal <<
"FATAL: CryptAcquireContext failed to delete key container!" << std::endl;
785 TR.Fatal << std::hex << GetLastError() << std::endl;
790 random_device.read( reinterpret_cast< char * >( &unsigned_32bit_seed ),
sizeof( uint32_t ));
792 random_device.close();
795 seed =
static_cast< int >( unsigned_32bit_seed );
796 real_seed = seed + seed_offset;
807 MPI_Comm_rank( MPI_COMM_WORLD, &mpi_rank );
809 MPI_Bcast( &real_seed, 1, MPI_INT, 0, MPI_COMM_WORLD );
815 T(
"core.init") <<
"'RNG device' seed mode, using '" << random_device_name <<
"', seed=" << seed <<
" seed_offset=" << seed_offset
816 <<
" real_seed=" << real_seed << std::endl;
826 std::cerr <<
"Initializing random generators... ok " << std::endl;std::cerr.flush();
836 if( run_type == _RND_TestRun_ ) {
837 T(
"core.init.random") <<
"RandomGenerator:init: _RND_TestRun_ mode, seed=" << start_seed <<
838 " RG_type=" << RGtype << std::endl;
841 T(
"core.init.random") <<
"RandomGenerator:init: Normal mode, seed=" << start_seed <<
842 " RG_type=" << RGtype << std::endl;
845 RandomGenerator::initializeRandomGenerators(start_seed, run_type, RGtype);
854 if( !option[ run::nodelay ]() ){
855 if( option[ run::delay ]() > 0 ) {
856 int waittime = option[ run::delay ]();
857 TR <<
"Delaying start of mini for " << waittime <<
" seconds due to -delay option" << std::endl;
858 utility::sys_sleep( waittime );
862 TR <<
"Delaying of mini for " << waittime <<
" seconds (maximum = "
865 <<
"This prevents extreme IO levels when multiple jobs start simultaneously on" << std::endl
866 <<
"large computer clusters and is default now. To prevent this add the option -nodelay" << std::endl
867 <<
"To change the random wait time use -run::random_delay <int> " << std::endl;
868 utility::sys_sleep( waittime );
877 if ( !option[ in::path::database ].user() ) {
879 char * descr = getenv(
"ROSETTA3_DB");
881 TR <<
"found database environment variable ROSETTA3_DB: "<< descr << std::endl;
886 uint32_t path_size =
sizeof( path );
889 _NSGetExecutablePath(path, &path_size );
892 readlink(
"/proc/self/exe", path, path_size );
895 TR <<
"There is some way to automatically figure out the path to rosetta_database with GetModuleFileName in Windows. This is already set up for linux and mac, its probably just one line to change in core/init.cc" << std::endl;
901 Size found = path_string.find(
"rosetta_source/");
902 if ( found != std::string::npos && path_size > 0){
903 std::string rosetta_exe_dir = path_string.substr(0,found);
904 database_path = rosetta_exe_dir +
"rosetta_database/";
905 TR <<
"Looking for database based on location of executable: " << database_path << std::endl;
907 TR <<
"Could not determine location of executable." << std::endl;
912 if ( database_path.size() > 0 ){
913 option[ in::path::database ].value( database_path );
915 TR <<
"Could not find database. Either specify -database or set environment variable ROSETTA3_DB." << std::endl;
927 void init(
int argc,
char * argv [])
964 std::cerr <<
"Initialization complete. " << std::endl;
971 if ( argc == 1 )
TR << std::endl <<
"USEFUL TIP: Type -help to get the options for this Rosetta executable." << std::endl << std::endl;
975 catch( utility::excn::EXCN_Msg_Exception &e){
988 int argc = args.size();
989 char **argv =
new char*[ argc ];
990 for(
int ii = 0; ii < argc; ++ii ) {
991 argv[ ii ] =
new char[ args[ii+1].size()+1 ];
992 strncpy( argv[ii], args[ii+1].c_str(), args[ii+1].
size() );
993 argv[ ii ][ args[ii+1].size() ] = 0;
1000 for (
int ii = 0; ii < argc; ++ii ) {
1001 delete[] argv[ ii ];