Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rna_design.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/AA.hh>
17 #include <core/conformation/Residue.hh>
18 #include <core/chemical/ChemicalManager.hh>
19 #include <core/scoring/ScoreFunction.hh>
20 #include <core/scoring/ScoreFunctionFactory.hh>
21 #include <core/scoring/constraints/ConstraintSet.fwd.hh>
22 #include <core/scoring/methods/EnergyMethodOptions.hh>
23 #include <core/pack/task/PackerTask.hh>
24 #include <core/pack/task/rna/RNA_ResidueLevelTask.hh>
25 #include <core/pack/task/TaskFactory.hh>
26 #include <core/pack/task/ResfileReader.hh>
27 #include <core/pack/pack_rotamers.hh>
28 #include <basic/options/option.hh>
30 #include <protocols/viewer/viewers.hh>
31 #include <core/pose/Pose.hh>
32 #include <core/init/init.hh>
33 
34 #include <core/io/pdb/pose_io.hh>
35 
36 #include <utility/vector1.hh>
37 #include <utility/io/ozstream.hh>
38 
39 
40 #include <ObjexxFCL/format.hh>
42 
43 //RNA stuff.
44 #include <protocols/farna/util.hh>
45 
46 
47 // C++ headers
48 //#include <cstdlib>
49 #include <fstream>
50 #include <iostream>
51 #include <string>
52 
53 
54 // option key includes
55 #include <basic/options/keys/out.OptionKeys.gen.hh>
56 #include <basic/options/keys/score.OptionKeys.gen.hh>
57 #include <basic/options/keys/in.OptionKeys.gen.hh>
58 #include <basic/options/keys/packing.OptionKeys.gen.hh>
59 
60 //Auto Headers
61 #include <platform/types.hh>
62 #include <core/import_pose/import_pose.hh>
63 #include <core/kinematics/Jump.hh>
64 #include <utility/vector0.hh>
66 #include <ObjexxFCL/FArray1D.hh>
67 
69 
70 //Auto using namespaces
71 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
72 namespace ObjexxFCL { namespace format { } } using namespace ObjexxFCL::format; // AUTO USING NS
73 //Auto using namespaces end
74 
75 
76 using namespace core;
77 using namespace protocols;
78 using namespace basic::options::OptionKeys;
79 using utility::vector1;
80 using io::pdb::dump_pdb;
81 
82 //Definition of new OptionKeys
83 // these will be available in the top-level OptionKey namespace:
84 // i.e., OPT_KEY( Type, key ) --> OptionKey::key
85 // to have them in a namespace use OPT_1GRP_KEY( Type, grp, key ) --> OptionKey::grp::key
86 OPT_KEY( Boolean, disable_o2prime_rotamers )
87 OPT_KEY( Boolean, disable_include_current )
88 OPT_KEY( Boolean, sample_chi )
89 OPT_KEY( Boolean, ss_ds_ts_assign )
90 OPT_KEY( Boolean, dump )
91 
92 ///////////////////////////////////////////////////////////////////////////////
93 void
94 rna_sequence_recovery_metrics( pose::Pose const & reference_pose, utility::vector1< pose::PoseOP > const & pose_list, std::string const & sequence_recovery_file )
95 {
96 
97  // make a local copy
98  pose::Pose pose( reference_pose );
99 
100  // Get information on ss, ds, ts residues in native pose.
101  Size const nres = pose.total_residue();
102  FArray1D_int struct_type( nres, -1 );
103  protocols::farna::check_base_pair( pose, struct_type );
104 
105  FArray1D_float recovery( nres, 0.0 );
106  for ( Size n = 1; n <= pose_list.size(); n++ ) {
107  for ( Size i = 1; i <= nres; i++ ) {
108  if ( (pose_list[n])->residue(i).aa() == pose.residue(i).aa() ) {
109  recovery( i ) += 1.0;
110  }
111  }
112  }
113 
114  recovery /= pose_list.size();
115 
116  Size num_ss( 0 ), num_ds( 0 ), num_ts( 0 );
117  Real frac_ss( 0.0 ), frac_ds( 0.0 ), frac_ts( 0.0 ), frac_overall( 0.0 );
118  for ( Size i = 1; i <= nres; i++ ) {
119  frac_overall += recovery(i);
120  switch ( struct_type(i) ) {
121  case 0 :
122  num_ss++;
123  frac_ss += recovery(i);
124  break;
125  case 1 :
126  num_ds++;
127  frac_ds += recovery(i);
128  break;
129  case 2 :
130  num_ts++;
131  frac_ts += recovery(i);
132  break;
133  }
134  }
135 
136  if ( num_ss > 0.0 ) frac_ss /= num_ss;
137  if ( num_ds > 0.0 ) frac_ds /= num_ds;
138  if ( num_ts > 0.0 ) frac_ts /= num_ts;
139  if ( nres > 0.0 ) frac_overall /= nres;
140 
141  std::map <Size, char > struct_symbol;
142  struct_symbol[ 0 ] = 'S';
143  struct_symbol[ 1 ] = 'D';
144  struct_symbol[ 2 ] = 'T';
145 
146  utility::io::ozstream out( sequence_recovery_file );
147 
148  for ( Size i = 1; i <= nres; i++ ) {
149  out << pose.residue(i).name1() << I(3,i) << " " << F(8,3,recovery(i)) << " " << struct_symbol[ struct_type(i) ] << std::endl;
150  }
151 
152  out << std::endl;
153  out << "SINGLE_STRANDED " << I(3,num_ss) << " " << F(9,4,frac_ss) << std::endl;
154  out << "DOUBLE_STRANDED " << I(3,num_ds) << " " << F(9,4,frac_ds) << std::endl;
155  out << "TERTIARY_STRUCT " << I(3,num_ts) << " " << F(9,4,frac_ts) << std::endl;
156  out << "OVERALL " << I(3,nres) << " " << F(9,4,frac_overall) << std::endl;
157 
158  out.close();
159 
160  std::cout << "Wrote stats to: " << sequence_recovery_file << std::endl;
161 
162 }
163 
164 
165 ///////////////////////////////////////////////////////////////////////////////
166 void
168 {
169 
170  using namespace basic::options;
171  using namespace basic::options::OptionKeys;
172  using namespace core::chemical;
173  using namespace core::scoring;
174 
175  ResidueTypeSetCOP rsd_set;
176  rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set( FA_STANDARD );
177 
179  std::string pdb_file = option[ in::file::s ][1];
180  core::import_pose::pose_from_pdb( pose, *rsd_set, pdb_file );
181  protocols::farna::ensure_phosphate_nomenclature_matches_mini( pose );
182 
183  dump_pdb( pose, "start.pdb");
184  pose::Pose save_pose( pose );
185 
186  pack::task::PackerTaskOP task( pack::task::TaskFactory::create_packer_task( pose ));
187  task->initialize_from_command_line();
188 
189  if ( basic::options::option[basic::options::OptionKeys::packing::resfile].user() ) {
190  pack::task::parse_resfile(pose, *task);
191  } else {
192  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
193  task->nonconst_residue_task( ii ).allow_aa( na_rad );
194  task->nonconst_residue_task( ii ).allow_aa( na_ura );
195  task->nonconst_residue_task( ii ).allow_aa( na_rgu );
196  task->nonconst_residue_task( ii ).allow_aa( na_rcy );
197  assert( task->design_residue(ii) );
198  }
199  }
200 
201  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
202 
203  //Hmmm, extras.
204  task->nonconst_residue_task( ii ).and_extrachi_cutoff( 0 );
205 
206  if ( option[ disable_o2prime_rotamers ]() ) task->nonconst_residue_task(ii).sample_proton_chi( false );
207 
208  if ( option[ sample_chi ]() ) task->nonconst_residue_task(ii).nonconst_rna_task().set_sample_rna_chi( true );
209 
210  // Can input this from command line:
211  // task->nonconst_residue_task( ii ).or_ex4( true );
212 
213  // Can input this from command line?
214  // task->nonconst_residue_task( ii ).or_ex1( true );
215 
216  // Screw this, can figure this out from command line.
217  // if ( !option[ disable_include_current ]() ) task->nonconst_residue_task( ii ).or_include_current( true );
218 
219  }
220 
221  ScoreFunctionOP scorefxn = get_score_function();
222 
223  // scorefxn->energy_method_options().exclude_DNA_DNA( exclude_DNA_DNA );
224  methods::EnergyMethodOptions options( scorefxn->energy_method_options() );
225  options.exclude_DNA_DNA( false );
226  scorefxn->set_energy_method_options( options );
227 
228  scorefxn->show( std::cout,pose );
229 
230  pose.dump_pdb( "start.pdb" );
231 
232  Size const nstruct = option[ out::nstruct ];
235 
236  pack::pack_rotamers_loop( pose, *scorefxn, task, nstruct, results, pose_list);
237 
238  std::string outfile( pdb_file );
239  Size pos( pdb_file.find( ".pdb" ) );
240  outfile.replace( pos, 4, ".pack.txt" );
241  protocols::farna::export_packer_results( results, pose_list, scorefxn, outfile, option[ dump ] );
242 
243  std::string sequence_recovery_file( pdb_file );
244  sequence_recovery_file.replace( pos, 4, ".sequence_recovery.txt" );
245  rna_sequence_recovery_metrics( save_pose, pose_list, sequence_recovery_file );
246 
247  // std::string const out_file_tag = "S_"+lead_zero_string_of( n, 4 );
248  // dump_pdb( pose, out_file_tag + ".pdb" );
249 
250  pose = *( pose_list[1] );
251  scorefxn->show( std::cout,pose );
252 
253 
254 }
255 
256 ///////////////////////////////////////////////////////////////
257 void
259 {
260  using namespace basic::options;
261  using namespace basic::options::OptionKeys;
262  using namespace core::chemical;
263  using namespace core::scoring;
264 
265  ResidueTypeSetCOP rsd_set;
266  rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set( FA_STANDARD );
267 
268  pose::PoseOP pose_op( new pose::Pose );
270 
271  for ( Size n = 1; n <= pdb_files.size(); n++ ) {
272  std::string const & pdb_file = pdb_files[ n ] ;
273  core::import_pose::pose_from_pdb( *pose_op, *rsd_set, pdb_file );
274  protocols::farna::ensure_phosphate_nomenclature_matches_mini( *pose_op );
275 
276  std::string sequence_recovery_file( pdb_file );
277  Size pos( pdb_file.find( ".pdb" ) );
278  sequence_recovery_file.replace( pos, 4, ".ss_ds_ts.txt" );
279 
281  pose_list.push_back( pose_op );
282  rna_sequence_recovery_metrics( *pose_op, pose_list, sequence_recovery_file );
283  }
284 
285 }
286 
287 
288 ///////////////////////////////////////////////////////////////
289 void*
290 my_main( void* )
291 {
292  using namespace basic::options;
293  using namespace basic::options::OptionKeys;
294 
295  if ( option[ ss_ds_ts_assign ] ) {
297  } else {
298  rna_design_test();
299  }
300  exit( 0 );
301 }
302 
303 
304 ///////////////////////////////////////////////////////////////////////////////
305 int
306 main( int argc, char * argv [] )
307 {
308  try {
309  using namespace basic::options;
310 
311  std::cout << std::endl << "Basic usage: " << argv[0] << " -s <pdb file> [ -resfile <resfile>] " << std::endl;
312  std::cout << std::endl << " Type -help for full slate of options." << std::endl << std::endl;
313 
314  //Uh, options? MOVE THESE TO OPTIONS NAMESPACE INSIDE CORE/OPTIONS.
315  NEW_OPT( disable_o2prime_rotamers, "In designing, don't sample 2'-OH",false);
316  NEW_OPT( disable_include_current, "In designing, don't include current",false);
317  NEW_OPT( sample_chi, "In designing RNA, chi torsion sample",false);
318  NEW_OPT( ss_ds_ts_assign, "Figure out assignment of residues to single-stranded, double-stranded, tertiary contact categories",false);
319  NEW_OPT( dump, "Dump pdb", false );
320 
321 
322  ////////////////////////////////////////////////////////////////////////////
323  // setup
324  ////////////////////////////////////////////////////////////////////////////
325  core::init::init(argc, argv);
326 
327 
328  ////////////////////////////////////////////////////////////////////////////
329  // end of setup
330  ////////////////////////////////////////////////////////////////////////////
331 
332  protocols::viewer::viewer_main( my_main );
333  } catch ( utility::excn::EXCN_Base const & e ) {
334  std::cout << "caught exception " << e.msg() << std::endl;
335  return -1;
336  }
337 }
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void rna_sequence_recovery_metrics(pose::Pose const &reference_pose, utility::vector1< pose::PoseOP > const &pose_list, std::string const &sequence_recovery_file)
Definition: rna_design.cc:94
def dump
Definition: __init__.py:177
vector0: std::vector with assert-checked bounds
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
common derived classes for thrown exceptions
tuple scorefxn
Definition: PyMOL_demo.py:63
void ss_ds_ts_assign_test()
Definition: rna_design.cc:258
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
basic::options::IntegerOptionKey const nstruct("nstruct")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
#define OPT_KEY(type, key)
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
Output file stream wrapper for uncompressed and compressed files.
void close()
Close the ofstream and reset the state.
Definition: ozstream.hh:430
double Real
Definition: types.hh:39
#define NEW_OPT(akey, help, adef)
std::string F(int const w, int const d, float const &t)
Fixed Point Format: float.
Definition: format.cc:387
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
void rna_design_test()
Definition: rna_design.cc:167
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
void init()
set global 'init_was_called' to true
Definition: init.cc:26
Program options global and initialization function.
void * my_main(void *)
Definition: rna_design.cc:290
std::string I(int const w, T const &t)
Integer Format.
Definition: format.hh:758
platform::Size Size
Definition: random.fwd.hh:30
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378
size_type size() const
Active Array Size.
Definition: FArray.hh:621
FArray1D: Fortran-Compatible 1D Array.
Definition: FArray1.hh:30