Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MinMultiHarmonicFunc.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 src/core/scoring/constraints/HarmonicFunc.hh
11 /// @brief Definition for functions used in definition of constraints.
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
14 
16 #include <core/types.hh>
17 #include <utility/pointer/ReferenceCount.hh>
18 #include <basic/Tracer.hh>
19 
20 
21 // C++ Headers
22 
23 namespace core {
24 namespace scoring {
25 namespace constraints {
26 
27 static basic::Tracer trMinMultiHarmonicFunc(
28  "fragment.picking.scores.MinMultiHarmonicFunc");
29 
31  n_ = x0_in.size(); //number of harmonics to consider
32  assert(x0_in.size() == sd_in.size()); //each x0 gets its own sd
33  x0_.clear();
34  sd_.clear();
35  for(Size i=1;i<=n_;++i) {
36  x0_.push_back( x0_in[i] );
37  sd_.push_back( sd_in[i] );
38  }
39 }
40 
41 
42 Real
43 MinMultiHarmonicFunc::func( Real const x ) const {
44 
45  //find the value that minimizes (x-x0)^2 / sd^2 among all the possible harmonic funcs
46  Real min = ( x-x0_[1] );
47  min *= min/ (sd_[1] * sd_[1]); //start at one
48  which_component_ = 1;
49  for(Size i=2;i<=x0_.size();++i) { //assumes at least 2 harmonic funcs are being considered
50  Real z = ( x-x0_[i] );
51  z = z*z / (sd_[i] * sd_[i]);
52  if( z < min ) {
53  which_component_ = i;
54  min = z;
55  }
56  }
57 
58  return min; // returns min value of (x-x0)^2 / sd^2
59 }
60 
61 Real
63 
64  Real min = ( x-x0_[1] );
65  Real deriv = min / (sd_[1] * sd_[1]);
66  min = min*deriv; // min will be the minimum of (x-x0)^2 / sd^2
67  which_component_ = 1;
68  for(Size i=2;i<=x0_.size();++i) {
69  Real z = ( x-x0_[i] );
70  Real const zderiv = z / (sd_[i] * sd_[i]);
71  z = z*zderiv; // z equals (x-x0)^2 / sd^2
72  if( z < min ) {
73  which_component_ = i;
74  min = z;
75  deriv = zderiv; // deriv = (x-x0) / sd^2 (actually it's 2x this value, as returned below)
76  }
77  }
78 
79  return 2 * deriv; // return 2 * (x-x0_) / ( sd_ * sd_ );
80 }
81 
82 void
83 MinMultiHarmonicFunc::read_data( std::istream& in ) {
84 
85  x0_.clear();
86  sd_.clear();
87  Real r;
88  std::string line;
89  getline( in, line );
90  std::istringstream line_stream( line );
91 
92  utility::vector1<Real> entries;
93  do {
94  line_stream >> r;
95  entries.push_back( r );
96  }
97  while( !line_stream.fail() );
98  n_ = entries.size() /2;
99  if(n_*2 != entries.size() ) {
100  trMinMultiHarmonicFunc.Warning<< "Expected even number of parameters but got"<<entries.size()<<
101  "; the last value seems to be useless or one is missing"<<std::endl;
102  }
103  for(Size i=1;i<=n_;++i) {
104  x0_.push_back( entries[i*2-1] );
105  sd_.push_back( entries[i*2] );
106  }
107 }
108 
109 void
110 MinMultiHarmonicFunc::show_definition( std::ostream &out ) const {
111 
112  out << "MINMULTIHARMONIC";
113  for(Size i=1;i<=n_;++i)
114  out<< " "<<x0_[i] << " " << sd_[i];
115  out << std::endl;
116 }
117 
118 Size
119 MinMultiHarmonicFunc::show_violations( std::ostream& out, Real x, Size verbose_level, Real threshold) const {
120  if (verbose_level > 100 ) {
121  out << "HARM " << this->func(x) << std::endl;
122  } else if (verbose_level > 70 ) {
123  if ( ( x < x0_[which_component_]) && ( this->func(x) > threshold ) ) out << "-";
124  else if ( ( x > x0_[which_component_]) && ( this->func(x) > threshold )) out << "+";
125  else out << ".";
126  }
127  return Func::show_violations( out, x, verbose_level, threshold);
128 }
129 
130 } // namespace constraints
131 } // namespace scoring
132 } // namespace core
133