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 // Unit Headers
12 
13 // Package Headers
16 
17 // Project Headers
18 #include <core/fragment/FragSet.hh>
20 #include <core/fragment/util.hh>
30 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
31 #include <core/sequence/util.hh>
33 #include <basic/options/option.hh>
34 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
35 #include <basic/options/keys/frags.OptionKeys.gen.hh>
36 #include <basic/options/keys/in.OptionKeys.gen.hh>
37 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 
39 // Utility headers
40 #include <utility/io/izstream.hh>
41 #include <basic/Tracer.hh>
42 
43 // C++ headers
44 #include <fstream>
45 
51 #include <utility/vector1.hh>
52 #include <basic/options/keys/broker.OptionKeys.gen.hh>
53 
54 //Auto Headers
55 static basic::Tracer tr("protocols.topo_broker",basic::t_info);
56 
57 namespace protocols {
58 namespace topology_broker {
59 
60 using namespace utility::excn;
61 using namespace core;
62 using namespace core::fragment;
63 
64 struct CmdLineData {
65  CmdLineData() : b_has_constraint_claimer( false ) {};
66  FragSetOP frags_large;
69 };
70 
71 //some modifiers for the fragment reading can be read from the stream
73  std::string file;
74  while ( is >> file ) {
75  if ( file[0] == '#' ) {
76  getline( is, file );
77  continue;
78  }
79  if ( file == "NTOP" ) {
80  Size ntop;
81  is >> ntop;
82  io.set_top_frag_num( ntop );
83  } else if ( file == "NCOPY" ) {
84  Size ncopy;
85  is >> ncopy;
86  io.set_ncopies( ncopy );
87  } else if ( file == "ANNOTATE" ) {
88  bool yesno;
89  is >> yesno;
90  io.set_read_annotation( yesno );
91  } else {
92  return io.read_data( file );
93  }
94  }
95  runtime_assert( 0 ); // shouldn't be able to get here
96  return NULL;
97 }
98 
99 void add_claims_from_stream( TopologyBroker& broker, std::istream& is , CmdLineData& cmdline_data ) {
100  std::string tag;
101  using namespace core::fragment;
102  using namespace basic::options;
103 
104  while ( is >> tag ) {
105  if ( tag[ 0 ]=='#' ) {
106  getline( is, tag );
107  continue;
108  } else if ( tag == "USE_INPUT_POSE" ) {
109  broker.use_job_pose( true );
110  } else if ( tag == "NO_USE_INPUT_POSE" ) {
111  broker.use_job_pose( false );
112  } else if ( tag == "CLAIMER" ) {
113  std::string claim_type;
114  is >> claim_type;
115  tr.Debug << "instantiate CLAIMER: " << claim_type << std::endl;
116  if ( claim_type == ConstraintClaimer::_static_type_name() ) cmdline_data.b_has_constraint_claimer = true;
118  broker.add( claim ); //register first, so that messages work immediatly!
119  is >> *claim;
120  } else if ( tag == "ABINITIO_FRAGS" ) {
121  tr.Debug << "install Abinitio fragments " << std::endl;
122 
123  //short cut for the FragmentClaimers need for abinitio runs:
124  std::string file;
125  while ( is >> tag && tag.substr(0,4) != "END_" ) {
126  if ( tag == "LARGE" ) {
127  FragmentIO frag_io(option[ OptionKeys::abinitio::number_9mer_frags ](),
128  option[ OptionKeys::frags::nr_large_copies ](),
129  option[ OptionKeys::frags::annotate ]() );
130  cmdline_data.frags_large = read_frags( is, frag_io );
131  } else if ( tag == "SMALL" ) {
132  FragmentIO frag_io(option[ OptionKeys::abinitio::number_3mer_frags ](),
133  1,
134  option[ OptionKeys::frags::annotate ]() );
135  cmdline_data.frags_small = read_frags( is, frag_io );
136  } else if ( tag[0] == '#' ) {
137  getline( is, tag );
138  }
139  }
140  } else {
141  throw utility::excn::EXCN_BadInput(" unrecognized tag " + tag );
142  }
143  } //while is tag
144 }
145 
146 void add_claims_from_file( TopologyBroker& broker, std::string const& file , CmdLineData& cmdline_data ) {
147  utility::io::izstream is;
148  if ( file != "NO_SETUP_FILE" ) {
149  is.open( file );
150  if ( !is.good() ) throw EXCN_FileNotFound( file );
151  }
152 
153  try {
154  add_claims_from_stream( broker, is , cmdline_data );
155  } catch ( EXCN_BadInput &excn ) {
156  throw EXCN_BadInput( excn.msg() + " occurred when reading file "+file ); //of course I loose the speciality of the EXCEPTION
157  }
158  //that might be just eof check for is.fail() ??? don't check...not my problem ?
159 }
160 
161 void add_cmdline_claims( TopologyBroker& broker, bool const do_I_need_frags ) {
162  using namespace basic::options;
163  using namespace basic::options::OptionKeys;
170 
171  CmdLineData cmdline_data;
172  if ( option[ OptionKeys::broker::setup ].user() ) {
173  FileVectorOption& files( option[ OptionKeys::broker::setup ] );
174  for ( Size i = 1; i<= files.size(); ++i ) {
175  add_claims_from_file( broker, files[ i ], cmdline_data );
176  }
177  }
178 
179  core::fragment::read_std_frags_from_cmd( cmdline_data.frags_large, cmdline_data.frags_small );
180  if ( !cmdline_data.frags_large || !cmdline_data.frags_small ) {
181  if(do_I_need_frags){
182  throw utility::excn::EXCN_BadInput( "expected LARGE and SMALL fragment sets in ABINITIO_FRAGS section or via command line ");
183  }
184  else{
185  return;
186  }
187  }
188 
190  broker.add(new FragmentClaimer(bml = new ClassicFragmentMover(cmdline_data.frags_large), "LargeFrags", new LargeFragWeight));
191  broker.add(new FragmentClaimer(bms = new ClassicFragmentMover(cmdline_data.frags_small), "SmallFrags", new SmallFragWeight));
192  broker.add(new FragmentClaimer(sms = new SmoothFragmentMover (cmdline_data.frags_small, /*dummy -*/ new GunnCost), "SmoothFrags", new SmoothFragWeight));
193 
194  broker.add( new LoopFragmentClaimer( cmdline_data.frags_small ) );
195  core::fragment::SecondaryStructureOP ss_def = new core::fragment::SecondaryStructure( *cmdline_data.frags_small, false /*no JustUseCentralResidue */ );
196  broker.add( new CutBiasClaimer( *ss_def ) );
197 
198  bms->set_end_bias( option[ OptionKeys::abinitio::end_bias ] ); //default is 30.0
199  bml->set_end_bias( option[ OptionKeys::abinitio::end_bias ] );
200  sms->set_end_bias( option[ OptionKeys::abinitio::end_bias ] );
201 
202  //check if there are any SequenceClaimers: if not make at least one from FASTA file
203  if ( !broker.has_sequence_claimer() ) {
204  using namespace basic::options::OptionKeys;
205  std::string sequence;
206  if ( option[ in::file::fasta ].user() ) {
207  sequence = core::sequence::read_fasta_file( option[ in::file::fasta ]()[1] )[1]->sequence();
208  tr.Info << "read fasta sequence: " << sequence.size() << " residues\n" << sequence << std::endl;
209  } else if ( option[ in::file::native ].user() ) {
210  pose::PoseOP native_pose = new pose::Pose;
211  core::import_pose::pose_from_pdb( *native_pose, option[ in::file::native ]() );
212  sequence = native_pose->sequence();
213  } else {
214  utility_exit_with_message("Error: can't read sequence! Use -in::file::fasta sequence.fasta or -in::file::native native.pdb!");
215  }
216  broker.add( new SequenceClaimer( sequence, core::chemical::CENTROID, "main" ) );
217  }
218 
219  if ( !cmdline_data.b_has_constraint_claimer && basic::options::option[ constraints::cst_file ].user() ) {
220  tr.Info << "add ConstraintClaimer to account for cmd-line constraints" << std::endl;
221  broker.add( new ConstraintClaimer( true /* read from cmd-line */ ) );
222  }
223  if ( !cmdline_data.b_has_constraint_claimer && basic::options::option[ constraints::cst_fa_file ].user() ) {
224  tr.Info << "add fa ConstraintClaimer to account for cmd-line constraints" << std::endl;
225  broker.add( new ConstraintClaimer( true /* read from cmd-line */, false /*centroid*/, true /*true*/ ) );
226  }
227 }
228 
229 }
230 }