Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
APBSWrapper.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/ABPSWrapper.fwd.hh
11 /// @brief APBSWrapper class definition
12 /// @author Sachko Honda (honda@apl.washington.edu)
13 
15 
16 // Project Headers
20 #include <core/pose/Pose.hh>
21 
22 // Numeric Headers
23 
24 // Utility Headers
25 #include <basic/Tracer.hh>
26 #include <string>
27 #include <algorithm>
28 #include <numeric>
29 #include <vector>
30 
31 #ifdef LINK_APBS_LIB
32 
33 #include <apbs/routines.h>
34 #include <apbs_driver.h>
35 
36 #endif
37 static basic::Tracer TR("core/scoring/APBSWrapper");
38 
39 namespace core {
40 namespace scoring{
41 std::string const PQR::chains( " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" );
43 {
44 }
45 
47  std::map<std::string, bool> const & charged_residues,
48  int dbg,
49  bool calcenergy)
50 {
51 
52  int natoms = count_atoms(pose);
53  pqr = new PQR(pose, natoms, charged_residues);
54  TR << "PQR data is prepared." << std::endl;
55  config = new APBSConfig(pose, natoms, dbg, calcenergy);
56  TR << "APBS config is prepared." << std::endl;
57  result = new APBSResult(config->nsims, config->natoms, config->dime,
58  config->i_param.calcforce,
59  config->i_param.calcenergy,
60  config->i_param.write_pot,
61  config->i_param.write_charge,
62  config->i_param.write_smol,
63  config->i_param.write_kappa,
64  config->i_param.write_diel,
65  config->i_param.write_atompot);
66  TR << "APBS result data structure is prepared." << std::endl;
67 }
70 
71  const int nwrites = result->nwrites;
72  int ret = 0;
73 
74 #ifdef LINK_APBS_LIB
75  std::vector< double * > raw_grid_data;
76  for(int i=0; i<nwrites; i++ ) {
77  raw_grid_data.push_back(result->grid_data[i].data());
78  }
79 
80  ret = apbsdrv_(&pqr->natoms_,
81  pqr->x.data(),
82  pqr->y.data(),
83  pqr->z.data(),
84  pqr->radius.data(),
85  pqr->charge.data(),
86  config->r_param.raw_array(),
87  config->i_param.raw_array(),
88  config->grid,
89  config->dime,
90  config->pdime,
91  config->glen,
92  config->center,
93  config->cglen,
94  config->fglen,
95  config->ccenter,
96  config->fcenter,
97  &config->ofrac,
98  &config->dbg,
99  config->ionq,
100  config->ionc,
101  config->ionr,
102  result->esEnergy.data(),
103  result->npEnergy.data(),
104  result->dx.data(),
105  result->dy.data(),
106  result->dz.data(),
107  result->qfx.data(),
108  result->qfy.data(),
109  result->qfz.data(),
110  result->ibx.data(),
111  result->iby.data(),
112  result->ibz.data(),
113  result->npx.data(),
114  result->npy.data(),
115  result->npz.data(),
116  result->dbx.data(),
117  result->dby.data(),
118  result->dbz.data(),
119  result->grid_meta,
120  raw_grid_data.data() );
121 #endif
122 
123  if( ret != 0 ) {
124  return NULL;
125  }
126  return result;
127 }
128 
129 int APBSWrapper::count_atoms( core::pose::Pose const & pose ) const
130 {
131  int nres = pose.total_residue();
132  int cntAtoms=0;
133  for ( int i=1; i<= nres; ++i ) {
134  conformation::ResidueCAP rsd = &pose.residue(i);
135  for ( Size j=1; j<= rsd->natoms(); ++j ) {
136  if ( rsd->atom_type(j).is_virtual() ) continue;
137  ++cntAtoms;
138  }
139  }
140  return cntAtoms;
141 }
142 
143 PQR::PQR(core::pose::Pose const & pose, int natoms,
144  std::map<std::string, bool> const & charged_residues)
145  : natoms_(natoms)
146 {
147  int nres = pose.total_residue();
148  int cntAtoms = 0;
149 
150  for ( int i=1; i<= nres; ++i ) {
151  conformation::ResidueCAP rsd = &pose.residue(i);
152  bool residue_charged = const_cast<std::map<std::string,bool>&>(charged_residues)[rsd->type().name()];
153  for ( Size j=1; j<=rsd->natoms(); ++j ) {
154  conformation::Atom const & atom( rsd->atom(j) );
155 
156  //skip outputing virtual atom unless specified.
157  //fixed so that the last atom in atom type set can be
158  //something other than a virtual atom --steven combs
159  if ( rsd->atom_type(j).is_virtual() ) continue;
160 
161  runtime_assert( rsd->chain() < chains.size() ); // silly restriction
162 
163  x.push_back(atom.xyz()(1));
164  y.push_back(atom.xyz()(2));
165  z.push_back(atom.xyz()(3));
166  charge.push_back(residue_charged? pose.residue_type(i).atom(j).charge() : 0.);
167  radius.push_back(rsd->atom_type(j).lj_radius());
168  ++cntAtoms;
169  }
170  }
171 }
173 
174 APBSResult::APBSResult(int nsims, int natoms, int grid_dimes[3],
175  int calcforce, int calcenergy,
176  int write_pot, int write_charge, int write_smol,
177  int write_kappa, int write_diel, int write_atompot )
178  : esEnergy(nsims),
179  npEnergy(nsims)
180 {
181  // allocate if force is to be calculated
182  if(calcforce) {
183  // allocate memory for these natoms-dimensioned data
184  for( int i=0; i<natoms; i++ ) {
185  dx.push_back(0);
186  dy.push_back(0);
187  dz.push_back(0);
188  qfx.push_back(0);
189  qfy.push_back(0);
190  qfz.push_back(0);
191  ibx.push_back(0);
192  npx.push_back(0);
193  dbx.push_back(0);
194  }
195  }
196  if(calcenergy) {
197  }
198  nwrites = write_pot
199  + write_charge
200  + write_smol
201  + write_kappa
202  + write_diel*3
203  + write_atompot;
204  grid_meta[0] = nwrites;
205  for(int i=1; i<13; i++) grid_meta[i] = 0.;
206 
207  for(int i=0; i<nwrites; i++) {
208  std::vector<double> i_data( grid_dimes[0] * grid_dimes[1] * grid_dimes[2], 0.);
209  grid_data.push_back( i_data );
210  }
211 }
213 
215  sim_type(1),
216  nlev(4),
217  grid_centering_mode(0),
218  coarse_centering_mode(0),
219  fine_centering_mode(0),
220  chgm(1),
221  pbe_mode(1),
222  bcfl(1),
223  srfm(1),
224  calcforce(0),
225  calcenergy(0),
226  write_pot(1),
227  write_charge(0),
228  write_smol(0),
229  write_kappa(0),
230  write_diel(0),
231  write_atompot(0),
232  use_pot(0),
233  iparam19(0),
234  apol_calcforce(0),
235  apol_calcenergy(0),
236  nions(4),
237  use_charge(0),
238  use_kappa(0),
239  use_diel(0)
240 {
241 }
243 
245 {
246  array[0] = sim_type;
247  array[1] = nlev;
248  array[2] = grid_centering_mode;
249  array[3] = coarse_centering_mode;
250  array[4] = fine_centering_mode;
251  array[5] = chgm;
252  array[6] = pbe_mode;
253  array[7] = bcfl;
254  array[8] = srfm;
255  array[9] = calcforce;
256  array[10] = calcenergy;
257  array[11] = write_pot;
258  array[12] = write_charge;
259  array[13] = write_smol;
260  array[14] = write_kappa;
261  array[15] = write_diel;
262  array[16] = write_atompot;
263  array[17] = use_pot;
264  array[18] = iparam19;
265  array[19] = apol_calcforce;
266  array[20] = apol_calcenergy;
267  array[21] = nions;
268  array[22] = use_charge;
269  array[23] = use_kappa;
270  array[24] = use_diel;
271  return array;
272 }
273 
275  pdie(4.),
276  nsdie(80.),
277  srad(1.4),
278  swin(0.3),
279  temp(310),
280  sdens(10),
281  gamma(0.105)
282 {
283 }
285 
287 {
288  array[0] = pdie;
289  array[1] = nsdie;
290  array[2] = srad;
291  array[3] = swin;
292  array[4] = temp;
293  array[5] = sdens;
294  array[6] = gamma;
295  array[7] = smpbe_vol;
296  array[8] = smpbe_size;
297  return array;
298 }
299 
300 APBSConfig::APBSConfig(core::pose::Pose const & pose, int natomsIn, int dbgIn, bool calcenergyIn)
301  :
302  dbg(dbgIn),
303  nsims(1),
304  natoms(natomsIn),
305  cfac(1.7),
306  fadd(20),
307  space(0.5),
308  ofrac(0.),
309  calcenergy(calcenergyIn)
310 {
311  ionq[0] = 1; ionq[1] = -1, ionq[2] = 2; ionq[3] = -2;
312  ionc[0] = .15; ionc[1] = .15, ionc[2] = 0; ionc[3] = 0;
313  ionr[0] = 2; ionr[1] = 2, ionr[2] = 2; ionr[3] = 2;
314  dime[0] = dime[1] = dime[2] = 1.;
315 
316  double min_r[] = {9999,9999,9999};
317  double max_r[] = {-9999,-9999,-9999};
318  // Find the min & max coords within the moleculer system to define the grid.
319  for (Size ires=1; ires<=pose.total_residue(); ++ires) {
320  for (Size iatom=1; iatom<=pose.residue(ires).natoms(); ++iatom) {
321  for (int i=0; i<3; ++i) {
322  min_r[i] = std::min(pose.residue(ires).xyz(iatom)[i], min_r[i]);
323  max_r[i] = std::max(pose.residue(ires).xyz(iatom)[i], max_r[i]);
324  }
325  }
326  }
327 
328  double length[3];
329  for(int i=0; i<3; i++ ) {
330  length[i] = max_r[i]- min_r[i]; // grid widths
331  ccenter[i] = (min_r[i] + max_r[i])/2.; // grid center coords
332  fcenter[i] = ccenter[i];
333  fglen[i] = length[i] + fadd;
334  cglen[i] = length[i] * cfac;
335  dime[i] = fglen[i] / space + 1;
336  }
337 }
339 {}
340 
341 
342 }
343 }