1 |
|
/********************************************************************** |
2 |
< |
main.cpp - Main conversion program, command-line handling. |
2 |
> |
atom2md.cpp - OpenBabel-based conversion program to OpenMD file, |
3 |
> |
command-line handling. |
4 |
|
|
5 |
|
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. |
6 |
< |
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison |
7 |
< |
Some portions Copyright (C) 2004-2005 by Chris Morley |
6 |
> |
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison |
7 |
> |
Some portions Copyright (C) 2004-2006 by Chris Morley |
8 |
> |
Some portions Copyright (C) 2008-2009 by J. Daniel Gezelter |
9 |
|
|
10 |
< |
This file is part of the Open Babel project. |
11 |
< |
For more information, see <http://openbabel.sourceforge.net/> |
10 |
> |
This file is part of both the OpenMD and Open Babel projects. |
11 |
> |
For more information, see <http://openmd.net> and <http://openbabel.sourceforge.net/> |
12 |
|
|
13 |
|
This program is free software; you can redistribute it and/or modify |
14 |
|
it under the terms of the GNU General Public License as published by |
21 |
|
***********************************************************************/ |
22 |
|
|
23 |
|
#include "config.h" |
24 |
< |
#if HAVE_IOSTREAM |
25 |
< |
#include <iostream> |
26 |
< |
#elif HAVE_IOSTREAM_H |
27 |
< |
#include <iostream.h> |
24 |
> |
|
25 |
> |
// used to set import/export for Cygwin DLLs |
26 |
> |
#ifdef WIN32 |
27 |
> |
#define USING_OBDLL |
28 |
|
#endif |
27 |
– |
#if HAVE_FSTREAM |
28 |
– |
#include <fstream> |
29 |
– |
#elif HAVE_FSTREAM_H |
30 |
– |
#include <fstream.h> |
31 |
– |
#endif |
32 |
– |
#if HAVE_SSTREAM |
33 |
– |
#include <sstream> |
34 |
– |
#elif |
35 |
– |
#include <sstream.h> |
36 |
– |
#endif |
29 |
|
|
30 |
+ |
#include <openbabel/babelconfig.h> |
31 |
+ |
|
32 |
+ |
#include <iostream> |
33 |
+ |
#include <fstream> |
34 |
+ |
#include <sstream> |
35 |
+ |
|
36 |
|
#include <string> |
37 |
|
#include <map> |
38 |
|
#if HAVE_CONIO_H |
43 |
|
extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); |
44 |
|
#endif |
45 |
|
|
46 |
< |
#include "openbabel/obconversion.hpp" |
47 |
< |
#include "brains/Register.hpp" |
46 |
> |
#include <openbabel/obconversion.h> |
47 |
> |
#include <openbabel/plugin.h> |
48 |
> |
#include <cstdlib> |
49 |
> |
#include <cstring> |
50 |
|
|
51 |
|
using namespace std; |
52 |
|
using namespace OpenBabel; |
53 |
< |
using namespace oopse; |
54 |
< |
void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, |
55 |
< |
int& arg, int argc, char *argv[]); |
53 |
> |
|
54 |
> |
void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, |
55 |
> |
int& arg, int argc, char *argv[]); |
56 |
|
void usage(); |
57 |
|
void help(); |
58 |
|
|
61 |
|
|
62 |
|
int main(int argc,char *argv[]) |
63 |
|
{ |
64 |
– |
registerOBFormats(); |
64 |
|
OBConversion Conv(&cin, &cout); //default input and output are console |
65 |
|
|
67 |
– |
// string GenOptions; |
66 |
|
OBFormat* pInFormat = NULL; |
67 |
|
OBFormat* pOutFormat = NULL; |
68 |
|
vector<string> FileList, OutputFileList; |
69 |
|
string OutputFileName; |
72 |
– |
// obMessageLevel filterLevel = obWarning; // 2 out of 5 |
70 |
|
|
71 |
|
// Parse commandline |
72 |
|
bool gotInType = false, gotOutType = false; |
73 |
< |
bool UseSavedOptions = false; |
73 |
> |
bool SplitOrBatch=false; |
74 |
|
|
75 |
< |
char *oext; |
76 |
< |
char *iext; |
75 |
> |
char *oext = NULL; |
76 |
> |
char *iext = NULL; |
77 |
> |
|
78 |
> |
// for use with command name to type conversion |
79 |
|
string inputExt; |
80 |
|
string outputExt; |
81 |
|
|
82 |
|
//Save name of program without its path (and .exe) |
83 |
|
string pn(argv[0]); |
84 |
< |
unsigned int pos; |
84 |
> |
string::size_type pos; |
85 |
|
#ifdef _WIN32 |
86 |
|
pos = pn.find(".exe"); |
87 |
|
if(pos!=string::npos) |
93 |
|
else |
94 |
|
program_name=argv[0]+pos+1; |
95 |
|
|
96 |
< |
const char* p; |
97 |
< |
int arg; |
98 |
< |
for (arg = 1; arg < argc; arg++) |
99 |
< |
{ |
100 |
< |
if (argv[arg]) |
101 |
< |
{ |
102 |
< |
if (argv[arg][0] == '-') |
103 |
< |
{ |
104 |
< |
switch (argv[arg][1]) |
105 |
< |
{ |
96 |
> |
const char* p; |
97 |
> |
int arg; |
98 |
> |
for (arg = 1; arg < argc; ++arg) |
99 |
> |
{ |
100 |
> |
if (argv[arg]) |
101 |
> |
{ |
102 |
> |
if (argv[arg][0] == '-') |
103 |
> |
{ |
104 |
> |
switch (argv[arg][1]) |
105 |
> |
{ |
106 |
|
|
107 |
< |
case 'V': |
108 |
< |
{ |
109 |
< |
cout << "Open Babel " << BABEL_VERSION << " -- " |
110 |
< |
<< __DATE__ << " -- " << __TIME__ << endl; |
111 |
< |
exit(0); |
112 |
< |
} |
107 |
> |
case 'V': |
108 |
> |
{ |
109 |
> |
cout << program_name << ": part of OpenMD " << |
110 |
> |
OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << |
111 |
> |
"." << OPENMD_VERSION_TINY << |
112 |
> |
" and Open Babel " << BABEL_VERSION << " -- " |
113 |
> |
<< __DATE__ << " -- " << __TIME__ << endl; |
114 |
> |
exit(0); |
115 |
> |
} |
116 |
|
|
117 |
< |
case 'i': |
118 |
< |
gotInType = true; |
119 |
< |
iext = argv[arg] + 2; |
120 |
< |
if(!*iext) |
121 |
< |
iext = argv[++arg]; //space left after -i: use next argument |
117 |
> |
case 'i': |
118 |
> |
gotInType = true; |
119 |
> |
iext = argv[arg] + 2; |
120 |
> |
if(!*iext) |
121 |
> |
iext = argv[++arg]; //space left after -i: use next argument |
122 |
|
|
123 |
< |
if (strncasecmp(iext, "MIME", 4) == 0) |
124 |
< |
{ |
125 |
< |
// get the MIME type from the next argument |
126 |
< |
iext = argv[++arg]; |
127 |
< |
pInFormat = Conv.FormatFromMIME(iext); |
128 |
< |
} |
129 |
< |
else |
130 |
< |
{ |
131 |
< |
//The ID provided by the OBFormat class is used as the identifying file extension |
132 |
< |
pInFormat = Conv.FindFormat(iext); |
133 |
< |
} |
134 |
< |
if(pInFormat==NULL) |
135 |
< |
{ |
136 |
< |
cerr << program_name << ": cannot read input format!" << endl; |
137 |
< |
usage(); |
138 |
< |
} |
139 |
< |
inputExt = iext; |
140 |
< |
break; |
123 |
> |
if (strncasecmp(iext, "MIME", 4) == 0) |
124 |
> |
{ |
125 |
> |
// get the MIME type from the next argument |
126 |
> |
iext = argv[++arg]; |
127 |
> |
pInFormat = Conv.FormatFromMIME(iext); |
128 |
> |
} |
129 |
> |
else |
130 |
> |
{ |
131 |
> |
//The ID provided by the OBFormat class is used as the identifying file extension |
132 |
> |
pInFormat = Conv.FindFormat(iext); |
133 |
> |
} |
134 |
> |
if(pInFormat==NULL) |
135 |
> |
{ |
136 |
> |
cerr << program_name << ": cannot read input format!" << endl; |
137 |
> |
usage(); |
138 |
> |
} |
139 |
> |
break; |
140 |
> |
|
141 |
> |
case 'o': |
142 |
> |
gotOutType = true; |
143 |
> |
oext = argv[arg] + 2; |
144 |
> |
if(!*oext) |
145 |
> |
oext = argv[++arg]; //space left after -i: use next argument |
146 |
|
|
147 |
< |
case 'o': |
148 |
< |
gotOutType = true; |
149 |
< |
oext = argv[arg] + 2; |
150 |
< |
if(!*oext) |
151 |
< |
oext = argv[++arg]; //space left after -i: use next argument |
152 |
< |
|
153 |
< |
if (strncasecmp(oext, "MIME", 4) == 0) |
154 |
< |
{ |
148 |
< |
// get the MIME type from the next argument |
149 |
< |
oext = argv[++arg]; |
150 |
< |
pOutFormat = Conv.FormatFromMIME(oext); |
151 |
< |
} |
152 |
< |
else |
153 |
< |
pOutFormat = Conv.FindFormat(oext); |
147 |
> |
if (strncasecmp(oext, "MIME", 4) == 0) |
148 |
> |
{ |
149 |
> |
// get the MIME type from the next argument |
150 |
> |
oext = argv[++arg]; |
151 |
> |
pOutFormat = Conv.FormatFromMIME(oext); |
152 |
> |
} |
153 |
> |
else |
154 |
> |
pOutFormat = Conv.FindFormat(oext); |
155 |
|
|
156 |
< |
if(pOutFormat==NULL) |
157 |
< |
{ |
158 |
< |
cerr << program_name << ": cannot write output format!" << endl; |
159 |
< |
usage(); |
160 |
< |
} |
161 |
< |
outputExt = oext; |
162 |
< |
break; |
163 |
< |
|
164 |
< |
case '?': |
165 |
< |
case 'H': |
166 |
< |
if(isalnum(argv[arg][2])) |
167 |
< |
{ |
168 |
< |
if(strncasecmp(argv[arg]+2,"all",3)) |
169 |
< |
{ |
170 |
< |
OBFormat* pFormat = Conv.FindFormat(argv[arg]+2); |
171 |
< |
if(pFormat) |
172 |
< |
{ |
173 |
< |
cout << argv[arg]+2 << " " << pFormat->Description() << endl; |
174 |
< |
if(strlen(pFormat->SpecificationURL())) |
175 |
< |
cout << "Specification at: " << pFormat->SpecificationURL() << endl; |
176 |
< |
} |
177 |
< |
else |
178 |
< |
cout << "Format type: " << argv[arg]+2 << " was not recognized" <<endl; |
179 |
< |
} |
180 |
< |
else |
181 |
< |
{ |
182 |
< |
Formatpos pos; |
183 |
< |
OBFormat* pFormat; |
184 |
< |
const char* str=NULL; |
185 |
< |
while(OBConversion::GetNextFormat(pos,str,pFormat)) |
186 |
< |
{ |
187 |
< |
if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) |
188 |
< |
continue; |
189 |
< |
cout << str << endl; |
190 |
< |
const char* p = strchr(pFormat->Description(),'\n'); |
191 |
< |
cout << p+1; //second line of description |
192 |
< |
if(strlen(pFormat->SpecificationURL())) |
193 |
< |
cout << "Specification at: " << pFormat->SpecificationURL(); |
194 |
< |
cout << endl << endl; |
195 |
< |
} |
196 |
< |
} |
197 |
< |
} |
198 |
< |
else |
199 |
< |
help(); |
200 |
< |
exit(0); |
156 |
> |
if(pOutFormat==NULL) |
157 |
> |
{ |
158 |
> |
cerr << program_name << ": cannot write output format!" << endl; |
159 |
> |
usage(); |
160 |
> |
} |
161 |
> |
break; |
162 |
> |
|
163 |
> |
/*case 'F': |
164 |
> |
if(!Conv.SetOutFormat("fpt")) |
165 |
> |
cout << "FingerprintFormat needs to be loaded" << endl; |
166 |
> |
else |
167 |
> |
{ |
168 |
> |
Conv.AddOption("F",OBConversion::OUTOPTIONS); |
169 |
> |
Conv.Write(NULL); |
170 |
> |
} |
171 |
> |
return 0; |
172 |
> |
*/ |
173 |
> |
case 'L': //display a list of plugin type or classes |
174 |
> |
{ |
175 |
> |
const char* param=NULL; |
176 |
> |
if(argc>arg+1) |
177 |
> |
param = argv[arg+2]; |
178 |
> |
OBPlugin::List(argv[arg+1], param); |
179 |
> |
return 0; |
180 |
> |
} |
181 |
> |
case '?': |
182 |
> |
case 'H': |
183 |
> |
if(isalnum(argv[arg][2]) || arg==argc-2) |
184 |
> |
{ |
185 |
> |
if(strncasecmp(argv[arg]+2,"all",3)) |
186 |
> |
{ |
187 |
> |
const char* pID= (arg==argc-2) ? argv[arg+1] : argv[arg]+2; |
188 |
> |
OBFormat* pFormat = Conv.FindFormat(pID); |
189 |
> |
if(pFormat) |
190 |
> |
{ |
191 |
> |
cout << pID << " " << pFormat->Description() << endl; |
192 |
> |
if(pFormat->Flags() & NOTWRITABLE) |
193 |
> |
cout << " This format is Read-only" << endl; |
194 |
> |
if(pFormat->Flags() & NOTREADABLE) |
195 |
> |
cout << " This format is Write-only" << endl; |
196 |
> |
|
197 |
> |
if(strlen(pFormat->SpecificationURL())) |
198 |
> |
cout << "Specification at: " << pFormat->SpecificationURL() << endl; |
199 |
> |
} |
200 |
> |
else |
201 |
> |
cout << "Format type: " << pID << " was not recognized" <<endl; |
202 |
> |
} |
203 |
> |
else |
204 |
> |
{ |
205 |
> |
OBPlugin::List("formats","verbose"); |
206 |
> |
} |
207 |
> |
} |
208 |
> |
else |
209 |
> |
help(); |
210 |
> |
return 0; |
211 |
|
|
212 |
+ |
case '-': //long option --name text |
213 |
+ |
{ |
214 |
+ |
//Do nothing if name is empty |
215 |
+ |
//Option's text is the next arg provided it doesn't start with - |
216 |
+ |
char* nam = argv[arg]+2; |
217 |
+ |
if(*nam != '\0') |
218 |
+ |
{ |
219 |
+ |
string txt; |
220 |
+ |
int i; |
221 |
+ |
for(i=0; i<Conv.GetOptionParams(nam, OBConversion::GENOPTIONS) |
222 |
+ |
&& arg<argc-1 && argv[arg+1];++i) //removed && *argv[arg+1]!='-' |
223 |
+ |
{ |
224 |
+ |
if(!txt.empty()) txt+=' '; |
225 |
+ |
txt += argv[++arg]; |
226 |
+ |
} |
227 |
+ |
if(*nam=='-') |
228 |
+ |
{ |
229 |
+ |
// Is a API directive, e.g.---errorlevel |
230 |
+ |
//Send to the pseudoformat "obapi" (without any leading -) |
231 |
+ |
OBConversion apiConv; |
232 |
+ |
OBFormat* pAPI= OBConversion::FindFormat("obapi"); |
233 |
+ |
if(pAPI) |
234 |
+ |
{ |
235 |
+ |
apiConv.SetOutFormat(pAPI); |
236 |
+ |
apiConv.AddOption(nam+1, OBConversion::GENOPTIONS, txt.c_str()); |
237 |
+ |
apiConv.Write(NULL, &std::cout); |
238 |
+ |
} |
239 |
+ |
} |
240 |
+ |
else |
241 |
+ |
// Is a long option name, e.g --addtotitle |
242 |
+ |
Conv.AddOption(nam,OBConversion::GENOPTIONS,txt.c_str()); |
243 |
+ |
} |
244 |
+ |
} |
245 |
+ |
break; |
246 |
|
|
247 |
< |
default: //single character general option |
248 |
< |
p = argv[arg]+1; |
249 |
< |
DoOption(p,Conv,OBConversion::GENOPTIONS,arg,argc,argv); |
250 |
< |
break; |
251 |
< |
} |
252 |
< |
} |
253 |
< |
else |
254 |
< |
{ |
255 |
< |
//filenames |
256 |
< |
if(!gotOutType) |
257 |
< |
FileList.push_back(argv[arg]); |
258 |
< |
else |
259 |
< |
OutputFileName = argv[arg]; |
260 |
< |
} |
261 |
< |
} |
262 |
< |
} |
263 |
< |
|
264 |
< |
//user didn't specify input and output format in commandline option |
265 |
< |
//try to parse it from program name (pdb2mdin means input format is pdb, output format is mdin) |
247 |
> |
case 'm': //multiple output files |
248 |
> |
SplitOrBatch=true; |
249 |
> |
break; |
250 |
> |
|
251 |
> |
case 'a': //single character input option |
252 |
> |
p = argv[arg]+2; |
253 |
> |
DoOption(p,Conv,OBConversion::INOPTIONS,arg,argc,argv); |
254 |
> |
break; |
255 |
> |
|
256 |
> |
case 'x': //single character output option |
257 |
> |
p = argv[arg]+2; |
258 |
> |
DoOption(p,Conv,OBConversion::OUTOPTIONS,arg,argc,argv); |
259 |
> |
break; |
260 |
> |
|
261 |
> |
default: //single character general option |
262 |
> |
p = argv[arg]+1; |
263 |
> |
DoOption(p,Conv,OBConversion::GENOPTIONS,arg,argc,argv); |
264 |
> |
break; |
265 |
> |
} |
266 |
> |
} |
267 |
> |
else |
268 |
> |
{ |
269 |
> |
//filenames |
270 |
> |
if(!gotOutType) |
271 |
> |
FileList.push_back(argv[arg]); |
272 |
> |
else |
273 |
> |
OutputFileName = argv[arg]; |
274 |
> |
} |
275 |
> |
} |
276 |
> |
} |
277 |
> |
|
278 |
> |
// user didn't specify input and output format in commandline option |
279 |
> |
// try to parse it from program name (pdb2md means input format is pdb, |
280 |
> |
// output format is md) |
281 |
> |
|
282 |
|
string formatName(program_name); |
283 |
|
pos = formatName.find_first_of("2"); |
284 |
|
if(pos!=string::npos) { |
285 |
|
if (!gotInType) |
286 |
< |
{ |
286 |
> |
{ |
287 |
|
string tmpExt = formatName.substr(0, pos); |
288 |
|
pInFormat = Conv.FindFormat(tmpExt.c_str()); |
289 |
< |
if(pInFormat==NULL) |
290 |
< |
{ |
291 |
< |
cerr << program_name << ": cannot read input format!" << endl; |
292 |
< |
usage(); |
293 |
< |
} else |
294 |
< |
{ |
289 |
> |
if(pInFormat==NULL) |
290 |
> |
{ |
291 |
> |
cerr << program_name << ": cannot read input format!" << endl; |
292 |
> |
usage(); |
293 |
> |
} else |
294 |
> |
{ |
295 |
|
gotInType = true; |
296 |
|
inputExt = tmpExt; |
297 |
< |
} |
298 |
< |
} |
297 |
> |
} |
298 |
> |
} |
299 |
|
|
300 |
|
if (!gotOutType) |
301 |
< |
{ |
301 |
> |
{ |
302 |
|
string tmpExt = formatName.substr(pos+1, string::npos); |
303 |
|
pOutFormat = Conv.FindFormat(tmpExt.c_str()); |
304 |
< |
if(pOutFormat==NULL) |
305 |
< |
{ |
306 |
< |
cerr << program_name << ": cannot write output format!" << endl; |
307 |
< |
usage(); |
308 |
< |
}else { |
309 |
< |
gotOutType = true; |
310 |
< |
outputExt = tmpExt; |
311 |
< |
} |
304 |
> |
if(pOutFormat==NULL) |
305 |
> |
{ |
306 |
> |
cerr << program_name << ": cannot write output format!" << endl; |
307 |
> |
usage(); |
308 |
> |
}else { |
309 |
> |
gotOutType = true; |
310 |
> |
outputExt = tmpExt; |
311 |
> |
} |
312 |
> |
} |
313 |
> |
} |
314 |
> |
|
315 |
> |
if(!gotOutType) //the last file is the output |
316 |
> |
{ |
317 |
> |
if(FileList.empty()) |
318 |
> |
{ |
319 |
> |
cerr << "No output file or format spec!" << endl; |
320 |
> |
usage(); |
321 |
> |
} |
322 |
> |
OutputFileName = FileList.back(); |
323 |
> |
FileList.pop_back(); |
324 |
|
} |
252 |
– |
} |
325 |
|
|
326 |
< |
if(FileList.empty()) |
326 |
> |
#ifdef _WIN32 |
327 |
> |
//Expand wildcards in input filenames and add to FileList |
328 |
> |
vector<string> tempFileList(FileList); |
329 |
> |
FileList.clear(); |
330 |
> |
vector<string>::iterator itr; |
331 |
> |
for(itr=tempFileList.begin();itr!=tempFileList.end();++itr) |
332 |
> |
DLHandler::findFiles (FileList, *itr); |
333 |
> |
#endif |
334 |
> |
|
335 |
> |
if (!gotInType) |
336 |
|
{ |
337 |
< |
cerr << "No input file or format spec!" <<endl; |
338 |
< |
usage(); |
337 |
> |
if(FileList.empty()) |
338 |
> |
{ |
339 |
> |
cerr << "No input file or format spec!" <<endl; |
340 |
> |
usage(); |
341 |
> |
} |
342 |
|
} |
343 |
|
|
344 |
< |
if (OutputFileName.empty()) |
345 |
< |
{ |
346 |
< |
pos = FileList.front().rfind("."); |
347 |
< |
if(pos==string::npos) |
348 |
< |
OutputFileName = FileList.front()+ "." + outputExt; |
349 |
< |
else |
350 |
< |
OutputFileName = FileList.front().substr(0, pos) + "." + outputExt; |
344 |
> |
if (!gotOutType) |
345 |
> |
{ |
346 |
> |
pOutFormat = Conv.FormatFromExt(OutputFileName.c_str()); |
347 |
> |
if(pOutFormat==NULL) |
348 |
> |
{ |
349 |
> |
cerr << program_name << ": cannot write output format!" << endl; |
350 |
> |
usage(); |
351 |
> |
} |
352 |
|
} |
353 |
|
|
354 |
< |
Conv.SetInAndOutFormats(pInFormat,pOutFormat); |
354 |
> |
if(!Conv.SetInFormat(pInFormat)) |
355 |
> |
{ |
356 |
> |
cerr << "Invalid input format" << endl; |
357 |
> |
usage(); |
358 |
> |
} |
359 |
> |
if(!Conv.SetOutFormat(pOutFormat)) |
360 |
> |
{ |
361 |
> |
cerr << "Invalid output format" << endl; |
362 |
> |
usage(); |
363 |
> |
} |
364 |
|
|
365 |
+ |
if(SplitOrBatch) |
366 |
+ |
{ |
367 |
+ |
//Put * into output file name before extension (or ext.gz) |
368 |
+ |
if(OutputFileName.empty()) |
369 |
+ |
{ |
370 |
+ |
OutputFileName = "*."; |
371 |
+ |
if (oext != NULL) |
372 |
+ |
OutputFileName += oext; |
373 |
+ |
} |
374 |
+ |
else |
375 |
+ |
{ |
376 |
+ |
string::size_type pos = OutputFileName.rfind(".gz"); |
377 |
+ |
if(pos==string::npos) |
378 |
+ |
pos = OutputFileName.rfind('.'); |
379 |
+ |
else |
380 |
+ |
pos = OutputFileName.rfind('.',pos-1); |
381 |
+ |
if(pos==string::npos) |
382 |
+ |
OutputFileName += '*'; |
383 |
+ |
else |
384 |
+ |
OutputFileName.insert(pos,"*"); |
385 |
+ |
} |
386 |
+ |
} |
387 |
|
|
272 |
– |
// send info message to clog -- don't mess up cerr or cout for user programs |
388 |
|
int count = Conv.FullConvert(FileList, OutputFileName, OutputFileList); |
389 |
< |
if ( count == 1 ) |
390 |
< |
clog << count << " molecule converted" << endl; |
391 |
< |
else |
277 |
< |
clog << count << " molecules converted" << endl; |
278 |
< |
|
389 |
> |
|
390 |
> |
Conv.ReportNumberConverted(count); |
391 |
> |
|
392 |
|
if(OutputFileList.size()>1) |
393 |
< |
{ |
394 |
< |
clog << OutputFileList.size() << " files output. The first is " << OutputFileList[0] <<endl; |
395 |
< |
} |
393 |
> |
{ |
394 |
> |
clog << OutputFileList.size() << " files output. The first is " << OutputFileList[0] <<endl; |
395 |
> |
} |
396 |
|
|
397 |
+ |
std::string messageSummary = obErrorLog.GetMessageSummary(); |
398 |
+ |
if (messageSummary.size()) |
399 |
+ |
{ |
400 |
+ |
clog << messageSummary << endl; |
401 |
+ |
} |
402 |
+ |
|
403 |
|
#ifdef _DEBUG |
404 |
|
//CM keep window open |
405 |
|
cout << "Press any key to finish" <<endl; |
409 |
|
return 0; |
410 |
|
} |
411 |
|
|
412 |
< |
void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, int& arg, int argc, char *argv[]) |
412 |
> |
void DoOption(const char* p, OBConversion& Conv, |
413 |
> |
OBConversion::Option_type typ, int& arg, int argc, char *argv[]) |
414 |
|
{ |
415 |
< |
while(p && *p) //can have multiple single char options |
416 |
< |
{ |
417 |
< |
char ch[2]="?"; |
418 |
< |
*ch = *p++; |
419 |
< |
const char* txt=NULL; |
420 |
< |
//Get the option text if needed |
421 |
< |
int nParams = Conv.GetOptionParams(ch, typ); |
422 |
< |
if(nParams) |
423 |
< |
{ |
424 |
< |
if(*p) |
425 |
< |
{ |
426 |
< |
txt = p; //use text immediately following the option letter |
427 |
< |
p=NULL; //no more single char options |
428 |
< |
} |
429 |
< |
else if(arg<argc-1) |
430 |
< |
{ |
431 |
< |
txt = argv[++arg]; //use text from next arg |
432 |
< |
if(*txt=='-') |
433 |
< |
{ |
434 |
< |
//...unless it is another option |
435 |
< |
cerr << "Option -" << ch << " takes a parameter" << endl; |
436 |
< |
exit(0); |
437 |
< |
} |
438 |
< |
} |
439 |
< |
} |
440 |
< |
Conv.AddOption(ch, typ, txt); |
441 |
< |
} |
415 |
> |
while(p && *p) //can have multiple single char options |
416 |
> |
{ |
417 |
> |
char ch[2]="?"; |
418 |
> |
*ch = *p++; |
419 |
> |
const char* txt=NULL; |
420 |
> |
//Get the option text if needed |
421 |
> |
int nParams = Conv.GetOptionParams(ch, typ); |
422 |
> |
if(nParams) |
423 |
> |
{ |
424 |
> |
if(*p) |
425 |
> |
{ |
426 |
> |
txt = p; //use text immediately following the option letter |
427 |
> |
p=NULL; //no more single char options |
428 |
> |
} |
429 |
> |
else if(arg<argc-1) |
430 |
> |
{ |
431 |
> |
txt = argv[++arg]; //use text from next arg |
432 |
> |
if(*txt=='-') |
433 |
> |
{ |
434 |
> |
//...unless it is another option |
435 |
> |
cerr << "Option -" << ch << " takes a parameter" << endl; |
436 |
> |
exit(0); |
437 |
> |
} |
438 |
> |
} |
439 |
> |
} |
440 |
> |
Conv.AddOption(ch, typ, txt); |
441 |
> |
} |
442 |
|
} |
443 |
|
|
444 |
|
void usage() |
445 |
|
{ |
446 |
< |
cout << "Open Babel " << BABEL_VERSION << " -- " << __DATE__ << " -- " |
447 |
< |
<< __TIME__ << endl; |
446 |
> |
cout << program_name << ": part of OpenMD " << |
447 |
> |
OPENMD_VERSION_MAJOR << "." << OPENMD_VERSION_MINOR << "." << |
448 |
> |
OPENMD_VERSION_TINY << " and OpenBabel " << BABEL_VERSION << " -- " |
449 |
> |
<< __DATE__ << " -- " << __TIME__ << endl; |
450 |
|
cout << "Usage: " << program_name |
451 |
|
<< " [-i<input-type>] <name> [-o<output-type>] <name>" << endl; |
452 |
|
cout << "Try -H option for more information." << endl; |
453 |
< |
/* |
453 |
> |
|
454 |
|
#ifdef _DEBUG |
455 |
|
//CM keep window open |
456 |
|
cout << "Press any key to finish" <<endl; |
457 |
|
getch(); |
458 |
|
#endif |
337 |
– |
*/ |
459 |
|
exit (0); |
460 |
|
} |
461 |
|
|
462 |
|
void help() |
463 |
|
{ |
464 |
< |
cout << "Open Babel converts chemical structures from one file format to another"<< endl << endl; |
464 |
> |
cout << program_name << " converts chemical structures from one file format to another"<< endl << endl; |
465 |
|
cout << "Usage: " << program_name << " <input spec> <output spec> [Options]" << endl << endl; |
466 |
|
cout << "Each spec can be a file whose extension decides the format." << endl; |
467 |
|
cout << "Optionally the format can be specified by preceding the file by" << endl; |
479 |
|
|
480 |
|
|
481 |
|
OBFormat* pDefault = OBConversion::GetDefaultFormat(); |
482 |
< |
if(pDefault) |
483 |
< |
cout << pDefault->TargetClassDescription();// some more options probably for OBMol |
482 |
> |
if(pDefault) |
483 |
> |
cout << pDefault->TargetClassDescription();// some more options probably for OBMol |
484 |
|
|
485 |
< |
OBFormat* pAPI= OBConversion::FindFormat("obapi"); |
486 |
< |
if(pAPI) |
487 |
< |
cout << pAPI->Description(); |
488 |
< |
|
489 |
< |
cout << "The following file formats are recognized:" << endl; |
485 |
> |
OBFormat* pAPI= OBConversion::FindFormat("obapi"); |
486 |
> |
if(pAPI) |
487 |
> |
cout << pAPI->Description(); |
488 |
> |
|
489 |
> |
cout << "The following file formats are recognized:" << endl; |
490 |
|
Formatpos pos; |
491 |
|
OBFormat* pFormat; |
492 |
|
const char* str=NULL; |
493 |
|
while(OBConversion::GetNextFormat(pos,str,pFormat)) |
494 |
< |
{ |
495 |
< |
if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) |
496 |
< |
continue; |
497 |
< |
cout << " " << str << endl; |
498 |
< |
} |
494 |
> |
{ |
495 |
> |
if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) |
496 |
> |
continue; |
497 |
> |
cout << " " << str << endl; |
498 |
> |
} |
499 |
|
cout << "\nSee further specific info and options using -H<format-type>, e.g. -Hpdb" << endl; |
500 |
|
} |
501 |
|
|