Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GunnCost.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 Cost computation for Gunn Moves
11 /// @author Oliver Lange
12 
13 // Unit Headers
15 
16 // Package Headers
17 
18 // Project Headers
19 #include <core/pose/Pose.hh>
22 #include <core/types.hh>
24 
25 #include <basic/prof.hh>
26 #include <basic/Tracer.hh>
27 
28 #include <protocols/moves/Mover.hh>
29 
30 
31 // Numeric Headers
32 #include <numeric/constants.hh>
33 
34 // Utility headers
35 #include <utility/vector1.fwd.hh>
36 #include <utility/pointer/ReferenceCount.hh>
37 #include <numeric/numeric.functions.hh>
38 
39 //// C++ headers
40 #include <cstdlib>
41 #include <string>
42 
44 #include <core/id/AtomID.hh>
45 #include <utility/vector1.hh>
46 
47 
48 namespace protocols {
49 namespace simple_moves {
50 
51 using namespace core;
52 
53 static basic::Tracer trGunnCost("protocols.FragmentMover.GunnCost");
54 
55 GunnCost::GunnCost() : FragmentCost( "GunnCost", 7.0 /*cutoff*/ ), frag_cache_("GunnCost") {}
56 GunnCost::GunnCost( core::Real cutoff ) : FragmentCost( "GunnCost", cutoff ), frag_cache_("GunnCost") {}
58 
59 void GunnCost::score( core::fragment::Frame const& frame, core::pose::Pose const& pose, ScoreList &scores ) {
60  runtime_assert ( frame.is_continuous() );
61 
62  scores.resize( frame.nr_frags() );
63 
64  if ( frame.length() == 1 ) {
65  for ( core::Size i=1; i<=frame.nr_frags(); i++ ) {
66  scores[ i ] = 5.0; //there are no scores below 2.95 .. 5.0 should give larger fragments a chance. all frags below 7 are considered
67  }
68  return; // jump out
69  }
70 
71  GunnTuple curr_pose_gunn;
72  compute_gunn( pose, frame.start(), frame.end(), curr_pose_gunn );
73  for ( core::Size i=1; i<=frame.nr_frags(); i++ ) {
74  GunnTuple frag_gunn;
75  if ( !frag_cache_.retrieve( frame, i, frag_gunn ) ) {
76  compute_gunn( frame, i, frag_gunn );
77  frag_cache_.store( frame, i, frag_gunn );
78  }
79  scores[ i ] = score_tuple( curr_pose_gunn, frag_gunn );
80  }
81 }
82 
83 void GunnCost::compute_gunn( core::fragment::Frame const& frame, core::Size frag_num, GunnTuple &data ) {
84  using namespace core::pose;
85 
86  PROF_START( basic::TEST3 );
87 
88  if ( frame.length() > various_length_poses_.size() ) {
89  various_length_poses_.resize( frame.length() );
90  }
91  PoseOP & poseptr = various_length_poses_[ frame.length() ];
92  if ( poseptr == 0 ) {
93  poseptr = new Pose;
94  frame.fragment_as_pose( frag_num, *poseptr, chemical::ChemicalManager::get_instance()->residue_type_set( chemical::CENTROID ) );
95  } else {
96  frame.fragment( frag_num ).apply( *poseptr, 1, frame.length() );
97  }
98 
99  compute_gunn( *poseptr, 1, frame.length(), data );
100 
101  PROF_STOP( basic::TEST3 );
102 }
103 
105 
106  if ( begin == end ) return; // can't compute gunn for 1-residue fragments...
107 
108  PointPosition p1,p2,p3,temp;
109  Vector x1,y1,z1; //res j
110  Vector x2,y2,z2; //res k
111  Vector R; // connection resj -> resk
112 
113  // setup coordinate system around res j
114  chemical::ResidueType const& rtj ( pose.residue_type ( begin ) );
115  id::AtomID Nj( rtj.atom_index ("N") , begin );
116  id::AtomID CAj( rtj.atom_index ("CA") , begin );
117  id::AtomID Cj( rtj.atom_index ("C") , begin );
118  p1 = pose.xyz ( Nj );
119  p2 = pose.xyz ( CAj );
120  p3 = pose.xyz ( Cj );
121  /*{
122  Vector d1,d2,d3;
123  d1 = p1-p2;
124  d2 = p1-p3;
125  d3 = p2-p3;
126  trGunnCost.Trace << "N-CA " << d1.length() << " N-C" << d2.length() << " CA-C " << d3.length()<< std::endl;
127  trGunnCost.Trace << p1[0] << " " << p1[1] << " " << p1[2] << std::endl;
128  trGunnCost.Trace << p2[0] << " " << p2[1] << " " << p2[2] << std::endl;
129  trGunnCost.Trace << p3[0] << " " << p3[1] << " " << p3[2] << std::endl;
130  }*/
131  x1 = p1 - p2;
132  x1.normalize();
133 
134  cross( x1, p3 - p2, z1 );
135  z1.normalize();
136 
137  cross( z1, x1, y1);
138 
139  // setup coordinate system around res k
140  chemical::ResidueType const& rtk ( pose.residue_type ( end ) );
141  id::AtomID Nk( rtk.atom_index ("N") , end );
142  id::AtomID Ck( rtk.atom_index ("C") , end );
143  id::AtomID CAk( rtk.atom_index ("CA") , end );
144 
145  p1 = pose.xyz ( Nk );
146  p2 = pose.xyz ( CAk );
147  p3 = pose.xyz ( Ck );
148  /*
149  trGunnCost.Trace << p1[0] << " " << p1[1] << " " << p1[2] << std::endl;
150  trGunnCost.Trace << p2[0] << " " << p2[1] << " " << p2[2] << std::endl;
151  trGunnCost.Trace << p3[0] << " " << p3[1] << " " << p3[2] << std::endl;
152  */
153  x2 = p1 - p2;
154  x2.normalize();
155 
156  cross( x2, p3 - p2, z2 );
157  z2.normalize();
158 
159  cross( z2, x2, y2 );
160 
161  // compute inter residue vector
162  R = pose.xyz( CAk ) - pose.xyz( CAj );
163  /* trGunnCost.Trace << R[0] << " " << R[1] << " " << R[2] << std::endl; */
164  // compute gunn quantities
165 
166  data.q6 = R.length();
167  R.normalize();
168 
169  data.q1 = dot_product( x1, R );
170  data.q2 = dot_product( x2, R );
171  data.q3 = dot_product( x1, x2) - data.q1 * data.q2;
172  data.q3 /= ( std::sqrt( (1-data.q1*data.q1) * (1-data.q2*data.q2) ) + .0001 );
173  data.q3 = std::acos( numeric::sin_cos_range( data.q3 ) );
174  data.q4 = std::acos( numeric::sin_cos_range( dot_product( y1, R ) / ( std::sqrt( 1-data.q1 * data.q1 ) + .0001 ) ) );
175  data.q5 = std::acos( numeric::sin_cos_range( dot_product( y2, R ) / ( std::sqrt( 1-data.q2 * data.q2 ) + .0001 ) ) );
176 
177 }
178 
180  using numeric::constants::d::pi_over_2;
181  using numeric::constants::d::pi;
182  Real c1,c2,c3,c4;
183  c1 = 2.035; //magic weights
184  c2 = 0.346;
185  c3 = 5.72;
186  c4 = 3.84;
187 
188  Real d3 ( std::abs( g1.q3 - g2.q3 ) );
189  if ( d3 > pi_over_2 ) d3 = pi - d3;
190  Real d4 ( std::abs( g1.q4 - g2.q4 ) );
191  if ( d4 > pi_over_2 ) d4 = pi - d4;
192  Real d5 ( std::abs( g1.q5 - g2.q5 ) );
193  if ( d5 > pi_over_2 ) d5 = pi - d5;
194 
195  Real cost = 2.92 +
196  c3 * std::log( 1.0 + ( std::abs( g1.q1 - g2.q1 ) + std::abs( g1.q2 - g2.q2 ) ) ) +
197  c2 * std::log( 1.0 + std::abs( g1.q6 - g2.q6 ) ) +
198  c1 * std::log( 1.0 + d3 ) +
199  c4 * std::log( 1.0 + d4 + d5 );
200  if ( cost < 2.95 ) cost = 100; // too similar
201  return cost;
202 }
203 
204 } //FragmentMover
205 } //protocols