Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChargeGrid.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 src/protocols/qsar/scoring_grid/ChargeGrid.cc
11 /// @author Sam DeLuca
12 /// @brief This is an implementation of equation 3 in Goodford, J. Med. Chem. 1985,28,849-857. doi:10.1021/jm00145a002
13 
17 
18 #include <core/pose/Pose.hh>
19 #include <core/pose/util.hh>
21 
22 #include <utility/tag/Tag.hh>
23 #include <utility/tools/make_vector.hh>
24 #include <utility/json_spirit/json_spirit_value.h>
25 
26 #include <numeric/xyz.json.hh>
27 
28 #include <boost/math/constants/constants.hpp>
29 
30 
31 
32 namespace protocols {
33 namespace qsar {
34 namespace scoring_grid {
35 
36 utility::json_spirit::Value ChargeAtom::serialize()
37 {
38  using utility::json_spirit::Value;
39  using utility::json_spirit::Pair;
40 
41  Pair xyz_record("xyz",numeric::serialize(xyz));
42  Pair nc_record("nc",Value(static_cast<boost::uint64_t>(neighbor_count)));
43  Pair charge_record("charge",Value(charge));
44 
45  return Value(utility::tools::make_vector(xyz_record,nc_record,charge_record));
46 
47 }
48 
49 void ChargeAtom::deserialize(utility::json_spirit::mObject data)
50 {
51  charge = data["charge"].get_real();
52  neighbor_count = data["nc"].get_int();
53  xyz = numeric::deserialize<core::Real>(data["xyz"].get_array());
54 }
56 {
58 }
59 
61 {
62  GridBaseOP charge_grid = new ChargeGrid();
63  charge_grid->parse_my_tag(tag);
64  return charge_grid;
65 }
66 
68 {
69 
70  return new ChargeGrid();
71 }
72 
73 
75 {
76  return "ChargeGrid";
77 }
78 
80  SingleGrid("ChargeGrid"),
81  zeta_(4.0),
82  epsilon_(80.0),
83  indirect_numerator_( (4.0 - 80.0) / (4.0 + 80.0) ),
84  epsilon_0_(8.854187817E-12)
85 {
86  //
87 }
88 
90  SingleGrid("ChargeGrid"),
91  zeta_(4.0),
92  epsilon_(80),
93  indirect_numerator_( (4.0 - 80.0) / (4.0 + 80.0) ),
94  epsilon_0_(8.854187817E-12)
95 {
96  //
97 }
98 
99 utility::json_spirit::Value ChargeGrid::serialize()
100 {
101  using utility::json_spirit::Value;
102  using utility::json_spirit::Pair;
103 
104  Pair base_data("base_data",SingleGrid::serialize());
105 
106  std::vector<Value> charge_atom_data;
107  for(std::list<ChargeAtom>::iterator it = charge_atom_list_.begin(); it != charge_atom_list_.end();++it)
108  {
109  charge_atom_data.push_back(it->serialize());
110  }
111 
112  Pair charge_atom_record("atoms",charge_atom_data);
113  return Value(utility::tools::make_vector(charge_atom_record,base_data));
114 
115 }
116 
117 void ChargeGrid::deserialize(utility::json_spirit::mObject data)
118 {
119 
120  charge_atom_list_.clear();
121  utility::json_spirit::mArray charge_atom_data(data["atoms"].get_array());
122  for(utility::json_spirit::mArray::iterator it = charge_atom_data.begin(); it != charge_atom_data.end();++it)
123  {
124  ChargeAtom current_atom;
125  current_atom.deserialize(it->get_obj());
126  charge_atom_list_.push_back(current_atom);
127  }
128 
129  SingleGrid::deserialize(data["base_data"].get_obj());
130 
131 }
132 
134 {
135 
136  setup_charge_atoms(pose);
137 
139  for(core::Size x_index =0; x_index < dimensions.x(); ++x_index)
140  {
141  for(core::Size y_index = 0; y_index < dimensions.y(); ++y_index)
142  {
143  for(core::Size z_index = 0; z_index < dimensions.z(); ++z_index)
144  {
145 
146  core::Vector pdb_coords(get_pdb_coords(x_index,y_index,z_index));
148  //first loop through the charge atoms to calculate neighbor count
149  //Maybe we should use a b-tree to do atom count calculation but it might not be worth the effort
150  std::list<ChargeAtom>::iterator protein_charge_atom_it = charge_atom_list_.begin();
151  for(; protein_charge_atom_it != charge_atom_list_.end(); ++protein_charge_atom_it)
152  {
153  if(protein_charge_atom_it->xyz.distance(pdb_coords) <= 4.0)
154  {
155  ++neighbor_count;
156  }
157  if(neighbor_count >= 12)
158  {
159  break;
160  }
161  }
162 
163  //dummy charge value is ignored on the grid atom side during
164  //el calculations. fix this later
165  ChargeAtom grid_charge_atom(pdb_coords,0.0,neighbor_count);
166 
167  //second loop through the charge atoms to calculate charge
168  protein_charge_atom_it = charge_atom_list_.begin();
169  core::Real total_el = 0.0;
170  for(; protein_charge_atom_it != charge_atom_list_.end(); ++protein_charge_atom_it)
171  {
172  total_el += charge_charge_electrostatic(pose,*protein_charge_atom_it,grid_charge_atom);
173  }
174 
175  set_point(pdb_coords,total_el);
176 
177  }
178  }
179  }
180 }
181 
182 void ChargeGrid::refresh(core::pose::Pose const & pose, core::Vector const & center, core::Size const & )
183 {
184  refresh(pose,center);
185 }
186 
188 {
189  refresh(pose,center);
190 }
191 
192 
194 {
195 
196 }
197 
198 core::Real ChargeGrid::score(core::conformation::Residue const & residue, core::Real const max_score, qsarMapOP /*qsar_map*/)
199 {
200  core::Real score = 0.0;
201  for(core::Size atom_index = 1; atom_index <= residue.natoms() && score < max_score; ++atom_index )
202  {
203  core::Vector const & atom_coord(residue.xyz(atom_index));
204  if(this->get_grid().is_in_grid(atom_coord.x(),atom_coord.y(),atom_coord.z()))
205  {
206  core::Real protein_charge = this->get_point(atom_coord.x(),atom_coord.y(),atom_coord.z());
207 
208 
209 
210  score += protein_charge*residue.atomic_charge(atom_index);
211  }
212  }
213  return score;
214 }
215 
217 {
218  core::Vector const & atom_coord(residue.xyz(atomno));
219  if(this->get_grid().is_in_grid(atom_coord.x(),atom_coord.y(),atom_coord.z()))
220  {
221  core::Real protein_charge = this->get_point(atom_coord.x(),atom_coord.y(),atom_coord.z());
222  return protein_charge*residue.atomic_charge(atomno);
223  }else
224  {
225  return 0;
226  }
227 }
228 
230 {
231  switch(n_atoms)
232  {
233  case 7:
234  return(0.4);
235  break;
236  case 8:
237  return(0.9);
238  break;
239  case 9:
240  return(1.4);
241  break;
242  case 10:
243  return(1.9);
244  break;
245  case 11:
246  return(2.6);
247  break;
248  default:
249  if(n_atoms <= 6)
250  {
251  return(0.0);
252  }else if(n_atoms >= 12)
253  {
254  return(4.0);
255  }else
256  {
257  utility_exit_with_message("This should never have happened");
258  }
259  break;
260  }
261  return(-1.0); //Something has gone rather wrong
262 }
263 
264 core::Real ChargeGrid::charge_charge_electrostatic(core::pose::Pose const & /*pose*/, ChargeAtom const & atom_q, ChargeAtom const & atom_p) const
265 {
266  core::Real distance = atom_q.xyz.distance(atom_p.xyz);
269 
270  assert(s_p >= 0);
271  assert(s_q >= 0);
272 
273  core::Real direct_term = ((atom_q.charge)/(4*boost::math::constants::pi<core::Real>()*epsilon_0_*distance) *zeta_);
274  core::Real indirect_term = (1.0/distance) + (indirect_numerator_ / std::sqrt(distance*distance + 4*s_p*s_q));
275  return direct_term*indirect_term;
276 
277 }
278 
279 
281 {
283  core::Size chain_begin = pose.conformation().chain_begin(chain_id);
284  core::Size chain_end = pose.conformation().chain_end(chain_id);
285 
286  for(core::Size current_residue_index = chain_begin; current_residue_index <= chain_end; ++current_residue_index)
287  {
288  core::conformation::Residue current_residue = pose.residue(current_residue_index);
289  for(core::Size current_atom_index = 1; current_atom_index <= current_residue.natoms();++current_atom_index)
290  {
291  core::id::AtomID current_atom_id(current_atom_index,current_residue_index);
292  core::Vector current_atom_coords(pose.xyz(current_atom_id));
293  core::Real current_atom_charge = current_residue.atomic_charge(current_atom_index);
294  core::Size current_atom_neighbor_count = 0;
295 
296  for(core::Size neighbor_residue_index = chain_begin; neighbor_residue_index <= chain_end; ++neighbor_residue_index)
297  {
298  //calculate neighbors within 12 A. stop counting after 12 since thats where the lookup table cuts off.
299  core::conformation::Residue neighbor_residue = pose.residue(neighbor_residue_index);
300  for(core::Size neighbor_atom_index = 1; neighbor_atom_index <= neighbor_residue.natoms();++neighbor_atom_index)
301  {
302  core::id::AtomID neighbor_atom_id(neighbor_atom_index,neighbor_residue_index);
303  core::Vector neighbor_atom_coords(pose.xyz(neighbor_atom_id));
304  if(neighbor_atom_coords.distance(neighbor_atom_coords) <= 4.0)
305  {
306  current_atom_neighbor_count++;
307  }
308 
309  if(current_atom_neighbor_count >= 12)
310  {
311  break;
312  }
313  }
314  charge_atom_list_.push_back(ChargeAtom(current_atom_coords,current_atom_charge,current_atom_neighbor_count));
315  }
316  }
317  }
318 }
319 
320 }
321 }
322 }
323