Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
extract_pdbs.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 extract_pdbs.cc
11 /// @brief simple application for extracting PDBs from a silent-file.
12 /// @author James Thompson
13 
14 // libRosetta headers
15 
16 #include <core/types.hh>
17 
18 #include <core/chemical/ResidueTypeSet.fwd.hh>
19 #include <core/chemical/ChemicalManager.hh>
20 
21 #include <core/pose/Pose.hh>
22 #include <core/pose/util.hh>
23 
24 #include <devel/init.hh>
25 
26 #include <basic/options/option.hh>
27 
28 #include <basic/Tracer.hh>
29 
30 #include <core/scoring/ScoreFunction.hh>
31 #include <core/scoring/ScoreFunctionFactory.hh>
32 
33 #include <core/import_pose/pose_stream/PoseInputStream.fwd.hh>
34 #include <core/import_pose/pose_stream/SilentFilePoseInputStream.hh>
35 
36 #include <core/pose/symmetry/util.hh>
37 
38 // C++ headers
39 #include <string>
40 
42 
43 // option key includes
44 
45 #include <basic/options/keys/in.OptionKeys.gen.hh>
46 #include <basic/options/keys/out.OptionKeys.gen.hh>
47 #include <basic/options/keys/score.OptionKeys.gen.hh>
48 
49 #include <utility/vector1.hh>
50 #include <utility/io/izstream.hh>
51 #include <boost/algorithm/string/erase.hpp>
52 
54 
55 
56 int
57 main( int argc, char* argv [] ) {
58  try {
59 
60  // define relevant options
63  OPT(in::file::tags);
64  OPT(in::file::silent_struct_type);
65  OPT(in::file::silent_renumber);
66  OPT(out::file::residue_type_set);
67  OPT(out::prefix);
69  OPT(in::file::rescore);
71  OPT(score::patch);
72 
73  using namespace core::chemical;
74  using namespace core::import_pose::pose_stream;
75  using namespace basic::options;
76  using namespace basic::options::OptionKeys;
77 
78  // options, random initialization
79  devel::init( argc, argv );
80 
81  std::string usage("");
82  usage += "\n\nusage: extract_pdbs [options] -in::file::silent <silent_files>\n";
83  usage += "\tTo see a list of other valid options, use the option -help.\n";
84 
85  if ( !option[ in::file::silent ].user() ) {
86  std::cerr << usage << std::endl;
87  std::exit(1);
88  }
89 
90  basic::Tracer tr( "extract_pdbs" );
91 
92  core::chemical::ResidueTypeSetCOP rsd_set( NULL );
93  if ( option[ out::file::residue_type_set ].user() ) {
94  rsd_set = ChemicalManager::get_instance()->residue_type_set(
95  option[ out::file::residue_type_set ]()
96  );
97  }
98  PoseInputStreamOP input;
99  if ( option[ in::file::silent ].user() ) {
100  if ( option[ in::file::tags ].user() ) {
101  input = PoseInputStreamOP( new SilentFilePoseInputStream(
103  option[ in::file::tags ]()
104  ) );
105  } else if ( option[ in::file::tagfile ].user() ) {
106 
108  utility::io::izstream tag_file( option[ in::file::tagfile ]() );
109  std::copy( std::istream_iterator< std::string >( tag_file ), std::istream_iterator< std::string >(),
110  std::back_inserter( input_tags ) );
111  input = PoseInputStreamOP( new SilentFilePoseInputStream( option[ in::file::silent ](), input_tags ) );
112 
113  } else {
114  input = PoseInputStreamOP( new SilentFilePoseInputStream( option[ in::file::silent ]() ) );
115  }
116  }
117 
118  core::scoring::ScoreFunctionOP scorefxn;
119 
120  if ( option[ in::file::rescore ]() ) {
121  scorefxn = core::scoring::get_score_function();
122  tr.Debug << "scoring using ScoreFunction with weights: " << std::endl;
123  scorefxn->show( tr.Debug );
124  tr.flush();
125  }
126 
128  std::string out_prefix = option[ out::prefix ]();
129  while ( input->has_another_pose() ) {
130  //fpd 'fill_pose' assumes an asymmetric pose is input
131  if ( core::pose::symmetry::is_symmetric( pose ) ) {
132  core::pose::symmetry::make_asymmetric_pose( pose );
133  }
134  if ( rsd_set ) {
135  input->fill_pose( pose, *rsd_set );
136  } else {
137  input->fill_pose( pose );
138  }
139 
140  // make sure the parent/template name gets included in the REMARK line of the PDB
141  using std::map;
142  using std::string;
143  map< string, string > score_line_strings( core::pose::get_all_score_line_strings( pose ) );
144  for ( map< string, string >::const_iterator it = score_line_strings.begin(),
145  end = score_line_strings.end();
146  it != end; ++it ) {
147  if ( it->first != "aln_id" ) continue;
148  core::pose::add_comment( pose, "parents", it->second );
149  }
150  std::string tag( tag_from_pose( pose ) );
151  // Many applications will put .pdb on the pose tag; remove it if it's there.
152  if ( tag.find( ".pdb" ) != std::string::npos ) {
153  tag.erase( tag.find( ".pdb" ) , tag.size() );
154  }
155  std::string fn( out_prefix + tag + ".pdb" );
156 
157  tr << "extracting Pose with tag " << tag << " into PDB file " << fn
158  << std::endl;
159 
160  if ( option[ in::file::rescore ]() ) {
161  tr.Debug << "rescoring Pose with tag " << tag << std::endl;
162  scorefxn->show( tr.Debug );
163  (*scorefxn)(pose);
164 
165  scorefxn->show( tr.Debug, pose );
166  pose.dump_scored_pdb( fn, *scorefxn );
167  } else {
168  pose.dump_pdb( fn );
169  }
170 
171  //fpd
172 
173  tr.flush();
174  }
175 
176  exit( 0 );
177 
178  } catch ( utility::excn::EXCN_Base const & e ) {
179  std::cout << "caught exception " << e.msg() << std::endl;
180  return -1;
181  }
182 
183  return 0;
184 } // main
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
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
common derived classes for thrown exceptions
tuple scorefxn
Definition: PyMOL_demo.py:63
tuple database
Tracer IO system.
izstream: Input file stream wrapper for uncompressed and compressed files
Definition: izstream.hh:44
Input file stream wrapper for uncompressed and compressed files.
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
int main(int argc, char *argv[])
Definition: extract_pdbs.cc:57
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
BooleanOptionKey const exit("options:exit")
Definition: OptionKeys.hh:51
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
Program options global and initialization function.
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373
THREAD_LOCAL basic::Tracer tr("struc_set_fragment_picker")
#define OPT(akey)
TracerProxy Debug
Definition: Tracer.hh:262
int const silent
Named verbosity levels.
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378