Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomTreeDiffJobOutputter.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/AtomTreeDiffJobOutputter.cc
11 /// @brief AtomTreeDiffJobOutputter
12 /// @author Gordon Lemmon (gordon.h.lemmon@vanderbilt.edu); Rocco Moretti (rmoretti@u.washington.edu)
13 
14 ///Unit headers
17 #include <protocols/jd2/Job.hh>
18 #include <protocols/jd2/Job.fwd.hh>
19 
20 ///Project headers
21 #include <core/pose/Pose.hh>
23 
24 ///Utility headers
25 #include <basic/Tracer.hh>
26 #include <core/svn_version.hh>
27 #include <basic/options/option.hh>
28 #include <utility/io/ozstream.hh>
29 // AUTO-REMOVED #include <utility/io/izstream.hh>
30 #include <utility/file/file_sys_util.hh>
31 
32 // option key includes
33 
34 #include <basic/options/keys/out.OptionKeys.gen.hh>
35 #include <basic/options/keys/run.OptionKeys.gen.hh>
36 
37 #include <utility/vector1.hh>
38 
39 
40 ///C++ headers
41 //#include <string>
42 //#include <sstream>
43 
44 static basic::Tracer TR("protocols.jd2.AtomTreeDiffJobOutputter");
45 
46 namespace protocols {
47 namespace jd2 {
48 
49 using namespace basic::options;
50 using namespace basic::options::OptionKeys;
51 
53  bb_precision_(6),
54  sc_precision_(4),
55  bondlen_precision_(2),
56  use_input_(false)
57 {
58 
59  set_precision( option[ out::file::atom_tree_diff_bb ], option[ out::file::atom_tree_diff_sc ], option[ out::file::atom_tree_diff_bl ] );
60 
61  // Add directory path and prefix/suffix (if specified) to plain file name:
62  outfile_name_= basic::options::option[ OptionKeys::out::file::atom_tree_diff ]();
63  {
64  /// TODO abstract this section to a generic file for all job outputters
66  std::ostringstream oss;
67  oss << basic::options::option[ basic::options::OptionKeys::out::prefix ]() << outfile.base()
68  << basic::options::option[ basic::options::OptionKeys::out::suffix ]();
69  outfile.base( oss.str() );
70  if ( basic::options::option[ basic::options::OptionKeys::out::path::pdb ].user() ){
71  outfile.path(basic::options::option[ basic::options::OptionKeys::out::path::pdb ]().path());
72  outfile.vol(basic::options::option[ basic::options::OptionKeys::out::path::pdb ]().vol());
73  } else if( basic::options::option[ basic::options::OptionKeys::out::path::all ].user() ){
74  outfile.path(basic::options::option[ basic::options::OptionKeys::out::path::all ]().path());
75  outfile.vol(basic::options::option[ basic::options::OptionKeys::out::path::all ]().vol());
76  }else{
77  outfile.path("");
78  outfile.vol("");
79  }
80 
81  if( basic::options::option[ basic::options::OptionKeys::out::pdb_gz ] && outfile.ext() != "gz" ) {
82  outfile.ext( ".gz" ); // else use input extension
83  }
84  outfile_name_ = outfile.name();
85  }
86 
87  //Looks like we want to only have the file open when we're actually writing, moved this to dump_pose
88 
89  /*
90  if( utility::file::file_exists(outfile_name) ) {
91  atom_tree_diff_.read_file(outfile_name);
92  out_.open_append( outfile_name.c_str() );
93  } else {
94  out_.open( outfile_name.c_str() );
95  if( basic::options::option[ basic::options::OptionKeys::run::version ] ) {
96  out_ << "# Mini-Rosetta version " << core::minirosetta_svn_version() << " from " << core::minirosetta_svn_url() << "\n";
97  }
98  }
99  if ( !out_.good() ) {
100  utility_exit_with_message( "Unable to open file: " + outfile_name + "\n" );
101  }
102  */
103 }
104 
106 
107 void
109  std::map< std::string, core::Real > scores;
110  for( Job::StringRealPairs::const_iterator it(job->output_string_real_pairs_begin()), end(job->output_string_real_pairs_end());
111  it != end; ++it) {
112  // Need to use operator[], as we want later (more recent) items in the string_real_pairs list to overwrite the earlier ones
113  // (e.g. if we've recomputed a value that was read in from the inital silent file.)
114  // Standard constructors/copy functions ignores items which are already in map.
115  scores[it->first] = it->second;
116  }
117 
118  std::string output= output_name(job);
119  dump_pose( output, pose, scores, job);
120 
121 }
122 
123 ///@brief Appends pose to atom tree diff file
124 void
126  std::string const & tag,
127  core::pose::Pose const & pose,
128  std::map< std::string, core::Real > scores,
129  JobCOP job
130 ){
131 
133  //atom_tree_diff_.read_file(outfile_name_);
134  out_.open_append( outfile_name_.c_str() );
135  } else {
136  out_.open( outfile_name_.c_str() );
137  if( basic::options::option[ basic::options::OptionKeys::run::version ] ) {
138  out_ << "# Mini-Rosetta version " << core::minirosetta_svn_version() << " from " << core::minirosetta_svn_url() << "\n";
139  }
140  }
141  if ( !out_.good() ) {
142  utility_exit_with_message( "Unable to open file: " + outfile_name_ + "\n" );
143  }
144 
145  if ( use_input_ && job ) {
146  // Use the input pose as the reference pose, matching the original ligand docking application.
147  std::string const ref_tag( job->input_tag() );
148  TR<< "ref_tag: "<< ref_tag<< std::endl;
149  if( last_ref_tag_ != ref_tag ){
150  TR<< "writing reference pose"<< std::endl;
151  std::map< std::string, core::Real > temp_scores;
152  temp_scores["is_reference_pose"]= 1;
153  job->get_pose(last_ref_pose_); // deep copy for reference pose
154  last_ref_tag_= ref_tag; // deep copy for reference pose
155  // Yes, we're outputting the input pose, but using the output tag -- we need the extra numbers on the end so we can slice them off when reading
157  }
158  } else {
159  // Use the current structure as the reference pose, if we don't already have an applicable one.
160  core::Size end= tag.find_last_of('_');
161  std::string const ref_tag= tag.substr(0, end);
162  TR<< "ref_tag: "<< ref_tag<< std::endl;
163  if( last_ref_tag_ != ref_tag ){
164  TR<< "writing reference pose"<< std::endl;
165  std::map< std::string, core::Real > temp_scores;
166  temp_scores["is_reference_pose"]= 1;
167  core::import_pose::atom_tree_diffs::dump_reference_pose(out_, "%REF%_"+tag, temp_scores, pose);
168  last_ref_tag_= ref_tag;// deep copy for reference pose
169  last_ref_pose_= pose;// deep copy for reference pose
170  }
171  }
172  if( used_tags_.find(tag) != used_tags_.end() ){
173  basic::Error() << "Tag " << tag << " already exists in silent file; writing structure anyway..." << std::endl;
174  }
176  used_tags_.insert(tag);
177  // Can't flush compressed streams -- results in file truncation
178  if ( out_.uncompressed() ) out_.flush();
179  out_.close();
180 }
181 
182 
183 void
185  JobCOP /*job*/,
186  core::pose::Pose const & /*pose*/,
187  std::string const & /*tag*/,
188  int /*copy_count*/, /*default -1 */
189  bool /*score_only*/ /*default false*/
190  ){
191  // do something with this function later
192  return;
193 }
194 
195 bool
197  // was the job completed beforehand ( in the silent file before this app even started) ?
198  if( used_tags_.find( output_name( job )) != used_tags_.end() ) return true;
199  // did WE complete the job later ?
200  if( job->completed() ) return true;
201 
202  return false;
203 }
204 
207  return affixed_numbered_name( job );
208 }
209 
210 void
211 AtomTreeDiffJobOutputter::set_precision(int bb_precision, int sc_precision, int bondlen_precision ) {
212  bb_precision_ = bb_precision;
213  sc_precision_ = sc_precision;
214  bondlen_precision_ = bondlen_precision;
215 }
216 
217 ///@brief use input as reference pose?
218 void
220  // Reset reference tag, in case we're changing course midstream
221  last_ref_tag_ = "";
222  use_input_ = use_input;
223 }
224 
225 //CREATOR SECTION
228 {
229  return "AtomTreeDiffJobOutputter";
230 }
231 
234  return new AtomTreeDiffJobOutputter;
235 }
236 
237 }//jd2
238 }//protocols