Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PoseBalls.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 core/scoring/packing/PoseBalls.cc
11 /// @brief
12 /// @author
13 
14 #include <core/pose/Pose.hh>
15 #include <core/pose/PDBInfo.hh>
19 
20 #include <basic/Tracer.hh>
21 
22 #include <map>
23 
24 // ObjexxFCL headers
25 #include <ObjexxFCL/string.functions.hh>
26 #include <ObjexxFCL/format.hh>
27 
29 #include <core/pose/util.hh>
30 #include <utility/vector1.hh>
31 
32 //Auto Headers
33 #include <core/pose/util.tmpl.hh>
34 
35 namespace core {
36 namespace scoring {
37 namespace packing {
38 
39 /// @details Auto-generated virtual destructor
41 
42 using namespace ObjexxFCL;
43 
44 static basic::Tracer TR("core.scoring.packing.PoseBalls");
45 
46 inline core::Real sqr ( core::Real x ) {
47  return x*x;
48 }
49 
50 // smoothed neighbor is between 9 and 11 A
51 inline core::Real sigmoidish_neighbor( core::Real sqdist ) {
52  if( sqdist > 121.0 ) {
53  return 0.0;
54  } else if( sqdist < 81.0 ) {
55  return 1.0;
56  } else {
57  Real dist = sqrt( sqdist );
58  return sqr(1.0 - sqr( (dist - 9.0) / (11.0 - 9.0) ) );
59  }
60 }
61 
62 /// @details Remove spaces from given string.
64 {
65  std::string trimmed_name( name );
66  left_justify( trimmed_name ); trim( trimmed_name ); // simpler way to dothis?
67  return trimmed_name;
68 }
69 
70 
71 
73  core::pose::Pose const & pose,
74  core::Size Hmode,
75  bool ignore_water
76 )
77 {
78  using namespace numeric;
79 
80  // std::cerr << "PoseBalls.cc:67 (" << pose.total_residue() << ")" << std::endl;
81  ObjexxFCL::FArray1D_char dssp_reduced_secstruct(pose.n_residue());
82  core::scoring::dssp::Dssp(pose).dssp_reduced(dssp_reduced_secstruct);
83 
84  // initialize index and vars
85  core::Size index = 0;
86  Size num_unrec = 0;
87  if( pose.pdb_info() ) num_unrec = pose.pdb_info()->get_num_unrecognized_atoms();
88  balls_ .reserve( pose.total_residue()*5 + num_unrec );
89  index_to_id_.reserve( pose.total_residue()*5 + num_unrec );
90  atom_name_ .reserve( pose.total_residue()*5 + num_unrec );
91  atom_type_ .reserve( pose.total_residue()*5 + num_unrec );
92  atom_parent_.reserve( pose.total_residue()*5 + num_unrec );
93  secstruct_ .reserve( pose.total_residue()*5 + num_unrec );
94  res_name_ .reserve( pose.total_residue()*5 + num_unrec );
95  is_heavy_ .reserve( pose.total_residue()*5 + num_unrec );
96  bfac_ .reserve( pose.total_residue()*5 + num_unrec );
97  core::pose::initialize_atomid_map( id_to_index_, pose );
98  id_to_index_.resize( pose.total_residue() + num_unrec );
99 
100 // std::cerr << "PoseBalls.cc:85 (" << ")" << std::endl;
101 
102  // add atoms in pose
103  core::Size skippedH = 0;
104  for( core::Size ir = 1; ir <= pose.total_residue(); ++ir ) {
105  for( core::Size ia = 1; ia <= pose.residue(ir).natoms(); ++ia ) {
106 // std::cerr << "PoseBalls.cc:91 (" << ")" << std::endl;
107  if( pose.residue(ir).is_virtual(ia) ) continue;
108  if ( Hmode == 0 ) { // no H's
109  if( pose.residue(ir).atom_type(ia).is_hydrogen() ) {
110  skippedH++;
111  continue;
112  }
113  } else if( Hmode == 1 ) { // polar H's only
114  if( pose.residue(ir).atom_type(ia).is_hydrogen() &&
115  !pose.residue(ir).atom_type(ia).is_polar_hydrogen() ) {
116  skippedH++;
117  continue;
118  }
119  } else if( Hmode == 2 ) {
120  ; // all Hs
121  }
122 // std::cerr << "PoseBalls.cc:107 (" << ")" << std::endl;
123  core::id::AtomID aid(ia,ir);
124  id_to_index_[ aid ] = ++index;
125  index_to_id_.push_back( aid );
126  balls_.push_back( Ball( pose.xyz(aid), pose.residue(ir).atom_type(ia).lj_radius() ) );
127  res_name_.push_back(pose.residue(ir).name3());
128  atom_num_.push_back(ia);
129  // if( pose.residue(ir).atom_type(ia).is_polar_hydrogen() ) {
130  // atom_type_.push_back(100+pose.residue(ir).atom_type_index(pose.residue(ir).atom_base(ia)));
131  // } else {
132  atom_type_.push_back(pose.residue(ir).atom_type_index(ia));
133  // }
134  secstruct_.push_back( dssp_reduced_secstruct(ir) );
135  atom_name_.push_back(pose.residue(ir).atom_type(ia).name());
136  if( pose.pdb_info() ) bfac_.push_back( pose.pdb_info()->temperature(ir,ia) );
137  else bfac_.push_back( 0.0 );
138  is_heavy_.push_back( pose.residue(ir).atom_type(ia).is_heavyatom() );
139  if( pose.residue(ir).atom_type(ia).is_hydrogen() /*&&
140  !pose.residue(ir).atom_type(ia).is_polar_hydrogen()*/ )
141  { // if is apolar H, set add surf to base heavy atom rather than H itself
142  core::Size iabase = pose.residue(ir).atom_base(ia);
143  atom_parent_.push_back( id_to_index(core::id::AtomID(iabase,ir)) );
144  } else {
145  atom_parent_.push_back(index);
146  }
147  res_num_.push_back(ir);
148  }
149  }
150 // std::cerr << "PoseBalls.cc:134 (" << ")" << std::endl;
151 
152  // add hetero atoms not in pose
153  // res num is *NOT* necessarially the same as PDBInfo res num!!!!!
155  std::map<core::Size,core::Size> atomcount;
156  std::map<core::Size,core::Size> resnum;
157  core::Size rescount = 0, skippedlig = 0, skippedligH = 0;
158  for( core::Size i = 1; i <= num_unrec; ++i ) {
159  core::pose::UnrecognizedAtomRecord const & a( pose.pdb_info()->get_unrecognized_atoms()[i] );
160  core::Real radius = arm.get_radius(a.atom_name(),a.res_name());
161  if( Hmode < 2 && radius <= 1.2 ) {
162  skippedligH++;
163  continue;
164  }
165  if( radius <= 0.1 ) {
166  skippedlig++;
167  continue;
168  }
169  if( ignore_water ) { // TODO other names for water?
170  if( "HOH" == (a.res_name()) || "DOD" == (a.res_name()) ) {
171  skippedlig++;
172  continue;
173  }
174  }
175  if( resnum.find(a.res_num()) == resnum.end() ) {
176  resnum[a.res_num()] = ++rescount + pose.total_residue();
177  atomcount[a.res_num()] = 0;
178  }
179  id_to_index_.resize( resnum[a.res_num()], pose.pdb_info()->get_unrecognized_res_size(a.res_num()) );
180  core::id::AtomID aid( ++atomcount[a.res_num()], resnum[a.res_num()] );
181  id_to_index_[ aid ] = ++index;
182  index_to_id_.push_back( aid );
183  atom_name_.push_back(a.atom_name());
184  atom_type_.push_back(0);
185  secstruct_.push_back('U');
186  atom_num_.push_back(atomcount[a.res_num()]);
187  atom_parent_.push_back(index);
188  is_heavy_.push_back( radius > 1.3 );
189  res_name_.push_back(a.res_name());
190  res_num_.push_back(resnum[a.res_num()]);
191  bfac_.push_back( a.temp() );
192  balls_.push_back( Ball( a.coords(), radius ) );
193 
194  }
195  nballs_ = index;
196  reset_surf();
197  compute_smooth_nb();
198 }
199 
200 
202 
203  using namespace numeric;
204 
205  // compute NB counts -- no Hs for neighbors
206  smooth_nb_.resize(nballs_);
207  // nbhist_.resize(29);
208  // for( core::Size i = 1; i <= 29; ++i ) nbhist_[i].resize(100,0);
209  for( core::Size i = 1; i <= nballs_; i++ ) smooth_nb_[i] = 0.0;
210  for( core::Size i = 1; i <= nballs_; i++ ) {
211  // if( is_heavy_[i] ) smooth_nb_[i] += 1.0;
212  // else continue;
213  xyzVector<Real> const & ixyz( balls_[i].xyz() );
214  core::Size atype = atom_type_[i];
215  if( atype >= 18 ) {
216  if( 'E'==secstruct_[i] ) atype = 18+3*(atype-18)+0;
217  else if( 'H'==secstruct_[i] ) atype = 18+3*(atype-18)+1;
218  else if( 'L'==secstruct_[i] ) atype = 18+3*(atype-18)+2;
219  else atype = 999;//std::cerr << "secstruct other than H E or L!!!! " << secstruct_[i] << std::endl;
220  }
221  for( core::Size j = 1; j <= nballs_; j++ ) {
222  if( !is_heavy_[j] ) continue;
223  xyzVector<Real> const & jxyz( balls_[j].xyz() );
224  Real const d2( ixyz.distance_squared(jxyz) );
225  if( d2 < 121.0 ) {
226  Real const sn( sigmoidish_neighbor(d2) );
227  smooth_nb_[i] += sn;
228  // smooth_nb_[j] += sn;
229 // if( atype > 29 || atype < 1 ) continue;
230 // if( i==j ) continue;
231 // Real d = sqrt(d2);
232 // for( core::Size idth = 1; idth <= 100; idth++ ) {
233 // Real dth = (Real)(idth) / 10.0;
234 // // std::cerr << "DIST " << d << " " << dth << " " << idth << std::endl;
235 // if( d < dth ) {
236 // nbhist_[atype][idth]++;
237 // break;
238 // }
239 // }
240  }
241  }
242  }
243 }
244 
245 
246 void
247 PoseBalls::output_pdb( std::ostream & out ) const {
248 
249  using namespace ObjexxFCL::fmt;
250 
251  for( Size i = 1; i <= nballs(); i++ ) {
252 
253  out << std::string("ATOM " + I( 5, i ) + " "+LJ(4,atom_name(i))+" "+LJ(3,res_name(i))+" " + " "
254  + I( 4, res_num(i) ) + " "
255  + F( 8, 3, ball(i).x() ) + F( 8, 3, ball(i).y() ) + F( 8, 3, ball(i).z() )
256  + F( 6, 2, 1.0 ) + ' ' + F( 5, 2, ball(i).r() ) ) + "\n";
257  }
258 
259 }
260 
261 
262 
263 } // namespace packing
264 } // namespace scoring
265 } // namespace core