Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
designability_score.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 #include <core/kinematics/Stub.hh>
12 #include <core/pose/Pose.hh>
15 #include <numeric/constants.hh>
16 #include <numeric/xyz.functions.hh>
17 #include <utility/io/izstream.hh>
18 #include <utility/io/ozstream.hh>
19 
20 namespace protocols{
21 namespace sic_dock{
22 
23 using platform::Real;
24 using numeric::min;
25 using numeric::max;
28 
29 void
31  core::kinematics::Stub const & sir,
32  core::kinematics::Stub const & sjr,
33  Real& dx, Real& dy, Real& dz,
34  Real& ex, Real& ey, Real& ez
35 ){
36  Vec d = sir.global2local(sjr.v);
37  dx = d.x();
38  dy = d.y();
39  dz = d.z();
40  Mat R = sir.M.transposed()*sjr.M;
41  // Real ang;
42  // Vec axis = rotation_axis(R,ang);
43  // ang = numeric::conversions::degrees(ang);
44  // std::cout << axis << " " << ang << std::endl;
45 
46  Real phi,psi,theta;
47  if( fabs(R.zx())-1.0 < 0.00001 ) {
48  theta = -asin(R.zx());
49  Real const ctheta = cos(theta);
50  psi = atan2(R.zy()/ctheta,R.zz()/ctheta);
51  phi = atan2(R.yx()/ctheta,R.xx()/ctheta);
52  } else {
53  if( R.zx() < 0.0 ) {
54  theta = numeric::constants::d::pi / 2.0;
55  psi = atan2(R.xy(),R.xz());
56  } else {
57  theta = -numeric::constants::d::pi / 2.0;
58  psi = atan2(-R.xy(),-R.xz());
59  }
60  phi = 0;
61  }
62  ex = psi;
63  ey = theta;
64  ez = phi;
65 }
66 
67 
69  std::string datadir
70 ){
71  hh = new char[16*16*16*24*12*24];
72  he = new char[16*16*16*24*12*24];
73  hl = new char[16*16*16*24*12*24];
74  ee = new char[16*16*16*24*12*24];
75  el = new char[16*16*16*24*12*24];
76  ll = new char[16*16*16*24*12*24];
77  fillarray(hh,datadir+"/hhpb.dat.gz.hist6.dat.gz.bin");
78  fillarray(he,datadir+"/hepb.dat.gz.hist6.dat.gz.bin");
79  fillarray(hl,datadir+"/hlpb.dat.gz.hist6.dat.gz.bin");
80  fillarray(ee,datadir+"/eepb.dat.gz.hist6.dat.gz.bin");
81  fillarray(el,datadir+"/elpb.dat.gz.hist6.dat.gz.bin");
82  fillarray(ll,datadir+"/llpb.dat.gz.hist6.dat.gz.bin");
83  // makebinary(hh,datadir+"/hhpb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
84  // makebinary(he,datadir+"/hepb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
85  // makebinary(hl,datadir+"/hlpb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
86  // makebinary(ee,datadir+"/eepb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
87  // makebinary(el,datadir+"/elpb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
88  // makebinary(ll,datadir+"/llpb.dat.gz.hist6.dat.gz"); // uncomment to gen binary files
89  // utility_exit_with_message("made binary file");
90 }
91 void
93  char *a, std::string fname
94 ){
95  std::cout << "reading " << fname << std::endl;
96  utility::io::izstream in(fname,std::ios::binary);
97  if(!in.good()) utility_exit_with_message("bad file");
98  in.read(a,16*16*16*24*12*24);
99  in.close();
100 }
101 void
103  char *a, std::string fname
104 ){
105  std::cout << "reading " << fname << std::endl;
106  utility::io::izstream in(fname);
107  if(!in.good()) utility_exit_with_message("bad file");
108  for(int i = 0; i < 16*16*16*24*12*24; ++i){
109  float f;
110  in >> f;
111  int tmp = (int)((log(f)+2.5)*12.0);
112  a[i] = (f==0.0f) ? ((char)-127) : ((char)max(-126,min(128,tmp)));
113  // std::cout << f << " " << tmp << " " << (int)a[i] << std::endl;
114  // if( i > 100) utility_exit_with_message("FOO");
115  }
116  in.close();
117  std::cout << "writing: " << fname+".bin.gz" << std::endl;
118  utility::io::ozstream out(fname+".bin",std::ios::out | std::ios::binary);
119  out.write(a,16*16*16*24*12*24);
120  out.close();
121  // std::cout << "writing: " << fname+".txt.gz for testing" << std::endl;
122  // utility::io::ozstream out2(fname+".txt.gz",std::ios::out);
123  // for(int i = 0; i < 16*16*16*24*12*24; ++i) out2 << (int)a[i] << std::endl;
124  // out2.close();
125 }
126 
127 float
129  core::kinematics::Stub const & s1,
130  core::kinematics::Stub const & s2,
131  char ss1, char ss2
132 ) const {
133  using numeric::constants::d::pi_2;
134  if( ss1=='L' || ss2=='L' ) return 0.0;
135  if( s1.global2local(s2.v).length_squared() > 64.0 ) return 0.0;
136  char *a = hh;
137  if( ss1=='E' && ss2=='E' ) a = ee;
138  else if( ss2=='E' || ss1=='E' ) a = he;
139  // if( ss1=='E' && ss2=='E' ) a = ee;
140  // // if( ss1=='L' && ss2=='L' ) a = ll;
141  // else if( ss1=='H' && ss2=='E' || ss1=='E' && ss2=='H' ) a = he;
142  // // if( ss1=='H' && ss2=='L' || ss1=='L' && ss2=='H' ) a = hl;
143  // // if( ss1=='E' && ss2=='L' || ss1=='L' && ss2=='E' ) a = el;
144  Real dx,dy,dz,ex,ey,ez;
145  if((ss1=='E' && ss2=='H') || (ss1=='L' && ss2=='H') || (ss1=='L' && ss2=='E')){
146  get_xform_stats(s2,s1,dx,dy,dz,ex,ey,ez); // reverse
147  } else get_xform_stats(s1,s2,dx,dy,dz,ex,ey,ez);
148  int idx = dx+8.0; // 0.0-0.999 -> 10
149  int idy = dy+8.0;
150  int idz = dz+8.0;
151  int iex = ex/pi_2*24.0 + 12.0;
152  int iey = ey/pi_2*24.0 + 6.0;
153  int iez = ez/pi_2*24.0 + 12.0;
154  int index = idx + 16*idy + 16*16*idz + 16*16*16*iex + 16*16*16*24*iey + 16*16*16*24*12*iez;
155  if( 0 > index || index >= 16*16*16*24*12*24 ) utility_exit_with_message("FOO");
156  // expensive memory lookup
157  char val = a[index];
158  //
159  // std::cout << (int)val << "'" << val << "'"<< std::endl;
160  return val == -127 ? 0.0 : min(10.0,exp(((float)val)/12.0-2.5));
161  // return val == -127 ? -15.0 : ((float)val)/12.0;
162 }
163 
164 float
166  core::pose::Pose const & pose,
167  platform::Size rsd1,
168  platform::Size rsd2
169 ) const {
170  if(!pose.residue(rsd1).is_protein()) return 0.0;
171  if(!pose.residue(rsd2).is_protein()) return 0.0;
172  if(!pose.residue(rsd1).has("CB")) return 0.0;
173  if(!pose.residue(rsd2).has("CB")) return 0.0;
174  Vec CBi = pose.residue(rsd1).xyz("CB");
175  Vec CAi = pose.residue(rsd1).xyz("CA");
176  Vec Ni = pose.residue(rsd1).xyz( "N");
177  core::kinematics::Stub sir(CBi,CAi,Ni);
178  Vec CBj = pose.residue(rsd2).xyz("CB");
179  Vec CAj = pose.residue(rsd2).xyz("CA");
180  Vec Nj = pose.residue(rsd2).xyz( "N");
181  if( CBi.distance_squared(CBj) > 64.0 ) return 0.0;
182  core::kinematics::Stub sjr(CBj,CAj,Nj);
183  return score(sir,sjr,pose.secstruct(rsd1),pose.secstruct(rsd2));
184 }
185 
186 float
188  core::pose::Pose & pose,
189  bool compute_ss
190 ) const {
191  if(compute_ss){
192  core::scoring::dssp::Dssp dssp(pose);
193  dssp.insert_ss_into_pose(pose);
194  }
195  float tot_score = 0.0;
196  for(platform::Size ir = 1; ir <= pose.n_residue(); ++ir){
197  for(platform::Size jr = ir+1; jr <= pose.n_residue(); ++jr){
198  float s1 = score(pose,ir,jr);
199  float s2 = score(pose,jr,ir);
200  // if( s1 < 0.0f ) std::cout << s1 << std::endl;
201  // if( s2 < 0.0f ) std::cout << s2 << std::endl;
202  tot_score += s1;
203  tot_score += s2;
204  }
205  }
206  return tot_score;
207 }
208 float
210  core::pose::Pose const & pose
211 ) const {
212  float tot_score = 0.0;
213  for(platform::Size ir = 1; ir <= pose.n_residue(); ++ir){
214  for(platform::Size jr = ir+1; jr <= pose.n_residue(); ++jr){
215  float s1 = score(pose,ir,jr);
216  float s2 = score(pose,jr,ir);
217  // if( s1 < 0.0f ) std::cout << s1 << std::endl;
218  // if( s2 < 0.0f ) std::cout << s2 << std::endl;
219  tot_score += s1;
220  tot_score += s2;
221  }
222  }
223  return tot_score;
224 }
225 
226 
227 } // end namespace sic_dock
228 } // end namespace protocols