1 |
#include <iostream> |
2 |
#include <fstream> |
3 |
#include <string> |
4 |
#include <vector> |
5 |
#include "forcerCmd.h" |
6 |
#include "PDBReader.hpp" |
7 |
#include "RigidBody.hpp" |
8 |
#include "GridBuilder.hpp" |
9 |
#include "SphereHarm.hpp" |
10 |
|
11 |
#define MK_STR(s) # s |
12 |
#define STR_DEFINE(t, s) t = MK_STR(s) |
13 |
#define CHARMM 1 |
14 |
#define AMBER 2 |
15 |
#define LJ 3 |
16 |
#define GAFF 4 |
17 |
#define OPLS 5 |
18 |
|
19 |
int count_tokens(char *line, char *delimiters); |
20 |
using namespace std; |
21 |
|
22 |
class Atype{ |
23 |
public: |
24 |
Atype() { |
25 |
mass = 0.0; |
26 |
rpar = 0.0; |
27 |
eps = 0.0; |
28 |
} |
29 |
|
30 |
void setMass(double m) {mass = m;} |
31 |
void setRpar(double rp) {rpar = rp;} |
32 |
void setEps(double e) {eps = e;} |
33 |
void setType(char* t) {strcpy(type, t);} |
34 |
double getMass() {return mass;} |
35 |
double getRpar() {return rpar;} |
36 |
double getEps() {return eps;} |
37 |
char *getType() {return type;} |
38 |
|
39 |
private: |
40 |
char type[100]; |
41 |
double mass; |
42 |
double rpar; |
43 |
double eps; |
44 |
}; |
45 |
|
46 |
int main(int argc, char* argv[]){ |
47 |
|
48 |
gengetopt_args_info args_info; |
49 |
|
50 |
vector<Atype*> vdwAtypes; |
51 |
vector<Atype*>::iterator i; |
52 |
Atype* at; |
53 |
RigidBody* rb; |
54 |
vector<VDWAtom*> theAtoms; |
55 |
vector<VDWAtom*>::iterator j; |
56 |
VDWAtom* atom; |
57 |
GridBuilder* gb; |
58 |
vector<double> sigmaGrid; |
59 |
vector<double> epsGrid; |
60 |
vector<double> sGrid; |
61 |
SphereHarm* harmonize; |
62 |
|
63 |
double mass, rpar, eps; |
64 |
double xyz3[3]; |
65 |
double moments[3][3]; |
66 |
string fileName; |
67 |
char vdwFileName[2002]; |
68 |
char structureFileName[2002]; |
69 |
char temp[200]; |
70 |
char readLine[500]; |
71 |
char xyzFile[200]; |
72 |
char shapeFile[200]; |
73 |
char shapeName[80]; |
74 |
FILE *vdwFile, *structureFile; |
75 |
char* ffPath_env = "VDW_PATH"; |
76 |
char* ffPath; |
77 |
char* eof_test; |
78 |
char* foo; |
79 |
char* myType; |
80 |
char* vType; |
81 |
char *token; |
82 |
const char *file; |
83 |
const char *period = "."; |
84 |
int k; |
85 |
int lineNum; |
86 |
int nTokens; |
87 |
int FF; |
88 |
int bandwidth; |
89 |
int gridwidth; |
90 |
short int gotMatch; |
91 |
|
92 |
//parse the command line options |
93 |
if (cmdline_parser (argc, argv, &args_info) != 0) |
94 |
exit(1) ; |
95 |
|
96 |
if (args_info.input_given){ |
97 |
fileName = args_info.input_arg; |
98 |
} |
99 |
else{ |
100 |
std::cerr << "Does not have input file name" << endl; |
101 |
exit(1); |
102 |
} |
103 |
|
104 |
file = fileName.c_str(); |
105 |
strcpy(xyzFile, file); |
106 |
token = strtok(xyzFile, period); |
107 |
strcpy(xyzFile, token); |
108 |
strcpy(shapeFile, token); |
109 |
strcpy(shapeName, token); |
110 |
strcat(xyzFile, "Ref.xyz"); |
111 |
strcat(shapeFile, ".shape"); |
112 |
strcat(shapeName, "_RB_0"); |
113 |
ofstream xfiles(xyzFile); |
114 |
|
115 |
//the bandwidth has a default value (default=16), so it is always given |
116 |
bandwidth = args_info.bandwidth_arg; |
117 |
gridwidth = bandwidth*2; |
118 |
|
119 |
if (args_info.charmm_given) { |
120 |
FF=CHARMM; |
121 |
strcpy(vdwFileName, "charmm27.vdw"); |
122 |
} |
123 |
|
124 |
if (args_info.amber_given) { |
125 |
FF=AMBER; |
126 |
strcpy(vdwFileName, "amber99.vdw"); |
127 |
} |
128 |
|
129 |
if (args_info.lj_given) { |
130 |
FF=LJ; |
131 |
strcpy(vdwFileName, "LJ.vdw"); |
132 |
} |
133 |
|
134 |
if (args_info.gaff_given) { |
135 |
FF=GAFF; |
136 |
strcpy(vdwFileName, "gaff.vdw"); |
137 |
} |
138 |
|
139 |
if (args_info.opls_given) { |
140 |
FF=OPLS; |
141 |
strcpy(vdwFileName, "oplsaal.vdw"); |
142 |
} |
143 |
|
144 |
|
145 |
printf ("opening %s\n", vdwFileName); |
146 |
vdwFile = fopen( vdwFileName, "r" ); |
147 |
|
148 |
if( vdwFile == NULL ){ |
149 |
|
150 |
// next see if the force path enviorment variable is set |
151 |
|
152 |
ffPath = getenv( ffPath_env ); |
153 |
if( ffPath == NULL ) { |
154 |
STR_DEFINE(ffPath, FRC_PATH ); |
155 |
} |
156 |
|
157 |
strcpy( temp, ffPath ); |
158 |
strcat( temp, "/" ); |
159 |
strcat( temp, vdwFileName ); |
160 |
strcpy( vdwFileName, temp ); |
161 |
|
162 |
printf ("opening %s\n", vdwFileName); |
163 |
vdwFile = fopen( vdwFileName, "r" ); |
164 |
|
165 |
if( vdwFile == NULL ){ |
166 |
|
167 |
printf( "Error opening the vanDerWaals parameter file: %s\n" |
168 |
"Have you tried setting the VDW_PARAM_DIR environment " |
169 |
"variable?\n", |
170 |
vdwFileName ); |
171 |
exit(-1); |
172 |
} |
173 |
} |
174 |
printf( "VDW file %s opened sucessfully.\n", vdwFileName ); |
175 |
lineNum = 0; |
176 |
|
177 |
eof_test = fgets( readLine, sizeof(readLine), vdwFile ); |
178 |
lineNum++; |
179 |
|
180 |
if( eof_test == NULL ){ |
181 |
printf("Error in reading Atoms from force file at line %d.\n", |
182 |
lineNum ); |
183 |
exit(-1); |
184 |
} |
185 |
|
186 |
while( eof_test != NULL ){ |
187 |
// toss comment lines |
188 |
if( readLine[0] != '!' && readLine[0] != '#' ){ |
189 |
|
190 |
nTokens = count_tokens(readLine, " ,;\t"); |
191 |
if (nTokens < 4) { |
192 |
printf("Not enough tokens on line %d.\n", lineNum); |
193 |
exit(-1); |
194 |
} |
195 |
|
196 |
at = new Atype(); |
197 |
foo = strtok(readLine, " ,;\t"); |
198 |
at->setType(foo); |
199 |
foo = strtok(NULL, " ,;\t"); |
200 |
mass = atof(foo); |
201 |
at->setMass(mass); |
202 |
foo = strtok(NULL, " ,;\t"); |
203 |
rpar = atof(foo); |
204 |
at->setRpar(rpar); |
205 |
foo = strtok(NULL, " ,;\t"); |
206 |
eps = atof(foo); |
207 |
at->setEps(eps); |
208 |
vdwAtypes.push_back(at); |
209 |
} |
210 |
eof_test = fgets( readLine, sizeof(readLine), vdwFile ); |
211 |
lineNum++; |
212 |
} |
213 |
|
214 |
fclose( vdwFile ); |
215 |
|
216 |
printf("%d Atom Types read from VDW file\n", vdwAtypes.size()); |
217 |
|
218 |
// Now, open and parse the input file! |
219 |
|
220 |
strcpy(structureFileName, fileName.c_str() ); |
221 |
|
222 |
PDBReader* PDBread = new PDBReader(); |
223 |
PDBread->setPDBfile(structureFileName); |
224 |
theAtoms = PDBread->getAtomList(); |
225 |
printf("Found %d atoms\n", theAtoms.size()); |
226 |
|
227 |
for( j = theAtoms.begin(); j != theAtoms.end(); ++j){ |
228 |
atom = *j; |
229 |
myType = atom->getType(); |
230 |
gotMatch = 0; |
231 |
|
232 |
for( i = vdwAtypes.begin(); i != vdwAtypes.end(); ++i){ |
233 |
at = *i; |
234 |
vType = at->getType(); |
235 |
|
236 |
if (!strcasecmp(myType, vType)) { |
237 |
atom->setMass(at->getMass()); |
238 |
atom->setRpar(at->getRpar()); |
239 |
atom->setEps(at->getEps()); |
240 |
gotMatch = 1; |
241 |
} |
242 |
} |
243 |
if (!gotMatch) { |
244 |
printf("No matches found for %s, ", myType); |
245 |
myType = atom->getBase(); |
246 |
printf("trying with BaseType %s\n", myType); |
247 |
for( i = vdwAtypes.begin(); i != vdwAtypes.end(); ++i){ |
248 |
at = *i; |
249 |
vType = at->getType(); |
250 |
if (!strcasecmp(myType, vType)) { |
251 |
atom->setMass(at->getMass()); |
252 |
atom->setRpar(at->getRpar()); |
253 |
atom->setEps(at->getEps()); |
254 |
gotMatch = 1; |
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
if (!gotMatch) { |
260 |
printf("No matches found with BaseType!\n"); |
261 |
} |
262 |
} |
263 |
|
264 |
rb = new RigidBody(); |
265 |
for( j = theAtoms.begin(); j != theAtoms.end(); ++j){ |
266 |
rb->addAtom(*j); |
267 |
} |
268 |
|
269 |
rb->calcRefCoords(); |
270 |
|
271 |
//print a reference coordinate xyz file |
272 |
xfiles << rb->getNumAtoms() << "\n\n"; |
273 |
for (k=0; k<rb->getNumAtoms(); k++){ |
274 |
rb->getAtomRefCoor(xyz3, k); |
275 |
xfiles << rb->getAtomBase(k) << "\t" << |
276 |
xyz3[0] << "\t" << xyz3[1] << "\t" << |
277 |
xyz3[2] << "\n"; |
278 |
} |
279 |
|
280 |
gb = new GridBuilder(rb, gridwidth); |
281 |
|
282 |
cout << "Doing GridBuilder calculations...\n"; |
283 |
gb->launchProbe(FF, sigmaGrid, sGrid, epsGrid); |
284 |
|
285 |
gb->printGridFiles(); |
286 |
|
287 |
//load the grid element values to the main grid vectors |
288 |
for (k=0; k<gridwidth*gridwidth; k++){ |
289 |
sigmaGrid.push_back(gb->passSig(k)); |
290 |
sGrid.push_back(gb->passS(k)); |
291 |
epsGrid.push_back(gb->passEps(k)); |
292 |
} |
293 |
|
294 |
//build the spherical harmonic transform object |
295 |
harmonize = new SphereHarm( bandwidth ); |
296 |
rb->getI(moments); |
297 |
harmonize->printShapesFileStart(shapeFile, shapeName, rb->getMass(), |
298 |
moments); |
299 |
|
300 |
//do the transforms and write to the shapes file |
301 |
harmonize->doTransforms(sigmaGrid); |
302 |
harmonize->printToShapesFile(shapeFile, 0); |
303 |
harmonize->doTransforms(sGrid); |
304 |
harmonize->printToShapesFile(shapeFile, 1); |
305 |
harmonize->doTransforms(epsGrid); |
306 |
harmonize->printToShapesFile(shapeFile, 2); |
307 |
|
308 |
//clean everything up |
309 |
harmonize->~SphereHarm(); |
310 |
} |
311 |
|
312 |
int count_tokens(char *line, char *delimiters) { |
313 |
/* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */ |
314 |
|
315 |
char *working_line; /* WORKING COPY OF LINE. */ |
316 |
int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */ |
317 |
char *strtok_ptr; /* POINTER FOR STRTOK. */ |
318 |
|
319 |
strtok_ptr= working_line= strdup(line); |
320 |
|
321 |
ntokens=0; |
322 |
while (strtok(strtok_ptr,delimiters)!=NULL) |
323 |
{ |
324 |
ntokens++; |
325 |
strtok_ptr=NULL; |
326 |
} |
327 |
|
328 |
free(working_line); |
329 |
return(ntokens); |
330 |
} |