Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileJobOutputter.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/FileJobOutputter.cc
11 /// @brief August 2008 job distributor as planned at RosettaCon08 - FileJobOutputter
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 ///Unit headers
16 #include <protocols/jd2/Job.hh>
17 
18 ///Project headers
19 // AUTO-REMOVED #include <core/pose/Pose.hh>
20 
23 
24 ///Utility headers
25 #include <basic/Tracer.hh>
26 #include <basic/options/option.hh>
27 #include <utility/io/ozstream.hh>
28 
29 // option key includes
30 
31 #include <basic/options/keys/out.OptionKeys.gen.hh>
32 #include <basic/options/keys/run.OptionKeys.gen.hh>
33 
34 #include <utility/vector1.hh>
35 
36 
37 
38 
39 ///C++ headers
40 //#include <string>
41 //#include <sstream>
42 
43 static basic::Tracer TR("protocols.jd2.FileJobOutputter");
44 
45 namespace protocols {
46 namespace jd2 {
47 
48 using namespace basic::options;
49 using namespace basic::options::OptionKeys;
50 
51 protocols::jd2::FileJobOutputter::FileJobOutputter() : parent(), write_scorefile_(false), scorefile_name_() {
52  TR.Debug << "FileJobOutputter ctor" << std::endl;
53  utility::file::FileName default_path( option[ out::path::all ]() );
54  if( option[ out::file::scorefile ].user() ){
55  write_scorefile_ = true;
56  scorefile_name_ = option[ out::file::scorefile ]();
57  if ( option[ out::path::score ].user() ) {
58  scorefile_name_.path( option[ out::path::score ]().path() );
59  }else if (! scorefile_name_.absolute() ) {
60  scorefile_name_.path( default_path.path() + "/" + scorefile_name_.path() );
61  }
62  }else if(option [out::file::score_only].user()){
63  write_scorefile_ = true;
64  scorefile_name_ = option[out::file::score_only]();
65  if (! scorefile_name_.absolute() ) scorefile_name_.path( default_path.path() + "/" + scorefile_name_.path() );
66  }else if ( !option[ run::no_scorefile ]() ) {
67  write_scorefile_ = true;
68  // set up all the information for the scorefile
69  utility::file::FileName outfile("score");
70  std::ostringstream oss;
71  //prefix, suffix
72  oss << option[ out::prefix ]() << outfile.base()
73  << option[ out::suffix ]();
74  outfile.base( oss.str() );
75  //path
76  if ( option[ out::path::score ].user() ) {
77  outfile.path( option[ out::path::score ]().path() );
78  outfile.vol( option[ out::path::score ]().vol() );
79  } else outfile.path( default_path.path() );
80  // determine the extension based on fullatom or centroid; this logic is usually wrong but .sc is okay anyway
81  if( option[ out::file::fullatom ] ) {
82  outfile.ext( ".fasc" );
83  } else {
84  outfile.ext( ".sc" );
85  }
86  scorefile_name_ = outfile.name();
87  }
88 }
89 
91 
93  JobCOP job,
94  core::pose::Pose const & pose,
95  std::string tag,
96  std::string scorefile
97 )
98 {
99  TR.Debug << "FileJobOutputter scorefile" << std::endl;
100  if (!write_scorefile_) return;
101  core::io::raw_data::ScoreFileData sfd((scorefile.empty() ? scorefile_name_.name() : scorefile));
102  std::map < std::string, core::Real > score_map;
103  std::map < std::string, std::string > string_map;
105 
106  // Adds StringReal job info into the score map for output in the scorefile.
107  for( Job::StringRealPairs::const_iterator it(job->output_string_real_pairs_begin()), end(job->output_string_real_pairs_end());
108  it != end;
109  ++it) {
110  score_map[it->first] = it->second;
111  }
112 
113  // Adds StringString job info into a map for output in the scorefile.
114  for( Job::StringStringPairs::const_iterator it(job->output_string_string_pairs_begin()), end(job->output_string_string_pairs_end());
115  it != end;
116  ++it) {
117  string_map[it->first] = it->second;
118  }
119 
120  sfd.write_pose( pose, score_map , (tag+output_name(job)), string_map );
121 }
122 
123 
124 ///@details this base class implementation will try to _append_ whatever string it gets to a file named after the job, with a user-specified suffix.
126  JobCOP job,
127  std::string const & data ){
128  TR.Debug << "FileJobOutputter::file" << std::endl;
129  if (data.empty()) return; //who needs empty files?
130 
131  //this almost certainly needs some sort of error handling - what do you think Andrew?
132  utility::io::ozstream out;
133  std::string const & miscfile_ext(option[ run::jobdist_miscfile_ext ].value());
134  out.open_append( output_name(job) + (miscfile_ext[0] == '.' ? "" : ".") + miscfile_ext );
135  out << data << std::flush;
136  out.close();
137 }
138 
139 
140 //void other_scorefile( std::string const & tag, core::pose::Pose const & pose, std::string const & o_scorefile );
141 
142 }//jd2
143 }//protocols