Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
fast_clustering.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 analyse sets of structures
12 /// @details This tool allows to superimpose structures using the wRMSD method [ Damm&Carlson, Biophys J (2006) 90:4558-4573 ]
13 /// @details Superimposed structures can be written as output pdbs and the converged residues can be determined
14 /// @author Oliver Lange
15 
16 #include <devel/init.hh>
17 #include <core/types.hh>
18 #include <protocols/toolbox/DecoySetEvaluation.hh>
19 #include <protocols/toolbox/Cluster.hh>
20 #include <protocols/toolbox/Cluster.impl.hh>
21 #include <core/io/silent/SilentFileData.hh>
22 
23 #include <protocols/loops/Loop.hh>
24 #include <protocols/loops/Loops.hh>
25 #include <protocols/loops/LoopsFileIO.hh>
26 
27 // Utility headers
29 #include <utility/io/ozstream.hh>
30 #include <utility/vector1.hh>
31 #include <basic/Tracer.hh>
32 #include <utility/exit.hh>
33 #include <utility/file/FileName.hh>
34 
35 // option key includes
36 #include <basic/options/keys/in.OptionKeys.gen.hh>
37 #include <basic/options/keys/cluster.OptionKeys.gen.hh>
38 
39 // ObjexxFCL includes
40 #include <ObjexxFCL/FArray1D.hh>
41 
42 #include <string>
43 
44 //Auto Headers
46 
47 
48 static THREAD_LOCAL basic::Tracer tr( "main" );
49 
50 using namespace core;
51 using namespace protocols;
52 //using namespace pose;
53 using namespace protocols::toolbox;
54 using namespace ObjexxFCL; //Farray
55 //using namespace ObjexxFCL::format;
56 
57 using namespace basic::options;
58 using namespace basic::options::OptionKeys;
59 using namespace core::io::silent;
60 
61 OPT_2GRP_KEY( File, out, file, cluster )
62 OPT_1GRP_KEY( File, rigid, in )
63 
65  using namespace basic::options;
66  using namespace basic::options::OptionKeys;
69  OPT( cluster::limit_cluster_size );
70  NEW_OPT( out::file::cluster, "write clustered structures to silent file with this name", "cluster.out" );
71  NEW_OPT( rigid::in, "residues that are considered for clustering", "rigid.loop");
72 }
73 
75  if ( !option[ rigid::in ].user() ) return;
76  loops::PoseNumberedLoopFileReader loop_file_reader;
77  loop_file_reader.hijack_loop_reading_code_set_loop_line_begin_token( "RIGID" );
78  std::ifstream is( option[ rigid::in ]().name().c_str() );
79  if ( !is ) utility_exit_with_message( "[ERROR] Error opening RBSeg file '" + option[ rigid::in ]().name() + "'" );
80  loops::SerializedLoopList loops = loop_file_reader.read_pose_numbered_loops_file(is, option[ rigid::in ](), false );
81  loops::Loops rigid = loops::Loops( loops );
82  for ( Size i=1; i<=natoms; ++i ) {
83  if ( rigid.is_loop_residue( i ) ) weights( i )=1.0;
84  else weights( i )=0.0;
85  }
86 }
87 
88 void read_structures( SilentFileData &sfd, DecoySetEvaluation& ensemble ) {
89  using namespace basic::options;
90  using namespace basic::options::OptionKeys;
91  if ( !option[ in::file::silent ].user() ) {
92  utility_exit_with_message("fast_clustering works only with -in:file:silent as input option");
93  }
95  for ( utility::vector1< utility::file::FileName >::const_iterator current_fn_ = silent_files.begin(); current_fn_ != silent_files.end(); ++current_fn_ ) {
96  tr.Debug << "reading " << *current_fn_ << std::endl;
97  sfd.read_file( *current_fn_ );
98  }
99  ensemble.push_back_CA_xyz_from_silent_file( sfd, true /*store energies*/ );
100 }
101 
102 void run() {
103  //bool store_energies ( true ); // unused ~Labonte
104 
105  DecoySetEvaluation ensemble;
106  SilentFileData sfd;
107  read_structures( sfd, ensemble );
108 
109  //initialize wRMSD weights with 1.0 unless we have -rigid:in file active
110  FArray1D_double weights( ensemble.n_atoms() , 1.0 );
111  read_input_weights( weights, ensemble.n_atoms() );
112  ensemble.set_weights( weights );
113 
114  SilentFileData kept_decoys;
115  cluster_silent_structs( ensemble, sfd.begin(), sfd.end(), kept_decoys, ClusterOptions( true ) );
116  std::string out_filename=option[ out::file::cluster ]();
117  { utility::io::ozstream out( out_filename ); } //open and close, to empty the file.
118  kept_decoys.write_all( out_filename );
119 
120  return;
121 }
122 
123 /////////////////////////////////////////////////////////////////////////////////////////////////////////
124 /// =============================== MAIN ============================================================
125 /////////////////////////////////////////////////////////////////////////////////////////////////////////
126 int
127 main( int argc, char * argv [] )
128 {
129  try {
130 
132  devel::init( argc, argv );
133 
134  try{
135  run();
136  } catch ( utility::excn::EXCN_Base& excn ) {
137  excn.show( std::cerr );
138  }
139  } catch ( utility::excn::EXCN_Base const & e ) {
140  std::cout << "caught exception " << e.msg() << std::endl;
141  return -1;
142  }
143 
144  return 0;
145 }
146 
147 
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
void run()
int main(int argc, char *argv[])
=============================== MAIN ============================================================ ...
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
#define OPT_2GRP_KEY(type, grp1, grp2, key)
virtual void show(std::ostream &) const =0
Program exit functions and macros.
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.
static THREAD_LOCAL basic::Tracer tr("main")
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
super::const_iterator const_iterator
Definition: vector1.hh:62
Output file stream wrapper for uncompressed and compressed files.
list native
Definition: ContactMap.py:108
#define NEW_OPT(akey, help, adef)
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
base class for Exception system
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
void read_input_weights(FArray1D_double &weights, Size natoms)
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
#define OPT_1GRP_KEY(type, grp, key)
void register_options()
#define OPT(akey)
void read_structures(SilentFileData &sfd, DecoySetEvaluation &ensemble)
platform::Size Size
Definition: random.fwd.hh:30
TracerProxy Debug
Definition: Tracer.hh:262
int const silent
Named verbosity levels.
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378