Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DarcElectrostatics.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 protocols/pockets/Fingerprint.cc
11 /// @brief protocols::pockets::Fingerprint functions
12 /// @author Ragul Gowthaman
13 
14 // Protocol Headers
15 #include <numeric/constants.hh>
18 // AUTO-REMOVED #include <core/init.hh>
19 
20 // Core Headers
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/OptionKeys.hh>
23 #include <basic/options/keys/fingerprint.OptionKeys.gen.hh>
24 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
25 #include <core/pose/Pose.hh>
26 // AUTO-REMOVED #include <core/pose/PDBInfo.hh>
27 #include <core/id/AtomID_Map.hh>
31 #include <core/types.hh>
32 #include <numeric/xyz.functions.hh>
33 #include <numeric/xyzMatrix.hh>
34 #include <numeric/conversions.hh>
35 #include <utility/io/ozstream.hh>
36 
37 // Utility Headers
38 #include <iostream>
39 #include <iomanip>
40 #include <fstream>
41 #include <ostream>
42 #include <string>
43 #include <sstream>
44 #include <cmath>
45 #include <map>
46 
47 #include <utility/vector1.hh>
48 
49 //Auto Headers
50 #include <numeric/random/random.fwd.hh>
51 
52 using namespace core;
53 using namespace core::scoring;
54 using namespace std;
55 
56 
57 namespace protocols {
58 namespace pockets {
59 
60 DarcElectrostaticsBase::DarcElectrostaticsBase () :
61  ReferenceCount()
62 {}
63 
64 
65 
66 void DelphiElectrostatics::setup_from_DelphiGrid( std::string const & input_filename, Size const & esp_grid_size, core::Real const & esp_grid_spacing, core::Real const & esp_grid_midpoint_x, core::Real const & esp_grid_midpoint_y, core::Real const & esp_grid_midpoint_z) {
67 
68  utility::vector1<core::Real> grid_point(4);
69 
70  grid_spacing_ = esp_grid_spacing;
71  core::Real midpoint_x = esp_grid_midpoint_x;
72  core::Real midpoint_y = esp_grid_midpoint_y;
73  core::Real midpoint_z = esp_grid_midpoint_z;
74  Size height = esp_grid_size;
75  Size width = esp_grid_size;
76  Size depth = esp_grid_size;
77 
78  std::string line;
79  ifstream inFile(input_filename.c_str());
80  if (!inFile) {
81  std::cout<< "Can't open input file " << input_filename << std::endl;
82  exit(1);
83  }
84 
85  //intialize electrostatic potential grid
86  std::vector < std::vector < std::vector <core::Real> > > esp_grid;
87  esp_grid.resize(height);
88  for( Size i=0; i<height; ++i){
89  esp_grid[i].resize(width);
90  for (Size j =0; j<width; ++j)
91  esp_grid[i][j].resize(depth);
92  }
93 
94  /*
95  for( Size i=1; i<=height; ++i){
96  for( Size j=1; j=<width; ++j){
97  for( Size k=1; k<=depth; ++k){
98  inFile >> esp_grid[i][j][k];
99  }
100  }
101  }
102  */
103 
104  for( Size i=1; i<=height; ++i){
105  // grid_point.x() = i * grid_spacing_ + ( midpoint_x - ( ((height+1)/2) * grid_spacing_) );
106  grid_point[1] = i * grid_spacing_ + midpoint_x;
107  for( Size j=1; j<=width; ++j){
108  grid_point[2] = j * grid_spacing_ + midpoint_y;// - ( ((width+1)/2) * grid_spacing_) );
109  for( Size k=1; k<=depth; ++k){
110  grid_point[3] = k * grid_spacing_ + midpoint_z;// - ( ((depth+1)/2) * grid_spacing_) );
111  inFile >> grid_point[4];
112  esp_grid_point_list_.push_back(grid_point);
113  }
114  }
115  }
116 
117 
118 
119  //DUMP ESP_GRID TO A PDB FILE
120  utility::io::ozstream outPDB_stream;
121  outPDB_stream.open("esp_grid.pdb", std::ios::out);
122  core::Size count =0;
123  for (std::list< utility::vector1<core::Real> >::const_iterator pd = esp_grid_point_list_.begin(); pd != esp_grid_point_list_.end(); ++pd) {
124  ++count;
125  outPDB_stream<<"HETATM"<<std::setw(5)<<count<<" C ESP A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<pd->at(1)<<std::setw(8)<<std::fixed<<std::setprecision(3)<<pd->at(2)<<std::setw(8)<<std::fixed<<std::setprecision(3)<<pd->at(3)<<" "<<std::setw(6)<<std::fixed<<std::setprecision(2)<<pd->at(4)<<std::endl;
126  }
127  outPDB_stream.close();
128  outPDB_stream.clear();
129  //END DUMP PDB FILE
130  }
131 
133  //trilinear_interpolation
134 
135  core::Size lig_res_num = 0;
136  for ( int j = 1, resnum = ligand_pose.total_residue(); j <= resnum; ++j ) {
137  if (!ligand_pose.residue(j).is_protein()){
138  lig_res_num = j;
139  break;
140  }
141  }
142  if (lig_res_num == 0){
143  std::cout<<"Error, no ligand to Calculate Electrostatic energy" << std::endl;
144  exit(1);
145  }
146 
147  //DUMP ligand_GRID TO A PDB FILE
148  utility::io::ozstream outPDB_stream;
149  outPDB_stream.open("lig_grid.pdb", std::ios::out);
150 
151 
152  core::Real x0,y0,z0,x1,y1,z1,x_d,y_d,z_d,V_000,V_100,V_010,V_110,V_001,V_101,V_011,V_111,c_00,c_10,c_01,c_11,c_0,c_1,c;
153  core::Real E_energy(0.);
155  conformation::Residue const & curr_rsd = ligand_pose.conformation().residue(lig_res_num);
156  for(Size i = 1, i_end = curr_rsd.nheavyatoms(); i <= i_end; ++i) {
157  ligand.x() = curr_rsd.atom(i).xyz()(1);
158  ligand.y() = curr_rsd.atom(i).xyz()(2);
159  ligand.z() = curr_rsd.atom(i).xyz()(3);
160 
161  x0 = (static_cast<int>(ligand.x()/grid_spacing_))*grid_spacing_;
162  y0 = (static_cast<int>(ligand.y()/grid_spacing_))*grid_spacing_;
163  z0 = (static_cast<int>(ligand.z()/grid_spacing_))*grid_spacing_;
164  x1 = x0 + grid_spacing_;
165  x1 = y0 + grid_spacing_;
166  x1 = z0 + grid_spacing_;
167 
168  x_d = (ligand.x() - x0)/(x1 - x0);
169  y_d = (ligand.y() - y0)/(y1 - y0);
170  z_d = (ligand.z() - z0)/(z1 - z0);
171  for (std::list< utility::vector1<core::Real> >::const_iterator pd = esp_grid_point_list_.begin(); pd != esp_grid_point_list_.end(); ++pd) {
172  if (pd->at(1) == x0 && pd->at(2)== y0 && pd->at(3) == z0 ) V_000 = pd->at(4);
173  if (pd->at(1) == x1 && pd->at(2)== y0 && pd->at(3) == z0 ) V_100 = pd->at(4);
174  if (pd->at(1) == x0 && pd->at(2)== y1 && pd->at(3) == z0 ) V_010 = pd->at(4);
175  if (pd->at(1) == x1 && pd->at(2)== y1 && pd->at(3) == z0 ) V_110 = pd->at(4);
176  if (pd->at(1) == x0 && pd->at(2)== y0 && pd->at(3) == z1 ) V_001 = pd->at(4);
177  if (pd->at(1) == x1 && pd->at(2)== y1 && pd->at(3) == z0 ) V_101 = pd->at(4);
178  if (pd->at(1) == x0 && pd->at(2)== y1 && pd->at(3) == z1 ) V_011 = pd->at(4);
179  if (pd->at(1) == x1 && pd->at(2)== y1 && pd->at(3) == z1 ) V_111 = pd->at(4);
180  }
181 
182  c_00 = (V_000 * (1 - x_d)) + (V_100 * x_d);
183  c_10 = (V_010 * (1 - x_d)) + (V_110 * x_d);
184  c_01 = (V_001 * (1 - x_d)) + (V_101 * x_d);
185  c_11 = (V_011 * (1 - x_d)) + (V_111 * x_d);
186  c_0 = (c_00 * (1 - y_d)) + (c_10 * y_d);
187  c_1 = (c_01 * (1 - y_d)) + (c_11 * y_d);
188  c = (c_0 * (1 - z_d)) + (c_1 * z_d);
189  E_energy += c * curr_rsd.atomic_charge(i);
190 
191  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0<<std::endl;
192  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0<<std::endl;
193  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0<<std::endl;
194  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0+grid_spacing_<<std::endl;
195  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0<<std::endl;
196  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0+grid_spacing_<<std::endl;
197  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0+grid_spacing_<<std::endl;
198  outPDB_stream<<"HETATM"<<std::setw(5)<<1<<" C GRD A 1 "<<std::setw(8)<<std::fixed<<std::setprecision(3)<<x0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<y0+grid_spacing_<<std::setw(8)<<std::fixed<<std::setprecision(3)<<z0+grid_spacing_<<std::endl;
199  }
200 
201  outPDB_stream.close();
202  outPDB_stream.clear();
203  //END DUMP PDB FILE
204 
205  std::cout<< "Delphi Electrostatics Energy: " << E_energy << std::endl;
206  return E_energy;
207 
208 }
209 
210 } // Pockets
211 } // protocols