ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/forcer.cpp
Revision: 1274
Committed: Tue Jun 15 20:29:26 2004 UTC (20 years, 3 months ago) by gezelter
File size: 5970 byte(s)
Log Message:
bug fix on vdw files

File Contents

# User Rev Content
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 gezelter 1274
112     printf ("opening %s\n", vdwFileName);
113 gezelter 1240 vdwFile = fopen( vdwFileName, "r" );
114    
115     if( vdwFile == NULL ){
116    
117     // next see if the force path enviorment variable is set
118    
119     ffPath = getenv( ffPath_env );
120     if( ffPath == NULL ) {
121     STR_DEFINE(ffPath, FRC_PATH );
122     }
123    
124     strcpy( temp, ffPath );
125     strcat( temp, "/" );
126     strcat( temp, vdwFileName );
127     strcpy( vdwFileName, temp );
128    
129 gezelter 1274 printf ("opening %s\n", vdwFileName);
130 gezelter 1240 vdwFile = fopen( vdwFileName, "r" );
131    
132     if( vdwFile == NULL ){
133    
134     printf( "Error opening the vanDerWaals parameter file: %s\n"
135 gezelter 1244 "Have you tried setting the VDW_PARAM_DIR environment "
136 gezelter 1240 "variable?\n",
137     vdwFileName );
138     exit(-1);
139     }
140 gezelter 1274 }
141     printf( "VDW file %s opened sucessfully.\n", vdwFileName );
142     lineNum = 0;
143    
144     eof_test = fgets( readLine, sizeof(readLine), vdwFile );
145     lineNum++;
146    
147     if( eof_test == NULL ){
148     printf("Error in reading Atoms from force file at line %d.\n",
149     lineNum );
150     exit(-1);
151     }
152    
153     while( eof_test != NULL ){
154     // toss comment lines
155     if( readLine[0] != '!' && readLine[0] != '#' ){
156    
157     nTokens = count_tokens(readLine, " ,;\t");
158     if (nTokens < 4) {
159     printf("Not enough tokens on line %d.\n", lineNum);
160     exit(-1);
161     }
162    
163     at = new Atype();
164     foo = strtok(readLine, " ,;\t");
165     at->setType(foo);
166     foo = strtok(NULL, " ,;\t");
167     mass = atof(foo);
168     at->setMass(mass);
169     foo = strtok(NULL, " ,;\t");
170     rpar = atof(foo);
171     at->setRpar(rpar);
172     foo = strtok(NULL, " ,;\t");
173     eps = atof(foo);
174     at->setEps(eps);
175     vdwAtypes.push_back(at);
176     }
177 gezelter 1240 eof_test = fgets( readLine, sizeof(readLine), vdwFile );
178     lineNum++;
179 gezelter 1274 }
180    
181     fclose( vdwFile );
182    
183 gezelter 1240 printf("%d Atom Types read from VDW file\n", vdwAtypes.size());
184    
185     // Now, open and parse the input file!
186    
187     strcpy(structureFileName, fileName.c_str() );
188    
189     PDBReader* PDBread = new PDBReader();
190     PDBread->setPDBfile(structureFileName);
191     theAtoms = PDBread->getAtomList();
192     printf("Found %d atoms\n", theAtoms.size());
193    
194     for( j = theAtoms.begin(); j != theAtoms.end(); ++j){
195     atom = *j;
196     myType = atom->getType();
197     gotMatch = 0;
198    
199     for( i = vdwAtypes.begin(); i != vdwAtypes.end(); ++i){
200     at = *i;
201     vType = at->getType();
202    
203     if (!strcasecmp(myType, vType)) {
204     atom->setMass(at->getMass());
205     atom->setRpar(at->getRpar());
206     atom->setEps(at->getEps());
207     gotMatch = 1;
208     }
209     }
210     if (!gotMatch) {
211     printf("No matches found for %s, ", myType);
212     myType = atom->getBase();
213     printf("trying with BaseType %s\n", myType);
214     for( i = vdwAtypes.begin(); i != vdwAtypes.end(); ++i){
215     at = *i;
216     vType = at->getType();
217     if (!strcasecmp(myType, vType)) {
218     atom->setMass(at->getMass());
219     atom->setRpar(at->getRpar());
220     atom->setEps(at->getEps());
221     gotMatch = 1;
222     }
223     }
224     }
225    
226     if (!gotMatch) {
227     printf("No matches found with BaseType!\n");
228     }
229     }
230    
231 gezelter 1271 rb = new RigidBody();
232     for( j = theAtoms.begin(); j != theAtoms.end(); ++j){
233 gezelter 1274 rb->addAtom(*j);
234 gezelter 1271 }
235 gezelter 1274
236     //GridBuilder gb = new GridBuilder(rb);
237 gezelter 1240 //gb->launchProbe(FF, sigmaGrid, sGrid, epsGrid);
238 gezelter 1274
239 gezelter 1240 }
240    
241     int count_tokens(char *line, char *delimiters) {
242     /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
243    
244     char *working_line; /* WORKING COPY OF LINE. */
245     int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */
246     char *strtok_ptr; /* POINTER FOR STRTOK. */
247    
248     strtok_ptr= working_line= strdup(line);
249    
250     ntokens=0;
251     while (strtok(strtok_ptr,delimiters)!=NULL)
252     {
253     ntokens++;
254     strtok_ptr=NULL;
255     }
256    
257     free(working_line);
258     return(ntokens);
259     }