Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlatHarmonicFunc.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/FlatHarmonicFunc.hh
11 /// @brief Definition for functions used in definition of constraints.
12 /// @author Chris King modified from James Thompson
13 
14 
16 
17 #include <core/types.hh>
18 #include <math.h>
19 
20 #include <utility/pointer/ReferenceCount.hh>
21 
22 // AUTO-REMOVED #include <numeric/angle.functions.hh>
23 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
24 // AUTO-REMOVED #include <basic/Tracer.hh>
25 
26 #include <sstream>
27 
28 
29 // C++ Headers
30 
31 
32 namespace core {
33 namespace scoring {
34 namespace constraints {
35 
36 Real
37 FlatHarmonicFunc::func( Real const x ) const
38 {
39  if( fabs( x - x0_ ) <= tol_ ) return 0.0;
40  else if( x > x0_ ){
41  Real const z = ( x - x0_ - tol_ ) / sd_;
42  return z * z;
43  }
44  else{
45  Real const z = ( x - x0_ + tol_ ) / sd_;
46  return z * z;
47  }
48 }
49 
50 Real
51 FlatHarmonicFunc::dfunc( Real const x ) const
52 {
53  if( fabs( x - x0_ ) <= tol_ ) return 0.0;
54  else if( x > x0_ ) return 2 * ( x - x0_ - tol_ ) / ( sd_ * sd_ );
55  else return 2 * ( x - x0_ + tol_ ) / ( sd_ * sd_ );
56 }
57 
58 void
59 FlatHarmonicFunc::read_data( std::istream& in ) {
60  in >> x0_ >> sd_ >> tol_;
61 }
62 
63 void
64 FlatHarmonicFunc::show_definition( std::ostream &out ) const {
65  out << "HARMONIC " << x0_ << " " << sd_ << " " << tol_ << std::endl;
66 }
67 
68 Size
69 FlatHarmonicFunc::show_violations( std::ostream& out, Real x, Size verbose_level, Real threshold) const {
70  if (verbose_level > 100 ) {
71  if( fabs( x - x0_ ) <= tol_ ) out << "HARM " << 0.0 << std::endl;
72  else if( x > x0_ ){
73  Real const z = ( x - x0_ - tol_ ) / sd_;
74  out << "HARM " << z << std::endl;
75  }
76  else{
77  Real const z = ( x - x0_ + tol_ ) / sd_;
78  out << "HARM " << z << std::endl;
79  }
80  } else if (verbose_level > 70 ) {
81  if ( x < x0_ + tol_ && ( this->func(x) > threshold ) ) out << "-";
82  else if ( x > x0_ + tol_ && ( this->func(x) > threshold )) out << "+";
83  else out << ".";
84  }
85  return Func::show_violations( out, x, verbose_level, threshold);
86 }
87 
88 } // namespace constraints
89 } // namespace scoring
90 } // namespace core
91