Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintEvaluator.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 PoseEvaluator
11 /// @brief PoseEvaluator
12 /// @detailed
13 ///
14 ///
15 /// @author Oliver Lange
16 
17 
18 
19 // Unit Headers
21 
22 // Package Headers
24 
26 
27 // Project Headers
29 #include <core/pose/Pose.hh>
34 // AUTO-REMOVED #include <core/scoring/constraints/NamedAtomPairConstraint.hh>
35 #include <core/id/Exceptions.hh>
37 
40 
41 
42 // AUTO-REMOVED #include <core/chemical/VariantType.hh>
45 // ObjexxFCL Headers
46 // AUTO-REMOVED #include <ObjexxFCL/string.functions.hh>
47 
48 // Utility headers
49 #include <basic/Tracer.hh>
50 #include <basic/prof.hh>
51 // AUTO-REMOVED #include <core/scoring/rms_util.hh>
52 #include <utility/file/file_sys_util.hh>
53 
55 #include <utility/vector1.hh>
56 
57 
58 // C++ headers
59 
60 static basic::Tracer tr("protocols.constraints_additional.ConstraintEvaluator");
61 
62 namespace protocols {
63 namespace constraints_additional {
64 
65 using namespace core;
66 using namespace scoring;
67 using namespace constraints;
68 
69 ConstraintEvaluator::ConstraintEvaluator( std::string tag, ConstraintSet const& cst, Size viol_level, Real threshold, Size max_seq_sep )
70  : name_( tag ),
71  constraints_( new ConstraintSet( cst ) ),
72  tried_fullatom_pose_( false ),
73  tried_centroid_pose_( false ),
74  file_name_( "" ),
75  viol_level_ ( viol_level ),
76  threshold_( threshold ),
77  max_seq_sep_( max_seq_sep ),
78  constraints_combine_ratio_( 1 ),
79  cst_source_( "n/a" )
80 {}
81 
82 ConstraintEvaluator::ConstraintEvaluator( std::string tag, ConstraintCOPs const& csts, Size viol_level, Real threshold, Size max_seq_sep )
83  : name_( tag ),
84  constraints_( new ConstraintSet() ),
85  tried_fullatom_pose_( false ),
86  tried_centroid_pose_( false ),
87  file_name_( "" ),
88  viol_level_ ( viol_level ),
89  threshold_( threshold ),
90  max_seq_sep_( max_seq_sep ),
91  constraints_combine_ratio_( 1 ),
92  cst_source_( "n/a" )
93 {
94  constraints_->add_constraints( csts );
95 }
96 
97 ConstraintEvaluator::ConstraintEvaluator( std::string tag, std::string file_name, Size viol_level, Real threshold, Size max_seq_sep )
98  : name_( tag ),
99  constraints_( NULL ),
100  tried_fullatom_pose_( false ),
101  tried_centroid_pose_( false ),
102  file_name_( file_name ),
103  viol_level_ ( viol_level ),
104  threshold_( threshold ),
105  max_seq_sep_( max_seq_sep ),
106  constraints_combine_ratio_( 1 ),
107  cst_source_( "n/a" )
108 {
109  //check file exists
111  utility_exit_with_message(" could not find file " + file_name_ );
112  }
113 }
114 
115 
117 
119 
121  if ( !now_cst ) {
122 
123  if ( pose.is_fullatom() && tried_fullatom_pose_ ) {
124  pose.constraint_set( NULL );
125  return;
126  }
127  if ( !pose.is_fullatom() && tried_centroid_pose_ ) {
128  pose.constraint_set( NULL );
129  return;
130  }
131 
132  runtime_assert( utility::file::file_exists( file_name_) ); //it has already been checked... here it is an assertion
133 
134  using namespace core::scoring::constraints;
135  // ConstraintCreatorCOP new_atom_pair_creator( new constraints_additional::NamedAtomPairConstraintCreator );
136  // ConstraintCreatorCOP orig_atom_pair_creator( ConstraintFactory::get_instance()->get_creator( "AtomPair" ) ); // <-- this may actually be a NamedAtomPairConstraintCreator, we don't know; restore it, when done.
137  // ConstraintFactory::get_instance()->replace_creator( new_atom_pair_creator );
138  try{
140  scoring::constraints::ConstraintCOPs added_constraints = now_cst->get_all_constraints();
143  utility::vector1< bool > combine_exclude_res;
144  scoring::constraints::combine_constraints( added_constraints, constraints_combine_ratio_, combine_exclude_res, sp ); // if combine_ratio_ > 1 this wil
145  now_cst = new ConstraintSet();
146  now_cst->add_constraints( added_constraints );
147  } catch ( core::id::EXCN_AtomNotFound& excn ) {
148  tr.Warning << " cannot use constraint file " << file_name_ << " on " << ( pose.is_fullatom() ? " fullatom " : " centroid " ) << " pose " << std::endl;
149  tr.Warning << " because: " << excn << std::endl;
150  now_cst = NULL;
151  pose.constraint_set( NULL );
152  if ( pose.is_fullatom() ) tried_fullatom_pose_ = true;
153  else tried_centroid_pose_ = true;
154  return;
155  }
156 
157  //restore original cst-type
158  //ConstraintIO::get_cst_factory().add_type( orig_atom_pair_type );
159  //ConstraintFactory::get_instance()->replace_creator( orig_atom_pair_creator );
160 
161  }
162 
163  runtime_assert( now_cst );
164 
166  if ( max_seq_sep_ > 0 ) {
167  new_cst = new constraints_additional::MaxSeqSepConstraintSet( *now_cst, pose.fold_tree() );
168  new_cst->set_max_seq_sep( max_seq_sep_ );
169  } else {
170  //if not specified we copy the max_seq_separation if present
172  if ( ms_set ) {
173  new_cst = new constraints_additional::MaxSeqSepConstraintSet( *now_cst, pose.fold_tree() );
174  new_cst->set_max_seq_sep( ms_set->max_seq_sep() );
175  }
176  }
177 
178  if ( new_cst ) {
179  pose.constraint_set( new_cst );
180  } else {
181  pose.constraint_set( now_cst );
182  }
183 
184  if ( pose.is_fullatom() ) fa_constraints_ = now_cst;
185  else constraints_ = now_cst;
186 
187 }
188 
190  // PROF_START( basic::TEST1 );
191  pose::Pose pose( pose_in );
192  // PROF_STOP( basic::TEST1 );
193 
194  // PROF_START( basic::TEST2 );
195  prepare_pose( pose_in, pose );
196  // PROF_STOP( basic::TEST2 );
197 
198  // PROF_START( basic::TEST3 );
199  ScoreFunction scfxn;
200  scfxn.set_weight( atom_pair_constraint, 1.0 );
201  core::Real score( scfxn( pose ) );
202  // PROF_STOP( basic::TEST3 );
203 
204  return score;
205 }
206 
208  if ( i == 1 ) { return name_; }
209  // if ( i == 2 ) { return name_ + "_viol"; }
210  runtime_assert( i <= 1 && i > 0 );
211  return ""; //make compiler happy
212 }
213 
214 
216  // PROF_START( basic::TEST1 );
217  pose::Pose pose( pose_in );
218  // PROF_STOP( basic::TEST1 );
219 
220  // PROF_START( basic::TEST2 );
221  prepare_pose( pose_in, pose );
222  // PROF_STOP( basic::TEST2 );
223 
224  // PROF_START( basic::TEST3 );
225  ScoreFunction scfxn;
226  scfxn.set_weight( atom_pair_constraint, 1.0 );
227  core::Real score( scfxn( pose ) );
228  // PROF_STOP( basic::TEST3 );
229 
230  pss.add_energy( name( 1 ), score );
231  if ( cst_source_ != "n/a" ) {
232  pss.add_string_value( "cst_source_"+name(1), cst_source_ );
233  }
234  // pss.add_energy( name( 2 ), pose.constraint_set()->show_violations( tr.Info, pose, viol_level_, threshold_ ) );
235  // return scfxn( pose );
236 
237 }
238 
239 }
240 }