ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/mengine.c
(Generate patch)
# Line 1 | Line 1
1 + /* NOTICE: this source code file has been modified for use with FreeMOL */
2 +
3 + #define notKEG_DEBUG
4 +
5   #define EXTERN
6   #include "pcwin.h"
7   #include "pcmod.h"
8   #include "energies.h"
5 #include "substr.h"
9   #include "pot.h"
10   #include "angles.h"
11  
# Line 23 | Line 26
26   #include <stdlib.h>
27   #include <unistd.h>
28   #include <string.h>
29 < #include <malloc.h>
27 <
28 < EXTERN FILE *pcmoutfile;
29 > //#include <malloc.h>
30  
31   struct t_rotbond {
32      int nbonds, bond[200][2], bond_res[200];
# Line 76 | Line 77
77   int main(int argc, char *argv[])
78   {
79      int i;
80 <    char *filename = NULL;
80 >    FILE *infile;
81      char *line = NULL;
82  
83 <    char *outfile = NULL;
84 <    char *mmff94file = NULL;
85 <    char *mmxfile = NULL;
83 >    char *infilename = NULL;
84 >    char *outfilename = NULL;
85 >    char *mmff94filename = NULL;
86 >    char *mmxfilename = NULL;                  
87 >    char *logfilename = NULL;
88  
89 +    int c;
90      int flags = 0;
91  
88 /*
89    filename = strdup("caffeine.sdf");
90    outfile = strdup("output.sdf");
91 */
92    mmff94file = strdup("mmff94.prm");
93    mmxfile = strdup("mmxconst.prm");
94
95    int c;
92      while ((c = getopt(argc, argv, "e:o:p:c:havdxi")) != -1) {
93        switch(c) {
94        case 'a':
# Line 113 | Line 109
109        case 'h':
110          usage();
111          exit(-1);
116 /*
112        case 'o':
113 <        outfile = strdup(optarg);
113 >        outfilename = strdup(optarg);
114          break;
115 + #if 0
116 +       // EXTERNAL PARAM FILES STILL NOT WORKING
117 +        // SOON THEY WILL
118        case 'p':
119 <        mmff94file = strdup(optarg);
119 >        mmff94filename = strdup(optarg);
120          break;
121        case 'c':
122 <        mmxfile = strdup(optarg);
122 >        mmxfilename = strdup(optarg);
123          break;
124 + #endif
125        case 'e':
126          logfilename = strdup(optarg);
127          break;
129 */
128        case '?':
129          if (isprint (optopt))
130           fprintf (stderr, "Unknown option `-%c'.\n", optopt);
# Line 140 | Line 138
138        }
139      }
140  
141 <    pcmoutfile = stdout;
142 <    initialize_pcmodel(mmxfile);
141 >    argc -= optind;
142 >    argv += optind;
143 >
144 >    if (argc == 1)
145 >      infilename = strdup(argv[0]);
146 >
147 > #ifdef KEG_DEBUG
148 >    if(!infilename)
149 >      infilename = strdup("caffeine.sdf");
150 >    if(!outfilename)
151 >      outfilename = strdup("output.sdf");
152 > #endif
153 >
154 >    /* default behavior is to use the hardcoded parameter files */
155 >
156 >    if(!mmff94filename) mmff94filename = strdup("|mmff94"); /* hard-coded builtins */
157 >    if(!mmxfilename) mmxfilename = strdup("|mmxconst"); /* hard-coded builtins */
158 >
159 >    /* if no input file provide, then use standard input */
160 >
161 >    if(infilename) {
162 >      infile = fopen(infilename,"rb");
163 >    } else {
164 >      infile = stdin;
165 >    }
166 >
167 >    /* if no output file provided, then use standard output */
168 >
169 >    if(outfilename) {
170 >      pcmoutfile = fopen(outfilename,"wb");
171 >    } else {
172 >      pcmoutfile = stdout;
173 >   }
174 >
175 >    /* if no log file provided, then use standard error */
176 >
177 >    if(logfilename) {
178 >      pcmlogfile = fopen(logfilename,"wb");
179 >    } else {
180 >      pcmlogfile = stderr;
181 >    }
182 >
183 >    /* initialize the system using parameter file */
184 >
185 >    initialize_pcmodel(mmxfilename);
186      initialize();
187      minim_values.iprint = 0; //FALSE;
188      initialize_gmmx();
189  
190 <    read_gmmxinp(mmff94file, stdin, flags);
190 >    /* run the job */
191  
192 <    fclose(pcmoutfile);
192 >    if (infile) {
193 >      read_gmmxinp(mmff94filename, infile, flags);
194 >    }
195  
196 <    free(mmff94file);
197 <    free(mmxfile);
198 < /*
199 <    free(filename);
200 <    free(outfile);
201 < */
196 >    /* release temporary strings */
197 >
198 >    if(infilename) free(infilename);
199 >    if(outfilename) free(outfilename);
200 >    if(mmff94filename) free(mmff94filename);
201 >    if(mmxfilename) free(mmxfilename);
202 >    if(logfilename) free(logfilename);
203 >
204 >    /* close file handles */
205 >
206 >    if(infile && (infile!=stdin)) fclose(infile);
207 >    if(pcmoutfile && (pcmoutfile!=stdout)) fclose(pcmoutfile);
208 >    if(pcmlogfile && (pcmlogfile!=stderr)) fclose(pcmlogfile);
209  
210      exit(0);
211   }
212 < //
212 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines