Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util.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 protocols/jd2/JobDistributor.cc
11 /// @brief August 2008 job distributor as planned at RosettaCon08 - Base class
12 /// @author Oliver Lange
13 
14 // Unit Headers
15 
16 #ifdef USEMPI
17 #include <mpi.h>
18 #endif
19 
20 #include <protocols/jd2/util.hh>
21 
26 #include <protocols/jd2/Job.hh>
28 #include <basic/message_listening/MessageListenerFactory.hh>
29 
31 
32 #include <core/pose/Pose.hh>
33 
37 
38 
39 #include <basic/Tracer.hh>
40 
41 #include <basic/options/keys/out.OptionKeys.gen.hh>
42 #include <basic/options/keys/in.OptionKeys.gen.hh>
43 // AUTO-REMOVED #include <basic/options/keys/jd2.OptionKeys.gen.hh>
44 #include <basic/options/keys/run.OptionKeys.gen.hh>
45 // AUTO-REMOVED #include <basic/options/keys/parser.OptionKeys.gen.hh>
46 // AUTO-REMOVED #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
47 #include <basic/options/option_macros.hh>
48 
49 #include <utility/mpi_util.hh>
50 #include <utility/assert.hh>
51 
53 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
54 #include <protocols/moves/Mover.hh>
55 
57 #include <utility/vector1.hh>
58 
59 
60 namespace protocols {
61 namespace jd2 {
62 
63 
66  using namespace basic::options::OptionKeys;
67  OPT( in::file::silent );
68  OPT( in::file::s );
69  OPT( in::file::l );
70  OPT( in::file::native );
71  OPT( in::file::silent_read_through_errors );
72  OPT( out::file::silent );
73  OPT( out::file::scorefile );
74  OPT( run::batches );
75  OPT( run::archive );
76 }
77 
78 
79 static basic::Tracer TR("protocols.jd2.JobDistributor");
80 
81 //multithreaded case requires specia
82 ///end parser interface, start Job Distributor interface/////////////
84  core::pose::Pose const & pose,
85  std::string const & stage_tag,
86  int copy_count,
87  bool score_only
88 ) {
89  JobDistributor* jd
91  if ( jd && jd->job_outputter() && jd->current_job() ) {
92  jd->job_outputter()->other_pose( jd->current_job(), pose, stage_tag, copy_count, score_only );
93  } else {
94  TR.Warning << "can't output intermediate pose if not running with jobdistributor ( jd2 / 2008 )" << std::endl;
95  }
96 }
97 
99  JobDistributor* jd
101  if ( jd && jd->job_outputter() && jd->current_job() ) {
102  return jd->job_outputter()->output_name( jd->current_job() );
103  } else return "NoTag";
104 }
105 
107  JobDistributor* jd
109  if ( jd ) {
110  return jd->get_current_batch();
111  } else return "NoJD2";
112 }
113 
114 bool jd2_used() {
115  JobDistributor* jd
117  return ( jd && jd->job_outputter() && jd->current_job() != JD2_BOGUS_JOB );
118 }
119 
122  if ( jd && jd->job_outputter() ) {
123  JobOP job = jd->current_job();
124  if ( job ) {
125  return jd->job_outputter()->filename( job );
126  }
127  }
128  return "JD2_OUTPUT_FILE_UNKNOWN"; //else
129 }
130 
131 void
132 write_score_tracer( core::pose::Pose const& pose_in, std::string tracer_point ) {
133  static basic::Tracer tr_score("protocols.jd2.score", basic::t_info, true /*muted by default*/ );
134 
135  if ( !tr_score.visible() ) return;
136 
137  JobDistributor* jd
139 
140  if ( !jd || !jd->job_outputter()) {
141  tr_score.Warning << "can't output intermediate pose if not running with jobdistributor ( jd2 / 2008 )" << std::endl;
142  return;
143  }
144 
148  JobCOP job( get_current_job() );
149  std::string tag( jd->job_outputter()->output_name( job ) );
150  ss->fill_struct( pose_in, tag );
151  add_job_data_to_ss( ss, job );
152 
153  core::pose::Pose pose( pose_in );
154  jd->job_outputter()->evaluate( pose, tag, *ss );
155 
156  ss->add_string_value("tracer_point", tracer_point );
157 
159  if ( !basic::options::option[ basic::options::OptionKeys::out::file::silent_print_all_score_headers ]() ) {
160  ss->print_header( tr_score );
161  }
162  sfd.write_silent_struct( *ss, tr_score, true /*write scores only*/ );
163  tr_score.flush();
164 }
165 
167  JobDistributor* jd
169  if ( jd && jd->job_inputter() ) {
170  return jd->current_job();
171  }
172  else return NULL;
173 }
174 
176  JobDistributor* jd
178  core::pose::PoseCOP pose( NULL );
179  if ( jd && jd->job_outputter() && jd->job_inputter() && jd->current_job() ) {
180  JobOP job = jd->current_job();
182  jd->job_inputter()->pose_from_job( *aPose, job);
183  pose = aPose;
184  }
185  return pose;
186 }
187 
189  using namespace core::pose;
190 
191  typedef Job::StringStringPairs::const_iterator str_iter;
192  for ( str_iter iter = job_op->output_string_string_pairs_begin(),
193  end = job_op->output_string_string_pairs_end();
194  iter != end; ++iter
195  ) {
196  ss->add_string_value(iter->first, iter->second );
197  }
198 
199  typedef Job::StringRealPairs::const_iterator real_iter;
200  for ( real_iter iter = job_op->output_string_real_pairs_begin(),
201  end = job_op->output_string_real_pairs_end();
202  iter != end; ++iter
203  ) {
204  ss->add_energy( iter->first, iter->second, 1.0 );
205  }
206 }
207 
208 
210  using namespace basic::options;
211  using namespace basic::options::OptionKeys;
212 
213  if ( option[ in::file::native ].user() ) {
214  core::pose::PoseOP native_pose = new core::pose::Pose;
216  if ( option[ in::file::fullatom ]() ) {
218  } else {
220  }
221  std::string native_pdb_file = option[ in::file::native ]();
222  core::import_pose::pose_from_pdb( *native_pose, *rsd_set, native_pdb_file );
223  mover.set_native_pose( native_pose );
224  }
225 }
226 
227 
228 #ifdef USEMPI
229 ///@brief returns communicator defined by the JobDistributor or MPI_COMM_WORLD
230 MPI_Comm const& current_mpi_comm() {
231  JobDistributor* jd
233  if ( jd ) {
234  MPIMultiCommJobDistributor* mpi_jd = dynamic_cast< MPIMultiCommJobDistributor* >( jd );
235  if ( mpi_jd ) {
236  return mpi_jd->current_mpi_comm();
237  }
238  }
239  //return MPI_COMM_WORLD; //causes warning: returning reference to temporary
240  //workaround to avoid warning ( MPI_COMM_WORLD is actually a macro )
241  TR.Trace << "Requested jd2::current_mpi_comm() but apparently flag -run:n_replica was not set.";
242  TR.Trace << "Returning MPI_COMM_WORLD" << std::endl;
243  static MPI_Comm my_mpi_comm_world = MPI_COMM_NULL;
244  MPI_Comm_dup( MPI_COMM_WORLD, &my_mpi_comm_world );
245  return my_mpi_comm_world;
246 }
247 #endif
248 
250  JobDistributor* jd
252  if ( jd ) {
253  MPIMultiCommJobDistributor* mpi_jd = dynamic_cast< MPIMultiCommJobDistributor* >( jd );
254  if ( mpi_jd ) {
255  return mpi_jd->sub_rank()+1;
256  }
257  }
258  return 0;
259 }
260 
261 } // jd2
262 } // protocols