Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PocketConstraint.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 // This file is made available under the Rosetta Commons license.
5 // See http://www.rosettacommons.org/license
6 // (C) 199x-2007 University of Washington
7 // (C) 199x-2007 University of California Santa Cruz
8 // (C) 199x-2007 University of California San Francisco
9 // (C) 199x-2007 Johns Hopkins University
10 // (C) 199x-2007 University of North Carolina, Chapel Hill
11 // (C) 199x-2007 Vanderbilt University
12 
13 /// @file protocols/pockets/PocketConstraint.cc
14 ///
15 /// @brief
16 /// @author David Johnson
17 
18 
22 
23 
24 #include <basic/options/option.hh>
25 #include <basic/options/keys/OptionKeys.hh>
27 #include <core/pose/PDBInfo.hh>
28 #include <core/pose/Pose.hh>
31 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintSet.hh>
35 // AUTO-REMOVED #include <core/chemical/AtomType.hh>
36 #include <basic/Tracer.hh>
37 #include <string>
38 #include <ObjexxFCL/string.functions.hh>
39 // AUTO-REMOVED #include <fstream>
40 #include <iostream>
41 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
42 #include <basic/options/keys/pocket_grid.OptionKeys.gen.hh>
43 // AUTO-REMOVED #include <basic/options/keys/out.OptionKeys.gen.hh>
44 #ifndef _WIN32
45 // AUTO-REMOVED #include <sys/time.h>
46 
47 #include <utility/vector1.hh>
48 
49 #endif
50 
51 namespace protocols {
52 namespace pockets {
53 
56 
59  return new PocketConstraint;
60 }
61 
63 {
64  return "Pocket";
65 }
66 
67 
68 static basic::Tracer TR("core.scoring.constraints.PocketConstraint");
69 
71  using namespace basic::options;
72  seqpos_ = 0;
73  weight_ = option[ OptionKeys::constraints::pocket_constraint_weight ]();
74  dumppdb_=option[ OptionKeys::pocket_grid::pocket_dump_pdbs ]();
75  totalres_=pose.total_residue();
76  if (option[ OptionKeys::pocket_grid::pocket_num_angles ] <1){
77  std::cout<<"PocketConstraint: invalid number of angles specified. Exiting."<<std::endl;
78  exit(999);
79  } else {
80  angles_ = option[ OptionKeys::pocket_grid::pocket_num_angles ];
81  }
82 
83 }
84 
86  std::istream & line_stream,
87  core::pose::Pose const & pose,
88  core::scoring::constraints::FuncFactory const & /* func_factory */)
89 {
90  init(pose);
91  std::string tmp;
92  std::string resid("");
93  if ((line_stream >> weight_>>resid )){
95  if ( residues_.size() == 0 ) {
96  std::cout << "ERROR!! Invalid residue to backrub around" << std::endl;
97  exit(1);
98  }
99  }
100  else{
101  std::cout << "ERROR!! Invalid PocketConstraint specification" << std::endl;
102  exit(1);
103  }
105 
106 }
107 
108 void PocketConstraint::show_def( std::ostream& out , core::pose::Pose const& /* pose */ ) const {
109  out << "PocketConstraint::show_def() " << std::endl;
110 }
111 
112 
114 
116  core::pose::Pose const & pose
117 ):
118  Constraint( core::scoring::pocket_constraint )
119 {
120  using namespace basic::options;
121  // for now, set the constraint to depend on ALL atom positions, ie. if ANYTHING moves we have to update the constraint
122  // later, we could pre-define residues near the selected residue and make the constraint depend only on these
123  // This is the residue we'll backrub around!!
124  //int const central_relax_pdb_number = option[ OptionKeys::pocket_grid::central_relax_pdb_num ];
125  init(pose);
126 
127  std::string resid(option[ OptionKeys::pocket_grid::central_relax_pdb_num ]);
128  int central_relax_pdb_number;
129  char chain = ' ';
130  std::size_t fpos( resid.find(':') );
131  if ( fpos != std::string::npos ) {
132  central_relax_pdb_number = ObjexxFCL::int_of( resid.substr(0,fpos) );
133  if (fpos != resid.size()-1 ) {
134  chain = resid[ fpos+1 ];
135  }
136  } else {
137  central_relax_pdb_number = ObjexxFCL::int_of( resid );
138  }
139 
140  for ( int j = 1, resnum = pose.total_residue(); j <= resnum; ++j ) {
141  if ( pose.pdb_info()->number(j) == central_relax_pdb_number ) {
142  //seqpos_ = j;
143  if (chain != ' '){
144  if ( pose.pdb_info()->chain(j) == chain ) {
145  seqpos_ = j;
146  }
147  }else{
148  seqpos_ = j;
149  }
150  }
151  }
152 
153  // Do not crash yet;
154  // if ( seqpos_ == 0 ) {
155  // std::cout << "ERROR!! Could not find residue to backrub around" << std::endl;
156  // exit(1);
157  // }
158 
159  if ( seqpos_ != 0 ) {
161  }
162 
163  // JK NOTE: WE'RE NOT USING THE "FUNC" SYSTEM, THIS COULD BE ADDED LATER....
164 
165 }
166 
168  Constraint( core::scoring::pocket_constraint )
169 {
170  seqpos_ = old.seqpos_;
171  totalres_ = old.totalres_;
172  pocketgrid_ = old.pocketgrid_;
173  dumppdb_ = old.dumppdb_;
174 }
175 
176 
178 
179 
180 void PocketConstraint::set_target_res( core::pose::Pose const & pose, Size new_seqpos ){
181  if (new_seqpos>pose.total_residue()){
182  std::cout << "ERROR!! Invalid residue to backrub around" << std::endl;
183  exit(1);
184  }
185  if ( seqpos_ != 0 ) {
186  seqpos_=new_seqpos;
188  }else{
189  std::cout << "ERROR!! Invalid residue to backrub around" << std::endl;
190  exit(1);
191  }
192 }
193 
194 
196  //std::cout<<size_x_<<" "<<size_y_<<" "<<size_z_<<"\n";
197  int central_relax_pdb_number;
198  char chain = ' ';
199  std::size_t fpos( resid.find(':') );
200  if ( fpos != std::string::npos ) {
201  central_relax_pdb_number = ObjexxFCL::int_of( resid.substr(0,fpos) );
202  if (fpos != resid.size()-1 ) {
203  chain = resid[ fpos+1 ];
204  }
205  } else {
206  central_relax_pdb_number = ObjexxFCL::int_of( resid );
207  }
208 
209  seqpos_ = 0;
210  for ( int j = 1, resnum = pose.total_residue(); j <= resnum; ++j ) {
211  if ( pose.pdb_info()->number(j) == central_relax_pdb_number ) {
212  //seqpos_ = j;
213  if (chain != ' '){
214  if ( pose.pdb_info()->chain(j) == chain ) {
215  seqpos_ = j;
216  }
217  }else{
218  seqpos_ = j;
219  }
220  }
221  }
222 
223  if ( seqpos_ != 0 ) {
225  } else {
226  std::cout << "ERROR!! Invalid residue to backrub around" << std::endl;
227  exit(1);
228  }
229 
230 }
231 
232 
233 
234 
235 // Calculates a score for this constraint using XYZ_Func, and puts the UNWEIGHTED score into
236 // emap. Although the current set of weights currently is provided, Constraint objects
237 // should put unweighted scores into emap.
238 void
240 {
241  //std::cout<< "hi\n";
242  //TR<<"hi\n";
243  if ( weights[ this->score_type() ] == 0 ) return;
244  if (seqpos_==0 && residues_.size()==0){
245  std::cout << "ERROR!! Invalid residue to backrub around" << std::endl;
246  exit(1);
247  }
248 
249 
250  core::Real cst_avg = 0;
251  core::Real largestPocketVol;
252 
253  for (core::Size angleCount=0; angleCount < (angles_ - 1); ++angleCount){
254  pocketgrid_ -> randomAngle();
255  if (seqpos_ != 0){
256  core::conformation::Residue const & curr_rsd ( xyz_func.residue(seqpos_) );
257  pocketgrid_->autoexpanding_pocket_eval( curr_rsd, xyz_func, totalres_ );
258  }else{
259  pocketgrid_->autoexpanding_pocket_eval( residues_, xyz_func, totalres_ );
260  }
261  core::Real largestPocketVol=pocketgrid_->netTargetPocketVolume();
262  cst_avg += largestPocketVol;
263  }
264 
265  pocketgrid_ -> zeroAngle();
266  if (seqpos_ != 0){
267  core::conformation::Residue const & curr_rsd ( xyz_func.residue(seqpos_) );
268  pocketgrid_->autoexpanding_pocket_eval( curr_rsd, xyz_func, totalres_ );
269  }else{
270  pocketgrid_->autoexpanding_pocket_eval( residues_, xyz_func, totalres_ );
271  }
272  core::Real cst_val = -1.;
273 
274  // core::Real largestPocketVol=pocketgrid_->netTargetPocketVolume();
275 
276  if (dumppdb_) pocketgrid_->dumpGridToFile();
277 
278  // core::Real vol=pocketgrid_->targetPocketVolume(surf_score, bur_score);
279  // core::Real sa=pocketgrid_->targetPocketSolventSurface();
280  // core::Real psa=pocketgrid_->targetPocketProteinSurface();
281  // core::Real hpsa=pocketgrid_->targetPocketHydrophobicProteinSurface();
282  // core::Real ppsa=pocketgrid_->targetPocketPolarProteinSurface();
283  // core::Real nps=pocketgrid_->targetPocketHeuristicScore();
284 
285  //core::Real largestPocketVol=pocketgrid_->largestTargetPocketVolume();
286  largestPocketVol=pocketgrid_->netTargetPocketVolume();
287  //core::Real largestPocketVol=0;
288 
289  cst_avg += largestPocketVol;
290  cst_avg /= angles_;
291  cst_val *= (cst_avg);
292  //cst_val *= (vol);
293  //cst_val *= (vol*vol/sa);
294  // std::cout<<"Vol: "<<vol<<" Solvent surface: "<<sa<<" Prot surface: "<<psa<<" Hprot surface: "<<hpsa<<" Pprot surface: "<<ppsa<<" New Score: "<<nps<<std::endl;
295  //std::cout<<"done4\n";
296  // cst_val *= distance(CB_curr,CA_curr);
297  emap[ this->score_type() ] += cst_val*weight_;
298  //std::cout<<cst_val<<" done5\n";
299 
300 }
301 
302 
303 void
305  core::id::AtomID const & ,
307  core::Vector & ,
308  core::Vector & ,
309  core::scoring::EnergyMap const & weights
310 ) const
311 {
312 
313  if ( weights[ this->score_type() ] == 0 ) return;
314 
315  using namespace basic::options;
316  if (!option[ OptionKeys::constraints::pocket_zero_derivatives ]()){
317  TR << "ERROR - derivatives not yet implemented for PocketConstraints." << std::endl;
318  std::exit(1);
319  }
320 
321  return;
322 
323 }
324 
325 
328 }
329 
330 
331 } // namespace constraints_additional
332 } // namespace protocols