ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/shapes/forcer.cpp
Revision: 1182
Committed: Fri May 21 14:23:20 2004 UTC (20 years, 11 months ago) by gezelter
File size: 4627 byte(s)
Log Message:
Changes for SHAPES potential

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 vector<Atype*> vdwAtypes;
47 vector<Atype*>::iterator iter;
48 double mass, rpar, eps;
49 string fileName;
50 char vdwFileName[2002];
51 char structureFileName[2002];
52 char temp[200];
53 char readLine[500];
54 FILE *vdwFile, *structureFile;
55 char* ffPath_env = "FORCE_PARAM_PATH";
56 char* ffPath;
57 char* eof_test;
58 char* foo;
59 int lineNum;
60 int nTokens;
61 Atype* at;
62 int FF;
63 vector <VDWAtom*> theAtoms;
64
65 //parse the command line options
66 if (cmdline_parser (argc, argv, &args_info) != 0)
67 exit(1) ;
68
69 if (args_info.input_given){
70 fileName = args_info.input_arg;
71 }
72 else{
73 cerr << "Does not have input file name" << endl;
74 exit(1);
75 }
76
77 if (args_info.charmm_given) {
78 FF=CHARMM;
79 strcpy(vdwFileName, "charmm27.vdw");
80 }
81
82 if (args_info.amber_given) {
83 FF=AMBER;
84 strcpy(vdwFileName, "amber99.vdw");
85 }
86
87 if (args_info.lj_given) {
88 FF=LJ;
89 strcpy(vdwFileName, "LJ.vdw");
90 }
91
92 if (args_info.gaff_given) {
93 FF=GAFF;
94 strcpy(vdwFileName, "gaff.vdw");
95 }
96
97 if (args_info.opls_given) {
98 FF=OPLS;
99 strcpy(vdwFileName, "oplsaal.vdw");
100 }
101
102 vdwFile = fopen( vdwFileName, "r" );
103
104 if( vdwFile == NULL ){
105
106 // next see if the force path enviorment variable is set
107
108 ffPath = getenv( ffPath_env );
109 if( ffPath == NULL ) {
110 STR_DEFINE(ffPath, FRC_PATH );
111 }
112
113 strcpy( temp, ffPath );
114 strcat( temp, "/" );
115 strcat( temp, vdwFileName );
116 strcpy( vdwFileName, temp );
117
118 vdwFile = fopen( vdwFileName, "r" );
119
120 if( vdwFile == NULL ){
121
122 printf( "Error opening the vanDerWaals parameter file: %s\n"
123 "Have you tried setting the FORCE_PARAM_PATH environment "
124 "variable?\n",
125 vdwFileName );
126 exit(-1);
127 }
128 printf( "VDW file %s opened sucessfully.\n", vdwFileName );
129 lineNum = 0;
130
131 eof_test = fgets( readLine, sizeof(readLine), vdwFile );
132 lineNum++;
133
134 if( eof_test == NULL ){
135 printf("Error in reading Atoms from force file at line %d.\n",
136 lineNum );
137 exit(-1);
138 }
139
140 while( eof_test != NULL ){
141 // toss comment lines
142 if( readLine[0] != '!' && readLine[0] != '#' ){
143
144 nTokens = count_tokens(readLine, " ,;\t");
145 if (nTokens < 4) {
146 printf("Not enough tokens on line %d.\n", lineNum);
147 exit(-1);
148 }
149
150 at = new Atype();
151 foo = strtok(readLine, " ,;\t");
152 at->setType(foo);
153 foo = strtok(NULL, " ,;\t");
154 mass = atof(foo);
155 at->setMass(mass);
156 foo = strtok(NULL, " ,;\t");
157 rpar = atof(foo);
158 at->setRpar(rpar);
159 foo = strtok(NULL, " ,;\t");
160 eps = atof(foo);
161 at->setEps(eps);
162 vdwAtypes.push_back(at);
163 }
164 eof_test = fgets( readLine, sizeof(readLine), vdwFile );
165 lineNum++;
166 }
167
168 fclose( vdwFile );
169 }
170 printf("%d Atom Types read from VDW file\n", vdwAtypes.size());
171
172 // Now, open and parse the input file!
173
174 strcpy(structureFileName, fileName.c_str() );
175
176 PDBReader* PDBread = new PDBReader();
177 PDBread->setPDBfile(structureFileName);
178 theAtoms = PDBread->getAtomList();
179 printf("Found %d atoms\n", theAtoms.size());
180
181 }
182
183 int count_tokens(char *line, char *delimiters) {
184 /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
185
186 char *working_line; /* WORKING COPY OF LINE. */
187 int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */
188 char *strtok_ptr; /* POINTER FOR STRTOK. */
189
190 strtok_ptr= working_line= strdup(line);
191
192 ntokens=0;
193 while (strtok(strtok_ptr,delimiters)!=NULL)
194 {
195 ntokens++;
196 strtok_ptr=NULL;
197 }
198
199 free(working_line);
200 return(ntokens);
201 }