Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pool_ConvergenceCheck.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 /// @author
13 
14 // type headers
15 #include <core/types.hh>
16 
17 //
18 // unit headers
20 // AUTO-REMOVED #include <protocols/moves/MonteCarlo.hh>
21 #include <utility/excn/Exceptions.hh>
22 
23 // package headers
28 #include <protocols/jd2/Job.hh>
29 #include <protocols/jd2/util.hh>
30 
31 #include <core/pose/Pose.fwd.hh>
33 
34 // utility headers
35 #include <utility/pointer/ReferenceCount.hh>
36 // #include "utility/basic_sys_util.h"
37 #include <basic/Tracer.hh>
38 #include <utility/exit.hh>
39 // C++ headers
40 #include <map>
41 #include <string>
42 
43 //Auto Headers
44 #include <utility/vector1.hh>
45 #include <numeric/xyzMatrix.hh>
46 #include <basic/prof.hh>
47 
48 static basic::Tracer tr("protocols.canonical_sampling.mc_convergence_check.Pool",basic::t_info);
49 
50 // Forward declarations
51 
52 namespace protocols {
53 namespace canonical_sampling {
54 namespace mc_convergence_checks {
55 
56 // @brief Auto-generated virtual destructor
58 
59 // @brief Auto-generated virtual destructor
61 
62 // @brief Auto-generated virtual destructor
64 
65 using namespace ObjexxFCL;
66 using namespace core;
67 using namespace basic;
68 
69 void Pool_RMSD::get( core::Size index , FArray2D<double>& result){
70  tr.Debug << "getting " << index << " coords of " << pool_.n_decoys() << std::endl;
71  FArray2P_double temp = pool_.coords( index );
72  result.dimension(temp.u1(),temp.u2(),0.0);
73  for(int i = 1; i <= result.u1(); i++){
74  for(int j = 1; j <= result.u2(); j++){
75  result( i, j ) = temp( i, j );
76  }
77  }
78 }
79 
81  tr.Debug << "getting tag " << index << " of " << tags_.size() << " which has value " << tags_[index] << std::endl;
82  return tags_[ index ];
83 }
84 
86  tags_.pop_back( );
87  tr.Debug << "checking size before popping back " << pool_.n_decoys() << std::endl;
88  pool_.pop_back_CA_xyz();
89  pool_.center_structure( pool_.n_decoys(), weights_ );
90  tr.Debug << "finished popping back. size is now " << pool_.n_decoys() << std::endl;
91  tr.Debug << "just checking that size of arrays match up " << tags_.size() << " " << pool_.n_decoys() << std::endl;
92 
93  runtime_assert( tags_.size() == pool_.n_decoys() );
94 
95 }
96 
98  tags_.clear();
99  pool_.clear();
100 }
101 
102 
104  excluded_residues_ = excluded_residues;
105 }
106 
107 void Pool_RMSD::fill_pool( std::string const& silent_file ) {
108  //tags_.clear();
109  //pool_.clear();
110  clear();
111 
113  try {
114  sfd.read_file( silent_file );
115  } catch( utility::excn::EXCN_BadInput const& excn ) {
116  excn.show( tr.Warning );
117  tr.Warning << "Pool_RMSD did not find any structures, will output n/a 10000 for converged_tag and converged_rmsd" << std::endl;
118  return;
119  }
120  pool_.push_back_CA_xyz_from_silent_file( sfd, false /*don't save energies*/ );
121  tags_.reserve( sfd.size() );
122  for ( io::silent::SilentFileData::iterator it=sfd.begin(), eit=sfd.end(); it!=eit; ++it ) {
123  tags_.push_back( it->decoy_tag() );
124  }
125  weights_.dimension( pool_.n_atoms(), 1.0 );
126  if ( pool_.n_decoys() ) pool_.center_all( weights_ ); //this centers all structures
127  reserve_size_ = 100;
128 }
129 
130 
132  if ( new_tag == "keep_silent_tag" ) {
133  new_tag = pss.decoy_tag();
134  }
135  add( pss.get_CA_xyz(), pss.nres(), new_tag );
136 }
137 
138 void Pool_RMSD::add( core::pose::Pose const& pose, std::string new_tag ) {
139  FArray2D_double coords( 3, pool_.n_atoms(), 0.0 );
140  runtime_assert( pool_.n_atoms() == pose.total_residue() );
141  toolbox::fill_CA_coords( pose, pool_.n_atoms(), coords );
142  add( coords, pose.total_residue(), new_tag );
143 }
144 
146 
147  if( weights_.size() == 0 ){
148  weights_.dimension( nres, 1.0 );
149  reserve_size_ = 100;
150  }
151 
152  PROF_START( basic::POOL_RMSD_ADD_STRUCTURE );
153  //runtime_assert( pool_.n_atoms() == nres );
154  if ( pool_.n_decoys_max() >= pool_.n_decoys() ) {
155  //pool_.reserve( pool_.n_decoys() + 100 );
156  pool_.reserve( pool_.n_decoys() + reserve_size_ ); //ek
157  // pool_.reserve( pool_.n_decoys() + reserve_size_ ); //ek
158  // tr.Debug << "pool can now hold a max of " << pool_.n_decoys() + reserve_size_;
159  }
160  tags_.push_back( new_tag );
161  pool_.push_back_CA_xyz( xyz, nres );
162  pool_.center_structure( pool_.n_decoys(), weights_ );
163 
164  runtime_assert( tags_.size() == pool_.n_decoys() );
165  PROF_STOP( basic::POOL_RMSD_ADD_STRUCTURE );
166 }
167 
168 
169 void Pool_RMSD::set_reserve_size( int max_size ){ //ek
170  reserve_size_ = max_size;
171 }
172 
173 
174 core::Size Pool_RMSD::evaluate_and_add(pose::Pose const& pose, std::string& cluster_center, core::Real& rms_to_cluster, core::Real transition_threshold) {
175  tr.Debug << "using Pool_RMSD::evaluate_and_add " << std::endl;
177  coords.redimension( 3, pose.total_residue() );
178  toolbox::fill_CA_coords( pose, pool_.n_atoms(), coords );
179  return evaluate_and_add( coords, cluster_center, rms_to_cluster, transition_threshold );
180 }
181 
182 core::Size Pool_RMSD::evaluate_and_add( ObjexxFCL::FArray2D_double& coords, std::string& best_decoy, core::Real& best_rmsd, core::Real transition_threshold ){
183  core::Size best_index = evaluate( coords, best_decoy, best_rmsd );
184  if( best_rmsd > transition_threshold ){
185  tr.Debug << "adding structure to pool " << std::endl;
186  using namespace ObjexxFCL;
187  //form tags of type: c.<cluster_number>.<decoy_in_group_nr>
189  std::string new_cluster_tag = "new."+lead_zero_string_of( size(), 8 )+".0"+"_"+jobname;
190  add( coords, coords.u2(), new_cluster_tag);
191  }
192  return best_index;
193 }
194 
196  if ( pool_.n_decoys() == 0 ) {
197  best_decoy = "n/a";
198  best_rmsd = 10000;
199  return 0;
200  }
201  FArray2D_double coords( pss.get_CA_xyz() );
202  runtime_assert( pss.nres() == pool_.n_atoms() );
203  return evaluate( coords, best_decoy, best_rmsd );
204 }
205 
206 core::Size Pool_RMSD::evaluate( core::pose::Pose const& fit_pose, std::string& best_decoy, core::Real& best_rmsd ) const {
207  if ( pool_.n_decoys() == 0 ) {
208  best_decoy = "n/a";
209  best_rmsd = 10000;
210  return 0;
211  }
212  FArray2D_double coords( 3, pool_.n_atoms(), 0.0 );
213  runtime_assert( pool_.n_atoms() <= fit_pose.total_residue() );
214  toolbox::fill_CA_coords( fit_pose, pool_.n_atoms(), coords );
215  return evaluate( coords, best_decoy, best_rmsd );
216 }
217 
218 core::Size Pool_RMSD::evaluate( FArray2D_double& coords, std::string& best_decoy, core::Real& best_rmsd ) const {
219  return evaluate( coords, best_decoy, best_rmsd, 1);
220  //return 0; //ek commented out, i need the index of the best-decoy!!
221 }
222 
223 //index indicates what index you start evaluation from
224 core::Size Pool_RMSD::evaluate( FArray2D_double& coords, std::string& best_decoy, core::Real& best_rmsd , core::Size index ) const {
225  PROF_START( basic::POOL_RMSD_EVALUATE );
226  if ( pool_.n_decoys() == 0 ) {
227  best_decoy = "n/a";
228  best_rmsd = 10000;
229  return 0;
230  }
231  tr.Debug << "evaluating: start from index " << index << " of " << pool_.n_decoys() << std::endl;
232 
233  FArray1D_double weights( pool_.n_atoms(), 1.0 );
234  for ( utility::vector1< core::Size >::const_iterator it = excluded_residues_.begin(); it!=excluded_residues_.end(); ++it ) {
235  weights( *it ) = 0.0;
236  }
237 
238  FArray1D_double transvec( 3 );
239  toolbox::reset_x( pool_.n_atoms(), coords, weights, transvec );//center coordinates
240  //n_atoms is simply # CA atoms in each "pose"
241  Real invn( 1.0 / pool_.n_atoms() );
242  best_rmsd = 1000000;
243  Size best_index( 0 );
244  for ( Size i = index; i <= pool_.n_decoys(); i++ ) {
246  ObjexxFCL::FArray2P_double xx2( pool_.coords( i ) );
247  toolbox::fit_centered_coords( pool_.n_atoms(), weights, xx2, coords, R );
248  Real rmsd( 0 );
249  for ( Size n = 1; n <= pool_.n_atoms(); n++) {
250  for ( Size d = 1; d<=3; ++d ) {
251  rmsd += ( coords( d, n ) - xx2( d, n ) ) * ( coords( d, n ) - xx2( d, n ) ) * invn;
252  }
253  }
254  rmsd = sqrt( rmsd );
255  if ( rmsd <= best_rmsd ) {
256  best_index = i;
257  best_rmsd = rmsd;
258  }
259  }
260 
261 
262  best_decoy = tags_[ best_index ];
263  PROF_STOP( basic::POOL_RMSD_EVALUATE );
264  return best_index;
265 }
266 
268  if ( reject ) return true; //dont bother for these
269 
270  core::Real best_rmsd;
271  std::string best_decoy;
272 
273  rmsd_pool_->evaluate( fit_pose, best_decoy, best_rmsd );
274 
275  //store in Job-Object:
276  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_string_pair( "pool_converged_tag", best_decoy );
277  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair( "pool_converged_rmsd", best_rmsd );
278  if ( best_rmsd <= threshold_ ) throw EXCN_Pool_Converged();
279  return best_rmsd >= threshold_;
280 }
281 
282 ///@brief evaluate pose and store values in Silent_Struct
284  core::Real best_rmsd;
285  std::string best_decoy;
286 
287  rmsd_pool_->evaluate( fit_pose, best_decoy, best_rmsd );
288 
289  pss.add_string_value( name( 1 ), best_decoy );
290  pss.add_energy( name( 2 ), best_rmsd );
291 // //store in Job-Object:
292 // protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_string_pair( "pool_converged_tag", best_decoy );
293 // protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair( "pool_converged_rmsd", best_rmsd );
294 
295 }
296 
297 ///@brief evaluate pose and store values in Silent_Struct
299  core::Real best_rmsd;
300  std::string best_decoy;
301 
302  rmsd_pool_->evaluate( pss, best_decoy, best_rmsd );
303 
304  pss.add_string_value( name( 1 ), best_decoy );
305  pss.add_energy( name( 2 ), best_rmsd );
306 // //store in Job-Object:
307 // protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_string_pair( "pool_converged_tag", best_decoy );
308 // protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair( "pool_converged_rmsd", best_rmsd );
309 
310 }
311 
312 } // mc_convergence_check
313 } // moves
314 } // rosetta