Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
stepwise.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 swa_monte_carlo.cc
11 /// @author Rhiju Das (rhiju@stanford.edu)
12 
13 // libRosetta headers
14 #include <core/types.hh>
15 #include <core/chemical/util.hh>
16 #include <core/scoring/ScoringManager.hh>
17 #include <core/scoring/ScoreFunctionFactory.hh>
18 #include <core/scoring/ScoreFunction.hh>
19 #include <core/init/init.hh>
20 #include <core/pose/Pose.hh>
21 #include <core/pose/full_model_info/FullModelInfo.hh>
22 #include <core/pose/full_model_info/util.hh>
23 #include <core/pose/util.hh>
24 #include <core/io/rna/RNA_DataReader.cc> // temporary, for scoring RNA chemical mapping data. Move into core?
25 #include <protocols/stepwise/setup/FullModelInfoSetupFromCommandLine.hh>
26 #include <protocols/stepwise/setup/StepWiseJobDistributor.hh>
27 #include <protocols/stepwise/setup/StepWiseCSA_JobDistributor.hh>
28 #include <protocols/stepwise/setup/StepWiseMonteCarloJobDistributor.hh>
29 #include <protocols/stepwise/monte_carlo/StepWiseMonteCarlo.hh>
30 #include <protocols/stepwise/monte_carlo/options/StepWiseMonteCarloOptions.hh>
31 #include <protocols/stepwise/monte_carlo/util.hh>
32 #include <protocols/stepwise/modeler/util.hh>
33 #include <protocols/stepwise/modeler/file_util.hh>
34 #include <protocols/stepwise/modeler/rna/util.hh>
35 #include <protocols/stepwise/monte_carlo/submotif/SubMotifLibrary.hh>
36 #include <protocols/viewer/viewers.hh>
37 
38 //////////////////////////////////////////////////
39 #include <basic/options/keys/score.OptionKeys.gen.hh>
40 #include <basic/options/option.hh>
41 #include <basic/options/keys/chemical.OptionKeys.gen.hh>
42 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
43 #include <basic/options/keys/in.OptionKeys.gen.hh> // for option[ in::file::tags ] and etc.
44 #include <basic/options/keys/full_model.OptionKeys.gen.hh>
45 #include <basic/options/keys/out.OptionKeys.gen.hh> // for option[ out::file::silent ] and etc.
46 #include <basic/options/keys/rna.OptionKeys.gen.hh>
47 #include <basic/options/keys/stepwise.OptionKeys.gen.hh>
48 
49 #include <basic/Tracer.hh>
50 #include <utility/vector1.hh>
51 #include <utility/file/FileName.hh>
52 
53 //////////////////////////////////////////////////////////
55 #include <ObjexxFCL/format.hh>
56 
57 // C++ headers
58 #include <fstream>
59 #include <iostream>
60 #include <sstream>
61 #include <string>
62 #include <list>
63 
64 using namespace protocols;
65 using namespace basic::options;
66 using namespace basic::options::OptionKeys;
67 using namespace basic::options::OptionKeys::stepwise::monte_carlo;
68 using utility::vector1;
69 
70 static THREAD_LOCAL basic::Tracer TR( "apps.pilot.rhiju.stepwise_monte_carlo" );
71 
72 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 void
75 {
76  using namespace core::pose;
77  using namespace core::scoring;
78  using namespace core::chemical;
79  using namespace core::pose::full_model_info;
80  using namespace protocols::stepwise;
81  using namespace protocols::stepwise::modeler;
82  using namespace protocols::stepwise::monte_carlo::submotif;
83  using namespace protocols::stepwise::setup;
84  using namespace protocols::stepwise::monte_carlo;
85  using namespace protocols::stepwise::monte_carlo::mover;
87  using namespace utility::file;
88 
89  bool const just_RNA = just_modeling_RNA( option[ in::file::fasta ]() );
90  ResidueTypeSetCAP rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set( FA_STANDARD );
91 
92  ScoreFunctionOP scorefxn;
93  if ( option[ score::weights ].user() ) scorefxn = get_score_function();
94  else if ( option[ OptionKeys::stepwise::lores ]() && !option[ OptionKeys::rna::farna::minimize_rna ]() ) {
95  scorefxn = ScoreFunctionFactory::create_score_function( "stepwise/rna/rna_lores_for_stepwise.wts" );
96  } else if ( just_RNA ) scorefxn = ScoreFunctionFactory::create_score_function( "stepwise/rna/rna_res_level_energy.wts" );
97  else scorefxn = ScoreFunctionFactory::create_score_function( "stepwise/stepwise_res_level_energy.wts" ); // RNA/protein.
98  if ( option[ OptionKeys::constraints::cst_file ].user() && !scorefxn->has_nonzero_weight( atom_pair_constraint ) ) scorefxn->set_weight( atom_pair_constraint, 1.0 );
99 
100  PoseOP native_pose, align_pose;
101  PoseOP pose_op = initialize_pose_and_other_poses_from_command_line( rsd_set );
102  pose::Pose & pose = *pose_op;
103  initialize_native_and_align_pose( native_pose, align_pose, rsd_set, pose_op );
104  // temporary, for scoring RNA chemical mapping data. Move into initalize_pose?
105  core::io::rna::get_rna_data_info( pose, option[ basic::options::OptionKeys::rna::data_file ](), scorefxn );
106 
107  // Get rid of this commented code when it is incorporated into a unit test.
108  // test_merge_and_slice_with_two_helix_test_case( input_poses, scorefxn ); exit( 0 );
109 
110  // setup test move specified via -stepwise:move option
111  StepWiseMove const test_move( option[ OptionKeys::stepwise::move ](), const_full_model_info( pose ).full_model_parameters() );
112 
113  // actual pose to be sampled... do not score pose is user has specified a move
114  if ( pose.total_residue() > 0 && test_move.move_type() == NO_MOVE ) ( *scorefxn )( pose );
115  Vector center_vector = ( align_pose != 0 ) ? get_center_of_mass( *align_pose ) : Vector( 0.0 );
116  protocols::viewer::add_conformation_viewer ( pose.conformation(), "current", 500, 500, false, ( align_pose != 0 ), center_vector );
117 
118  StepWiseMonteCarloOP stepwise_monte_carlo( new StepWiseMonteCarlo( scorefxn ) );
119  stepwise_monte_carlo->set_native_pose( align_pose ); //allows for alignment to be to non-native
120  stepwise_monte_carlo->set_move( test_move );
121 
122  StepWiseMonteCarloOptionsOP options( new StepWiseMonteCarloOptions );
123  options->initialize_from_command_line();
124  stepwise_monte_carlo->set_options( options );
125  if ( ( options->from_scratch_frequency() > 0.0 || const_full_model_info( *pose_op ).other_pose_list().size() > 0 ) && !scorefxn->has_nonzero_weight( other_pose ) ) scorefxn->set_weight( other_pose, 1.0 ); // critical if more than one pose shows up and focus switches...
126 
127  std::string const silent_file = option[ out::file::silent ]();
128  if ( option[ out::overwrite ]() ) remove_silent_file_if_it_exists( silent_file );
129  stepwise_monte_carlo->set_out_path( FileName( silent_file ).path() );
130  stepwise_monte_carlo->set_submotif_library( SubMotifLibraryCOP( new SubMotifLibrary( rsd_set, options->lores() /*include_submotifs_from_jump_library*/, options->use_first_jump_for_submotif() ) ) );
131 
132  // main loop
133  StepWiseJobDistributorOP stepwise_job_distributor( new StepWiseMonteCarloJobDistributor( stepwise_monte_carlo, silent_file, option[ out::nstruct ]() ) );
134  if ( option[ csa::csa_bank_size ].user() ) {
135  stepwise_job_distributor = StepWiseJobDistributorOP( new StepWiseCSA_JobDistributor( stepwise_monte_carlo, silent_file, option[ out::nstruct ](), option[ csa::csa_bank_size ](), option[ csa::csa_rmsd ](), option[ csa::csa_output_rounds ]() ) );
136  }
137  stepwise_job_distributor->set_native_pose( native_pose );
138  stepwise_job_distributor->set_superimpose_over_all( option[ OptionKeys::stepwise::superimpose_over_all ]() );
139  stepwise_job_distributor->initialize( pose );
140 
141  while ( stepwise_job_distributor->has_another_job() ) {
142  stepwise_job_distributor->apply( pose );
143  }
144 
145 }
146 
147 ///////////////////////////////////////////////////////////////
148 void*
149 my_main( void* )
150 {
151  clock_t const my_main_time_start( clock() );
153  protocols::viewer::clear_conformation_viewers();
154  std::cout << "Total time to run " << static_cast<Real>( clock() - my_main_time_start ) / CLOCKS_PER_SEC << " seconds." << std::endl;
155  exit( 0 );
156 }
157 
158 
159 ///////////////////////////////////////////////////////////////////////////////
160 int
161 main( int argc, char * argv [] )
162 {
163  try {
164  std::cout << std::endl << "Basic usage: " << argv[0] << " -fasta <fasta file with sequence> -s <start pdb> -input_res <input pdb1> [ -native <native pdb file> ] " << std::endl;
165  std::cout << std::endl << " Type -help for full slate of options." << std::endl << std::endl;
166 
167  option.add_relevant( in::file::fasta );
168  option.add_relevant( in::file::input_res );
169  option.add_relevant( in::file::native );
170  option.add_relevant( out::file::silent );
171  option.add_relevant( out::overwrite );
172  option.add_relevant( out::nstruct );
173  option.add_relevant( score::weights );
174  option.add_relevant( constraints::cst_file );
175  option.add_relevant( OptionKeys::full_model::other_poses );
176  option.add_relevant( OptionKeys::full_model::jump_res );
177  option.add_relevant( OptionKeys::full_model::root_res );
178  option.add_relevant( OptionKeys::full_model::virtual_sugar_res );
179  option.add_relevant( OptionKeys::full_model::cutpoint_open );
180  option.add_relevant( OptionKeys::full_model::cutpoint_closed );
181  option.add_relevant( OptionKeys::full_model::sample_res );
182  option.add_relevant( OptionKeys::full_model::motif_mode );
183  option.add_relevant( OptionKeys::full_model::rna::force_syn_chi_res_list );
184  option.add_relevant( OptionKeys::full_model::rna::bulge_res );
185  option.add_relevant( OptionKeys::full_model::extra_min_res );
186  option.add_relevant( OptionKeys::full_model::rna::terminal_res );
187  option.add_relevant( OptionKeys::full_model::rna::block_stack_above_res );
188  option.add_relevant( OptionKeys::full_model::rna::block_stack_below_res );
190  option.add_relevant( OptionKeys::stepwise::monte_carlo::skip_deletions );
191  option.add_relevant( OptionKeys::stepwise::monte_carlo::add_delete_frequency );
192  option.add_relevant( OptionKeys::stepwise::monte_carlo::minimize_single_res_frequency );
193  option.add_relevant( OptionKeys::stepwise::monte_carlo::switch_focus_frequency );
194  option.add_relevant( OptionKeys::stepwise::monte_carlo::just_min_after_mutation_frequency );
195  option.add_relevant( OptionKeys::stepwise::monte_carlo::submotif_frequency );
196  option.add_relevant( OptionKeys::stepwise::monte_carlo::allow_internal_hinge_moves );
197  option.add_relevant( OptionKeys::stepwise::monte_carlo::allow_internal_local_moves );
198  option.add_relevant( OptionKeys::stepwise::monte_carlo::allow_skip_bulge );
199  option.add_relevant( OptionKeys::stepwise::monte_carlo::temperature );
200  option.add_relevant( OptionKeys::stepwise::monte_carlo::allow_variable_bond_geometry );
201  option.add_relevant( OptionKeys::stepwise::monte_carlo::csa::csa_bank_size );
202  option.add_relevant( OptionKeys::stepwise::monte_carlo::csa::csa_rmsd );
203  option.add_relevant( OptionKeys::stepwise::monte_carlo::csa::csa_output_rounds );
204  option.add_relevant( OptionKeys::stepwise::superimpose_over_all );
205  option.add_relevant( OptionKeys::stepwise::move );
206  option.add_relevant( OptionKeys::stepwise::num_random_samples );
207  option.add_relevant( OptionKeys::stepwise::num_pose_minimize );
208  option.add_relevant( OptionKeys::stepwise::align_pdb );
209  option.add_relevant( OptionKeys::stepwise::enumerate );
210  option.add_relevant( OptionKeys::stepwise::preminimize );
211  option.add_relevant( OptionKeys::stepwise::atr_rep_screen );
212  option.add_relevant( OptionKeys::stepwise::min_type );
213  option.add_relevant( OptionKeys::stepwise::min_tolerance );
214  option.add_relevant( OptionKeys::stepwise::virtualize_free_moieties_in_native );
215  option.add_relevant( OptionKeys::stepwise::new_move_selector );
216  option.add_relevant( OptionKeys::stepwise::rna::erraser );
217  option.add_relevant( OptionKeys::stepwise::rna::force_centroid_interaction );
218  option.add_relevant( OptionKeys::stepwise::rna::rebuild_bulge_mode );
219  option.add_relevant( OptionKeys::stepwise::rna::integration_test );
220  option.add_relevant( OptionKeys::stepwise::protein::allow_virtual_side_chains );
221  option.add_relevant( OptionKeys::rna::corrected_geo );
222  option.add_relevant( OptionKeys::rna::data_file );
223 
224  core::init::init(argc, argv);
225 
226  protocols::viewer::viewer_main( my_main );
227 
228  } catch ( utility::excn::EXCN_Base const & e ) {
229  std::cout << "caught exception " << e.msg() << std::endl;
230  return -1;
231  }
232 }
233 
234 
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
File name class supporting Windows and UN*X/Linux format names.
Definition: FileName.hh:37
void stepwise_monte_carlo()
Definition: stepwise.cc:74
tuple scorefxn
Definition: PyMOL_demo.py:63
xyzVector< Real > Vector
Tracer IO system.
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
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
string min_type
Definition: loops_kic.py:76
list native
Definition: ContactMap.py:108
double Real
Definition: types.hh:39
int main(int argc, char *argv[])
Definition: stepwise.cc:161
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
void init()
set global 'init_was_called' to true
Definition: init.cc:26
Program options global and initialization function.
void * my_main(void *)
Definition: stepwise.cc:149
int const silent
Named verbosity levels.
static THREAD_LOCAL basic::Tracer TR("apps.pilot.rhiju.stepwise_monte_carlo")
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378