Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compute_sasa.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 core/scoring/packstat/compute_sasa.hh
11 ///
12 /// @brief
13 /// @author will sheffler
14 
15 
16 #ifndef INCLUDED_core_scoring_packstat_compute_sasa_hh
17 #define INCLUDED_core_scoring_packstat_compute_sasa_hh
18 
22 
23 #include <core/types.hh>
24 #include <core/pose/Pose.fwd.hh>
25 // AUTO-REMOVED #include <core/id/AtomID_Map.hh>
26 
27 #include <utility/pointer/owning_ptr.hh>
28 #include <utility/pointer/ReferenceCount.hh>
29 
30 #include <numeric/constants.hh>
31 #include <numeric/trig.functions.hh>
32 
33 // AUTO-REMOVED #include <ObjexxFCL/ObjexxFCL.hh>
34 #include <ObjexxFCL/ubyte.hh>
35 // AUTO-REMOVED #include <ObjexxFCL/FArray3D.hh>
36 #include <ObjexxFCL/FArray2D.hh>
37 #include <ObjexxFCL/Fmath.hh>
38 
39 // AUTO-REMOVED #include <map>
40 
42 #include <utility/vector1.hh>
43 
44 
45 
46 namespace core {
47 namespace scoring {
48 namespace packstat {
49 
50  namespace old {
51 
52  // this lookup table is used in sasa computation (also in void.cc)
53  extern short const bit_count[];
54 
55  extern int const nbytes;
56  extern int const nphi;
57  extern int const ntheta;
58  extern int const nolp;
59  extern int const nori;
60  extern int const maskbits;
61 
62  extern ObjexxFCL::FArray2D_int angles;
63  extern ObjexxFCL::FArray2D_ubyte masks;
64 
65  ///cj Reads in sampling/SASA-angles.dat sampling/SASA-masks.dat
66  void input_sasa_dats();
67 
68  ///cj getting overlap from a to b (or i to j, see below)
69  ///cj this returns the degree of overlap between two atoms
70  ///cj adapted from erics code in area.c GetD2
71  ///cj returns value from 1 to 100
72  ///cj This calculation is based on the law of cosines,
73  ///cj see LeGrand and Merz, Journal of Computational
74  ///cj Chemistry 14(3):349-52 (1993).
75  ///cj Note that equation (4) is wrong, the denominator
76  ///cj should be 2r r instead of 2r r
77  ///cj i iq i q
78  inline
79  void
81  //Vector const & a,
82  //FArray1_float const & a,
83  PackstatReal const ra,
84  //Vector const & b,
85  PackstatReal const rb,
86  PackstatReal const dist,
87  int & olp
88  )
89  {
90  PackstatReal epsilon,costh;
91 
92  //cj min distance cutoff
93  epsilon = 0.01;
94 
95  if ( dist < epsilon ) {
96  //cj atoms too close, causes round off error
97  //cj use this cutoff
98  if ( ra < rb ) {
99  olp = 100;
100  } else {
101  olp = 1;
102  }
103  } else if ( rb+dist <= ra ) {
104  //cj If atom a completely engulfs atom b, consider a to have
105  //cj no overlap due to atom b.
106  olp = 1;
107  } else if ( rb+dist <= ra ) {
108  //cj If atom a is completely engulfed by atom b, then turn it
109  //cj completely off (i.e. d2 = 99).
110  olp = 100;
111  } else {
112  //cj Otherwise, compute the amount of overlap using the law of cosines.
113  //cj "costh" is the angle of the cone of intersection that atom b
114  //cj imposes on atom a. "ra" is the radius of atom a, and "rb" is
115  //cj the radius of atom b. "sqrtd" is the actual distance between
116  //cj the a and b centers, while "dist" is the square of this distance.
117  costh = (ra*ra+dist*dist-rb*rb)/(2*ra*dist);
118  olp = static_cast< int >((1.0f-costh)*50)+1;
119  if ( olp > 100 ) {
120  olp = 100;
121  } else if ( olp < 0 ) {
122  //cj We already hopefully accounted for this possibility by requiring that
123  //cj dist < epsilon, but in case not we don't want a potential bug to go
124  //cj unnoticed.
125  // TRcs << "problem in calculating overlap between:" << std::endl;
126  // TRcs << "a " <<
127  // F( 7, 3, a(1) ) << ' ' << F( 7, 3, a(2) ) << ' ' << F( 7, 3, a(3) ) <<
128  // std::endl;
129  // TRcs << "b " <<
130  // F( 7, 3, b(1) ) << ' ' << F( 7, 3, b(2) ) << ' ' << F( 7, 3, b(3) ) <<
131  // std::endl;
132  // TRcs << "ra=" << SS( ra ) << std::endl;
133  // TRcs << "rb=" << SS( rb ) << std::endl;
134  // TRcs << "dist=" << SS( dist ) << std::endl;
135  // TRcs << "costh=" << SS( costh ) << std::endl;
136  // TRcs << "Teminiating calculation" << std::endl;
137  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
138  }
139  }
140  }
141 
142  ///cj gets the orientation of a to b (i to j, see below)
143  ///cj does this by calculating two angles, aphi and theta
144  inline
145  void
147  XYZ const & a,
148  XYZ const & b,
149  //FArray1_float const & a,
150  //FArray1_float const & b,
151  int & aphi,
152  int & theta,
153  PackstatReal dist
154  )
155  {
156  using namespace numeric::constants::d;
157  using numeric::sin_cos_range;
158 
159  // pb -- static can cause problems in multi-threading
160  //apl allocate this once only
161  //static FArray1D_float diff( 3 );
162  XYZ diff( ( a - b ) / dist );
163 
164  //cj figure the difference between a and b
165  //apl - You've already computed the distance! reuse it.
166  //diff(1) = (a(1)-b(1) ) / dist;
167  //diff(2) = (a(2)-b(2) ) / dist;
168  //diff(3) = (a(3)-b(3) ) / dist;
169 
170  //cj now figure out polar values of aphi and theta
171  //cj Normalize the difference
172  //cj first get the length of the vector
173  //vector_normalize(diff);
174 
175  //cj figuring aphi
176 
177  PackstatReal p = std::acos( sin_cos_range( diff(3) ) );
178 
179  p *= nphi / pi_2;
180  aphi = static_cast< int >( p );
181  ++aphi; // for fortran goes from 1 to n
182  if ( aphi > nphi ) aphi = 1;
183 
184  //cj figuring theta
185  PackstatReal t = std::atan2(diff(2),diff(1));
186  t *= ntheta / pi_2;
187  theta = static_cast< int >( t );
188  ++theta; // for fortran goes from 1 to n
189  if ( theta < 1 ) {
190  theta += ntheta;
191  } else if ( theta > ntheta ) {
192  theta = 1;
193  }
194 
195  }
196 
197  } // end namespace old
198 
199 
200 
201  using core::pose::Pose;
202  using core::Real;
203  using utility::vector1;
204 
206  SasaResult(size_t Nprobes, size_t Nspheres);
207  ObjexxFCL::FArray2D<PackstatReal> sphere_sasa;
209  // utility::vector1<numeric::xyzVector<PackstatReal> > sasa_centers;
210  };
211 
213  SasaOptions();
228  };
229 
232 
235  core::Real volume,surface_area,surface_accessibility;
237  };
238  struct OrderCBC {
239  bool operator() ( CavityBallCluster const & a, CavityBallCluster const & b ) {
240  return a.volume > b.volume;
241  }
242  };
243 
244 
245  PosePackData
247  core::pose::Pose const & pose,
248  int include_water = -1
249  );
250 
252  Spheres & spheres,
253  SasaOptions const & opts
254  );
255 
256  CavBalls
258  CavBalls & cavballs,
259  SasaOptions const & opts
260  );
261 
262  CavBalls
264  Spheres & spheres,
265  CavBalls & cavballs,
266  SasaOptions const & opts
267  );
268 
269  void
271  CavBalls & cavballs,
272  SasaOptions const & opts
273  );
274 
275  void
277  Spheres & spheres,
278  CavBalls & cavballs,
279  PackstatReal dis
280  );
281 
284  CavBalls & cavballs,
285  SasaOptions const & opts
286  );
287 
288 
291  XYZ const & xyz,
292  Spheres & spheres, // assumes spheres is sorted on x!
293  SasaResultOP result,
294  SasaOptions const & opts
295  );
296 
297  CavBalls
299  CavBalls cavballs,
300  PackstatReal spacing
301  );
302 
303 
304  core::Real
306  PosePackData & pd,
307  core::Size oversample = 0
308  );
309 
310  core::Real
312  Pose const & pose,
313  core::Size oversample = 0
314  );
315 
318  PosePackData & pd,
319  core::Size oversample = 0
320  );
321 
324  Pose const & pose,
325  core::Size oversample = 0
326  );
327 
328  core::Real
330  PosePackData & pd,
331  int const seqpos,
332  core::Size oversample = 0
333  );
334 
335  core::Real
337  Pose const & pose,
338  int const seqpos,
339  core::Size oversample = 0
340  );
341 
342  // std::pair<core::Real,core::Real>
343  // compute_packing_scores(
344  // PosePackData & pd,
345  // core::Size oversample = 0
346  // );
347  //
348  // std::pair<core::Real,core::Real>
349  // compute_packing_scores(
350  // Pose const & pose,
351  // core::Size oversample = 0
352  // );
353 
356  PosePackData & pd,
357  core::Size oversample = 0
358  );
359 
362  Pose const & pose,
363  core::Size oversample = 0
364  );
365 
366  //std::map<id::AtomID,Real>
367  //cavity_distance_constraint( Pose & pose, Size rsd );
368 
369  template< class T >
371  using namespace core;
372  using namespace numeric;
373  using namespace utility;
374  using namespace old;
375 
376  input_sasa_dats();
377 
378  int olp, aphi, theta, point, masknum;
379 
380  Size const Nspheres( S.size() );
381  ObjexxFCL::FArray2D_ubyte atom_sasa_masks( old::nbytes, Nspheres, NULL );
382 
383  for( size_t i = 1; i <= Nspheres; ++i ) {
384  for( size_t j = 1; j < i; ++j ) {
385  PackstatReal const dist_sq = S[i].xyz.distance_squared(S[j].xyz);
386  PackstatReal const dth = S[i].radius+S[j].radius+2*probe;
387  if ( dist_sq > dth*dth ) continue;
388  if ( dist_sq <= 0.0 ) continue;
389  PackstatReal const dist = std::sqrt(dist_sq);
390  PackstatReal const irad = S[i].radius + probe;
391  PackstatReal const jrad = S[j].radius + probe;
392  // account for j overlapping i:
393  get_overlap(irad,jrad,dist,olp);
394  get_orientation(S[i].xyz,S[j].xyz,aphi,theta,dist);
395  point = angles(aphi,theta);
396  masknum = point*100+olp;
397  for ( int bb = 1, l = atom_sasa_masks.index(bb,i); bb <= nbytes; ++bb, ++l ) {
398  atom_sasa_masks[ l ] = ObjexxFCL::bit::bit_or( atom_sasa_masks[ l ], masks(bb,masknum) );
399  }
400  // account for i overlapping j:
401  get_overlap(jrad,irad,dist,olp);
402  get_orientation(S[j].xyz,S[i].xyz,aphi,theta,dist);
403  point = angles(aphi,theta);
404  masknum = point*100+olp;
405  for ( int bb = 1, l = atom_sasa_masks.index(bb,j); bb <= nbytes; ++bb, ++l ) {
406  atom_sasa_masks[ l ] = ObjexxFCL::bit::bit_or( atom_sasa_masks[ l ], masks(bb,masknum) );
407  }
408  } // sphere j
409  } // sphere i
410 
411  // compute sasas
412  PackstatReal total = 0.0;
413  PackstatReal fraction,total_sa,expose;
414  for( size_t is = 1; is <= Nspheres; ++is ) {
415  PackstatReal const irad = S[is].radius;
416  int ctr = 0;
417  for ( size_t bb = 1, l = atom_sasa_masks.index(bb,is); (int)bb <= nbytes; ++bb, ++l ) {
418  ctr += bit_count[atom_sasa_masks[ l ]];
419  }
420  fraction = static_cast< PackstatReal >( ctr ) / maskbits;
421  if( csa ) total_sa = 4.0 * numeric::constants::d::pi * ( irad * irad ); // 4*pi*r**2 -- this is M.S.A, not SASA
422  else total_sa = 4.0 * numeric::constants::d::pi * ( (irad+probe) * (irad+probe) ); // 4*pi*r**2 -- this is M.S.A, not SASA
423  expose = ( 1.0f - fraction ) * total_sa;
424  S[is].sasa = expose;
425  total += expose;
426  } // is
427 
428  return total;
429 
430  }
431 
432 
433  void output_packstat_pdb( core::pose::Pose & pose, std::ostream & out );
434 
435 
436 } // namespace packstat
437 } // namespace scoring
438 } // namespace core
439 
440 #endif // INCLUDED_core_scoring_packstat_compute_sasa_HH