Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDBJobOutputter.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/PDBJobOutputter.cc
11 /// @brief August 2008 job distributor as planned at RosettaCon08 - PDBJobOutputter
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 ///Unit headers
17 #include <protocols/jd2/Job.hh>
18 
19 ///Project headers
20 // AUTO-REMOVED #include <core/conformation/Residue.hh>
21 // AUTO-REMOVED #include <core/pose/Pose.hh>
22 //#include <core/pose/datacache/CacheableDataType.hh>
23 #include <core/io/pdb/pose_io.hh>
24 // AUTO-REMOVED #include <core/scoring/Energies.hh>
25 // AUTO-REMOVED #include <core/scoring/EnergyMap.hh>
26 
27 //#include <basic/datacache/CacheableStringFloatMap.hh>
28 //#include <basic/datacache/BasicDataCache.hh>
29 
30 ///Utility headers
31 #include <basic/Tracer.hh>
32 #include <utility/io/ozstream.hh>
33 #include <utility/file/file_sys_util.hh>
34 //#include <utility/file/FileName.hh>
35 #include <core/types.hh>
36 #include <basic/options/option.hh>
37 
38 ///C++ headers
39 //#include <string>
40 //#include <map>
41 #include <sstream>
42 
43 // option key includes
44 
45 #include <basic/options/keys/run.OptionKeys.gen.hh>
46 #include <basic/options/keys/out.OptionKeys.gen.hh>
47 
48 #include <core/io/pdb/file_data.hh>
49 #include <utility/vector1.hh>
50 
51 
52 
53 
54 static basic::Tracer TR("protocols.jd2.PDBJobOutputter");
55 
56 namespace protocols {
57 namespace jd2 {
58 
60  : parent(), extension_(".pdb")
61 {
62  using namespace basic::options::OptionKeys;
63  using basic::options::option;
64 
65  TR.Debug << "Using PDBJobOutputter (base class) for JobDistributor" << std::endl;
66 
67  if ( option[ out::pdb_gz ] ) {
68  extension_ = ".pdb.gz";
69  }
70 
71  if ( option[ out::path::pdb ].user() ) {
72  path_ = option[ out::path::pdb ]().path();
73  } else if (option[ out::path::all ].user() ) {
74  path_ = option[ out::path::all ]().path();
75  } else {
76  path_ = "";
77  }
78 }
79 
81 
82 //////////////////////////////creating output functions/////////////////////////////////////////
83 
85  JobCOP job,
86  core::pose::Pose const & pose
87 )
88 {
89  using namespace basic::options::OptionKeys;
90  using basic::options::option;
91  TR.Debug << "PDBJobOutputter::final_pose" << std::endl;
92 
93  utility::io::ozstream out( path_ + extended_name(job) );
94  if ( !out.good() ) utility_exit_with_message( "Unable to open file: " + path_ + extended_name(job) + "\n" );
95  dump_pose(job, pose, out);
96  out.close();
97  scorefile(job, pose);
98 }
99 
101  JobCOP job,
102  core::pose::Pose const & pose,
103  std::string const & tag,
104  int /*copy_count*/, /*default -1 */
105  bool /* score_only*/ /*default false*/
106 ){
107  TR.Debug << "PDBJobOutputter::other_pose" << std::endl;
108  runtime_assert( !tag.empty() ); //else you'll overwrite your pdb when the job finishes
109 
110  std::string const file(tag + extended_name(job));
111  utility::io::ozstream out( file );
112  if ( !out.good() ) utility_exit_with_message( "Unable to open file: " + file + "\n" );
113  dump_pose(job, pose, out);
114  out.close();
115 
116  //these are separate options because leaving the default on other_pose_scorefile is totally valid, but you can't both specify it on the command line and leave it blank
117  //THIS FUNCTIONALITY IS GOING TO BE DEPRECATED SOON
118  if( basic::options::option[ basic::options::OptionKeys::run::other_pose_to_scorefile ].value() ){
119  scorefile(job, pose, tag, basic::options::option[ basic::options::OptionKeys::run::other_pose_scorefile ].value());
120  }
121 }
122 
123 ///@details private function (just prevents code duplication) to fill ozstream
125  JobCOP job,
126  core::pose::Pose const & pose,
127  utility::io::ozstream & out
128 )
129 {
131  extract_scores(pose, out);
132  //extract_extra_scores(pose, out);
133  extract_data_from_Job( job, out );
134 }
135 
136 /////////////////////////////////state of output functions/////////////////////////////////
139 }
140 
142  return affixed_numbered_name( job );
143 }
144 
146  return output_name(job) + extension_;
147 }
148 
149 ////////////////////////////////////////score-related functions///////////////////////////////////
150 
151 ///@brief this function extracts the pose's scores for printing
152 /// @details In order for this to work as expected, the Pose's cached energies
153 /// must match up with the (current) conformation.
154 /// A good time to do this is at the end of your protocol's apply() method:
155 /// scorefxn( pose );
157  core::pose::Pose const & pose,
158  utility::io::ozstream & out
159 )
160 {
161  core::io::pdb::extract_scores( pose, out );
162 }
163 
164 //THIS FUNCTION WILL MOVE HIGHER IN THE HIERARCHY AT SOME POINT
165 ///@brief this function extracts the pose's scores for printing
166 void protocols::jd2::PDBJobOutputter::extract_data_from_Job( JobCOP job, utility::io::ozstream & out ){
167  //TR << "protocols::jd2::PDBJobOutputter::extract_data_from_Job" << std::endl;
168 
169  for( Job::Strings::const_iterator it(job->output_strings_begin()), end(job->output_strings_end());
170  it != end;
171  ++it) {
172  out << *it << std::endl;
173  //TR << *it << std::endl;
174  }
175 
176  for( Job::StringStringPairs::const_iterator it(job->output_string_string_pairs_begin()), end(job->output_string_string_pairs_end());
177  it != end;
178  ++it) {
179  out << it->first << " " << it->second << std::endl;
180  //TR << it->first << " " << it->second << std::endl;
181  }
182 
183  for( Job::StringRealPairs::const_iterator it(job->output_string_real_pairs_begin()), end(job->output_string_real_pairs_end());
184  it != end;
185  ++it) {
186  out << it->first << " " << it->second << std::endl;
187  //TR << it->first << " " << it->second << std::endl;
188  }
189 
190 }
191 
192 
193 //This function is deprecated for now - might return in the future
194 // ///@brief this function extracts the pose's extra data/scores for printing
195 // ///@details YOU are responsible for putting things into the pose's ARBITRARY_FLOAT_DATA in the DataCache. I suggest core::pose::util::setPoseExtraScores.
196 // void protocols::jd2::PDBJobOutputter::extract_extra_scores(
197 // core::pose::Pose const & pose,
198 // utility::io::ozstream & out)
199 // {
200 // using namespace core::pose::datacache;
201 // //is there extra data?
202 // if( !pose.data().has( ( CacheableDataType::ARBITRARY_FLOAT_DATA ) ) ){
203 // //TR << "no ARBITRARY_FLOAT_DATA" << std::endl;
204 // return;
205 // }
206 
207 // //get the data
208 // //basic::CacheableStringFloatMapCOP data( dynamic_cast< basic::datacache::CacheableStringFloatMap const* > (pose.data().get_const_ptr(CacheableDataType::ARBITRARY_FLOAT_DATA)() ) );
209 // //runtime_assert( data != NULL );
210 // typedef std::map< std::string, float > StringFloatMap;
211 // StringFloatMap data( (dynamic_cast< basic::datacache::CacheableStringFloatMap const* > (pose.data().get_const_ptr(CacheableDataType::ARBITRARY_FLOAT_DATA)() ) )->map() );
212 
213 // if (data.empty()) return;
214 
215 // //TR << "POSE EXTRA SCORES:" << std::endl;
216 // out << "POSE EXTRA SCORES:" << std::endl;
217 
218 // //iterate through the map
219 // for(StringFloatMap::const_iterator it(data.begin()), end(data.end()); it != end; ++it){
220 // //TR << it->first << " " << it->second << std::endl;
221 // out << it->first << " " << it->second << std::endl;
222 // }
223 
224 // return;
225 // }
226 
227 //CREATOR SECTION
230 {
231  return "PDBJobOutputter";
232 }
233 
236  return new PDBJobOutputter;
237 }
238 
239 }//jd2
240 }//protocols