ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/forcer.cpp
Revision: 1275
Committed: Tue Jun 15 22:36:23 2004 UTC (20 years, 3 months ago) by chrisfen
File size: 6104 byte(s)
Log Message:
Added a bandwidth command-line option

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