Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintClaimer.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 TopologyBroker
11 /// @brief top-class (Organizer) of the TopologyBroker mechanism
12 /// @detailed responsibilities:
13 /// @author Oliver Lange
14 
15 // Unit Headers
17 
18 // Package Headers
22 
23 //#include <protocols/topology_broker/DofClaim.hh>
24 
25 // Project Headers
26 #include <core/pose/Pose.hh>
27 #include <protocols/loops/Loops.hh>
30 // #include <core/kinematics/MoveMap.hh>
31 // #include <core/fragment/FragSet.hh>
32 // #include <protocols/simple_moves/FragmentMover.hh>
33 
34 
35 #include <core/id/Exceptions.hh>
36 
37 // ObjexxFCL Headers
38 
39 // Utility headers
40 #include <utility/excn/Exceptions.hh>
41 //#include <utility/io/izstream.hh>
42 //#include <utility/io/ozstream.hh>
43 //#include <utility/io/util.hh>
44 #include <basic/Tracer.hh>
45 #include <basic/options/option.hh>
46 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
47 //// C++ headers
48 // AUTO-REMOVED #include <fstream>
49 
51 #include <utility/vector1.hh>
52 
53 
54 // option key includes
55 
56 static basic::Tracer tr("protocols.topo_broker",basic::t_info);
57 //static numeric::random::RandomGenerator RG(18828234);
58 
59 namespace protocols {
60 namespace topology_broker {
61 
62 //static numeric::random::RandomGenerator RG(812739); // <- Magic number, do not change it!
63 
64 using namespace core;
65 using namespace scoring::constraints;
67  filename_( "NO_FILE"),
68  tag_( "NO_TAG" ),
69  constraints_( NULL ),
70  bCentroid_( true ),
71  bFullatom_( false ),
72  bCmdFlag_( false ),
73  combine_ratio_( 1 ),
74  drop_random_rate_( 0.0 ),
75  skip_redundant_( false ),
76  skip_redundant_width_( 1 ),
77  filter_weight_( 0.0 ),
78  filter_name_( "" )
79 {}
80 
82  filename_( filename ),
83  tag_( tag ),
84  constraints_( NULL ),
85  bCentroid_( true ),
86  bFullatom_( false ),
87  bCmdFlag_( false ),
88  combine_ratio_( 1 ),
89  drop_random_rate_( 0 ),
90  skip_redundant_( false ),
91  skip_redundant_width_( 1 ),
92  filter_weight_( 0.0 ),
93  filter_name_( "" )
94 {}
95 
96 ConstraintClaimer::ConstraintClaimer( bool CmdFlag, bool centroid, bool fullatom )
97  : filename_( "" ),
98  tag_( "" ),
99  constraints_( NULL ),
100  bCentroid_( centroid ),
101  bFullatom_( fullatom ),
102  bCmdFlag_( CmdFlag ),
103  combine_ratio_( 1 ),
104  drop_random_rate_( 0 ),
105  skip_redundant_( false ),
106  skip_redundant_width_( 1 ),
107  filter_weight_( 0.0 ),
108  filter_name_( "" )
109 {
110  runtime_assert( CmdFlag );
111 }
112 
114 }
115 
117  using namespace basic::options;
118  using namespace basic::options::OptionKeys;
119  tr.Debug << "ConstraintClaimer::new_decoy: cst-modus: " << ( bFullatom_ ? " fullatom " : "no fullatom" )
120  << ( bCentroid_ ? " centroid " : " no centroid " )
121  << std::endl;
122  if ( bCmdFlag_ && option[ constraints::combine ].user() ) {
123  combine_ratio_ = option[ constraints::combine ]();
124  }
125 
126  if ( bCmdFlag_ && ( option[ constraints::skip_redundant ]() || option[ constraints::skip_redundant_width ].user() ) ) {
127  skip_redundant_ = true;
128  skip_redundant_width_ = option[ constraints::skip_redundant_width ];
129  }
130 
131 
132  if ( bCmdFlag_ && option[ constraints::cst_file ].user() ) {
133  // reads and sets constraints -- this might be different each time we call this function
134  std::string old_filename = filename_;
136  if ( old_filename != filename_ ) constraints_ = NULL;
137  }
138  if ( bCmdFlag_ && option[ constraints::cst_fa_file ].user() && bFullatom_ && !bCentroid_ ) {
139  std::string old_filename = filename_;
141  if ( old_filename != filename_ ) constraints_ = NULL;
142  }
143 }
144 
145 
146 
148  using namespace basic::options;
149  bool fullatom( pose.is_fullatom() );
150  if ( fullatom && !bFullatom_ ) return;
151  if ( !fullatom && !bCentroid_ ) return;
152  tr.Debug << "add constraints "<< tag_ << std::endl;
153  if ( constraints_ ) {
154  tr.Debug << " constraint set is currently for a " <<( constraint_ref_pose_.is_fullatom() ? "fullatom" : "centroid") << " pose "
155  << "\n will now remap them to a " << (fullatom ? "fullatom" : "centroid") << " pose" << std::endl;
156  }
157  std::string const new_sequence ( pose.annotated_sequence( true ) );
158  if ( bCmdFlag_ && option[ OptionKeys::constraints::combine_exclude_region ].user() && combine_exclude_res_.size() == 0 && sequence_ != new_sequence ) {
159  std::string const file( option[ OptionKeys::constraints::combine_exclude_region ]() );
160  std::ifstream is( file.c_str() );
161 
162  if (!is.good()) {
163  utility_exit_with_message( "[ERROR] Error opening RBSeg file '" + file + "'" );
164  }
165 
168  loops::SerializedLoopList loops = reader.read_pose_numbered_loops_file(is, file, false );
169  loops::Loops rigid_core = loops::Loops( loops );
170 
171  combine_exclude_res_.resize( pose.total_residue(), false );
173  }
174  if ( !constraints_ || sequence_ != new_sequence ) {
175  tr.Info << " read constraints from " << filename_ << "\n for pose " << new_sequence << "..." << std::endl;
177  sequence_ = new_sequence;
178  } else {
179  ConstraintSetOP new_cst(NULL);
180  try {
181  new_cst = constraints_->remapped_clone( constraint_ref_pose_, pose );
182  } catch( core::id::EXCN_AtomNotFound& excn ) {
183  tr.Error << "[ERROR] failed attempt to add constraints to the "
184  << (fullatom ? "fullatom" : "centroid") << " pose" << std::endl;
185  tr.Error << excn << std::endl;
186  if ( tr.Debug.visible() ) {
187  pose.dump_pdb("new_pose_failed_constraints.pdb");
188  constraint_ref_pose_.dump_pdb("cst_ref_pose.pdb");
189  }
190  constraints_->show_definition( tr.Error, constraint_ref_pose_ );
191  tr.Error << std::endl;
192  tr.Error << " try to recover by reading in original constraints from " << filename_ << "\n for pose " << new_sequence << "..." << std::endl;
194  }
195 
196  constraints_ = new_cst;
197  }
198  constraint_ref_pose_ = pose;
199 
200  scoring::constraints::ConstraintCOPs added_constraints = constraints_->get_all_constraints();
203 
206  scoring::constraints::combine_constraints( added_constraints, combine_ratio_, combine_exclude_res_, sp ); // if combine_ratio_ > 1 this will randomly combine constraints into multipletts with OR logic
207  pose.add_constraints( added_constraints );
208  if ( tr.Trace.visible() ) {
209  pose.constraint_set()->show_definition( tr.Trace, pose );
210  }
211 
212 }
213 
214 bool ConstraintClaimer::read_tag( std::string tag, std::istream& is ) {
215  if ( tag == "file" || tag == "FILE" || tag == "CST_FILE" ) {
216  is >> filename_;
217  } else if ( tag == "NO_CENTROID" ) {
218  bCentroid_ = false;
219  } else if ( tag == "CENTROID" ) {
220  bCentroid_ = true;
221  } else if ( tag == "FULLATOM" ) {
222  bFullatom_ = true;
223  } else if ( tag == "SKIP_REDUNDANT" ) {
224  skip_redundant_ = true;
225  is >> skip_redundant_width_;
226  if ( !is.good() ) skip_redundant_width_ = 1;
227  } else if ( tag == "CMD_FLAG" ) {
228  bCmdFlag_ = true;
229  } else if ( tag == "COMBINE_RATIO" ) {
230  is >> combine_ratio_;
231  } else if ( tag == "DROP_RANDOM_RATE" ) {
232  is >> drop_random_rate_;
233  } else if ( tag == "FILTER_WEIGHT" ) {
234  is >> filter_weight_;
235  } else if ( tag == "FILTER_NAME" ) {
236  is >> filter_name_;
237  } else return Parent::read_tag( tag, is );
238  return true;
239 }
240 
242  filename_ = file;
243  constraints_ = NULL;
244  fa_constraints_ = NULL;
245 }
246 
247 void ConstraintClaimer::set_fullatom( bool setting ) {
248  bFullatom_ = setting;
249  constraints_ = NULL;
250  fa_constraints_ = NULL;
251 }
252 
253 void ConstraintClaimer::set_centroid( bool setting ) {
254  bCentroid_ = setting;
255  constraints_ = NULL;
256  fa_constraints_ = NULL;
257 }
258 
260  skip_redundant_ = setting > 0;
261  skip_redundant_width_=setting;
262  constraints_ = NULL;
263  fa_constraints_ = NULL;
264 }
265 
267  combine_ratio_ = setting;
268  constraints_ = NULL;
269  fa_constraints_ = NULL;
270 }
271 
273  filter_weight_ = setting;
274 }
275 
276 
277 
278 } //topology_broker
279 } //protocols