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