Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rna_minimize.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
11 /// @brief
12 
13 
14 // libRosetta headers
15 #include <core/types.hh>
16 #include <core/chemical/ChemicalManager.hh>
17 #include <core/id/NamedAtomID.hh>
18 #include <core/id/AtomID.hh>
19 #include <core/io/silent/BinarySilentStruct.hh>
20 #include <core/scoring/ScoreFunctionFactory.hh>
21 #include <core/scoring/constraints/ConstraintSet.hh>
22 #include <core/scoring/constraints/ConstraintSet.fwd.hh>
23 #include <core/scoring/constraints/ConstraintIO.hh>
24 #include <core/scoring/ScoreFunction.hh>
25 #include <core/scoring/rms_util.hh>
26 #include <basic/database/open.hh>
27 #include <basic/options/option.hh>
29 #include <protocols/viewer/viewers.hh>
30 #include <core/pose/Pose.hh>
31 #include <core/pose/util.hh>
32 #include <protocols/stepwise/setup/FullModelInfoSetupFromCommandLine.hh>
33 #include <core/pose/annotated_sequence.hh>
34 #include <core/init/init.hh>
35 
36 #include <core/io/pdb/pose_io.hh>
37 #include <core/import_pose/import_pose.hh>
38 #include <core/import_pose/pose_stream/PoseInputStream.hh>
39 #include <core/import_pose/pose_stream/PoseInputStream.fwd.hh>
40 #include <core/import_pose/pose_stream/PDBPoseInputStream.hh>
41 #include <core/import_pose/pose_stream/SilentFilePoseInputStream.hh>
42 #include <utility/vector1.hh>
44 
45 //RNA stuff.
46 #include <protocols/farna/setup/RNA_DeNovoPoseSetup.hh>
47 #include <protocols/farna/movers/RNA_Minimizer.hh>
48 #include <protocols/farna/options/RNA_MinimizerOptions.hh>
49 #include <protocols/farna/util.hh>
50 #include <protocols/stepwise/modeler/util.hh> // for other_pose.
51 #include <protocols/stepwise/modeler/align/util.hh>
52 #include <protocols/toolbox/AtomLevelDomainMap.hh>
53 
54 // C++ headers
55 #include <iostream>
56 #include <string>
57 
58 // option key includes
59 #include <basic/options/keys/out.OptionKeys.gen.hh>
60 #include <basic/options/keys/in.OptionKeys.gen.hh>
61 #include <basic/options/keys/rna.OptionKeys.gen.hh>
62 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
63 #include <basic/options/keys/full_model.OptionKeys.gen.hh>
64 #include <basic/options/keys/score.OptionKeys.gen.hh>
65 
67 
68 OPT_KEY( String, params_file )
69 OPT_KEY( Boolean, one_torsion_test )
70 
71 using namespace core;
72 using namespace protocols;
73 using namespace basic::options::OptionKeys;
74 using utility::vector1;
75 using io::pdb::dump_pdb;
76 
77 //Definition of new OptionKeys
78 // these will be available in the top-level OptionKey namespace:
79 // i.e., OPT_KEY( Type, key ) --> OptionKey::key
80 // to have them in a namespace use OPT_1GRP_KEY( Type, grp, key ) --> OptionKey::grp::key
81 
82 
83 ///////////////////////////////////////////////////////////////////////////////
84 void
86 {
87  using namespace basic::options;
88  using namespace basic::options::OptionKeys;
89  using namespace core::scoring::constraints;
90  using namespace core::chemical;
91  using namespace core::scoring;
92  using namespace core::kinematics;
93  using namespace core::io::silent;
94  using namespace core::import_pose::pose_stream;
95  using namespace core::pose::full_model_info;
96  using namespace protocols::toolbox;
97  using namespace protocols::farna;
98  using namespace protocols::farna::movers;
99  using namespace protocols::stepwise;
100  using namespace protocols::stepwise::setup;
101 
102  ResidueTypeSetCOP rsd_set;
103  rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set( FA_STANDARD );
104 
105  // is_dump_pdb
106  bool is_dump_pdb( true );
107  if ( option[ in::file::silent ].user() ) is_dump_pdb = false;
108  if ( option[ out::pdb ].user() ) is_dump_pdb = option[ out::pdb ];
109 
110  // input stream
111  PoseInputStreamOP input;
112  if ( option[ in::file::silent ].user() ) {
113  if ( option[ in::file::tags ].user() ) {
114  SilentFilePoseInputStreamOP input1( new SilentFilePoseInputStream(
116  option[ in::file::tags ]()
117  ) );
118  input1->set_order_by_energy( true );
119  input = input1;
120  } else {
121  SilentFilePoseInputStreamOP input1( new SilentFilePoseInputStream( option[ in::file::silent ]() ) );
122  input1->set_order_by_energy( true );
123  input = input1;
124  }
125  } else {
126  input = PoseInputStreamOP( new PDBPoseInputStream( option[ in::file::s ]() ) );
127  }
128 
129  // native pose setup
131  bool native_exists( false );
132  if ( option[ in::file::native ].user() ) {
133  std::string native_pdb_file = option[ in::file::native ];
134  core::import_pose::pose_from_pdb( native_pose, *rsd_set, native_pdb_file );
135  cleanup( native_pose );
136  native_exists = true;
137  }
138 
139  // minimizer setup
140  RNA_MinimizerOptionsOP options( new RNA_MinimizerOptions );
141  options->initialize_from_command_line();
142  RNA_Minimizer rna_minimizer( options );
143 
144  // Silent file output setup
145  std::string const silent_file = option[ out::file::silent ]();
146  SilentFileData silent_file_data;
147 
148  // other poses -- for scoring collections of poses connected by (virtual) loops, using full_model_info.
150  if ( option[ full_model::other_poses ].user() ) get_other_poses( other_poses, option[ full_model::other_poses ](), rsd_set );
151 
153 
154  Size i( 0 );
155 
156  if ( option[params_file].user() ) utility_exit_with_message( " -params_file not supported in rna_minimize anymore." );
157 
158  while ( input->has_another_pose() ) {
159 
160  input->fill_pose( pose, *rsd_set );
161  i++;
162 
163  if ( !option[ in::file::silent ].user() ) {
164  cleanup( pose );
165  fill_full_model_info_from_command_line( pose, other_poses ); // only does something if -in:file:fasta specified.
166  }
167 
168  if ( option[OptionKeys::constraints::cst_fa_file].user() ) {
169  // Just Reads the first cst_file...
170  // Not sure why but the constraint depends on the start pose given.
171  // Initialize a new pose to avoid the instability.
173  core::pose::make_pose_from_sequence( test_pose, pose.annotated_sequence(), *rsd_set );
174  ConstraintSetOP cst_set = ConstraintIO::get_instance()->read_constraints(
175  option[OptionKeys::constraints::cst_fa_file][1], ConstraintSetOP( new ConstraintSet ), test_pose );
176  pose.constraint_set( cst_set );
177  }
178 
179  // RNA_DeNovoPoseSetup parameters;
180  // if ( option[params_file].user() ) {
181  // parameters.initialize_for_de_novo_protocol(
182  // pose, option[params_file],
183  // basic::database::full_name("sampling/rna/1jj2_RNA_jump_library.dat"),
184  // false /*ignore_secstruct*/
185  // );
186  // // parameters.set_suppress_bp_constraint( 1.0 );
187  // parameters.setup_base_pair_constraints( pose );
188  // //rna_minimizer.set_atom_level_domain_map( parameters.atom_level_domain_map() );
189  // }
190 
191  AtomLevelDomainMapOP atom_level_domain_map( new AtomLevelDomainMap( pose ) );
192  if ( option[ in::file::minimize_res ].user() ) {
193  // don't allow anything to move, and then supply minimize_res as 'extra' minimize_res.
194  atom_level_domain_map->set( false );
195  options->set_extra_minimize_res( option[ in::file::minimize_res ]() );
196  rna_minimizer.set_options( options );
197  } else if ( option[ one_torsion_test ]() ) {
198  // atom_level_domain_map->set( false );
199  // for ( Size n = 1; n <= pose.residue(1).natoms(); n++ ) atom_level_domain_map->set_domain( id::AtomID( n, 1 ), 1 );
200  // for ( Size n = 1; n <= pose.residue(2).natoms(); n++ ) atom_level_domain_map->set_domain( id::AtomID( n, 2 ), 2 );
201  // atom_level_domain_map->set( id::NamedAtomID( " P ", 2 ), pose, false );
202  // atom_level_domain_map->set( id::NamedAtomID( " O5'", 2 ), pose, false );
203  } else {
204  atom_level_domain_map->set( true );
205  }
206  rna_minimizer.set_atom_level_domain_map( atom_level_domain_map );
207 
208 
209  // graphics viewer.
210  if ( i == 1 ) protocols::viewer::add_conformation_viewer( pose.conformation(), "current", 400, 400 );
211 
212 
213  // do it
214  pose::Pose pose_init = pose;
215  rna_minimizer.apply( pose );
216 
217  // tag
218  std::string tag = tag_from_pose( pose );
219  Size pos = tag.find( ".pdb" ); // remove ".pdb"
220  if ( pos != std::string::npos ) tag.replace( pos, 4, "" );
221  tag += "_minimize";
222 
223  // Do alignment to native
224  if ( native_exists ) {
225  utility::vector1< Size > superimpose_res;
226  for ( Size k = 1; k <= pose.total_residue(); ++k ) superimpose_res.push_back( k );
227  core::id::AtomID_Map< id::AtomID > const & alignment_atom_id_map_native =
228  protocols::stepwise::modeler::align::create_alignment_id_map_legacy( pose, native_pose, superimpose_res ); // perhaps this should move to toolbox.
229  core::scoring::superimpose_pose( pose, native_pose, alignment_atom_id_map_native );
230  core::scoring::superimpose_pose( pose_init, native_pose, alignment_atom_id_map_native );
231  }
232 
233  BinarySilentStruct s( pose, tag );
234 
235  if ( native_exists ) {
236  Real const rmsd_init = all_atom_rmsd( native_pose, pose_init );
237  Real const rmsd = all_atom_rmsd( native_pose, pose );
238  std::cout << "All atom rmsd: " << rmsd_init << " to " << rmsd << std::endl;
239  s.add_energy( "rms", rmsd );
240  s.add_energy( "rms_init", rmsd_init );
241 
242  // Stem RMSD
243  // if ( option[params_file].user() ) {
244  // std::list< Size > stem_residues( parameters.get_stem_residues( pose ) );
245  // if ( !stem_residues.empty()/*size() > 0*/ ) {
246  // Real const rmsd_stems = all_atom_rmsd( native_pose, pose, stem_residues );
247  // s.add_energy( "rms_stem", rmsd_stems );
248  // std::cout << "Stems rmsd: " << rmsd_stems << std::endl;
249  // }
250  // }
251  }
252 
253  std::cout << "Outputting " << tag << " to silent file: " << silent_file << std::endl;
254  silent_file_data.write_silent_struct( s, silent_file, false /*write score only*/ );
255 
256  std::string const out_file = tag + ".pdb";
257  if ( is_dump_pdb ) {
258  dump_pdb( pose, out_file );
259  }
260 
261  }
262 
263 }
264 
265 
266 ///////////////////////////////////////////////////////////////
267 void*
268 my_main( void* )
269 {
271 
272  protocols::viewer::clear_conformation_viewers();
273  exit( 0 );
274 }
275 
276 
277 ///////////////////////////////////////////////////////////////////////////////
278 int
279 main( int argc, char * argv [] )
280 {
281  try {
282  using namespace basic::options;
283  using namespace basic::options::OptionKeys;
284 
285  std::cout << std::endl << "Basic usage: " << argv[0] << " -s <pdb file> " << std::endl;
286  std::cout << " " << argv[0] << " -in:file:silent <silent file> " << std::endl;
287  std::cout << std::endl << " Type -help for full slate of options." << std::endl << std::endl;
288 
289  utility::vector1< Size > blank_size_vector;
290 
291  option.add_relevant( OptionKeys::rna::vary_geometry );
292  option.add_relevant( OptionKeys::rna::farna::minimize::skip_coord_constraints );
293  option.add_relevant( OptionKeys::rna::farna::minimize::skip_o2prime_trials );
294  option.add_relevant( OptionKeys::rna::farna::minimize::deriv_check );
295  option.add_relevant( OptionKeys::constraints::cst_fa_file );
296  option.add_relevant( in::file::minimize_res );
299  NEW_OPT( params_file, "Input file for pairings", "" );
300  NEW_OPT( one_torsion_test, "tracking down problem with geom_sol", false );
301 
302  ////////////////////////////////////////////////////////////////////////////
303  // setup
304  ////////////////////////////////////////////////////////////////////////////
305  core::init::init(argc, argv);
306 
307  ////////////////////////////////////////////////////////////////////////////
308  // end of setup
309  ////////////////////////////////////////////////////////////////////////////
310  protocols::viewer::viewer_main( my_main );
311  } catch ( utility::excn::EXCN_Base const & e ) {
312  std::cout << "caught exception " << e.msg() << std::endl;
313  return -1;
314  }
315 }
316 
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void * my_main(void *)
std::string String
Definition: remodel.cc:69
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
common derived classes for thrown exceptions
static void add_relevant(const OptionKey &key)
add OptionKey to list of application relevant options
Functions for opening database files.
def namespace
Definition: exclude.py:223
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
#define OPT_KEY(type, key)
void rna_fullatom_minimize_test()
Definition: rna_minimize.cc:85
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
list native
Definition: ContactMap.py:108
double Real
Definition: types.hh:39
#define NEW_OPT(akey, help, adef)
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
int main(int argc, char *argv[])
void init()
set global 'init_was_called' to true
Definition: init.cc:26
Program options global and initialization function.
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373
platform::Size Size
Definition: random.fwd.hh:30
int const silent
Named verbosity levels.