ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/shapes/forcer.cpp
Revision: 1184
Committed: Fri May 21 18:34:52 2004 UTC (20 years, 1 month ago) by gezelter
File size: 5860 byte(s)
Log Message:
Got PDB reading working, and matching atom types too!

File Contents

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