Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BindingSiteConstraint.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
11 /// @brief
12 
13 // Unit headers
15 
16 // Package headers
22 
23 // Project headers
24 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
25 #include <core/pose/Pose.hh>
26 #include <core/id/AtomID.hh>
27 // AUTO-REMOVED #include <core/id/NamedAtomID.hh>
28 
31 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
32 #include <numeric/model_quality/rms.hh>
33 
34 #include <utility/string_util.hh>
35 
36 // Utility Headers
37 #include <basic/Tracer.hh>
38 
42 #include <utility/vector1.hh>
43 #include <numeric/xyz.functions.hh>
44 
45 //Auto Headers
47 #include <core/kinematics/Jump.hh>
48 
49 
50 
51 static basic::Tracer tr("core.io.constraints");
52 
53 namespace protocols {
54 namespace constraints_additional {
55 
56 // database of binding sites
57 std::map< core::id::AtomID , numeric::xyzVector< core::Real > > protocols::constraints_additional::BindingSiteConstraint::rot_db;
58 
59 ///c-tor
61  utility::vector1< AtomID > const & atms,
62  core::pose::Pose const &start_pose,
63  core::scoring::ScoreType scoretype /// ? TO DO -- give own scoretype
64 ):
65 Constraint( scoretype ),
66 atms_(atms) {
67  init ( start_pose );
68 }
69 
70 void BindingSiteConstraint::init( core::pose::Pose const &start_pose ) {
71  // grab binding-site atom positions from starting pose
72  // error-checking is handled in parser -- here we assume #constr >= 2 and all atmids exist
74  int natoms = atms_.size();
75 
76  tgt_pos_.dimension( 3, natoms );
77  for ( int i = 1; i <= natoms; ++i ) {
78  numeric::xyzVector< core::Real > x_i = start_pose.xyz( atms_[i] );
79  com += x_i;
80  for ( int k = 0; k < 3; ++k )
81  tgt_pos_(k+1,i) = x_i[k];
82  }
83 
84  // center at the origin
85  com /= atms_.size();
86  for (int i=1; i<=(int)atms_.size(); ++i)
87  for ( int k = 0; k < 3; ++k )
88  tgt_pos_(k+1,i) -= com[k];
89 
90  // also create centroid constraints
91  core::pose::Pose start_pose_copy = start_pose;
94 
95  tgt_pos_centroid_.dimension( 3, natoms );
96  for ( int i = 1; i <= natoms; ++i ) {
97  core::id::AtomID atm_i;
98  if ( atms_[i].atomno() > 5 )
99  atm_i = core::id::AtomID( start_pose_copy.residue( atms_[i].rsd() ).natoms() , atms_[i].rsd() );
100  else
101  atm_i = atms_[i];
102  numeric::xyzVector< core::Real > x_i = start_pose_copy.xyz( atm_i );
103  com += x_i;
104  for ( int k = 0; k < 3; ++k )
105  tgt_pos_centroid_(k+1,i) = x_i[k];
106  }
107 
108  // center at the origin
109  com /= atms_.size();
110  for (int i=1; i<=(int)atms_.size(); ++i)
111  for ( int k = 0; k < 3; ++k )
112  tgt_pos_centroid_(k+1,i) -= com[k];
113 }
114 
115 /// ctor from a vector of atom positions (in lieu of a pose)
117  utility::vector1< AtomID > const & atms,
118  ObjexxFCL::FArray2D< core::Real > tgt_pos,
119  ObjexxFCL::FArray2D< core::Real > tgt_pos_centroid,
120  core::scoring::ScoreType scoretype /// ? TO DO -- give own scoretype
121 ):
122  Constraint( scoretype ),
123  atms_(atms),
124  tgt_pos_(tgt_pos),
125  tgt_pos_centroid_(tgt_pos_centroid)
126 {}
127 
128 ///
129 void
131  // filler
132  //std::cerr << "BindingSiteConstraint::score( core::scoring::constraints::XYZ_Func const & xyz, core::scoring::EnergyMap const &, core::scoring::EnergyMap & emap ) " << std::endl;
133 
134  // get optimally-aligned RMS
135  core::Real bs_score = 0.0;
136  for (int i=1; i<=(int)atms_.size(); ++i) {
137  core::Real this_dist = rot_db[ atms_[i] ].length();
138  bs_score += this_dist*this_dist;
139  //std::cerr << " " << bs_score << " <= +" << this_dist << "^2\n";
140  }
141 
142  emap[ this->score_type() ] += bs_score;
143 }
144 
145 // do some pre-scoring calculations
146 void
148  // filler
149  //std::cerr << "BindingSiteConstraint::setup_for_scoring() " << std::endl;
150 
151  // align the >target atoms< to the >template atoms<
153  utility::vector1< bool > align_centroid;
154 
155  for (int i=1; i<=(int)atms_.size(); ++i) {
156  core::chemical::ResidueType const & rsd_type = xyz.residue( atms_[i].rsd() ).type();
157  core::id::AtomID atm_i;
158  bool aln_cent_i = false;
159 
160  // is pose centroid?? then we need to remap atmids
161  if ( rsd_type.residue_type_set().name() == core::chemical::CENTROID && atms_[i].atomno() > 5 ) {
162  //std::cerr << "ATOM " << atms_[i].rsd() << " , " << atms_[i].atomno() << " (" << pose.residue( atms_[i].rsd() ).natoms() << ")" << std::endl;
163  //std::cerr << "Remapping ATOM " << atms_[i].rsd() << " , " << atms_[i].atomno() << " to CENTROID" << std::endl;
164  atm_i = core::id::AtomID( xyz.residue( atms_[i].rsd() ).natoms() , atms_[i].rsd() );
165  aln_cent_i = true;
166  } else {
167  atm_i = atms_[i];
168  }
169 
170  templ_atms.push_back( xyz( atm_i ) );
171  align_centroid.push_back( aln_cent_i );
172  }
173  pre_align (templ_atms, align_centroid);
174 }
175 
176 // align the atoms
177 // ... placing a vector -- from each atom to the the rotated >target< atoms -- in the database
178 void
181  utility::vector1< bool > const & align_centroid
182  ) const {
183  int natoms = templ_atms.size();
184 
185  if ( natoms != (int)atms_.size() ) {
186  utility_exit_with_message( "BindingSiteConstraint::align() bad argument" );
187  }
188 
189  // copy coords into Real arrays
190  ObjexxFCL::FArray2D< core::Real > tmpl_pos( 3, natoms );
192  for ( int i = 1; i <= natoms; ++i ) {
193  numeric::xyzVector< core::Real > const &x_i = templ_atms[i];
194  com += x_i;
195  for ( int k = 0; k < 3; ++k )
196  tmpl_pos(k+1,i) = x_i[k];
197  }
198 
199  // center at the origin
200  com /= natoms;
201  for (int i=1; i<=natoms; ++i)
202  for ( int k = 0; k < 3; ++k )
203  tmpl_pos(k+1,i) -= com[k];
204 
205  // get optimal superposition
206  // rotate TARGET to the TEMPLATE
207  ObjexxFCL::FArray1D< numeric::Real > ww( natoms, 1.0 );
208  ObjexxFCL::FArray2D< numeric::Real > uu( 3, 3, 0.0 );
209  numeric::Real ctx;
210  ObjexxFCL::FArray2D< core::Real > tgt_pos_mixed( 3 , natoms );
211 
212  for (int i=1; i<=natoms; ++i) {
213  if (align_centroid[i]) {
214  for ( int k = 1; k <= 3; ++k ) {
215  tgt_pos_mixed(k,i) = tgt_pos_centroid_(k,i);
216  }
217  } else {
218  for ( int k = 1; k <= 3; ++k ) {
219  tgt_pos_mixed(k,i) = tgt_pos_(k,i);
220  }
221  }
222  }
223  ObjexxFCL::FArray2D< core::Real > tgt_pos_copy( 3 , natoms );
224  for (int i=1; i<=natoms; ++i)
225  for ( int k = 1; k <= 3; ++k )
226  tgt_pos_copy(k,i) = tgt_pos_mixed(k,i);
227 
228  numeric::model_quality::findUU( tgt_pos_mixed, tmpl_pos, ww, natoms, uu, ctx );
229 
231  R.xx( uu(1,1) ); R.xy( uu(2,1) ); R.xz( uu(3,1) );
232  R.yx( uu(1,2) ); R.yy( uu(2,2) ); R.yz( uu(3,2) );
233  R.zx( uu(1,3) ); R.zy( uu(2,3) ); R.zz( uu(3,3) );
234 
235  // apply rotation
236  // if one atom appears in multiple templates this will overwrite previous atom's position ...
237  // perhaps this should be checked for in the constraint parser
238  for ( int i = 1; i <= natoms; ++i ) {
239  numeric::xyzVector< core::Real > x_i( tgt_pos_copy(1,i) , tgt_pos_copy(2,i) , tgt_pos_copy(3,i) );
241  numeric::xyzVector< core::Real > y_i( tmpl_pos(1,i) , tmpl_pos(2,i) , tmpl_pos(3,i) );
242  //rot_db[ atms_[i] ] = rx_i;
243  rot_db[ atms_[i] ] = (rx_i - y_i); // store the direction template to target
244 
245  ///////////////
246  ///////////////
247  //std::cerr << " tgt: ATOM " << i << ": " << tgt_pos_copy(1,i) << " , "
248  // << tgt_pos_copy(2,i) << " , "
249  // << tgt_pos_copy(3,i) << std::endl;
250  //std::cerr << " tmpl:ATOM " << i << ": " << tmpl_pos(1,i) << " , "
251  // << tmpl_pos(2,i) << " , "
252  // << tmpl_pos(3,i) << std::endl;
253  //std::cerr << " del: ATOM " << i << ": " << rot_db[ atms_[i] ][0] << " , "
254  // << rot_db[ atms_[i] ][1] << " , "
255  // << rot_db[ atms_[i] ][2] << "\n\n";
256  ///////////////
257  ///////////////
258  }
259 }
260 
261 // call the setup_for_derivatives for each constraint
262 void
264  // filler
265  //std::cerr << "BindingSiteConstraint::setup_for_derivatives() " << std::endl;
266  setup_for_scoring( xyz, scfxn );
267 }
268 
269 // atom deriv
270 void
272  AtomID const & atom,
274  core::Vector & F1,
275  core::Vector & F2,
276  core::scoring::EnergyMap const & weights
277 ) const {
278  // filler
279  //std::cerr << "BindingSiteConstraint::fill_f1_f2() " << std::endl;
280  if ( std::find( atms_.begin() , atms_.end() , atom ) == atms_.end()) return;
281 
282  numeric::xyzVector< core::Real > atom_x = -xyz(atom);
283  numeric::xyzVector< core::Real > const f2( rot_db[ atom ] );
284  numeric::xyzVector< core::Real > atom_y = f2 + atom_x; // a "fake" atom in the direcion of the gradient
285  numeric::xyzVector< core::Real > const f1( atom_x.cross( atom_y ) );
286 
287  //std::cerr << " f1 = " << f1[0] << " , " << f1[1] << " , " << f1[2] << std::endl;
288  //std::cerr << " f2 = " << f2[0] << " , " << f2[1] << " , " << f2[2] << std::endl;
289 
290  F1 -= f1*weights[ this->score_type() ]*2;
291  F2 -= f2*weights[ this->score_type() ]*2;
292 }
293 
296  return "BindingSite";
297 }
298 
299 ///
302 {
303  return atms_.size();
304 }
305 
308 {
309  utility::vector1< AtomID > atms_remap;
310 
311  for (int i=1; i<=(int) atms_.size(); ++i) {
312  if ( seqmap[atms_[i].rsd()] != 0 ) {
313  atms_remap.push_back( AtomID( atms_[i].atomno(), seqmap[atms_[i].rsd()] ) );
314  }
315  }
316 
317  if (atms_remap.size() > 2)
319  else
320  return NULL;
321 }
322 
323 ///
324 core::id::AtomID const &
326 {
327  if ( n >= 1 && n <= atms_.size() )
328  return atms_[n];
329  else
330  utility_exit_with_message( "BindingSiteConstraint::atom() bad argument" );
331 
332  return atms_[1]; // stop the compiler from complaining
333 }
334 
335 void
336 BindingSiteConstraint::show( std::ostream& out ) const {
337  out << "BindingSiteConstraint::show() " << std::endl;
338 }
339 
340 void
341 BindingSiteConstraint::show_def( std::ostream& out , core::pose::Pose const& /* pose */ ) const {
342  out << "BindingSiteConstraint::show_def() " << std::endl;
343 }
344 
346 BindingSiteConstraint::show_violations( std::ostream& /*out*/, core::pose::Pose const& /*pose*/, core::Size /*verbose_level*/, core::Real /*threshold*/ ) const {
347  /*
348  if (verbose_level > 80) {
349  out << "AtomPairConstraint ("
350  << core::pose.residue_type(atom1_.rsd() ).atom_name( atom1_.atomno() ) << ":" << atom1_.atomno() << "," << atom1_.rsd() << "-"
351  << core::pose.residue_type(atom2_.rsd() ).atom_name( atom2_.atomno() ) << ":" << atom2_.atomno() << "," << atom2_.rsd() << ") " ;
352  };
353  return func_->show_violations( out, dist( pose ), verbose_level );
354  */
355  return 0;
356 }
357 
358 /*
359 ///@details one line definition "BindingSite atom1 res1 ... atomN resN"
360 void
361 BindingSiteConstraint::read_def(
362  std::istream& data,
363  core::pose::Pose const& pose,
364  core::scoring::constraints::FuncFactory const& func_factory
365 ) {
366  core::Size res;
367  std::string name;
368 
369  std::string line;
370  // = data.getline();
371  getline( data, line );
372  std::vector< std::string > tokens = utility::split( line );
373 
374  // to do? atm name -> centroid conversion
375  tr.Debug << "read: ";
376  int npairs = tokens.size() / 2;
377  for (int i=0; i<npairs; ++i) {
378  name = tokens[2*i];
379  res = (core::Size) atoi(tokens[2*i + 1].c_str());
380  tr.Debug << " " << name << " " << res;
381 
382  atms_.push_back( core::id::AtomID( pose.residue_type( res ).atom_index( name ), res ) );
383  if ( res > pose.total_residue() ) {
384  tr.Debug << "** ignored **";
385  continue;
386  }
387  }
388 
389  // get positions from start pose
390  init ( pose );
391 }
392 */
393 
394 /// @brief Format should look like:
395 /// Dunbrack seqpos_ rot_vec_pos_ rot_bin_ bonus_
396 void
398  std::istream & line_stream,
399  core::pose::Pose const & pose,
400  core::scoring::constraints::FuncFactory const & /* func_factory */
401 ) {
402 
403  core::Size res; // ?
404  std::string name; // ?
405 
406  // to do? atm name -> centroid conversion
408  tr.Debug << "read: ";
409  while ( line_stream >> name >> res ) {
410  tr.Debug << " " << name << " " << res ;
411  atms.push_back( core::id::AtomID( pose.residue_type( res ).atom_index( name ), res ) );
412  if ( res > pose.total_residue() ) {
413  tr.Debug << "** ignored **";
414  continue;
415  }
416  }
417  tr.Debug << std::endl;
418  atms_ = atms;
419  init( pose );
420 }
421 
422 
423 
424 }
425 }