Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AmbiguousNMRConstraint.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 contains declarations for a type of constraint that holds a number of constraints
12 /// @brief where only the lowest one is evaluated
13 /// @author Florian Richter (floric@u.washington.edu, march 2008)
14 
15 
21 #include <core/pose/Pose.hh>
22 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintIO.hh>
23 #include <utility/excn/Exceptions.hh>
24 #include <basic/prof.hh>
25 
26 //Auto Headers
29 #include <utility/vector1.hh>
30 #include <numeric/xyzVector.hh>
31 
32 
33 namespace core {
34 namespace scoring {
35 namespace constraints {
36 
37 ////////////////////////////////////////////////////////////////////////////////////////////////////
38 /// @brief Constructor
41  func_( func )
42 {
43  // init_cst_score_types();
44  assert ( member_constraints().size() == 0 );
45 }
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
47 /// @brief Constructor
50  func_( func )
51 {
52  // init_cst_score_types();
53  assert ( member_constraints().size() > 0 );
54 }
55 ////////////////////////////////////////////////////////////////////////////////////////////////////
56 // void
57 // AmbiguousNMRConstraint::init_cst_score_types()
58 // {
59 // cst_score_types_.clear();
60 // cst_score_types_.push_back(atom_pair_constraint);
61 // }
62 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 /// @brief ScoreFunction, scores all member constraints but only reports the lowest one
64 void
65 AmbiguousNMRConstraint::score( XYZ_Func const & xyz_func, EnergyMap const & /*weights*/, EnergyMap & emap ) const
66 {
67 
68  core::Real cum_invdist6 = 0;
69 
70  for( ConstraintCOPs::const_iterator member_it = member_constraints().begin(); member_it != member_constraints().end(); member_it++){
72  cst_in_casted = dynamic_cast< AmbiguousNMRDistanceConstraint const * >( (*member_it).get() );
73  if ( cst_in_casted ) cum_invdist6 += cst_in_casted->inv_dist6( xyz_func );
74  if ( !cst_in_casted ) {
75  AtomPairConstraintCOP cst_in_casted;
76  cst_in_casted = dynamic_cast< AtomPairConstraint const * >( (*member_it).get() );
77  if ( cst_in_casted ) {
78  Real dist = cst_in_casted->dist( xyz_func );
79  Real inv_dist = 1.0/dist;
80  Real inv_dist2 = inv_dist*inv_dist;
81  cum_invdist6 += inv_dist2*inv_dist2*inv_dist2;
82  } else {
83  runtime_assert( 0 == 1 );
84  }
85  }
86  }
87  //add lowest score to the actual emap
88  Real eff_dist = pow( cum_invdist6, -1.0/6 );
89  emap[ score_type() ] += get_func().func( eff_dist );
90 } //score
91 
92 
95 {
96  return dist( ConformationXYZ( pose.conformation() ) );
97 }
98 
101 {
102  core::Real cum_invdist6 = 0;
103 
104  for( ConstraintCOPs::const_iterator member_it = member_constraints().begin(); member_it != member_constraints().end(); member_it++){
105  AmbiguousNMRDistanceConstraintCOP cst_in_casted;
106  PROF_START( basic::NOESY_ASSIGN_DIST_CST_CAST );
107  cst_in_casted = dynamic_cast< AmbiguousNMRDistanceConstraint const* >( (*member_it).get() );
108  PROF_STOP( basic::NOESY_ASSIGN_DIST_CST_CAST );
109  if ( cst_in_casted ) cum_invdist6 += cst_in_casted->inv_dist6( xyz );
110  if ( !cst_in_casted ) {
111  AtomPairConstraintCOP cst_in_casted;
112  PROF_START( basic::NOESY_ASSIGN_DIST_CST_CAST );
113  cst_in_casted = dynamic_cast< AtomPairConstraint const* >( (*member_it).get() );
114  PROF_STOP( basic::NOESY_ASSIGN_DIST_CST_CAST );
115  if ( cst_in_casted ) {
116  Real dist = cst_in_casted->dist( xyz );
117  Real inv_dist = 1.0/dist;
118  Real inv_dist2 = inv_dist*inv_dist;
119  cum_invdist6 += inv_dist2*inv_dist2*inv_dist2;
120  } else {
121  runtime_assert( 0 == 1 );
122  }
123  }
124  }
125  //add lowest score to the actual emap
126  Real eff_dist = pow( cum_invdist6, -1.0/6 );
127  return eff_dist;
128 }
129 
132 {
133  ConstraintCOPs new_csts;
134  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); ++cst_it ){
135  ConstraintOP new_cst = (*cst_it)->remap_resid( seqmap );
136  if( new_cst ) new_csts.push_back( new_cst );
137  }
138  if( new_csts.size() > 0 ){
139  return ConstraintOP( new AmbiguousNMRConstraint( new_csts, get_func().clone() ) );
140  }
141  else return NULL;
142 }
143 
144 
145 /// @brief function to minimize lowest scoring member constraint
146 void
148  AtomID const & atom,
149  XYZ_Func const & xyz,
150  Vector & F1,
151  Vector & F2,
152  EnergyMap const & weights
153 ) const
154 {
155  //active_constraint_->fill_f1_f2(atom, conformation, F1, F2, weights);
156  Real eff_dist = dist( xyz );
157  Real out_wderiv( weights[ score_type() ] * get_func().dfunc( eff_dist ));
158  Real in_deriv = -1.0/6.0 * pow( eff_dist, 7.0 );
159  // tr.Trace << "deriv for atom " << atom << eff_dist << " " << out_wderiv << " " << in_deriv << std::endl;
160 
161  // tr.Trace << "the_other_atoms: " << the_other_atoms.size() << " " << the_other_atoms.front() << std::endl;
162  //Vector f1(0.0), f2(0.0);
163  for( ConstraintCOPs::const_iterator member_it = member_constraints().begin(); member_it != member_constraints().end(); member_it++){
164  Vector f1(0.0), f2(0.0);
165 
166  //fpd hack to get at vector from atom i->j
167  (*member_it)->fill_f1_f2( atom, xyz, f1, f2, weights );
168  core::Real member_cst_is_scaled_by = weights[ (*member_it)->score_type() ] * (*member_it)->get_func().dfunc( eff_dist
169 );
170 
171  core::Real scale_i = -6.0*pow((*member_it)->dist( xyz ),-7.0);
172 
173  if (std::fabs(member_cst_is_scaled_by) > 1e-14) scale_i /= member_cst_is_scaled_by;
174 
175  F1 += 1.0 * scale_i * out_wderiv * in_deriv * f1;
176  F2 += 1.0 * scale_i * out_wderiv * in_deriv * f2;
177  }
178  // tr.Trace << "wderiv " << wderiv << std::endl;
179 
180 
181  // tr.Trace << "wderiv " << wderiv << std::endl;
182 // F1 += out_wderiv * in_deriv * f1;
183 // F2 += out_wderiv * in_deriv * f2;
184 }
185 
186 
187 // void
188 // AmbiguousNMRConstraint::show( std::ostream& out) const
189 // {
190 // out << "AmbiguousNMRConstraint Active constraint:" << std::endl;
191 // out << "AmbiguousNMRConstraint containing the following " << member_constraints().size() << " constraints: " << std::endl;
192 // for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
193 // (*cst_it)->show(out);
194 // }
195 
196 // out << " ...all member constraints of this AmbiguousNMRConstraint shown." << std::endl;
197 // }
198 
199 ////////////////////////////////////////////////////////////////////////////////////////////////////
200 ///@details read definition of a multiconstraint. Since a MultiConstraint is essentially a vector of
201 void
203  std::istream& data,
204  core::pose::Pose const& pose,
205  FuncFactory const & func_factory
206 )
207 {
208  std::string func_type;
209  data >> func_type;
210 
211  func_ = func_factory.new_func( func_type );
212  func_->read_data( data );
213 
214  if ( data.good() ) {
215  //chu skip the rest of line since this is a single line defintion.
216  while( data.good() && (data.get() != '\n') ) {}
217  if ( !data.good() ) data.setstate( std::ios_base::eofbit );
218  }
219  MultiConstraint::read_def( data, pose, func_factory );
220 }
221 
222 void AmbiguousNMRConstraint::show_def( std::ostream& out, pose::Pose const& pose ) const {
223  out << type() << " ";
224  if ( func_ ) func_->show_definition( out );
225  else out << std::endl;
226  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
227  (*cst_it)->show_def( out, pose );
228  // out<<std::endl;
229  }
230  out << "End_"<< type() << std::endl;
231 }
232 
233 Size
234 AmbiguousNMRConstraint::show_violations( std::ostream& out, pose::Pose const& pose, Size verbose_level, Real threshold ) const
235 {
236  Size total_viol = 0;
237  bool passed( false );
238  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
239  Size viol = (*cst_it)->show_violations( out, pose, verbose_level, threshold);
240  if ( viol == 0 && verbose_level > 70 ) {
241  utility::vector1< int > pos_list( (*cst_it)->residues() );
242  passed = true;
243  out << "\nResiduePairConstraints (" << pos_list[1] << ", " << pos_list[pos_list.size()] << " ) . of total: 1 0 violated" << std::endl;
244  }
245  total_viol += viol;
246  }
247  if ( !passed && verbose_level > 70 ) {
248  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
249  utility::vector1< int > pos_list( (*cst_it)->residues() );
250  out << "\nResiduePairConstraints (" << pos_list[1] << ", " << pos_list[pos_list.size()] << " ) + of total: 1 1 violated" << std::endl;
251  }
252  }
253  return func_->show_violations( out, dist( pose ), verbose_level, threshold );
254 }
255 
256 void
258 {
259  ConstraintCOP cst_in_casted;
260  cst_in_casted = dynamic_cast< AmbiguousNMRDistanceConstraint const* >( cst_in.get() );
261  if ( !cst_in_casted ) {
262  cst_in_casted = dynamic_cast< AtomPairConstraint const* >( cst_in.get() );
263  }
264  if ( !cst_in_casted ) {
265  throw utility::excn::EXCN_BadInput( "failed attempt to add " + cst_in->type() + " to AmbiguousNMRConstraint. Can only add AmbiguousNMRDistanceConstraint and AtomPairConstraint");
266  }
267 
269 }
270 
271 
272 } //constraints
273 } //scoring
274 } //core