Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
remodel.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 apps/public/remodel.cc
11 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
12 /// @author Possu Huang
13 
14 // project headers
15 #include <basic/options/option.hh>
16 #include <basic/options/keys/in.OptionKeys.gen.hh>
17 #include <basic/options/keys/out.OptionKeys.gen.hh>
18 #include <basic/options/keys/packing.OptionKeys.gen.hh>
19 #include <basic/options/keys/pose_metrics.OptionKeys.gen.hh>
20 #include <basic/options/keys/run.OptionKeys.gen.hh>
21 #include <basic/options/keys/ufv.OptionKeys.gen.hh>
22 #include <basic/options/keys/remodel.OptionKeys.gen.hh>
23 #include <basic/Tracer.hh>
24 
25 // utility headers
26 #include <utility/file/FileName.hh>
27 #include <utility/io/izstream.hh>
29 
30 #include <core/chemical/ChemicalManager.hh>
31 #include <core/io/pdb/pose_io.hh>
32 #include <core/import_pose/import_pose.hh>
33 #include <core/pose/Pose.hh>
34 #include <core/pose/annotated_sequence.hh>
35 #include <core/scoring/dssp/Dssp.hh>
36 #include <core/scoring/ScoreFunction.hh>
37 #include <core/scoring/ScoreFunctionFactory.hh>
38 
39 #include <protocols/forge/build/ConnectRight.hh>
40 #include <protocols/forge/build/RelativeConnectRight.hh>
41 #include <protocols/forge/build/RelativeSequencePosition.hh>
42 #include <protocols/forge/build/SegmentInsert.hh>
43 #include <protocols/forge/build/SegmentRebuild.hh>
44 #include <protocols/forge/components/BDR.hh>
45 #include <protocols/forge/remodel/RemodelMover.hh>
46 #include <protocols/jd2/JobDistributor.hh>
47 #include <protocols/jd2/JobOutputter.hh>
48 #include <protocols/simple_filters/PoseMetricEvaluator.hh>
49 #include <protocols/viewer/viewers.hh>
50 #include <protocols/moves/PyMolMover.hh>
51 
52 #include <devel/init.hh>
53 
54 // boost headers
55 #include <boost/lexical_cast.hpp>
56 #include <boost/tokenizer.hpp>
57 #include <boost/algorithm/string.hpp>
58 
59 // C++ headers
60 #include <string>
61 #include <vector>
62 
64 
65 using namespace basic::options;
66 using namespace basic::options::OptionKeys;
67 using namespace core;
68 
69 typedef std::string String;
70 typedef std::vector< OptionKey const * > KeyVec;
71 
72 static THREAD_LOCAL basic::Tracer TR( "apps.public.remodel" );
73 
74 
75 std::string usage_string;
76 
77 
78 /// @brief
79 /// the usage prompt that gets printed when the user doesn't enter any arguments or uses the -h flag since the application
80 /// specific help Rosetta bring up with the -help flag is, in fact, not helpful.
81 ///
82 void init_usage_prompt( std::string exe ) {
83 
84  // place the prompt up here so that it gets updated easily; global this way, but that's ok
85  std::stringstream usage_stream;
86  usage_stream
87  << "Usage: " << exe
88  << "\n"
89  << "\n\t-database path/to/rosetta/database"
90  << "\n\t-s pdb | -silent silent_file read in input PDB file or silent file"
91  << "\n\t-pdb_gz | -silent_gz compress output PDB or silent files"
92  << "\n"
93  << "\n\t-remodel:blueprint blueprint_file blueprint file which explains how to run remodel"
94  << "\n"
95  << "\n\t-remodel::num_trajectory number of build trajectories to run (default: 10)"
96  << "\n\t-remodel::dr_cycles <int> number of design/refine cycles to run (default: 3)"
97  << "\n"
98  << "\n\t-remodel::quick_and_dirty only do fragment sampling; bypass refinement of final structures which is slow. useful in early stages of design when one wants to sample different loop lengths to find appropriate setup (default: false)"
99  << "\n"
100  << "\n\t-remodel::bypass_fragments skip creation of fragments for remodelling; do refinement only. no extensions or deletions are honored in the blueprint (default: false)"
101  << "\n\t-remodel::use_blueprint_sequence find fragments which have the same amino acid sequence and secondary structure as what is specified in the second column of the blueprint file (default: false)"
102  << "\n\t-remodel::use_same_length_fragments harvest fragments that match the length of the segment being rebuilt (default: true)"
103  << "\n"
104  << "\n\t-remodel::build_disulf use Remodel to find residue pairs - between the \"build\" and \"landing\" residues - which would make good disulfide bonds (default: false)"
105  << "\n\t-remodel::match_rt_limit <float> the score cutoff to use for determining how closely a potential disulfide must match observed disulfide distributions (default: 0.4)"
106  << "\n\t-remodel::disulf_landing_range <range> the range within which Remodel attempts to find disulfides for positions in the \"build\" region (default: none)"
107  << "\n"
108  << "\n\t-remodel::use_pose_relax add fast relax to the refinement stage (instead of the default minimization step), but use constraints in a similar way (default: false)"
109  << "\n\t-remodel::run_confirmation use kinematic loop closure algorithm for build confirmation (default: false)"
110  << "\n\t-remodel::swap_refine_confirm_protocols swap protocols used for refinement and confirmation test; i.e. use kinematic loop closure instead of CCD closure (default: false)"
111  << "\n\t-remodel::repeat_structure build identical repeats this many times (default: 1)"
112  << "\n"
113  << "\n\t-symmetry::symmetry_definition text file describing symmetry setup (default: none)"
114  << "\n"
115  << "\n\t-enzdes::cstfile enzyme design constraints file"
116  << "\n\t-remodel::cstfilter threshold to put on the atom_pair_constraint score type filter during the centroid build phase refinement (default: 10)"
117  << "\n"
118  << "\n\t-remodel::domainFusion::insert_segment_from_pdb segment PDB file to be inserted into the input structure"
119  << "\n"
120  << "\n\t-remodel::checkpoint turns on checkpointing, for use in preemptive scheduling environments. writes out the best pdbs collected after each design step. (default: false)"
121  << "\n\t-remodel::use_clusters specifies whether to perform clustering during structure aggregation (default: false)"
122  << "\n\t-remodel::save_top the number of final lowest scoring pdbs to keep (default: 5)"
123  << "\n"
124  << "\n\t-remodel::generic_aa <letter> residue type to use as placeholder during centroid phase (default: V)"
125  << "\n\t-remodel::cen_sfxn score function to be used for centroid phase building (default: remodel_cen)"
126  << "\n\t-remodel::cen_minimize centroid minimization after fragment building (default: false)"
127  << "\n"
128  << "\n\t-run::chain <letter> chain id of the chain to remodel, if a multichain structure is given (default: -)"
129  << "\n"
130  << "\n\t[-overwrite]"
131  << "\n\t[-ignore_unrecognized_res]"
132  << "\n\t[-mute core.io core.conformation core.pack core.scoring]"
133 
134  << "\n\nPlease see the Rosetta Remodel documentation in the Rosetta Manual for more information, including a list of all available options."
135  << "\nhttp://www.rosettacommons.org/manual_guide"
136 
137  << "\n\n";
138  usage_string = usage_stream.str();
139 
140 }
141 
142 
144 
145  using namespace basic::options::OptionKeys;
146 
147  keys.push_back( &in::path::database );
148  keys.push_back( &out::nstruct );
149  keys.push_back( &run::max_retry_job );
150  keys.push_back( &pose_metrics::neighbor_by_distance_cutoff );
151 }
152 
153 
155 
156  using namespace basic::options::OptionKeys;
157 
158  keys.push_back( &in::file::s );
159  keys.push_back( &in::file::silent );
160  keys.push_back( &in::file::vall );
161  keys.push_back( &remodel::blueprint);
162 
163  keys.push_back( &out::pdb_gz );
164  keys.push_back( &out::pdb );
165  keys.push_back( &out::silent_gz );
166 
167  keys.push_back( &out::file::o );
168  keys.push_back( &out::file::silent );
169  keys.push_back( &out::file::silent_struct_type );
170 }
171 
172 
173 void register_options( KeyVec & keys ) {
175 
176  for ( KeyVec::const_iterator i = keys.begin(), ie = keys.end(); i != ie; ++i ) {
177  option.add_relevant( **i );
178  }
179 }
180 
181 
184 
185  bool flags_ok = true;
186  for ( KeyVec::const_iterator i = keys.begin(), ie = keys.end(); i != ie; ++i ) {
187  flags_ok &= option[ **i ].specified_report();
188  }
189 
190  return flags_ok;
191 }
192 
193 
195  using namespace basic::options::OptionKeys;
196  using core::pose::annotated_to_oneletter_sequence;
198 
199  bool flags_ok = true;
200 
201  if ( option[ run::max_retry_job ] < 0 ) {
202  flags_ok = false;
203  TR.Fatal << "run:max_retry_job must be positive!" << std::endl;
204  }
205 
206  return flags_ok;
207 }
208 
209 
210 /// @brief load ufv loops from file
211 /// @return number of loops read
213  protocols::forge::components::BDR & bdr,
215 )
216 {
217  using namespace basic::options::OptionKeys;
218  using core::Size;
220  using protocols::forge::build::BuildInstructionOP;
221  using protocols::forge::build::Interval;
222  using protocols::forge::build::SegmentRebuild;
223  using std::istringstream;
224 
225  utility::io::izstream in( filename );
226 
227  Size left, right;
228  String ss, aa_during_build, aa_during_design_refine;
229  bool use_sequence_biased_fragments = false;
230 
231  Size count = 0;
232  String line;
234  while ( getline( in, line ) ) {
235  // split by whitespace " \n\t"
236  boost::tokenizer< boost::char_separator< char > > tokens( line, boost::char_separator< char >( " \n\t" ) );
237  entries.assign( tokens.begin(), tokens.end() );
238 
239  // skip empty and comment lines
240  if ( entries.size() == 0 || ( entries.size() > 0 && entries.begin()->at( 0 ) == '#' ) ) {
241  continue;
242  }
243 
244  if ( entries.size() >= 3 ) {
245  left = boost::lexical_cast< Size >( entries[ 1 ] );
246  right = boost::lexical_cast< Size >( entries[ 2 ] );
247  ss = entries[ 3 ];
248 
249  aa_during_build = entries.size() >= 4 ? entries[ 4 ] : String();
250  aa_during_design_refine = entries.size() >= 5 ? entries[ 5 ] : String();
251 
252  if ( aa_during_build.length() == 1 && aa_during_build.at( 0 ) == '-' ) {
253  aa_during_build = String();
254  }
255 
256  use_sequence_biased_fragments |= !aa_during_build.empty();
257 
258  bdr.add_instruction(
259  BuildInstructionOP( new SegmentRebuild(
260  Interval( left, right ),
261  ss, aa_during_build,
262  core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::FA_STANDARD ),
263  option[ ufv::keep_junction_torsions ]
264  ) ),
265  aa_during_design_refine
266  );
267 
268  ++count;
269 
270  TR << "added loop: [" << left << ", " << right << "] " << ss << " "
271  << aa_during_build << " " << aa_during_design_refine << std::endl;
272 
273  } else {
274  // error message
275  TR.Error << "ERROR: too few columns in line of ufv_loops file: " << line << std::endl;
276  std::exit( 1 );
277  }
278  }
279 
280  in.close();
281 
282  bdr.use_sequence_bias( use_sequence_biased_fragments );
283 
284  return count;
285 }
286 
287 
288 void setup_segment_insert( protocols::forge::components::BDR & bdr ) {
289  using namespace basic::options::OptionKeys;
291  using core::pose::Pose;
292  using core::Size;
293  using protocols::forge::build::ConnectRight;
294  using protocols::forge::build::CountFromLeft;
295  using protocols::forge::build::CountFromLeftOP;
296  using protocols::forge::build::Interval;
297  using protocols::forge::build::RelativeConnectRight;
298  using protocols::forge::build::RelativeConnectRightOP;
299  using protocols::forge::build::SegmentInsert;
300  using protocols::forge::build::SegmentInsertOP;
302  using protocols::forge::build::SegmentInsertConnectionScheme::N;
303  using protocols::forge::build::SegmentInsertConnectionScheme::RANDOM_SIDE;
304  using core::scoring::dssp::Dssp;
305 
306  using core::import_pose::pose_from_pdb;
307 
308  // option transmute; just for safety
309  String aa_during_build;
310  String aa_during_design_refine;
311  String connection_scheme_str;
312 
313  if ( option[ ufv::aa_during_build ].user() ) {
314  aa_during_build = option[ ufv::aa_during_build ];
315  }
316 
317  if ( option[ ufv::aa_during_design_refine ].user() ) {
318  aa_during_design_refine = option[ ufv::aa_during_design_refine ];
319  }
320 
321  if ( option[ ufv::insert::connection_scheme ].user() ) {
322  connection_scheme_str = option[ ufv::insert::connection_scheme ];
323  boost::to_upper( connection_scheme_str ); // force uppercase letters
324  }
325 
326  // Read pdbs.
327  // If 'attached' exists, it should already be in proper rigid body
328  // orientation wrt to 'insert'.
329  bool const use_attached = option[ ufv::insert::attached_pdb ].user();
330 
331  Pose insert;
332  core::import_pose::pose_from_pdb( insert, option[ ufv::insert::insert_pdb ] );
333  Dssp dssp_i( insert );
334  dssp_i.insert_ss_into_pose( insert );
335 
336  RelativeConnectRightOP rcr;
337 
338  if ( use_attached ) {
339  Pose attached;
340  core::import_pose::pose_from_pdb( attached, option[ ufv::insert::attached_pdb ] );
341  Dssp dssp_a( attached );
342  dssp_a.insert_ss_into_pose( attached );
343 
344  // Squish together insert <-> attached so we can extract the jump.
345  // We attach to the middle of each pdb. Optimally we should find the
346  // closest CAs between the structures, but we're just testing so it's
347  // fine for now.
348  Pose insert_plus_attached = insert;
349 
350  Size const insert_jump_pos = insert.n_residue() % 2 == 0 ? insert.n_residue() / 2 : insert.n_residue() / 2 + 1;
351  Size const attached_jump_pos = attached.n_residue() % 2 == 0 ? attached.n_residue() / 2 : attached.n_residue() / 2 + 1;
352  Size const shifted_attached_jump_pos = attached_jump_pos + insert.n_residue();
353 
354  ConnectRight cr( insert_jump_pos, attached_jump_pos, attached );
355  cr.modify( insert_plus_attached );
356 
357  // setup RelativeConnectRight
358  CountFromLeftOP cfl( new CountFromLeft() );
359  cfl->p = insert_jump_pos;
360  cfl->left_skip = option[ ufv::ss ].value().find( SegmentInsert::insertion_char() );
361 
362  rcr = RelativeConnectRightOP( new RelativeConnectRight( cfl, attached_jump_pos, attached ) );
363  rcr->extract_rt( insert_plus_attached, insert_jump_pos, shifted_attached_jump_pos );
364  rcr->use_rt( true );
365  }
366 
367  // setup SegmentInsert
368  protocols::forge::build::SegmentInsertConnectionScheme::Enum connection_scheme = RANDOM_SIDE;
369  if ( !connection_scheme_str.empty() ) {
370  if ( connection_scheme_str == "N2C" ) {
371  connection_scheme = N;
372  } else if ( connection_scheme_str == "C2N" ) {
373  connection_scheme = C;
374  }
375  }
376 
377  SegmentInsertOP si( new SegmentInsert(
378  Interval( option[ ufv::left ], option[ ufv::right ] ),
379  option[ ufv::ss ], aa_during_build,
380  insert,
381  false, // force false for now
382  connection_scheme
383  ) );
384 
385  // add to BDR
386  bdr.add_instruction( si, aa_during_design_refine );
387  if ( use_attached ) {
388  bdr.add_instruction( rcr );
389  bdr.create_directed_dependency( si, rcr );
390  }
391 }
392 
393 
394 void* graphics_main( void* ) {
395 
396  using namespace basic::options::OptionKeys;
397  using core::Size;
399  using protocols::simple_filters::PoseMetricEvaluator;
400  using protocols::forge::build::Interval;
401  using protocols::forge::build::SegmentRebuild;
402  using protocols::forge::remodel::RemodelMover;
403  using protocols::forge::remodel::RemodelMover_OP;
404  using protocols::forge::components::BDR_OP;
405  using protocols::jd2::JobDistributor;
406 
407  // option transmute; just for safety
408  /*String aa_during_build;
409  String aa_during_design_refine;
410 
411  if ( option[ ufv::aa_during_build ].user() ) {
412  aa_during_build = option[ ufv::aa_during_build ];
413  }
414 
415  if ( option[ ufv::aa_during_design_refine ].user() ) {
416  aa_during_design_refine = option[ ufv::aa_during_design_refine ];
417  }
418  */
419  // init BDR
420  RemodelMover_OP rmdl( new RemodelMover );
421 
422  // run job
423  JobDistributor::get_instance()->go( rmdl );
424 
425  protocols::viewer::clear_conformation_viewers();
426  exit( 0 ); // ensures graceful exit of graphics.
427 }
428 
429 
430 int main( int argc, char * argv [] ) {
431  try {
432  // check to see if no flags or the -h flag were specified.
433  if ( argc == 1 || ( argc > 1 && strcmp(argv[ 1 ], "-h") == 0 ) ) {
434  init_usage_prompt( argv[0] );
436  exit(0);
437  }
438 
439  KeyVec optional_options;
440  fill_optional_options( optional_options );
441 
442  // register options so help file appears correctly
443  register_options( optional_options );
444 
445  // initialize rosetta
446  devel::init( argc, argv );
447 
448  // viewer_main() just calls graphics_main with the parameter NULL and returns 0
449  protocols::viewer::viewer_main( graphics_main );
450  } catch ( utility::excn::EXCN_Base const & e ) {
451  std::cout << "caught exception " << e.msg() << std::endl;
452  return -1;
453  }
454  return 0;
455 }
456 
457 
#define THREAD_LOCAL
void fill_optional_options(KeyVec &keys)
Definition: remodel.cc:154
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
core::Size load_loops_from_file(protocols::forge::components::BDR &bdr, utility::file::FileName const &filename)
load ufv loops from file
Definition: remodel.cc:212
std::string String
Definition: remodel.cc:69
void fill_required_options(KeyVec &keys)
Definition: remodel.cc:143
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
std::vector< OptionKey const * > KeyVec
Definition: remodel.cc:70
std::istream & getline(std::istream &stream, Fstring &s)
Get Line from Stream.
Definition: Fstring.cc:1610
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
void setup_segment_insert(protocols::forge::components::BDR &bdr)
Definition: remodel.cc:288
File name class supporting Windows and UN*X/Linux format names.
Definition: FileName.hh:37
Abstract automatic hidden index key for options.
common derived classes for thrown exceptions
void * graphics_main(void *)
Definition: remodel.cc:394
tuple database
#define C(a, b)
Definition: functions.cc:27
void close()
Close the ifstream and reset the state.
Definition: izstream.hh:219
static void add_relevant(const OptionKey &key)
add OptionKey to list of application relevant options
static THREAD_LOCAL basic::Tracer TR("basic.options")
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.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
bool check_required_options(KeyVec &keys)
Definition: remodel.cc:182
TracerProxy Error
Definition: Tracer.hh:262
File name class supporting Windows and UN*X/Linux format names.
basic::options::IntegerOptionKey const nstruct("nstruct")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
static char * line
Definition: Svm.cc:2683
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
BooleanOptionKey const exit("options:exit")
Definition: OptionKeys.hh:51
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
TracerProxy Fatal
channels with predefined priority levels.
Definition: Tracer.hh:262
void register_options(KeyVec &keys)
Definition: remodel.cc:173
int main(int argc, char *argv[])
Definition: remodel.cc:430
Program options global and initialization function.
std::string usage_string
Definition: remodel.cc:75
void init_usage_prompt(std::string exe)
the usage prompt that gets printed when the user doesn't enter any arguments or uses the -h flag sinc...
Definition: remodel.cc:82
platform::Size Size
Definition: random.fwd.hh:30
int const silent
Named verbosity levels.
bool check_option_conflicts()
Definition: remodel.cc:194