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 61 | Line 62
62   void search_rings(int);
63   */
64  
65 +
66 + void usage(void) {
67 +  printf("\nUsage: mengine [-hvdxi] reads sdf on stdin, writes on stdout\n\n"
68 +         "-h\tThis help page\n"
69 +         "-v\tVerbose output\n"
70 +         "-a\tAdd hydrogen atoms; delete existing ones\n"
71 +         "-d\tEvaluate dipole moment\n"
72 +         "-x\tEvaluate XlogP\n"
73 +         "-i\tEvaluate vibrational data\n\n");
74 + }
75 +
76   /* ==================================================== */
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;
77    flags = flags | DO_DIPOLE;
78    flags = flags | DO_XLOGP;
79    flags = flags | DO_VIBRATION;
91  
92 < /*
93 <    filename = strdup("caffeine.sdf");
94 <    outfile = strdup("output.sdf");
95 < */
96 <    mmff94file = strdup("mmff94.prm");
97 <    mmxfile = strdup("mmxconst.prm");
98 <    logfilename= strdup("error.log");
92 >    while ((c = getopt(argc, argv, "e:o:p:c:havdxi")) != -1) {
93 >      switch(c) {
94 >      case 'a':
95 >        flags = flags | DO_ADDH;
96 >        break;
97 >      case 'd':
98 >        flags = flags | DO_DIPOLE;
99 >        break;
100 >      case 'x':
101 >        flags = flags | DO_XLOGP;
102 >        break;
103 >      case 'i':
104 >        flags = flags | DO_VIBRATION;
105 >        break;
106 >      case 'v':
107 >        VERBOSE = 1;
108 >        break;
109 >      case 'h':
110 >        usage();
111 >        exit(-1);
112 >      case 'o':
113 >        outfilename = strdup(optarg);
114 >        break;
115 > #if 0
116 >       // EXTERNAL PARAM FILES STILL NOT WORKING
117 >        // SOON THEY WILL
118 >      case 'p':
119 >        mmff94filename = strdup(optarg);
120 >        break;
121 >      case 'c':
122 >        mmxfilename = strdup(optarg);
123 >        break;
124 > #endif
125 >      case 'e':
126 >        logfilename = strdup(optarg);
127 >        break;
128 >      case '?':
129 >        if (isprint (optopt))
130 >         fprintf (stderr, "Unknown option `-%c'.\n", optopt);
131 >        else
132 >          fprintf (stderr,
133 >                   "Unknown option character `\\x%x'.\n",
134 >                   optopt);
135 >        return 1;
136 >      default:
137 >        abort ();
138 >      }
139 >    }
140 >
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 <    pcmoutfile = stdout;
184 <    initialize_pcmodel(mmxfile);
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(logfilename, outfile, 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 <    free(logfilename);
199 < /*
200 <    free(filename);
201 <    free(outfile);
202 < */
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