Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
minirosetta.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief
12 
13 #ifdef BOINC
14 #include <utility/io/ozstream.hh>
17 #include <protocols/boinc/boinc.hh>
18 #include "boinc_zip.h"
19 #endif // BOINC
20 
21 /// Must have this after BOINC stuff to avoid windows build error
22 #include <core/io/silent/util.hh>
23 #include <protocols/abinitio/AbrelaxApplication.hh>
24 #include <protocols/abinitio/IterativeAbrelax.hh>
25 #include <protocols/cyclic_peptide_predict/SimpleCycpepPredictApplication.hh>
26 #include <protocols/jd2/archive/ArchiveManager.hh>
27 #include <protocols/abinitio/BrokerMain.hh>
28 #include <protocols/boinc/util.hh>
29 #include <protocols/comparative_modeling/cm_main.hh>
30 #include <protocols/medal/MedalMain.hh>
31 #include <protocols/symmetric_docking/SymDockProtocol.hh>
32 #include <protocols/rbsegment_relax/RBSegmentRelax_main.hh>
33 #include <protocols/loop_build/LoopBuild.hh>
34 #include <protocols/loophash/Mover_LoopHashRefine.hh>
35 #include <protocols/abinitio/vs_test.hh>
36 #include <protocols/jd2/JobDistributor.hh>
37 #include <protocols/ligand_docking/ligand_dock_impl.hh>
38 #include <protocols/flxbb/FlxbbDesign_main.hh>
39 #include <protocols/ddg/ddG_main.hh>
40 #include <protocols/canonical_sampling/CanonicalSamplingApplication.hh>
41 #include <protocols/canonical_sampling/CanonicalSamplingMover.hh>
42 #include <protocols/frag_picker/nonlocal/NonlocalFragsMain.hh>
43 #include <protocols/star/StarAbinitioMain.hh>
44 
45 #ifdef BOINC
46 #include <protocols/boinc/boinc.hh>
47 #include <protocols/init/init.hh>
48 #endif
49 
50 #ifdef WIN32
51 #include <protocols/init/init.hh>
52 #include <core/import_pose/import_pose.hh>
53 #include <core/io/pdb/pose_io.hh>
54 #endif
55 
56 #include <core/types.hh>
57 
58 #ifndef BOINC
59 #ifndef WIN32
60 #include <devel/init.hh>
61 #endif
62 #endif
63 
64 #ifdef BOINC
65 #include <core/pose/Pose.hh>
66 #include <core/import_pose/import_pose.hh>
67 #include <core/io/pdb/pose_io.hh>
68 #include <core/io/silent/util.hh>
69 #include <core/pose/util.hh>
70 #endif
71 
72 #include <basic/options/option.hh>
73 #include <utility/exit.hh>
75 
76 // option key includes
77 #include <basic/options/keys/in.OptionKeys.gen.hh>
78 #include <basic/options/keys/run.OptionKeys.gen.hh>
79 #include <basic/options/keys/jd2.OptionKeys.gen.hh>
80 #include <basic/options/keys/boinc.OptionKeys.gen.hh>
81 
82 #include <protocols/checkpoint/Checkpoint.hh>
83 #include <protocols/jd2/BOINCJobDistributor.hh>
84 #include <protocols/relax/relax_main.hh>
85 #include <utility/vector0.hh>
86 #include <utility/vector1.hh>
87 
89 public:
90  DummyMover() : protocols::moves::Mover( "DummyMover" ) {}
91  virtual ~DummyMover(){}
92  virtual void apply( core::pose::Pose & ) {
93  std::cerr << "DummyMover::apply() should never have been called!"
94  << " (JobDistributor/Parser should have replaced DummyMover.)" << std::endl;
95  runtime_assert(false); // will enable a backtrace in gdb
96  }
97  virtual std::string get_name() const { return "DummyMover"; }
98 };
99 
100 int
101 main( int argc, char * argv [] )
102 {
103  try {
104 
105  using namespace basic::options;
106  using namespace basic::options::OptionKeys;
107  using std::string;
108  using utility::vector1;
109 
110 #ifdef BOINC // BOINC STUFF
111 
112  // initialize boinc
113  using namespace protocols::boinc;
114  Boinc boinc_wu = Boinc::instance();
115  boinc_wu.initialize_worker(); //The shared memory gets created here.
116 
117  // make sure -use_filters flag is not ambiguous
118  for (int i=0; i<argc; ++i) {
119  if (!strcmp(argv[i], "-use_filters")) {
120  std::cerr << "Fixing ambiguous flag " << argv[i];
121  char tmpstr[] = "-abinitio::use_filters";
122  argv[i] = tmpstr;
123  std::cerr << " to " << argv[i] << std::endl;
124  }
125  }
126  // print command to stderr
127  std::cerr << "command:";
128  for ( int i=0; i< argc; ++i ) {
129  std::cerr << ' ' << argv[i];
130  }
131  std::cerr << std::endl;
132 
133 #endif
134 
135  // has to be called before core::init::init. Which is really stupid.
136 #ifdef BOINC // BOINC STUFF
137  std::cerr << "Registering options.. " << std::endl;std::cerr.flush();
138 #endif
143  //protocols::canonical_sampling::register_options();
145 
146 
147 #ifdef BOINC // BOINC STUFF
148  std::cerr << "Initializing broker options ..." << std::endl;std::cerr.flush();
149 #endif
150  protocols::abinitio::register_options_broker();
151  // options, random initialization
152 #ifdef BOINC // BOINC STUFF
153  std::cerr << "Initializing core..." << std::endl;std::cerr.flush();
154 #endif
155 
156 #ifndef BOINC
157 #ifndef WIN32
158  // No devel in BOINC builds
159  devel::init( argc, argv );
160 #endif
161 #endif
162 
163 #ifdef BOINC
164  protocols::init::init( argc, argv );
165 #endif
166 #ifdef WIN32
167  protocols::init::init( argc, argv );
168 #endif
169 
170 #ifdef BOINC // BOINC STUFF
171 
172 #ifdef BOINC_GRAPHICS
173  // read the work unit description file if one exists
174  std::cerr << "Setting WU description ..." << std::endl;std::cerr.flush();
175  Boinc::set_wu_desc();
176  Boinc::set_randomly_cycle_appearance( option[run::protocol]() != "simple_cycpep_predict" ); // Set whether the app should randomly cycle the graphics
177 #endif
178 
179  // unzip an archive?
180  if (option[ in::file::zip ].user()) {
181  std::string resolvedfile = option[ in::file::zip ]();
182  bool is_database = false;
183  if (resolvedfile == "minirosetta_database.zip") {
184  is_database = true;
185  }
186  if (is_database && utility::file::file_exists( "minirosetta_database.zip.is_extracted" )) {
187  std::cerr << "Using previously extracted minirosetta_database." << std::endl;std::cerr.flush();
188  } else {
189  utility::boinc::resolve_filename( resolvedfile );
190  if (!utility::file::file_exists( resolvedfile )) {
191  utility_exit_with_message("in::file::zip "+
192  option[ in::file::zip ]()+" does not exist!");
193  } else {
194  std::cerr << "Unpacking zip data: " << resolvedfile << std::endl;std::cerr.flush();
195  boinc_zip(UNZIP_IT, resolvedfile, "./");
196  if (is_database) {
197  utility::io::ozstream data( "minirosetta_database.zip.is_extracted" );
198  }
199  }
200  }
201  }
202 
203  // unzip an archive of files specific to a given BOINC workunit.
204  if ( option[ in::file::boinc_wu_zip ].user() ) {
205  std::cerr << "Unpacking WU data ..." << std::endl; std::cerr.flush();
206  vector1< string > files = option[ in::file::boinc_wu_zip ]();
207  for( vector1< string >::const_iterator it = files.begin(), end = files.end(); it != end; ++it ) {
208  std::string resolvedfile = *it;
209  utility::boinc::resolve_filename( resolvedfile );
210  if ( !utility::file::file_exists( resolvedfile ) ) {
211  utility_exit_with_message( "in::file::boinc_wu_zip " +
212  *it + " does not exist!"
213  );
214  } else {
215  std::cerr << "Unpacking data: " << resolvedfile << std::endl;std::cerr.flush();
216  boinc_zip(UNZIP_IT, resolvedfile, "./");
217  }
218  }
219  }
220 
221  // override database option and set to current directory
222  std::cerr << "Setting database description ..." << std::endl;std::cerr.flush();
223 
224  option[in::path::database].value("minirosetta_database");
225 
226  std::cerr << "Setting up checkpointing ..." << std::endl;std::cerr.flush();
227 #endif
228  if ( option[ run::checkpoint ] || option[ run::checkpoint_interval ].user() ) {
229  protocols::checkpoint::checkpoint_with_interval( option[ run::checkpoint_interval ] );
230  }
231 
232 #ifdef BOINC_GRAPHICS
233  std::cerr << "Setting up graphics native ..." << std::endl;std::cerr.flush();
234  // set native for graphics
235  if ( option[ in::file::native ].user() ) {
236  core::pose::PoseOP native_pose_( new core::pose::Pose );
237  core::import_pose::pose_from_pdb( *native_pose_, option[ in::file::native ]() );
238  if ( native_pose_->total_residue() <= protocols::boinc::MAX_NATIVE_POSE_RESIDUES ) {
239  core::pose::set_ss_from_phipsi( *native_pose_ );
240  protocols::boinc::Boinc::set_graphics_native_pose( *native_pose_ );
241  }
242  }
243 
244  protocols::boinc::Boinc::set_shared_memory_fully_initialized(); //Signal that the shared memory is fully initialized at this point, and can be used by the graphics app.
245 #endif
246 
247 
248  // RUN PROTOCOL
249  // catch *any* exception.
250  try{
251  if ( option[ run::protocol ]() == "abrelax" ) {
252  protocols::abinitio::AbrelaxApplication abrelax;
253  abrelax.run();
254  } else if ( option[run::protocol]() == "simple_cycpep_predict" ) {
255  protocols::cyclic_peptide_predict::SimpleCycpepPredictApplication peppredict;
256  peppredict.run();
257  } else if ( option[ run::protocol ]() == "symdock" ) {
258  protocols::symmetric_docking::SymDock_main();
259  } else if ( option[ run::protocol ]() == "broker" ) {
260  protocols::abinitio::Broker_main();
261  } else if ( option[ run::protocol ]() == "loophash" ) {
262  protocols::loophash::loophash_main();
263  } else if ( option[ run::protocol ]() == "ligand_dock" ) {
264  ligand_dock_main();
265  } else if ( option[ run::protocol ]() == "relax" ) {
266  protocols::relax::Relax_main( true );
267  } else if ( option[ run::protocol ]() == "looprelax" ) {
268  protocols::loop_build::LoopBuild_main( true );
269  } else if ( option[ run::protocol ]() == "threading" ) {
270  protocols::comparative_modeling::cm_main();
271  } else if ( option[ run::protocol ]() == "medal" ) {
272  protocols::medal::Medal_main(NULL);
273  } else if ( option[ run::protocol ]() == "medal_exchange" ) {
274  protocols::medal::MedalExchange_main(NULL);
275  } else if ( option[ run::protocol ]() == "star" ) {
276  protocols::star::StarAbinitio_main(NULL);
277  } else if ( option[ run::protocol ]() == "rbsegmentrelax" ) {
278  protocols::RBSegmentRelax_main( );
279  } else if ( option[ run::protocol ]() == "boinc_debug" ) {
280  protocols::abinitio::run_boinc_debug();
281  } else if ( option[ run::protocol ]() == "flxbb" ) {
282  protocols::flxbb::FlxbbDesign_main();
283  } else if ( option[ run::protocol ]() == "jd2_scripting" ) {
284  protocols::moves::MoverOP mover( new DummyMover );
285  option[ jd2::dd_parser ].value( true ); // This option MUST be set true if we're using rosetta_scripts.
286  // To avoid accidental crashes, we'll do so programatically
287  protocols::jd2::BOINCJobDistributor::get_instance()->go( mover );
288  } else if ( option[run::protocol]() == "ddg" ) {
289  protocols::ddG_main();
290  } else if ( option[run::protocol]() == "canonical_sampling" ) {
291  protocols::canonical_sampling::canonical_sampling_main();
292  } else if ( option[run::protocol]() == "nonlocal_frags" ) {
293  protocols::frag_picker::nonlocal::NonlocalFrags_main();
294  } else {
296  "Invalid protocol requested: "+ option[ run::protocol ]()
297  );
298  return 0; // makes compiler happy
299  }
300  //---code to do a in spot score cut necessary for running centroid abinitio through boinc
301 #ifdef BOINC
302  double runtime = protocols::boinc::Boinc::get_boinc_wu_cpu_time();
303 #else
304  double runtime = -1; //-1 does not do filtering
305 #endif
306  if ( option[boinc::score_cut_pct].user() ) {
307  double minTimePerModel = 61; //seconds per model min time for boinc.
308  protocols::boinc::boincOutputFilter(runtime,minTimePerModel); //ideally score cut alone, but an additional filter that allows only 1 structure every 61 seconds.
309  }
310 #ifdef BOINC
311 
312  // gzip the output silent files.
313  std::cerr << "reached end of minirosetta::main()" << std::endl;
315 
316  // ideally these would be called in the dtor but the way we have the singleton pattern set up the dtors don't get
317  // called
318  protocols::boinc::Boinc::worker_finish_summary( protocols::boinc::Boinc::decoy_count() + 2 , protocols::boinc::Boinc::decoy_count() + 2 , 2 );
319  protocols::boinc::Boinc::worker_shutdown(); // Does not return.
320  utility_exit_with_message( "reached end of minirosetta::main() after worker_shutdown(); " );
321 #endif
322  } catch ( utility::excn::EXCN_Base& excn ) {
323  std::cerr << "std::cerr: Exception was thrown: " << std::endl;
324  excn.show( std::cerr );
325  std::cout << "std::cout: Exception was thrown: " << std::endl;
326  excn.show( std::cout ); //so its also seen in a >LOG file
327 #ifdef USEMPI
328  MPI_Abort( MPI_COMM_WORLD, 911 );
329 #endif
330  return 1; // MUST return non-0 - otherwise BOINC does not abort!
331  }
332 
333  } catch ( utility::excn::EXCN_Base const & e ) {
334  std::cout << "caught exception " << e.msg() << std::endl;
335  return -1;
336  }
337  return 0;
338 }
339 
340 #ifdef BOINC
341 #ifdef _WIN32
342 
343 /*******************************************************
344  * Windows: Unix applications begin with main() while Windows applications
345  * begin with WinMain, so this just makes WinMain() process the command line
346  * and then invoke main()
347  */
348 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
349  LPSTR Args, int WinMode)
350 {
351  LPSTR command_line;
352  char* argv[1024];
353  int argc;
354 
355  command_line = GetCommandLine();
356  argc = parse_command_line( command_line, argv );
357  return main(argc, argv);
358 }
359 #endif
360 #endif
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void register_options()
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
vector0: std::vector with assert-checked bounds
Wrappers to make BOINC work.
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
utility::keys::lookup::end< KeyType > const end
Platform independent operations on files (except I/O)
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
Definition: exit.hh:63
long gzip(std::string const &uncompressedfile, bool overwrite)
gzip: file compression
Definition: gzip_util.cc:42
int main(int argc, char *argv[])
Definition: minirosetta.cc:101
common derived classes for thrown exceptions
tuple database
virtual void show(std::ostream &) const =0
virtual ~DummyMover()
Definition: minirosetta.cc:91
Program exit functions and macros.
virtual std::string get_name() const
Definition: minirosetta.cc:97
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
Output file stream wrapper for uncompressed and compressed files.
list native
Definition: ContactMap.py:108
virtual void apply(core::pose::Pose &)
Definition: minirosetta.cc:92
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
bool file_exists(std::string const &path)
Does File Exist?
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
Must have this after BOINC stuff to avoid windows build error.
Definition: minirosetta.cc:88
void init()
set global 'init_was_called' to true
Definition: init.cc:26
Program options global and initialization function.
ocstream & flush()
Flush the stream.
Definition: ocstream.hh:143