Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BoundConstraint.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 /// @brief Inserts a Fragment into a Pose, similar to old Rosetta++ main_frag_trial algorithm.
11 /// @author Oliver Lange
12 /// @author James Thompson
13 
14 // Unit Headers
16 
17 // Package Headers
18 
19 // Project Headers
20 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintIO.hh>
21 #include <basic/Tracer.hh>
22 #include <utility/exit.hh>
23 
24 // ObjexxFCL Headers
25 #include <ObjexxFCL/format.hh>
26 #include <ObjexxFCL/string.functions.hh>
27 
28 // Utility headers
29 
30 static basic::Tracer tr("core.constraints.BoundFunc",basic::t_info);
31 
32 // C++ headers
33 
34 namespace core {
35 namespace scoring {
36 namespace constraints {
37 
38 
39 
40 Real
41 BoundFunc::func( Real const x ) const
42 {
43 
44 //Real const rswitch_offset (( rswitch_ * rswitch_ ) - rswitch_ );
45 Real delta;
46 if ( x > ub_ ) {
47 delta = x - ub_;
48 } else if ( lb_ <= x ) {
49 delta = 0;
50 } else if ( x < lb_ ) {
51 delta = lb_ - x;
52 }
53 // tr.Trace << "evaluate x in [ lb_ ub_ ]: delta " << x << " " << lb_ << " " << ub_ << " " << delta << std::endl;
54 
55 delta/=sd_;
56 
57 if ( x > ub_ + rswitch_*sd_ ) {
58 return 2 * rswitch_ * delta - rswitch_ * rswitch_;
59 } else {
60 return delta * delta;
61 }
62 }
63 
64 Real
65 BoundFunc::dfunc( Real const x ) const {
66 
67 
68 Real delta;
69 if ( x > ub_ ) {
70 delta = x - ub_;
71 } else if ( lb_ <= x ) {
72 delta = 0;
73 } else if ( x < lb_ ) {
74 delta = lb_ - x;
75 }
76 if ( x > ub_ + rswitch_*sd_ ) {
77 return 2.0*rswitch_/sd_;
78 }
79 return 2.0 * (delta) / ( sd_ * sd_ ) * (( x < lb_ ) ? (-1.0) : 1.0);
80 }
81 
82 
83 Size
84 BoundFunc::show_violations( std::ostream& out, Real x, Size verbose_level, Real threshold) const {
85  if (verbose_level > 100) {
86  out << " " << type_ << " " ;
87  }
88  if ( verbose_level > 75 ) {
89  out << x << " [ " << lb_ << " , " << ub_ << "] ";
90  if ( x < lb_ && ( this->func(x) > threshold ) ) out << "TOO SHORT";
91  else if ( x > ub_ && ( this->func(x) > threshold ) ) out << "VIOLATED";
92  else out << "PASSED";
93  if ( verbose_level > 80 ) {
94  out << " " << type_ << "\n";
95  } else out << "\n";
96  } else if ( verbose_level > 100 ) {
97  out << x << " in[ " << lb_ << " , " << ub_ << " ] ";
98  if ( x < lb_ ) out << (x - lb_) / sd_ << "\n";
99  else if ( x > ub_ ) out << (x - ub_) / sd_ << "\n";
100  else out << "0.0\n";
101  } else if (verbose_level > 70 ) {
102  if ( x < lb_ && ( this->func(x) > threshold ) ) out << "-";
103  else if ( x > ub_ && ( this->func(x) > threshold )) out << "+";
104  else out << ".";
105  }
106 
107 
108  if ( this->func(x) <= threshold ) return 0;
109  return 1;
110 }
111 
112 void
113 BoundFunc::show_definition( std::ostream &out ) const {
114  using namespace ObjexxFCL::fmt;
115  std::streamsize const input_precision(out.precision()); // bug #0000005; SML
116  out << "BOUNDED " << std::setprecision( 4 ) << RJ(7, lb_) << " " << RJ(7, ub_) << " " << RJ(3,sd_) << " ";
117  if ( rswitch_ != 0.5 ) out << RJ(5,rswitch_ ) << " ";
118  out << type_;
119  out << std::setprecision(input_precision) << "\n";
120 }
121 
122 void
123 BoundFunc::read_data( std::istream& in ) {
124  using namespace ObjexxFCL;
125  basic::Tracer trInfo("core.io.constraints", basic::t_info );
126  std::string tag;
127  in >> lb_ >> ub_ >> sd_ >> tag;
128  if ( !in.good() ) {
129  in.setstate( std::ios_base::failbit );
130  }
131  if ( is_float( tag ) ) {
132  rswitch_ = float_of( tag );
133  in >> type_;
134  } else {
135  //std::string line;
136  // getline( in, line );
137  type_ = tag;//+line;
138  }
139 }
140 
141 
142 void
143 PeriodicBoundFunc::show_definition( std::ostream &out ) const
144 {
145  using namespace ObjexxFCL::fmt;
146  out << "PERIODICITYBOUNDED " << RJ(7, periodicity_) << " ";
147  parent::show_definition( out );
148 }
149 
150 void
151 PeriodicBoundFunc::read_data( std::istream& in )
152 {
153  in >> periodicity_ ;
154  parent::read_data( in );
155 }
156 
157 
158 void
160 {
161  using namespace ObjexxFCL::fmt;
162  out << "OFFSETPERIODICITYBOUNDED offset" << RJ(7, offset_) << " period " << RJ(7, periodicity_) << " ";
163  parent::show_definition( out );
164 }
165 
166 void
168 {
169  in >> offset_ >> periodicity_ ;
170  parent::read_data( in );
171 }
172 
173 
174 }
175 }
176 } //core