Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintSet.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 // Unit headers
15 
16 // Package headers
18 #include <core/scoring/constraints/DOF_Constraint.hh> //Special constraints.
21 
22 // Project headers
23 #include <core/conformation/Conformation.hh> //for attaching/detaching
24 #include <core/pose/Pose.hh>
25 #include <core/scoring/ScoreFunction.hh> //need to pass in weights
26 #include <basic/Tracer.hh>
27 #include <basic/prof.hh>
28 
29 
30 // C++ Headers
31 #include <set>
32 
35 #include <utility/vector0.hh>
36 #include <utility/vector1.hh>
37 
38 //Auto Headers
41 
42 
43 
44 
45 
46 namespace core {
47 namespace scoring {
48 namespace constraints {
49 
50 /// @details Auto-generated virtual destructor
52 
53 static basic::Tracer tr("core.scoring.ConstraintSet");
54 
56 :
57  revision_id_( 0 ),
58  revision_id_current_( false ),
59  conformation_pt_( NULL )
60 {}
61 
63 :
64  ReferenceCount(),
65  residue_pair_constraints_( other.residue_pair_constraints_.size() ),
66  revision_id_( 0 ),
67  revision_id_current_( false ),
68  conformation_pt_( NULL )
69 {
70  basic::ProfileThis doit( basic::CONSTRAINT_SET_COPY );
71 
72  // Loop over residue 1
73  for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii ) {
74 
75  if ( ! other.residue_pair_constraints_exists( ii ) ) continue;
76 
77  bool first_insert ( true );
78 
79  // Loop over residue 2
81  iter = other.residue_pair_constraints_[ ii ]->begin(),
82  iter_end = other.residue_pair_constraints_[ ii ]->end();
83  iter != iter_end; ++iter ) {
84  if ( first_insert ) {
86  first_insert = false;
87  }
88  residue_pair_constraints_[ ii ]->insert( iter->first, iter->second->clone() );
89  }
90  }
91 
93  iter = other.intra_residue_constraints_.begin(),
94  iter_end = other.intra_residue_constraints_.end();
95  iter != iter_end; ++iter ) {
96  intra_residue_constraints_.insert( iter->first, iter->second->clone() );
97  }
98 
100 
102 
103 }
104 
106  Size start_residue,
107  Size end_residue )
108 :
109  ReferenceCount(),
110  residue_pair_constraints_( other.residue_pair_constraints_.size() ),
111  revision_id_( 0 ),
112  revision_id_current_( false ),
113  conformation_pt_( NULL )
114 {
115  basic::ProfileThis doit( basic::CONSTRAINT_SET_COPY );
116 
117  for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii ) {
118 
119  if ( ! other.residue_pair_constraints_exists( ii ) ) continue;
120 
121  bool first_insert ( true );
123  iter = other.residue_pair_constraints_[ ii ]->begin(),
124  iter_end = other.residue_pair_constraints_[ ii ]->end();
125  iter != iter_end; ++iter ) {
126 
127  if( ((ii < start_residue) || (ii > end_residue)) &&
128  (( iter->first < start_residue) || (iter->first > end_residue )) ) {
129  continue; // do not insert unless eihter end of constraint is in range
130  }
131 
132 
133  if ( first_insert ) {
135  first_insert = false;
136  }
137  // All Constraints are now immutable, and so do not ever need to be cloned.
138  //residue_pair_constraints_[ ii ]->insert( iter->first, iter->second->clone() );
139  residue_pair_constraints_[ ii ]->insert( iter->first, iter->second );
140  }
141  }
142 
144  iter = other.intra_residue_constraints_.begin(),
145  iter_end = other.intra_residue_constraints_.end();
146  iter != iter_end; ++iter ) {
147  // All Constraints are now immutable, and so do not ever need to be cloned.
148  //intra_residue_constraints_.insert( iter->first, iter->second->clone() );
149  if( (( iter->first < start_residue) || (iter->first > end_residue )) ) {
150  continue; // do not insert unless eihter end of constraint is in range
151  }
152  intra_residue_constraints_.insert( iter->first, iter->second );
153  }
154 
156 
158 
159 }
160 
162  return new ConstraintSet( *this );
163 }
164 
165 /// @brief Copies the data from this ConstraintSet into a new object and returns
166 /// an OP atoms are mapped to atoms with the same name in dest pose ( e.g. for
167 /// switch from centroid to fullatom ) if a sequence_mapping is present it is
168 /// used to map residue numbers .. NULL = identity mapping to the new object.
169 /// This will really clone all constraints since they have to change their
170 /// atom-numbers and residue-numbers
172  pose::Pose const & src,
173  pose::Pose const & dest,
174  id::SequenceMappingCOP smap /*default NULL*/
175 ) const {
177  ConstraintSetOP new_set = new ConstraintSet;
178  for ( ConstraintCOPs::const_iterator it = all_cst.begin(), eit = all_cst.end(); it!=eit; ++it ) {
179  ConstraintCOP new_cst = (*it)->remapped_clone( src, dest, smap );
180  if ( new_cst ) new_set->add_constraint( new_cst );
181  }
182  return new_set;
183 }
184 
185 /// @brief
186 /// same as remapped clone, but it also steals coordinates from src pose
188  pose::Pose const & src,
189  pose::Pose const & dest,
190  id::SequenceMappingCOP smap /*default NULL*/
191 ) const {
193  ConstraintSetOP new_set = new ConstraintSet;
194  for ( ConstraintCOPs::const_iterator it = all_cst.begin(), eit = all_cst.end(); it!=eit; ++it ) {
195  ConstraintOP new_cst = (*it)->clone();
196  new_cst->steal_def( src );
197  new_cst = new_cst->remapped_clone( src, dest, smap );
198  if ( new_cst ) new_set->add_constraint( new_cst );
199  }
200  return new_set;
201 }
202 
203 
204 void
206  id::SequenceMapping const & smap
207 ) {
208 
209  if( ! this->has_constraints() ) return; //in this case we don't have to worry about anything
210 
212 
213  assert( all_cst.size() != 0 );
214 
215  //nuke the current constraints
216  clear();
217 
218  for ( ConstraintCOPs::const_iterator it = all_cst.begin(), eit = all_cst.end(); it!=eit; ++it ) {
219 
220  ConstraintCOP new_cst = (*it)->remap_resid( smap );
221 
222  if( new_cst ) this->add_constraint( new_cst );
223 
224  else tr.Debug << "when remapping the constraint set, one constraint could not be remapped. :( "<< std::endl;
225 
226  }
227 
228 }
229 
230 void
232  conformation::Residue const & rsd,
233  pose::Pose const &,
234  ScoreFunction const &,
236  ResSingleMinimizationData & res_data_cache
237 ) const
238 {
240  if ( iter != intra_residue_constraints_.end() ) {
241  res_data_cache.set_data( cst_res_data, new CstMinimizationData( iter->second ) );
242  }
243 }
244 
245 
246 void
248  conformation::Residue const & rsd1,
249  conformation::Residue const & rsd2,
250  pose::Pose const &,
251  ScoreFunction const &,
255  ResPairMinimizationData & respair_data_cache
256 ) const
257 {
258  Size resno1 = rsd1.seqpos();
259  Size resno2 = rsd2.seqpos();
260  if ( ! residue_pair_constraints_[ resno1 ] ) return;
261  ResidueConstraints::const_iterator iter = residue_pair_constraints_[ resno1 ]->find( resno2 );
262  if ( iter != residue_pair_constraints_[ resno1 ]->end() ) {
263  respair_data_cache.set_data( cst_respair_data, new CstMinimizationData( iter->second ) );
264  }
265 }
266 
267 void
269  pose::Pose & pose,
270  ScoreFunction const & scfxn
271 ) const {
272  // iterate through all constraints and call setup_for_scoring
273  ConformationXYZ confxyz( pose.conformation() );
274  for ( int i=1; i <= (int) residue_pair_constraints_.size() ; ++i ) {
275  if (!residue_pair_constraints_[i]) continue;
276 
277  ResidueConstraints const & seqpos_constraints( *residue_pair_constraints_[ i ] );
279  it= seqpos_constraints.begin(),
280  ite= seqpos_constraints.end();
281  it != ite; ++it ) {
282  it->second->setup_for_scoring( confxyz, scfxn );
283  }
284  }
285 
287  ++it ) {
288  it->second->setup_for_scoring( confxyz, scfxn );
289  }
290 
292 }
293 
294 void
296  // iterate through all constraints and call setup_for_scoring
297  ConformationXYZ confxyz( pose.conformation() );
298  for ( int i=1; i <= (int) residue_pair_constraints_.size() ; ++i ) {
299  if (!residue_pair_constraints_[i]) continue;
300 
301  ResidueConstraints const & seqpos_constraints( *residue_pair_constraints_[ i ] );
302  for ( ResidueConstraints::const_iterator it= seqpos_constraints.begin(),
303  ite= seqpos_constraints.end(); it != ite; ++it ) {
304  it->second->setup_for_derivatives( confxyz, scfxn );
305  }
306  }
307 
309  ++it ) {
310  it->second->setup_for_derivatives( confxyz, scfxn );
311  }
312 
314 }
315 
316 ///
317 void
319  Residue const & rsd1,
320  Residue const & rsd2,
321  Pose const &, // pose,
322  ScoreFunction const & scorefxn,
323  EnergyMap & emap
324 ) const
325 {
326  Size const pos1( rsd1.seqpos() ), pos2( rsd2.seqpos() );
327  if ( residue_pair_constraints_.size() < pos1 || !residue_pair_constraints_[pos1] ) return;
328  ResidueConstraints const & pos1_constraints( *residue_pair_constraints_[ pos1 ] );
329  ResidueConstraints::const_iterator it( pos1_constraints.find( pos2 ) );
330  if ( it == pos1_constraints.end() ) return;
331  Constraints const & pair_constraints( *(it->second) );
332  pair_constraints.residue_pair_energy( rsd1, rsd2, scorefxn.weights(), emap );
333 }
334 
335 /// This could be made much more efficient by a mapping from AtomID's to constraints
336 void
338  id::AtomID const & atom_id,
339  pose::Pose const & pose,
340  ScoreFunction const & scfxn,
341  EnergyMap const & weights,
342  Vector & F1,
343  Vector & F2
344  ) const
345 {
346 
347  // Derivatives for intraresidue and two-body constraints are evaluated using the MinimizationGraph
348 
349  Size const seqpos( atom_id.rsd() );
350  deprecated_eval_atom_derivative_for_residue_pairs( atom_id, pose, scfxn, weights, F1, F2 );
351 
352  { // intraresidue constraints
354  if ( it != intra_residue_constraints_.end() ) {
355  it->second->eval_ws_atom_derivative( atom_id, pose.conformation(), weights, F1, F2 );
356  }
357  }
358 
359  { // nonpair constraints
360  non_residue_pair_constraints_.eval_ws_atom_derivative( atom_id, pose.conformation(), weights, F1, F2 );
361  }
362 
363 }
364 
365 void
367  id::AtomID const & atom_id,
368  pose::Pose const & pose,
369  ScoreFunction const &,
370  EnergyMap const & weights,
371  Vector & F1,
372  Vector & F2
373  ) const
374 {
375  non_residue_pair_constraints_.eval_ws_atom_derivative( atom_id, pose.conformation(), weights, F1, F2 );
376 }
377 
378 void
380  id::AtomID const & atom_id,
381  pose::Pose const & pose,
382  ScoreFunction const &,
383  EnergyMap const & weights,
384  Vector & F1,
385  Vector & F2
386  ) const
387 {
388  // residue pair constraints:
389  Size const seqpos( atom_id.rsd() );
390  if ( residue_pair_constraints_.size() >= seqpos && residue_pair_constraints_[ seqpos ] ) {
391  ResidueConstraints const & seqpos_constraints( *residue_pair_constraints_[ seqpos ] );
392  for ( ResidueConstraints::const_iterator it= seqpos_constraints.begin(), ite= seqpos_constraints.end(); it != ite;
393  ++it ) {
394  it->second->eval_ws_atom_derivative( atom_id, pose.conformation(), weights, F1, F2 );
395  }
396  }
397 }
398 
399 
400 ///
401 void
403  conformation::Residue const & rsd,
404  pose::Pose const &, // pose,
405  ScoreFunction const & sfxn,
406  EnergyMap & emap
407 ) const
408 {
410  if ( it != intra_residue_constraints_.end() ) {
411  it->second->intra_residue_energy( rsd, sfxn.weights(), emap );
412  }
413 }
414 
415 ///
416 void
418  conformation::Residue const & rsd,
419  EnergyMap & emap
420 ) const
421 {
423  if ( it != intra_residue_constraints_.end() ) {
424  it->second->intra_residue_energy( rsd, emap /*dummy -- not actually used in this function? */, emap );
425  }
426 }
427 
428 
429 
430 /// Does *NOT* zero the emap values, just adds the additional contribution to the
431 /// existing emap energies (so can be called inside finalize_total_energies)
432 void
434  Pose const & pose,
435  ScoreFunction const & sfxn,
436  EnergyMap & emap
437 ) const
438 {
440 
441  // Real dof_score(0.0);
442  // for ( DOF_ConstraintOPs::const_iterator it=dof_constraints_.begin(), ite = dof_constraints_.end(); it != ite; ++it ) {
443  // DOF_ConstraintOP const & dof_constraint( *it );
444  // dof_score = dof_constraint->func( pose.dof( dof_constraint->dof_id() ) );
445  // emap[ dof_constraint->score_type() ] += dof_score;
446  // }
447 
448 }
449 
450 /*Real
451 ConstraintSet::eval_dof_derivative(
452  id::DOF_ID const & id,
453  id::TorsionID const &, // tor,
454  pose::Pose const & pose,
455  ScoreFunction const &, // scorefxn,
456  EnergyMap const & weights
457 ) const
458 {
459  if ( dof_constraints_.empty() ) return 0.0;
460 
461 // DOF_ConstraintOPs::const_iterator it( dof_constraints_.find( id ) ); // will this be too slow??
462 // Real deriv(0.0);
463 // if ( it != dof_constraints_.end() ) {
464 // DOF_ConstraintOP const & dof_constraint( it->second );
465 // deriv = weights[ dof_constraint->score_type() ] * dof_constraint->dfunc( pose.dof( it->first ) );
466 // }
467  Real deriv( 0.0 );
468  for ( DOF_ConstraintOPs::const_iterator it=dof_constraints_.begin(), ite = dof_constraints_.end(); it != ite; ++it ) {
469  DOF_ConstraintOP const & dof_constraint( *it );
470  if ( dof_constraint->dof_id() != id ) continue;
471  deriv += weights[ dof_constraint->score_type() ] * dof_constraint->dfunc( pose.dof( dof_constraint->dof_id() ) );
472  }
473 
474  return deriv;
475 }*/
476 
477 
478 /// helper, static
479 void
481  int const seqpos,
482  ConstraintCOP cst,
483  ResidueConstraints & residue_constraints
484 )
485 {
486  if ( !residue_constraints.has( seqpos ) ) {
487  residue_constraints.insert( seqpos, new Constraints() );
488  //residue_constraints.insert( std::make_pair( seqpos, ConstraintsOP( new Constraints() ) ) );
489  }
490  residue_constraints.find( seqpos )->second->add_constraint( cst );
491 }
492 
493 ///
494 /// private
495 // this function is called twice with interchanged pos1/pos2 parameters ---> all constraints are added symmetrically
496 void
498 {
499  if ( residue_pair_constraints_.size() < pos1 ) residue_pair_constraints_.resize( pos1, 0 );
501 
503 }
504 
505 
506 void
508  for( ConstraintCOPs::iterator it = cst_list.begin();
509  it != cst_list.end();
510  it++) {
511  add_constraint(*it);
512  }
513 }
514 
515 ///
516 void
518 {
520 
521  // figure out if it's inter-res, residue_pair, or 3+body
522  utility::vector1< int > pos_list( cst->residues() );
523 
524  if ( pos_list.size() == 1 ) {
525  // intra-res
526  tr.Trace << "add intra-res constraint " << std::endl;
528  } else if ( pos_list.size() == 2 ) {
529  // rsd-pai
530  tr.Trace << "add res constraint " << std::endl;
531  add_residue_pair_constraint( pos_list[1], pos_list[2], cst );
532  add_residue_pair_constraint( pos_list[2], pos_list[1], cst );
533  } else {
534  // 3+ body
535  tr.Trace << "add 3+body constraint " << std::endl;
537  }
538 }
539 
540 /// helper, static
541 bool
543  int const seqpos,
544  ConstraintCOP cst,
545  ResidueConstraints & residue_constraints,
546  bool object_comparison
547 )
548 {
549  if ( !residue_constraints.has( seqpos ) ) return false;
550 
551  ResidueConstraints::iterator csts_it = residue_constraints.find( seqpos );
552 
553  //if( residue_constraints.find( seqpos )->second->remove_constraint( cst ) ) {
554  if( csts_it->second->remove_constraint( cst, object_comparison ) ) {
555 
556  if( csts_it->second->size() == 0 ) residue_constraints.erase( seqpos );
557 
558  return true;
559  }
560 
561  return false;
562 }
563 
564 ///
565 /// private
566 // this function is called twice with interchanged pos1/pos2 parameters ---> all constraints are removed symmetrically
567 bool
569  Size const pos1,
570  Size const pos2,
571  ConstraintCOP cst,
572  bool object_comparison )
573 {
574  if ( residue_pair_constraints_.size() < pos1 ) return false;
575  if ( !residue_pair_constraints_[ pos1 ] ) return false;
576 
577  bool return_val = remove_constraint_from_residue_constraints( pos2, cst, *(residue_pair_constraints_[ pos1 ] ), object_comparison );
578 
579  //don't forget to resize residue_pair_constraints_ if we removed the last constraint from the back
580  if( ( (*residue_pair_constraints_[ pos1 ]).size() == 0 ) && residue_pair_constraints_.size() == pos1 ) {
581 
582  for( core::Size ii = residue_pair_constraints_.size(); ii >= 1; --ii) {
583 
584  if( residue_pair_constraints_[ ii ] ) {
585  if( (*residue_pair_constraints_[ ii ]).size() != 0) break;
586  }
587  residue_pair_constraints_.pop_back();
588  }
589  }
590 
591  return return_val;
592 }
593 
594 
595 
596 bool
598  ConstraintCOPs cst_list,
599  bool object_comparison )
600 {
601 
602  bool success = false;
603  for( ConstraintCOPs::iterator it = cst_list.begin();
604  it != cst_list.end();
605  it++) {
606  success = remove_constraint(*it, object_comparison);
607  if( success == false ) return false;
608  }
609 
610  return success;
611 } //remove_constraints function
612 
613 
614 ///
615 bool
617  ConstraintCOP cst,
618  bool object_comparison )
619 {
621 
622  // figure out if it's inter-res, residue_pair, or 3+body
623  utility::vector1< int > pos_list( cst->residues() );
624 
625  bool success = false;
626  if ( pos_list.size() == 1 ) {
627  // intra-res
628  tr.Trace << "remove intra-res constraint " << std::endl;
629  success = remove_constraint_from_residue_constraints( pos_list[1], cst, intra_residue_constraints_, object_comparison );
630  } else if ( pos_list.size() == 2 ) {
631  // rsd-pai
632  tr.Trace << "remove res constraint " << std::endl;
633  success = remove_residue_pair_constraint( pos_list[1], pos_list[2], cst, object_comparison )
634  && remove_residue_pair_constraint( pos_list[2], pos_list[1], cst, object_comparison );
635  } else {
636  // 3+ body
637  tr.Trace << "remove 3+body constraint " << std::endl;
638  success = non_residue_pair_constraints_.remove_constraint( cst, object_comparison );
639  }
640  return success;
641 }
642 
643 ///
644 void
646 {
648  dof_constraints_.push_back( new DOF_Constraint( id, func, t ) );
649 }
650 
651 
652 /// @brief Returns all constraints in the set as a flat list, regardless of type.
653 /// @details This will be fairly inefficient if there are many, many constraints.
656 {
657  // OPs implement operator< so they're OK to use in sets and maps.
658  // Set takes care of duplicate insertions (from residue pair constraints).
659  std::map<std::string, ConstraintCOP> all_constr;
660  std::stringstream constraintString;
662  for(Constraints::const_iterator i = j->second->begin(), i_end = j->second->end(); i != i_end; ++i) {
663  constraintString.str("");
664  (*i)->show(constraintString);
665  all_constr.insert(std::make_pair(constraintString.str(),*i));
666  }
667  }
668  for( ResiduePairConstraints::const_iterator k = residue_pair_constraints_.begin(), j_end = residue_pair_constraints_.end(); k != j_end; ++k ) {
669  if( ! *k ) continue; // some entries may be null
670  for(ResidueConstraints::const_iterator j = (**k).begin(), i_end = (**k).end(); j != i_end; ++j) {
671  for(Constraints::const_iterator i = j->second->begin(), i_end = j->second->end(); i != i_end; ++i) {
672  constraintString.str("");
673  (*i)->show(constraintString);
674  all_constr.insert(std::make_pair(constraintString.str(),*i));
675  }
676  }
677  }
679  constraintString.str("");
680  (*i)->show(constraintString);
681  all_constr.insert(std::make_pair(constraintString.str(),*i));
682  }
683  // Copy final set contents into a list to return to user...
685  for(std::map<std::string, ConstraintCOP>::iterator i = all_constr.begin(), i_end = all_constr.end(); i != i_end; ++i) {
686  all.push_back(i->second);
687  }
688  return all;
689 }
690 
693 {
694  if ( residue_pair_constraints_.size() < resid || !residue_pair_constraints_[ resid ] ) return empty_rsdcst_.begin();
695  return residue_pair_constraints_[ resid ]->begin();
696 }
697 
700 {
701  if ( residue_pair_constraints_.size() < resid || !residue_pair_constraints_[ resid ] ) return empty_rsdcst_.end();
702  return residue_pair_constraints_[ resid ]->end();
703 }
704 
705 
706 void
708 
709  if( event.conformation != conformation_pt_ ) {
710  std::cerr << "HUH?!? weird stuff is going on. ConstraintSet is hearing length voices that it shouldn't" << std::endl;
711 
712  return;
713  }
714 
715  //if the signal is invalidate, let's just detach from the conformation
717 
718  this->detach_from_conformation();
719  return;
720  }
721 
722 
723  id::SequenceMapping smap( event );
724 
725  this->remap_residue_positions( smap );
726 }
727 
728 
729 void
732 
733  switch ( event.tag ) {
734 
735  case ConnectionEvent::DISCONNECT:
736  if( event.conformation == conformation_pt_ ) {
737  this->detach_from_conformation();
738  } else {
739  tr.Error << "ERROR: HUH?!? weird stuff is going on. ConstraintSet is hearing disconnection voices that it shouldn't" << std::endl;
740  }
741  break;
742 
743  case ConnectionEvent::TRANSFER:
744  // Disconnect -- ConstraintSet does not honor TRANSFER tag.
745  break;
746 
747  default: // do nothing
748  break;
749 
750  }
751 }
752 
753 void
755 
756  if( conformation_pt_ != 0 ) this->detach_from_conformation();
757 
758  conformation_pt_ = conformation;
759 
762 
763 }
764 
765 void
767 
768  if( conformation_pt_ == 0 ) return;
769 
772 
773  conformation_pt_ = NULL;
774 }
775 
776 
777 Size
779 {
780  if ( ! revision_id_current_ ) {
781  ++revision_id_;
782  revision_id_current_ = true;
783  }
784  return revision_id_;
785 }
786 
787 void
789 {
790  revision_id_current_ = false;
791 }
792 
793 
794 // only prints out pair ResiduePairConstraints at the moment
795 void
797  std::ostream& out
798 ) const {
799  using namespace core::scoring::constraints;
800  out << "ResiduePairConstraints: total: " << residue_pair_constraints_.size() << " plotting active..." << std::endl;
801  for ( Size ii = 1; ii <= residue_pair_constraints_.size(); ++ii ) {
802 
803  if ( ! residue_pair_constraints_exists( ii ) ) continue;
804 
806  iter = residue_pair_constraints_[ ii ]->begin(),
807  iter_end = residue_pair_constraints_[ ii ]->end();
808  iter != iter_end; ++iter ) {
809 
810  // iter->first is the other seqpos, iter->second is the ConstraintCOP
811  if ( residue_pair_constraint_exists( ii, iter->first ) ) {
812  out << "ResiduePairConstraints (" << ii << "," << iter->first << ")" << std::endl;
813  iter->second->show( out );
814  out << std::endl;
815  }
816  // print out the residue pair constraints for residue ii
817  }
818  } // for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii )
819 
820 }
821 
822 void
824  std::ostream& out,
825  pose::Pose const& pose
826 ) const {
827  using namespace core::scoring::constraints;
828 
829  // Intra-Residue
831  it != eit; ++it ) {
832  it->second->show_definition( out, pose );
833  }
834 
835  // Residue-Pairs
836  for ( Size ii = 1; ii <= residue_pair_constraints_.size(); ++ii ) {
837  if ( ! residue_pair_constraints_exists( ii ) ) continue;
838 
840  iter = residue_pair_constraints_[ ii ]->begin(),
841  iter_end = residue_pair_constraints_[ ii ]->end();
842  iter != iter_end; ++iter ) {
843 
844  // iter->first is the other seqpos, iter->second is the ConstraintCOP
845  if ( residue_pair_constraint_exists( ii, iter->first ) ) {
846  if ( ii < iter->first ) {
847  //out << "ResiduePairConstraints (" << ii << "," << iter->first << ")" << std::endl;
848  iter->second->show_definition( out, pose );
849  // out << std::endl;
850  }
851  }
852  // print out the residue pair constraints for residue ii
853  }
854  } // for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii )
855 
856  // 3+ body Constraints
858  eit = non_residue_pair_constraints_.end(); it != eit; ++it ) {
859  (*it)->show_def( out, pose );
860  }
861 }
862 
863 void
865  std::ostream& out
866 ) const {
867  using namespace core::scoring::constraints;
868 
869  core::Size intercount=0;
870  for ( Size ii = 1; ii <= residue_pair_constraints_.size(); ++ii ) {
871  if ( ! residue_pair_constraints_exists( ii ) ) continue;
873  iter = residue_pair_constraints_[ ii ]->begin(),
874  iter_end = residue_pair_constraints_[ ii ]->end();
875  iter != iter_end; ++iter ) {
876 
877  // iter->first is the other seqpos, iter->second is the ConstraintCOP
878  if ( residue_pair_constraint_exists( ii, iter->first ) ) {
879  if ( ii > iter->first ) {
880  intercount++;
881  }
882  }
883  }
884  } // for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii )
885  out << "IntraRes: " << intra_residue_constraints_.size()
886  << " InterRes: " << intercount
887  << " NonRes: " << non_residue_pair_constraints_.size()
888  << std::endl;
889 }
890 
891 
892 // only prints out pair ResiduePairConstraints at the moment
893 Size
895  std::ostream& out,
896  pose::Pose& pose,
897  Size verbose_level,
898  Real threshold
899 ) const {
900  using namespace core::scoring::constraints;
901  Size total_viol=0;
902  setup_for_scoring( pose, ScoreFunction() ); //make sure the constraints are in good shape. (eg. named->numbers)
903  // Intra-Residue
905  if ( verbose_level>0) out << "IntraResidueConstraints: ... ";
906  if ( verbose_level>50 ) out << std::endl;
908  it != eit; ++it ) {
909  if ( verbose_level>50 ) out << "IntraResidueConstraints ( " << it->first << " ) ";
910  Size viol = it->second->show_violations( out, pose, verbose_level, threshold );
911  if ( verbose_level>50 ) out << " " << viol << " violated" << std::endl;
912  total_viol += viol;
913  }
914  }
915 
916  if ( verbose_level>0) out << "ResiduePairConstraints: ... ";
917  if ( verbose_level>50 ) out << std::endl;
918  for ( Size ii = 1; ii <= residue_pair_constraints_.size(); ++ii ) {
919  if ( ! residue_pair_constraints_exists( ii ) ) continue;
921  iter = residue_pair_constraints_[ ii ]->begin(),
922  iter_end = residue_pair_constraints_[ ii ]->end();
923  iter != iter_end; ++iter ) {
924 
925  // iter->first is the other seqpos, iter->second is the ConstraintCOP
926  if ( residue_pair_constraint_exists( ii, iter->first ) ) {
927  Size viol ( 0 );
928  if ( ii > iter->first ) {
929  if ( verbose_level>50 ) out << "ResiduePairConstraints ( " << ii << " , " << iter->first << " ) ";
930  if ( verbose_level>80 ) out << std::endl;
931  viol=iter->second->show_violations( out, pose, verbose_level, threshold );
932  if ( verbose_level>50 ) out << " " << viol << " violated" << std::endl;
933  total_viol+=viol;
934  }
935  }
936  // print out the residue pair constraints for residue ii
937  }
938  } // for ( Size ii = 1; ii <= other.residue_pair_constraints_.size(); ++ii )
939 
940  // 3+ body Constraints
942  if ( verbose_level>0) out << "MultiConstraints: ... ";
943  if ( verbose_level>50 ) out << std::endl;
945  eit = non_residue_pair_constraints_.end(); it != eit; ++it ) {
946  Size viol( 0 );
947  if ( verbose_level>80 ) out << std::endl;
948  viol=(*it)->show_violations( out, pose, verbose_level, threshold );
949  if ( verbose_level>50 ) out << " " << viol << " violated" << std::endl;
950  total_viol+=viol;
951  }
952  }
953  if ( verbose_level>0 ) out << "total violations: "<< total_viol << std::endl;
954  return total_viol;
955 }
956 
957 void
959 {
963  dof_constraints_.clear();
964 
966 
967 }
968 
969 bool
971 {
972  bool empty = true;
974  residue_pair_constraints_.size() ||
976  dof_constraints_.size() ) empty = false;
977 
978  return empty;
979 }
980 
981 
982 std::ostream & operator << (std::ostream & os, ConstraintSet const & set)
983 {
984  set.show(os);
985  return os;
986 }
987 
988 
989 } // constraints
990 } // scoring
991 } // core
992