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 + /*
4 +   Kevin: please remove the "not" below or simply define KEG_DEBUG at
5 +   compile time in order to activate your preferred debug / testing
6 +   behaviors.  This is more robust approach then using comments...
7 + */
8 +
9 + #define not KEG_DEBUG
10 +
11   #define EXTERN
12   #include "pcwin.h"
13   #include "pcmod.h"
14   #include "energies.h"
5 #include "substr.h"
15   #include "pot.h"
16   #include "angles.h"
17  
# Line 23 | Line 32
32   #include <stdlib.h>
33   #include <unistd.h>
34   #include <string.h>
35 < #include <malloc.h>
27 <
28 < EXTERN FILE *pcmoutfile;
35 > //#include <malloc.h>
36  
37   struct t_rotbond {
38      int nbonds, bond[200][2], bond_res[200];
# Line 61 | Line 68
68   void search_rings(int);
69   */
70  
71 +
72 + void usage(void) {
73 +  printf("\nUsage: mengine [-hvdxi] reads sdf on stdin, writes on stdout\n\n"
74 +         "-h\tThis help page\n"
75 +         "-v\tVerbose output\n"
76 +         "-a\tAdd hydrogen atoms; delete existing ones\n"
77 +         "-d\tEvaluate dipole moment\n"
78 +         "-x\tEvaluate XlogP\n"
79 +         "-i\tEvaluate vibrational data\n\n");
80 + }
81 +
82   /* ==================================================== */
83   int main(int argc, char *argv[])
84   {
85      int i;
86 <    char *filename = NULL;
86 >    FILE *infile;
87      char *line = NULL;
88  
89 <    char *outfile = NULL;
90 <    char *mmff94file = NULL;
91 <    char *mmxfile = NULL;
89 >    char *infilename = NULL;
90 >    char *outfilename = NULL;
91 >    char *mmff94filename = NULL;
92 >    char *mmxfilename = NULL;                  
93      char *logfilename = NULL;
94  
95 +    int c;
96      int flags = 0;
77    flags = flags | DO_DIPOLE;
78    flags = flags | DO_XLOGP;
79    flags = flags | DO_VIBRATION;
97  
98 < /*
99 <    filename = strdup("caffeine.sdf");
100 <    outfile = strdup("output.sdf");
101 < */
102 <    mmff94file = strdup("mmff94.prm");
103 <    mmxfile = strdup("mmxconst.prm");
104 <    logfilename= strdup("error.log");
98 >    while ((c = getopt(argc, argv, "e:o:p:c:havdxi")) != -1) {
99 >      switch(c) {
100 >      case 'a':
101 >        flags = flags | DO_ADDH;
102 >        break;
103 >      case 'd':
104 >        flags = flags | DO_DIPOLE;
105 >        break;
106 >      case 'x':
107 >        flags = flags | DO_XLOGP;
108 >        break;
109 >      case 'i':
110 >        flags = flags | DO_VIBRATION;
111 >        break;
112 >      case 'v':
113 >        VERBOSE = 1;
114 >        break;
115 >      case 'h':
116 >        usage();
117 >        exit(-1);
118 >      case 'o':
119 >        outfilename = strdup(optarg);
120 >        break;
121 > #if 0
122 >       // EXTERNAL PARAM FILES STILL NOT WORKING
123 >      case 'p':
124 >        mmff94filename = strdup(optarg);
125 >        break;
126 >      case 'c':
127 >        mmxfilename = strdup(optarg);
128 >        break;
129 > #endif
130 >      case 'e':
131 >        logfilename = strdup(optarg);
132 >        break;
133 >      case '?':
134 >        if (isprint (optopt))
135 >         fprintf (stderr, "Unknown option `-%c'.\n", optopt);
136 >        else
137 >          fprintf (stderr,
138 >                   "Unknown option character `\\x%x'.\n",
139 >                   optopt);
140 >        return 1;
141 >      default:
142 >        abort ();
143 >      }
144 >    }
145 >
146 >    argc -= optind;
147 >    argv += optind;
148 >
149 >    if (argc == 1)
150 >      infilename = strdup(argv[0]);
151 >
152 > #ifdef KEG_DEBUG
153 >    if(!infilename)
154 >      infilename = strdup("caffeine.sdf");
155 >    if(!outfilename)
156 >      outfilename = strdup("output.sdf");
157 > #endif
158 >
159 >    /* default behavior is to use the hardcoded parameter files */
160 >
161 >    if(!mmff94filename) mmff94filename = strdup("|mmff94"); /* hard-coded builtins */
162 >    if(!mmxfilename) mmxfilename = strdup("|mmxconst"); /* hard-coded builtins */
163 >
164 >    /* if no input file provide, then use standard input */
165 >
166 >    if(infilename) {
167 >      infile = fopen(infilename,"rb");
168 >    } else {
169 >      infile = stdin;
170 >    }
171 >
172 >    /* if no output file provided, then use standard output */
173 >
174 >    if(outfilename) {
175 >      pcmoutfile = fopen(outfilename,"wb");
176 >    } else {
177 >      pcmoutfile = stdout;
178 >    }
179 >
180 >    /* if no log file provided, then use standard error */
181 >
182 >    if(logfilename) {
183 >      pcmlogfile = fopen(logfilename,"wb");
184 >    } else {
185 >      pcmlogfile = stderr;
186 >    }
187 >
188 >    /* initialize the system using parameter file */
189  
190 <    pcmoutfile = stdout;
90 <    initialize_pcmodel(mmxfile);
190 >    initialize_pcmodel(mmxfilename);
191      initialize();
192      minim_values.iprint = 0; //FALSE;
193      initialize_gmmx();
194  
195 <    read_gmmxinp(logfilename, outfile, mmff94file, stdin, flags);
195 >    /* run the job */
196  
197 <    fclose(pcmoutfile);
197 >    if (infile) {
198 >      read_gmmxinp(mmff94filename, infile, flags);
199 >    }
200  
201 <    free(mmff94file);
202 <    free(mmxfile);
203 <    free(logfilename);
204 < /*
205 <    free(filename);
206 <    free(outfile);
207 < */
201 >    /* release temporary strings */
202 >
203 >    if(infilename) free(infilename);
204 >    if(outfilename) free(outfilename);
205 >    if(mmff94filename) free(mmff94filename);
206 >    if(mmxfilename) free(mmxfilename);
207 >    if(logfilename) free(logfilename);
208 >
209 >    /* close file handles */
210 >
211 >    if(infile && (infile!=stdin)) fclose(infile);
212 >    if(pcmoutfile && (pcmoutfile!=stdout)) fclose(pcmoutfile);
213 >    if(pcmlogfile && (pcmlogfile!=stderr)) fclose(pcmlogfile);
214  
215      exit(0);
216   }
217 < //
217 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines