1 /// @file PBAMFlowWrap.cpp
2 /// @author Lisa Felberg
3 /// @brief c interface for the C++
4 /// @ingroup PBAM
5 /// @version $Id$
6 /// @attention
7 /// @verbatim
8 ///
9 /// APBS -- Adaptive Poisson-Boltzmann Solver
10 ///
11 /// Nathan A. Baker (nathan.baker@pnnl.gov)
12 /// Pacific Northwest National Laboratory
13 ///
14 /// Additional contributing authors listed in the code documentation.
15 ///
16 /// Copyright (c) 2010-2015 Battelle Memorial Institute. Developed at the
17 /// Pacific Northwest National Laboratory, operated by Battelle Memorial
18 /// Institute, Pacific Northwest Division for the U.S. Department of Energy.
19 ///
20 /// Portions Copyright (c) 2002-2010, Washington University in St. Louis.
21 /// Portions Copyright (c) 2002-2010, Nathan A. Baker.
22 /// Portions Copyright (c) 1999-2002, The Regents of the University of
23 /// California.
24 /// Portions Copyright (c) 1995, Michael Holst.
25 /// All rights reserved.
26 ///
27 /// Redistribution and use in source and binary forms, with or without
28 /// modification, are permitted provided that the following conditions are met:
29 ///
30 /// Redistributions of source code must retain the above copyright notice, this
31 /// list of conditions and the following disclaimer.
32 ///
33 /// Redistributions in binary form must reproduce the above copyright notice,
34 /// this list of conditions and the following disclaimer in the documentation
35 /// and/or other materials provided with the distribution.
36 ///
37 /// Neither the name of the developer nor the names of its contributors may be
38 /// used to endorse or promote products derived from this software without
39 /// specific prior written permission.
40 ///
41 /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42 /// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 /// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 /// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45 /// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46 /// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47 /// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48 /// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49 /// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 /// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
51 /// THE POSSIBILITY OF SUCH DAMAGE.
52 ///
53 /// @endverbatim
54 #include "PBSAMWrap.h"
55 #include "PBSAM.h"
56 #include <iostream>
57
58 using namespace std;
59
getPBSAMParams()60 PBSAMInput getPBSAMParams()
61 {
62 // create the pbam
63 PBSAM pbsam;
64
65 // get the struct for use in the c code
66 PBSAMInput pbsamI = pbsam;
67 return pbsamI;
68 }
69
70 /*
71 PBAMInput getPBAMParams()
72 {
73 // get the struct for use in the c code
74 PBAMInput pbamI;
75 return pbamI;
76 } */
77
78
79 // print the PBAM flow structure for debugging
printPBSAMStruct(PBAMInput pbamIn,PBSAMInput pbsamIn)80 void printPBSAMStruct( PBAMInput pbamIn, PBSAMInput pbsamIn )
81 {
82 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
83 printf("PBAMInput: %.1f, %.1f, %.1f, %.3f and\n runtype: %s\n runname: %s\n",
84 pbamIn.temp_,
85 pbamIn.idiel_,
86 pbamIn.sdiel_,
87 pbamIn.salt_,
88 pbamIn.runType_,
89 pbamIn.runName_);
90 printf("Here's some more: %d, %.2lf, %d, %s, %d\t pts: %d, ntrj: \
91 %d, termcb: %s\n",
92 pbamIn.randOrient_,
93 pbamIn.boxLen_,
94 pbamIn.pbcType_,
95 pbamIn.map3D_,
96 pbamIn.grid2Dct_,
97 pbamIn.gridPts_,
98 pbamIn.ntraj_,
99 pbamIn.termCombine_);
100
101 if(strncmp(pbamIn.runType_, "dynamics", 8)== 0)
102 {
103 for (int i=0; i<pbamIn.nmol_; i++)
104 {
105 printf("This is mol %d movetype: %s, diff: %7.4lf, rot: %7.4lf\n",
106 i, pbamIn.moveType_[i], pbamIn.transDiff_[i], pbamIn.rotDiff_[i]);
107 for (int j=0; j < pbamIn.ntraj_; j++)
108 printf("This is traj %d, xyzfname: %s\n", j, pbamIn.xyzfil_[i][j]);
109 }
110
111 for (int i=0; i<pbamIn.termct_; i++)
112 printf("This is termination cond %d: %s, val is %7.3f\n", i,
113 pbamIn.termnam_[i], pbamIn.termval_[i]);
114 }
115
116 printf("Now printing for PBSAM\n");
117 printf("This is tolsp: %.1f\n", pbsamIn.tolsp_);
118 for (int i=0; i<pbamIn.nmol_; i++)
119 {
120 printf("This is mol %d imat: %s, surf: %s, exp: %s\n",
121 i, pbsamIn.imatfil_[i], pbsamIn.surffil_[i], pbsamIn.expfil_[i]);
122 }
123 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
124 }
125
126 // For python wrap
runPBSAMSphinxWrap(double xyzrc[][AT_MAX][XYZRCWIDTH],int nmol,int natm[1],PBAMInput pbamfin,PBSAMInput pbsamfin)127 PBAMOutput runPBSAMSphinxWrap(double xyzrc[][AT_MAX][XYZRCWIDTH],
128 int nmol,
129 int natm[1],
130 PBAMInput pbamfin,
131 PBSAMInput pbsamfin)
132 {
133 // convert xyzrc to a vector of Molecules
134 printf("Inside pbamrun sphinx\n");
135 printPBSAMStruct(pbamfin, pbsamfin);
136 vector<shared_ptr <BaseMolecule> > mols;
137 for (int mol=0; mol < nmol; mol++)
138 {
139 int ncg(0), nchg(0);
140 int natoms = natm[mol];
141 vector<double> vdw, chg, vdwS;
142 vector<Pt> cgpos, sPos;
143 string difftype;
144 double dtr, drot;
145
146 if (string(pbamfin.runType_) == "dynamics")
147 {
148 difftype = string(pbamfin.moveType_[mol]);
149 dtr = pbamfin.transDiff_[mol];
150 drot = pbamfin.rotDiff_[mol];
151 }
152 else
153 {
154 difftype = "stat";
155 dtr = 0.0;
156 drot = 0.0;
157 pbamfin.ntraj_ = 0;
158 pbamfin.termct_ = 0;
159 pbamfin.contct_ = 0;
160 }
161
162 for (int i=0; i < natoms; i++)
163 {
164 char resName[RESLEN]; //TODO: use sphinx for RESNAME
165 string rName = string(resName);
166 if (rName == "CEN")
167 {
168 sPos.push_back( Pt(xyzrc[mol][i][0],
169 xyzrc[mol][i][1],
170 xyzrc[mol][i][2]));
171 vdwS.push_back(xyzrc[mol][i][3]);
172 ncg++;
173 }else
174 {
175 cgpos.push_back( Pt(xyzrc[mol][i][0],
176 xyzrc[mol][i][1],
177 xyzrc[mol][i][2]));
178 vdw.push_back(xyzrc[mol][i][3]);
179 chg.push_back(xyzrc[mol][i][4]);
180 nchg++;
181 }
182 }
183
184
185 if (ncg == 0)
186 {
187 mols.push_back(make_shared<MoleculeSAM>(mol, 0, difftype, chg, cgpos, vdw,
188 string(pbsamfin.surffil_[mol]), pbsamfin.tolsp_,
189 drot, dtr));
190 mols[mol]->write_pqr("cg_mol"+to_string(mol)+".pqr");
191 }
192 else
193 mols.push_back(make_shared<MoleculeSAM>(mol, 0, difftype, chg,
194 cgpos, vdw, sPos,
195 vdwS, dtr, drot));
196 }
197
198
199 // create the PBAM object
200 PBSAM pbsam( pbamfin, pbsamfin, mols );
201
202 PBAMOutput pbamOut = pbsam.run_apbs( );
203 return pbamOut;
204 }
205
206 // to call from APBS
207 #ifdef PBSAM_APBS
runPBSAMWrapAPBS(PBAMInput pbamParams,PBSAMInput pbsamParams,Valist * Molecules[],int nmls)208 PBAMOutput runPBSAMWrapAPBS(PBAMInput pbamParams, PBSAMInput pbsamParams,
209 Valist* Molecules[], int nmls )
210 {
211 // convert Valist to a vector of MoleculeSAMs
212 printf("Inside pbsamrun\n");
213 vector<shared_ptr<BaseMolecule> > mols;
214
215 for (unsigned int mol=0; mol < nmls; mol++)
216 {
217 Vatom *atom;
218 unsigned int natoms = Valist_getNumberAtoms(Molecules[mol]);
219
220 int ncg(0), nchg(0);
221 vector<double> vdw, chg, vdwS;
222 vector<Pt> cgpos, sPos;
223 string difftype;
224 double dtr, drot;
225
226 if (string(pbamParams.runType_) == "dynamics")
227 {
228 difftype = string(pbamParams.moveType_[mol]);
229 dtr = pbamParams.transDiff_[mol];
230 drot = pbamParams.rotDiff_[mol];
231 }
232 else
233 {
234 difftype = "stat";
235 dtr = 0.0;
236 drot = 0.0;
237 pbamParams.ntraj_ = 0;
238 pbamParams.termct_ = 0;
239 pbamParams.contct_ = 0;
240 }
241
242 for (unsigned int i=0; i < natoms; i++)
243 {
244 char resName[RESLEN];
245 atom = Valist_getAtom(Molecules[mol], i);
246 Vatom_getResName(atom, resName);
247 string rName = string(resName);
248 if (rName == "CEN")
249 {
250 vdwS.push_back(Vatom_getRadius(atom));
251 sPos.push_back(Pt(Vatom_getPosition(atom)[0],
252 Vatom_getPosition(atom)[1],
253 Vatom_getPosition(atom)[2]));
254 ncg++;
255 }else
256 {
257 cgpos.push_back( Pt(Vatom_getPosition(atom)[0],
258 Vatom_getPosition(atom)[1],
259 Vatom_getPosition(atom)[2]));
260 vdw.push_back(Vatom_getRadius(atom));
261 chg.push_back(Vatom_getCharge(atom));
262 nchg++;
263 }
264 }
265
266
267 if (ncg == 0)
268 {
269 mols.push_back(make_shared<MoleculeSAM>(mol, 0, difftype, chg, cgpos, vdw,
270 string(pbsamParams.surffil_[mol]), pbsamParams.tolsp_,
271 drot, dtr));
272 mols[mol]->write_pqr("cg_mol"+to_string(mol)+".pqr");
273 }
274 else
275 mols.push_back(make_shared<MoleculeSAM>(mol, 0, difftype, chg, cgpos,
276 vdw, sPos, vdwS, dtr, drot));
277 }
278
279 // create the PBAM object
280 PBSAM pbsam( pbamParams, pbsamParams, mols );
281
282 // run PBAM!
283 PBAMOutput pbamO = pbsam.run_apbs( );
284
285 return pbamO;
286 }
287 #endif // PBAM_APBS
288