Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SICFast.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 
11 
14 
15 #include <basic/options/keys/sicdock.OptionKeys.gen.hh>
16 #include <basic/options/option.hh>
17 #include <basic/options/option_macros.hh>
18 #include <numeric/constants.hh>
19 #include <numeric/xyz.functions.hh>
20 #include <numeric/xyz.io.hh>
21 #include <ObjexxFCL/format.hh>
22 #include <ObjexxFCL/string.functions.hh>
23 #include <utility/io/ozstream.hh>
24 #include <utility/string_util.hh>
25 #include <core/id/AtomID_Map.hh>
26 #include <core/scoring/sasa.hh>
28 #include <core/pose/util.hh>
29 #include <core/kinematics/Stub.hh>
30 #include <boost/foreach.hpp>
32 
33 namespace protocols {
34 namespace sic_dock {
35 
36 using platform::Size;
37 using platform::Real;
38 using std::string;
39 using utility::vector1;
42 using ObjexxFCL::format::RJ;
43 using numeric::min;
44 using numeric::max;
45 using std::cout;
46 using std::cerr;
47 using std::endl;
49 typedef numeric::xyzVector<platform::Real> Vec;
50 typedef numeric::xyzMatrix<platform::Real> Mat;
51 
52 inline double dist_score( double const & sqdist, double const & start, double const & stop ) {
53  if ( sqdist > stop*stop ) {
54  return 0.0;
55  } else if ( sqdist < start*start ) {
56  return 1.0;
57  } else {
58  double dist = sqrt( sqdist );
59  return (stop-dist)/(stop-start);
60  //return sqr(1.0 - sqr( (dist - start) / (stop - start) ) );
61  }
62 }
63 
65  CLD(clash_dis),
66  CLD2(sqr(CLD)),
67  BIN(CLD*basic::options::option[basic::options::OptionKeys::sicdock::hash_2D_vs_3D]()),
68  h1_(NULL),h2_(NULL)
69 {}
70 
72  CLD(basic::options::option[basic::options::OptionKeys::sicdock::clash_dis]()),
73  CLD2(sqr(CLD)),
74  BIN(CLD*basic::options::option[basic::options::OptionKeys::sicdock::hash_2D_vs_3D]()),
75  h1_(NULL),h2_(NULL)
76 {}
77 
79  if ( h1_ ) delete h1_;
80  if ( h2_ ) delete h2_;
81 }
82 
83 
84 void
86  core::pose::Pose const & pose
87 ) {
88  init(pose,pose);
89 }
90 
91 void
93  core::pose::Pose const & pose,
94  core::id::AtomID_Map<platform::Real> const & clash_atoms
95 ){
96  init(pose,pose,clash_atoms,clash_atoms);
97 }
98 
99 void
101  core::pose::Pose const & pose1,
102  core::pose::Pose const & pose2
103 ){
104  using core::id::AtomID;
105  core::id::AtomID_Map<platform::Real> clashmap1,clashmap2;
106  core::pose::initialize_atomid_map( clashmap1,pose1,-1.0);
107  core::pose::initialize_atomid_map( clashmap2,pose2,-1.0);
108  for ( Size i = 1; i <= pose1.n_residue(); ++i ) {
109  for ( int j = 1; j <= ((pose1.residue(i).name3()=="GLY")?4:5); ++j ) {
110  clashmap1[AtomID(j,i)] = pose1.residue(i).atom_type(j).lj_radius();
111  }
112  }
113  for ( Size i = 1; i <= pose2.n_residue(); ++i ) {
114  for ( int j = 1; j <= ((pose2.residue(i).name3()=="GLY")?4:5); ++j ) {
115  clashmap2[AtomID(j,i)] = pose2.residue(i).atom_type(j).lj_radius();
116  }
117  }
118  init(pose1,pose2,clashmap1,clashmap2);
119 }
120 
121 void
123  core::pose::Pose const & pose1,
124  core::pose::Pose const & pose2,
125  core::id::AtomID_Map<platform::Real> const & clash_atoms1,
126  core::id::AtomID_Map<platform::Real> const & clash_atoms2
127 ){
128  using core::id::AtomID;
129 
130  if ( h1_ ) delete h1_;
131  if ( h2_ ) delete h2_;
132  h1_ = new xyzStripeHashPose(pose1,clash_atoms1,CLD+0.01);
133  h2_ = new xyzStripeHashPose(pose2,clash_atoms2,CLD+0.01);
134 }
135 
136 
137 inline
138 bool
140  vector1<Vec> const & pb,
141  vector1<Vec> const & pa,
142  double & xmx, double & xmn,
143  double & ymx, double & ymn
144 ){
145  // get bounds for plane hashess
146  double xmx1=-9e9,xmn1=9e9,ymx1=-9e9,ymn1=9e9;
147  xmx=-9e9,xmn=9e9,ymx=-9e9,ymn=9e9;
148  for ( vector1<Vec>::const_iterator ia = pb.begin(); ia != pb.end(); ++ia ) {
149  xmx1 = max(xmx1,ia->x()); xmn1 = min(xmn1,ia->x());
150  ymx1 = max(ymx1,ia->y()); ymn1 = min(ymn1,ia->y());
151  }
152  for ( vector1<Vec>::const_iterator ib = pa.begin(); ib != pa.end(); ++ib ) {
153  xmx = max(xmx,ib->x()); xmn = min(xmn,ib->x());
154  ymx = max(ymx,ib->y()); ymn = min(ymn,ib->y());
155  }
156  xmx = min(xmx,xmx1); xmn = max(xmn,xmn1);
157  ymx = min(ymx,ymx1); ymn = max(ymn,ymn1);
158  if ( ymn > ymx || xmn > xmx ) return false; //utility_exit_with_message("slide disjoint, maybe something wrong.");
159  return true;
160 }
161 
162 
163 inline
164 void
166  vector1<Vec> const & pb,
167  vector1<Vec> const & pa,
168  double const & xmx,
169  double const & xmn,
170  double const & ymx,
171  double const & ymn,
172  double const & BIN,
173  ObjexxFCL::FArray2D<Vec> & ha,
174  ObjexxFCL::FArray2D<Vec> & hb,
175  int & xlb,
176  int & ylb,
177  int & xub,
178  int & yub
179 ){
180  xlb = (int)(xmn/BIN)-2; xub = (int)(xmx/BIN+0.999999999)+2; // one extra on each side for correctness,
181  ylb = (int)(ymn/BIN)-2; yub = (int)(ymx/BIN+0.999999999)+2; // and one extra for outside atoms
182  ha.dimension(xub-xlb+1,yub-ylb+1,Vec(0,0,-9e9));
183  hb.dimension(xub-xlb+1,yub-ylb+1,Vec(0,0, 9e9));
184  int const xsize = xub-xlb+1;
185  int const ysize = yub-ylb+1;
186  for ( vector1<Vec>::const_iterator ia = pb.begin(); ia != pb.end(); ++ia ) {
187  int const ix = (int)((ia->x()/BIN)-xlb+0.999999999);
188  int const iy = (int)((ia->y()/BIN)-ylb+0.999999999);
189  if ( ix < 1 || ix > xsize || iy < 1 || iy > ysize ) continue;
190  if ( ha(ix,iy).z() < ia->z() ) ha(ix,iy) = *ia;
191  // bool const test = !( ix < 1 || ix > xsize || iy < 1 || iy > ysize) && ha(ix,iy).z() < ia->z();
192  // ha(ix,iy) = test ? *ia : ha(ix,iy);
193  }
194  for ( vector1<Vec>::const_iterator ib = pa.begin(); ib != pa.end(); ++ib ) {
195  int const ix = (int)((ib->x()/BIN)-xlb+0.999999999);
196  int const iy = (int)((ib->y()/BIN)-ylb+0.999999999);
197  if ( ix < 1 || ix > xsize || iy < 1 || iy > ysize ) continue;
198  if ( hb(ix,iy).z() > ib->z() ) hb(ix,iy) = *ib;
199  // bool const test = !( ix < 1 || ix > xsize || iy < 1 || iy > ysize ) && hb(ix,iy).z() > ib->z();
200  // hb(ix,iy) = test ? *ib : hb(ix,iy);
201  }
202 
203 }
204 
205 inline
206 double
208  int const & xlb,
209  int const & ylb,
210  int const & xub,
211  int const & yub,
212  ObjexxFCL::FArray2D<Vec> const & ha,
213  ObjexxFCL::FArray2D<Vec> const & hb,
214  double const & clashdis2
215 ){
216  int const xsize=xub-xlb+1, ysize=yub-ylb+1;
217  double m = 9e9;
218  for ( int i = 1; i <= xsize; ++i ) { // skip 1 and N because they contain outside atoms (faster than clashcheck?)
219  for ( int j = 1; j <= ysize; ++j ) {
220  for ( int k = -1; k <= 1; ++k ) {
221  if ( i+k < 1 || i+k > xsize ) continue;
222  for ( int l = -1; l <= 1; ++l ) {
223  if ( j+l < 1 || j+l > ysize ) continue;
224  double const xa1 = ha(i,j).x();
225  double const ya1 = ha(i,j).y();
226  double const xb1 = hb(i+k,j+l).x();
227  double const yb1 = hb(i+k,j+l).y();
228  double const d21 = (xa1-xb1)*(xa1-xb1)+(ya1-yb1)*(ya1-yb1);
229  if ( d21<clashdis2 ) {
230  double const dz = hb(i+k,j+l).z() - ha(i,j).z() - sqrt(clashdis2-d21);
231  if ( dz<m ) m=dz;
232  }
233  }
234  }
235  }
236  }
237  return m;
238 }
239 
241  Vec const dof;
244  int contacts;
245  CorrectionVisitor(Vec const & dof_in, Real const & clash_dis_sq_in) : dof(dof_in),clash_dis_sq(clash_dis_sq_in),correction(9e9),contacts(0) {}
246  void visit(
247  numeric::xyzVector<double> const & v,
248  numeric::xyzVector<double> const & c,
249  double /*vr*/,
250  double /*cr*/
251  ){
252  double const dxy2 = dof.cross(v-c).length_squared();
253  if ( dxy2 < clash_dis_sq ) {
254  double const dz = dof.dot(v) - dof.dot(c) - sqrt(clash_dis_sq-dxy2);
255  correction = min(dz,correction);
256  contacts++;
257  }
258  }
259 };
260 
261 inline
262 double
264  xyzStripeHashPose *xh,
265  Xform const & xform_to_struct2_start,
266  vector1<Vec> const & pa,
267  vector1<Real> const & radii,
268  Vec const & ori,
269  double const & clash_dis_sq,
270  double const & mindis_approx
271 ){
272  double mindis = mindis_approx;
273  Mat Rori = rotation_matrix_degrees( (ori.z() < -0.99999) ? Vec(1,0,0) : (Vec(0,0,1)+ori.normalized())/2.0 , 180.0 );
274  Vec hash_ori = xform_to_struct2_start.R.transposed() * ori;
275  while ( true ) {
276  CorrectionVisitor visitor(hash_ori,clash_dis_sq);
277  vector1<Real>::const_iterator irad = radii.begin();
278  for ( vector1<Vec>::const_iterator ipa = pa.begin(); ipa != pa.end(); ++ipa,++irad ) {
279  Vec const v = ~xform_to_struct2_start*(Rori*((*ipa)-Vec(0,0,mindis)));
280  xh->visit_lax(v,*irad,visitor);
281  }
282  if ( visitor.contacts == 0 ) {
283  mindis = 9e9;
284  break;
285  }
286  mindis += visitor.correction;
287  if ( fabs(visitor.correction) < 0.001 ) break;
288  }
289  return mindis; // now fixed
290 }
291 
292 double
294  Xform const & xa,
295  Xform const & xb,
296  Vec ori
297 ) const {
298  ori.normalize();
299 
300  // get rotated points
301  utility::vector1<Vec> pa(h1_->natom()), pb(h2_->natom());
302  utility::vector1<Vec>::iterator ipa(pa.begin()),ipb(pb.begin());
303  for ( xyzStripeHashPose::const_iterator i = h1_->begin(); i != h1_->end(); ++i,++ipa ) *ipa = xa*(*i-h1_->translation());
304  for ( xyzStripeHashPose::const_iterator i = h2_->begin(); i != h2_->end(); ++i,++ipb ) *ipb = xb*(*i-h2_->translation());
305  utility::vector1<Real> ra;
306  for ( xyzStripeHashPose::const_iterator i = h1_->begin(); i != h1_->end(); ++i ) ra.push_back(i.radius());
307 
308  double xmx,xmn,ymx,ymn;
309  int xlb,ylb,xub,yub;
310  ObjexxFCL::FArray2D<Vec> ha,hb; // 2D hashes
311 
312  // rotate points, should merge with above
313  Mat rot = rotation_matrix_degrees( (ori.z() < -0.99999) ? Vec(1,0,0) : (Vec(0,0,1)+ori)/2.0 , 180.0 );
314  for ( vector1<Vec>::iterator ia = pb.begin(); ia != pb.end(); ++ia ) *ia = rot*(*ia);
315  for ( vector1<Vec>::iterator ib = pa.begin(); ib != pa.end(); ++ib ) *ib = rot*(*ib);
316 
317  if ( ! get_bounds_intersection(pb,pa,xmx,xmn,ymx,ymn) ) return 9e9;
318 
319  fill_plane_hash(pb,pa,xmx,xmn,ymx,ymn,BIN,ha,hb,xlb,ylb,xub,yub);
320 
321  double const mindis_approx = get_mindis_with_plane_hashes(xlb,ylb,xub,yub,ha,hb,CLD2);
322  if ( fabs(mindis_approx) > 9e8 ) return 9e9;
323 
324  double const mindis = refine_mindis_with_xyzHash(h2_,xb,pa,ra,ori,CLD2,mindis_approx);
325  if ( fabs(mindis) > 9e8 ) return 9e9;
326 
327  return -mindis;
328 }
329 
330 double
332  Xforms const & x1s,
333  Xforms const & x2s,
334  Vec ori
335 ) const {
336  Real t = -9e9;
337  BOOST_FOREACH ( Xform const & x1,x1s ) {
338  BOOST_FOREACH ( Xform const & x2,x2s ) {
339  Real tmp = slide_into_contact(x1,x2,ori);
340  if ( tmp < 9e8 ) t = max(t,tmp);
341  }
342  }
343  return t;
344 }
345 
346 double
348  core::kinematics::Stub const & xa,
349  core::kinematics::Stub const & xb,
350  Vec ori
351 ) const {
352  return slide_into_contact(Xform(xa.M,xa.v),Xform(xb.M,xb.v),ori);
353 }
354 
355 } // namespace sic_dock
356 } // namespace protocols
double dist_score(double const &sqdist, double const &start, double const &stop)
Definition: SICFast.cc:52
Stub class – an object of orthogonal coordinate frame.
Definition: Stub.hh:45
c
DEPRECATED convert between the real-valued chi dihedrals and the rotamer well indices.
void init(core::pose::Pose const &pose1)
Definition: SICFast.cc:85
A molecular system including residues, kinematics, and energies.
Definition: Pose.hh:153
Real lj_radius() const
Lennard-Jones 6-12 potential parameter – atom radius.
Definition: AtomType.hh:135
core::pose::xyzStripeHashPose * h2_
Definition: SICFast.hh:84
bool get_bounds_intersection(vector1< Vec > const &pb, vector1< Vec > const &pa, double &xmx, double &xmn, double &ymx, double &ymn)
Definition: SICFast.cc:139
double slide_into_contact_DEPRICATED(core::kinematics::Stub const &xmob, core::kinematics::Stub const &xfix, Vec ori) const
Definition: SICFast.cc:347
Size n_residue() const
Returns the number of residues in the pose conformation example(s): pose.n_residue() See also: Pose P...
Definition: Pose.cc:760
std::string const & name3() const
Returns this residue's 3-letter representation.
Definition: Residue.hh:1950
Map from Atom identifiers to contained values class.
core::Real Real
Definition: design_utils.cc:74
double slide_into_contact(Xform const &xmob, Xform const &xfix, Vec ori) const
Definition: SICFast.cc:293
numeric::xyzVector< platform::Real > Vec
void fill_plane_hash(vector1< Vec > const &pb, vector1< Vec > const &pa, double const &xmx, double const &xmn, double const &ymx, double const &ymn, double const &BIN, ObjexxFCL::FArray2D< Vec > &ha, ObjexxFCL::FArray2D< Vec > &hb, int &xlb, int &ylb, int &xub, int &yub)
Definition: SICFast.cc:165
void initialize_atomid_map(id::AtomID_Map< T > &atom_map, pose::Pose const &pose)
Initialize an AtomID_Map for a given Pose using the AtomID_Map's current default fill values...
Definition: util.tmpl.hh:260
numeric::xyzMatrix< platform::Real > Mat
Atom identifier class. Defined by the atom number and the residue number.
Definition: AtomID.hh:38
Matrix M
coord frame by 3x3 matrix, each column is a unit vector
Definition: Stub.hh:169
double refine_mindis_with_xyzHash(xyzStripeHashPose *xh, Xform const &xform_to_struct2_start, vector1< Vec > const &pa, vector1< Real > const &radii, Vec const &ori, double const &clash_dis_sq, double const &mindis_approx)
Definition: SICFast.cc:263
static core::Size rot(2)
numeric::xyzVector< platform::Real > Vec
Definition: SICFast.hh:31
double get_mindis_with_plane_hashes(int const &xlb, int const &ylb, int const &xub, int const &yub, ObjexxFCL::FArray2D< Vec > const &ha, ObjexxFCL::FArray2D< Vec > const &hb, double const &clashdis2)
Definition: SICFast.cc:207
std::vector< numeric::xyzVector< core::Real > > xa
Definition: TMalign.cc:65
Definition for functions used in definition of constraints.
Stub class.
routines which calculate solvent accessible surface area
platform::Real Real
Definition: types.hh:35
void visit(numeric::xyzVector< double > const &v, numeric::xyzVector< double > const &c, double, double)
Definition: SICFast.cc:246
core::pose::xyzStripeHashPose * h1_
Definition: SICFast.hh:84
Pose utilities.
A class for defining atom parameters, known as atom_types.
CorrectionVisitor(Vec const &dof_in, Real const &clash_dis_sq_in)
Definition: SICFast.cc:245
Residue const & residue(Size const seqpos) const
Returns the Residue at position (read access) Note: this method will trigger a refold if eit...
Definition: Pose.cc:900
core::Size Size
Definition: design_utils.cc:75
Map from Atom identifiers to contained values class.
numeric::xyzVector< core::Real > t
Definition: TMalign.cc:72
AtomType const & atom_type(int const atomno) const
Returns the AtomType of this residue's atom with index number
Definition: Residue.hh:184
numeric::Xforms Xforms
Vector v
center point by a vector
Definition: Stub.hh:175