ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/forcer.cpp
Revision: 1286
Committed: Tue Jun 22 20:38:04 2004 UTC (20 years, 10 months ago) by chrisfen
File size: 6902 byte(s)
Log Message:
Now prints out a .xyz file of the reference configuration

File Contents

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