Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LocalCoordinateConstraint.hh
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
12 
13 #ifndef INCLUDED_core_scoring_constraints_LocalCoordinateConstraint_hh
14 #define INCLUDED_core_scoring_constraints_LocalCoordinateConstraint_hh
15 
21 #include <core/pose/Pose.fwd.hh>
22 #include <core/id/AtomID.hh>
23 #include <core/kinematics/Stub.hh>
24 
25 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
26 // AUTO-REMOVED #include <core/id/NamedStubID.hh>
27 
28 // C++ Headers
29 #include <cstdlib>
30 #include <iostream>
31 
32 #include <utility/vector1.hh>
33 
34 //Auto Headers
36 #include <core/kinematics/Jump.hh>
37 
38 
39 
40 //#include <map>
41 
42 namespace core {
43 namespace scoring {
44 namespace constraints {
45 
49 
50 ///
51 
53 public:
54 
55 
58  atom_( id::BOGUS_ATOM_ID ),
60  func_( NULL ) {}
61 
62  ///c-tor
64  id::AtomID const & a1,
65  id::StubID const & fixed_stub_in,
66  Vector const & xyz_target_in,
67  FuncOP func,
69  ):
70  Constraint( scotype ),
71  atom_(a1),
72  fixed_stub_( fixed_stub_in ),
73  xyz_target_( xyz_target_in ),
74  func_( func )
75  {
76  runtime_assert( fixed_stub_.atom( 1 ) == fixed_stub_.center() || !fixed_stub_.center().valid() );
77  //don't allow 4-atom stubs, because that changes other functions
78  }
79 
81 
82  virtual std::string type() const {
83  return "LocalCoordinateConstraint";
84  }
85 
86  virtual ConstraintOP clone() const {
87  return new LocalCoordinateConstraint( *this );
88  }
89 
90  /// @brief Copies the data from this Constraint into a new object and returns an OP
91  /// atoms are mapped to atoms with the same name in dest pose ( e.g. for switch from centroid to fullatom )
92  /// if a sequence_mapping is present it is used to map residue numbers .. NULL = identity mapping
93  /// to the new object. Intended to be implemented by derived classes.
94  virtual ConstraintOP remapped_clone( pose::Pose const& src, pose::Pose const& dest, id::SequenceMappingCOP map=NULL ) const;
95 
96  virtual
98  remap_resid( core::id::SequenceMapping const &seqmap ) const;
99 
100  ///
101  void show( std::ostream& out ) const
102  {
103  out << "LocalCoordinateConstraint ("
104  << atom_.atomno() << "," << atom_.rsd() << "-"
105  << fixed_stub_ << ")" << std::endl;
106  func_->show( out );
107  }
108 
109  // @brief Reads the definition of a Constraint from the given std::istream,
110  // using the given Pose, and the given FuncFactory. This method is intended
111  // to be overridden by derived classes if they'd like to use the
112  // ConstraintIO machinery.
113  virtual void read_def( std::istream &, pose::Pose const &, FuncFactory const & );
114 
115  ///
116  void show_def( std::ostream& out, pose::Pose const& pose ) const;
117 
118  // @brief take coordinates, distances, angles, etc from given pose
119  ///
120  virtual void steal_def( pose::Pose const& );
121 
122  using Constraint::score;
123 
124  ///
125  Real
126  score(
127  Vector const & xyz, //target
128  Vector const & s1, //fixed_stub.a
129  Vector const & s2, //fixed_stub.b
130  Vector const & s3 //fixed_stub.c
131  ) const;
132 
133  ///
134  void
135  score( XYZ_Func const & xyz, EnergyMap const &, EnergyMap & emap ) const
136  {
137  emap[ this->score_type() ] += score( xyz( atom_ ),
138  xyz( fixed_stub_.atom( 1 ) ),
139  xyz( fixed_stub_.atom( 2 ) ),
140  xyz( fixed_stub_.atom( 3 ) )
141  );
142  }
143 
144  // atom deriv
145  void
147  AtomID const & atom,
148  XYZ_Func const & xyz,
149  Vector & F1,
150  Vector & F2,
151  EnergyMap const & weights
152  ) const
153  {
154  utility_exit_with_message( " derivative of LocalCoordinateConstraint not supported yet " );
155  if ( atom != atom_ ) return;
156 
157  Vector const & xyz1( xyz( atom_ ) ), xyz2( xyz_target_ );
158 
159  Vector const f2( xyz1 - xyz2 );
160  Real const dist( f2.length() ), deriv( dfunc( dist ) );
161  if ( deriv != 0.0 && dist != 0.0 ) {
162  Vector const f1( xyz1.cross( xyz2 ) );
163  // jk: double F1 and F2 because the target is fixed
164  // (matches deriv_check, and minimizes faster)
165  // rhiju: No, JK, this isn't working...
166  F1 += ( ( deriv / dist ) * f1 ) * weights[ this->score_type() ];
167  F2 += ( ( deriv / dist ) * f2 ) * weights[ this->score_type() ];
168  }
169  }
170 
171 
172 
173  ///
174  Size
175  natoms() const
176  {
177  return 4;
178  }
179 
180  ///
181  AtomID const &
182  atom( Size const n ) const
183  {
184  if ( n == 1 ) {
185  return atom_;
186  } else if ( n <= 4 ) {
187  return fixed_stub_.atom( n - 1 );
188  } else {
189  utility_exit_with_message( "LocalCoordinateConstraint::atom() bad argument" );
190  }
191  return atom_;
192  }
193 
194  Real
195  dist( pose::Pose const & pose ) const;
196 
197  virtual Size show_violations(
198  std::ostream& out,
199  pose::Pose const& pose,
200  Size verbose_level,
201  Real threshold = 1
202  ) const;
203 
204  void set_fixed_stub( id::StubID new_stub ) {
205  fixed_stub_ = new_stub;
206  }
207 
208  Vector xyz_target( core::pose::Pose const& local_frame_pose ) const;
209 
210  void set_xyz_target( Vector const& xyz_in, core::pose::Pose const& local_frame_pose );
211 
212 private:
213 
214  // functions
215  Real
216  func( Real const theta ) const
217  {
218  return func_->func( theta );
219  }
220 
221  // deriv
222  Real
223  dfunc( Real const theta ) const
224  {
225  return func_->dfunc( theta );
226  }
227 
228 private:
229  // data
234 };
235 
236 }
237 }
238 }
239 
240 #endif