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