Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AmbiguousMultiConstraint.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 
11 /// @file
12 /// @brief contains declarations for a type of constraint that holds a number of constraints
13 /// @brief where only the lowest N are evaluated
14 /// @author Florian Richter (floric@u.washington.edu, march 2008)
15 
16 
19 
20 #include <utility/sort_predicates.hh>
21 
22 //C++ headers
23 #include <list>
24 
25 #include <utility/vector1.hh>
26 
27 
28 
29 namespace protocols {
30 namespace constraints_additional {
31 
32 ////////////////////////////////////////////////////////////////////////////////////////////////////
33 /// @brief Constructor
35  core::Size num_act_csts
36 ):
38  num_active_constraints_(num_act_csts)
39 {
40  active_constraints_.clear();
41 }
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 /// @brief Constructor
45  core::Size num_act_csts,
47  AmbiguousConstraint( cst_in ),
48  num_active_constraints_(num_act_csts)
49 {
50  active_constraints_.clear();
51 }
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 /// @brief ScoreFunction, scores all member constraints but only reports the lowest N ones
54 /// @brief note: this could potentially be made faster if the cur_emap isn't copied, but instead
55 /// @brief pushed back right away into score_cst_pairs and then score_cst_pairs.last() is handed
56 /// @brief to the member_it->score() function
57 void
59  core::scoring::constraints::XYZ_Func const & xyz_func,
60  core::scoring::EnergyMap const & weights,
62 ) const
63 {
64  using namespace core::scoring::constraints;
65  using namespace core::scoring;
66 
67  runtime_assert( member_constraints().size() >= num_active_constraints_ );
68 
69  typedef std::pair< ConstraintCOP, EnergyMap > cst_emap_pair;
70  typedef std::pair< core::Real, cst_emap_pair > score_cst_pair;
71  //std::cout << "scoring ambiguous constraint..." << std::endl;
72 
73  std::list< score_cst_pair > score_cst_pairs;
74 
75  //low_total_cst_score_ = 1000000;
76  //low_EMap_.zero( cst_score_types_ );
77 
78  // first, we score every constraint and save the result in a list
79  for( ConstraintCOPs::const_iterator
80  member_it = member_constraints().begin();
81  member_it != member_constraints().end(); member_it++){
82  EnergyMap cur_emap;
83  (*member_it)->score(xyz_func, weights, cur_emap);
84  core::Real cur_score = calculate_total_cst_score( weights, cur_emap);
85  score_cst_pairs.push_back( score_cst_pair( cur_score, cst_emap_pair( *member_it, cur_emap ) ) );
86  }
87 
88  //then we sort the list by score
89  score_cst_pairs.sort( utility::SortFirst< core::Real, cst_emap_pair >() );
90 
91  active_constraints_.clear();
92  //and go through and add the information of the relevant constraints to the emap,
93  //as well as note the active constraints
94  core::Size counter(1);
95  for( std::list< score_cst_pair >::iterator cst_it = score_cst_pairs.begin() ;
96  counter <= num_active_constraints_; ++cst_it){
97 
98 
99  emap[constant_constraint] += cst_it->second.second[constant_constraint];
100  emap[coordinate_constraint] += cst_it->second.second[coordinate_constraint];
101  emap[atom_pair_constraint] += cst_it->second.second[atom_pair_constraint];
102  emap[angle_constraint] += cst_it->second.second[angle_constraint];
103  emap[dihedral_constraint] += cst_it->second.second[dihedral_constraint];
104  emap[backbone_stub_constraint] += cst_it->second.second[backbone_stub_constraint];
105 
106  active_constraints_.push_back( cst_it->second.first );
107 
108  //don't forget to increment the counter
109  counter++;
110  }
111 
112 } //score
113 
114 
117 {
118  using namespace core::scoring::constraints;
119 
120  ConstraintCOPs new_csts;
121 
122  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); ++cst_it ){
123 
124  ConstraintOP new_cst = (*cst_it)->remap_resid( seqmap );
125 
126  if( new_cst ) new_csts.push_back( new_cst );
127 
128  }
129 
130  if( new_csts.size() > 0 ){
132  }
133  else return NULL;
134 
135 }
136 
137 
138 /// @brief function to minimize the N lowest scoring member constraints
139 void
141  core::id::AtomID const & atom,
143  core::Vector & F1,
144  core::Vector & F2,
145  core::scoring::EnergyMap const & weights
146 ) const
147 {
148  using namespace core::scoring::constraints;
149 
150  runtime_assert( active_constraints_.size() == num_active_constraints_ );
151  for( ConstraintCOPs::const_iterator cst_it = active_constraints_.begin(); cst_it != active_constraints_.end(); ++cst_it ){
152  assert( *cst_it ) ;
153  (*cst_it)->fill_f1_f2(atom, xyz, F1, F2, weights);
154  }
155 }
156 
157 void
158 AmbiguousMultiConstraint::show( std::ostream& out) const
159 {
160  using namespace core::scoring::constraints;
161  out << "AmbiguousMultiConstraint containing the following " << member_constraints().size() << " constraints: " << std::endl;
162  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
163  (*cst_it)->show(out);
164  }
165 
166  out << " ...all member constraints of this AmbiguousMultiConstraint shown." << std::endl;
167 }
168 
170 AmbiguousMultiConstraint::show_violations( std::ostream& out, core::pose::Pose const& pose, core::Size verbose_level, core::Real threshold ) const
171 {
172  using namespace core::scoring::constraints;
173 
174  if ( verbose_level >= 70 ) {
175  Size total_viol( 0 );
176  if ( verbose_level >=80 ) out << type() << " " << member_constraints().size() << " ";
177  for( ConstraintCOPs::const_iterator cst_it = active_constraints_.begin(); cst_it != active_constraints_.end(); cst_it++){
178 
179  //out << "active ";
180  total_viol += (*cst_it)->show_violations( out, pose, verbose_level, threshold );
181  }
182  return total_viol;
183  }
184  return 0;
185 }
186 
187 }
188 }
189