--- trunk/src/applications/atom2md/atom2md.cpp 2006/08/02 18:06:18 1020 +++ trunk/src/applications/atom2md/atom2md.cpp 2008/01/23 03:45:33 1210 @@ -1,12 +1,14 @@ /********************************************************************** -main.cpp - Main conversion program, command-line handling. +atom2md.cpp - OpenBabel-based conversion program to OOPSE MD file, + command-line handling. Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. -Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison -Some portions Copyright (C) 2004-2005 by Chris Morley +Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison +Some portions Copyright (C) 2004-2006 by Chris Morley +Some portions Copyright (C) 2008 by J. Daniel Gezelter -This file is part of the Open Babel project. -For more information, see +This file is part of both the OOPSE and Open Babel projects. +For more information, see and This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,40 +21,37 @@ GNU General Public License for more details. ***********************************************************************/ #include "config.h" -#if HAVE_IOSTREAM - #include -#elif HAVE_IOSTREAM_H - #include + +// used to set import/export for Cygwin DLLs +#ifdef WIN32 +#define USING_OBDLL #endif -#if HAVE_FSTREAM - #include -#elif HAVE_FSTREAM_H - #include -#endif -#if HAVE_SSTREAM - #include -#elif - #include -#endif +#include + +#include +#include +#include + #include #include #if HAVE_CONIO_H #include #endif +#include #if !HAVE_STRNCASECMP extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); #endif -#include "openbabel/obconversion.hpp" -#include "brains/Register.hpp" +#include using namespace std; using namespace OpenBabel; -using namespace oopse; -void DoOption(const char* p, OBConversion& Conv, OBConversion::Option_type typ, - int& arg, int argc, char *argv[]); + +void DoOption(const char* p, OBConversion& Conv, + OBConversion::Option_type typ, int& arg, int argc, + char *argv[]); void usage(); void help(); @@ -61,19 +60,16 @@ int main(int argc,char *argv[]) int main(int argc,char *argv[]) { - registerOBFormats(); OBConversion Conv(&cin, &cout); //default input and output are console -// string GenOptions; OBFormat* pInFormat = NULL; OBFormat* pOutFormat = NULL; vector FileList, OutputFileList; string OutputFileName; -// obMessageLevel filterLevel = obWarning; // 2 out of 5 // Parse commandline bool gotInType = false, gotOutType = false; - bool UseSavedOptions = false; + bool SplitOrBatch=false; char *oext; char *iext; @@ -82,7 +78,7 @@ int main(int argc,char *argv[]) //Save name of program without its path (and .exe) string pn(argv[0]); - unsigned int pos; + string::size_type pos; #ifdef _WIN32 pos = pn.find(".exe"); if(pos!=string::npos) @@ -94,193 +90,296 @@ int main(int argc,char *argv[]) else program_name=argv[0]+pos+1; - const char* p; - int arg; - for (arg = 1; arg < argc; arg++) - { - if (argv[arg]) - { - if (argv[arg][0] == '-') - { - switch (argv[arg][1]) - { + const char* p; + int arg; + for (arg = 1; arg < argc; ++arg) + { + if (argv[arg]) + { + if (argv[arg][0] == '-') + { + switch (argv[arg][1]) + { - case 'V': - { - cout << "Open Babel " << BABEL_VERSION << " -- " - << __DATE__ << " -- " << __TIME__ << endl; - exit(0); - } + case 'V': + { + cout << program_name << ": part of OOPSE " << + OOPSE_VERSION_MAJOR << "." << OOPSE_VERSION_MINOR << + "." << OOPSE_VERSION_TINY << + " and Open Babel " << BABEL_VERSION << " -- " + << __DATE__ << " -- " << __TIME__ << endl; + exit(0); + } - case 'i': - gotInType = true; - iext = argv[arg] + 2; - if(!*iext) - iext = argv[++arg]; //space left after -i: use next argument + case 'i': + gotInType = true; + iext = argv[arg] + 2; + if(!*iext) + iext = argv[++arg]; // space left after -i: use next + // argument - if (strncasecmp(iext, "MIME", 4) == 0) - { - // get the MIME type from the next argument - iext = argv[++arg]; - pInFormat = Conv.FormatFromMIME(iext); - } - else - { - //The ID provided by the OBFormat class is used as the identifying file extension - pInFormat = Conv.FindFormat(iext); - } - if(pInFormat==NULL) - { - cerr << program_name << ": cannot read input format!" << endl; - usage(); - } - inputExt = iext; - break; + if (strncasecmp(iext, "MIME", 4) == 0) + { + // get the MIME type from the next argument + iext = argv[++arg]; + pInFormat = Conv.FormatFromMIME(iext); + } + else + { + // The ID provided by the OBFormat class is used as the + // identifying file extension + pInFormat = Conv.FindFormat(iext); + } + if(pInFormat==NULL) + { + cerr << program_name << ": cannot read input format!" + << endl; + usage(); + } + break; + + case 'o': + gotOutType = true; + oext = argv[arg] + 2; + if(!*oext) + oext = argv[++arg]; // space left after -i: use next + // argument - case 'o': - gotOutType = true; - oext = argv[arg] + 2; - if(!*oext) - oext = argv[++arg]; //space left after -i: use next argument - - if (strncasecmp(oext, "MIME", 4) == 0) - { - // get the MIME type from the next argument - oext = argv[++arg]; - pOutFormat = Conv.FormatFromMIME(oext); - } - else - pOutFormat = Conv.FindFormat(oext); + if (strncasecmp(oext, "MIME", 4) == 0) + { + // get the MIME type from the next argument + oext = argv[++arg]; + pOutFormat = Conv.FormatFromMIME(oext); + } + else + pOutFormat = Conv.FindFormat(oext); - if(pOutFormat==NULL) - { - cerr << program_name << ": cannot write output format!" << endl; - usage(); - } - outputExt = oext; - break; - - case '?': - case 'H': - if(isalnum(argv[arg][2])) - { - if(strncasecmp(argv[arg]+2,"all",3)) - { - OBFormat* pFormat = Conv.FindFormat(argv[arg]+2); - if(pFormat) - { - cout << argv[arg]+2 << " " << pFormat->Description() << endl; - if(strlen(pFormat->SpecificationURL())) - cout << "Specification at: " << pFormat->SpecificationURL() << endl; - } - else - cout << "Format type: " << argv[arg]+2 << " was not recognized" <Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) - continue; - cout << str << endl; - const char* p = strchr(pFormat->Description(),'\n'); - cout << p+1; //second line of description - if(strlen(pFormat->SpecificationURL())) - cout << "Specification at: " << pFormat->SpecificationURL(); - cout << endl << endl; - } - } - } - else - help(); - exit(0); + if(pOutFormat==NULL) + { + cerr << program_name << ": cannot write output format!" + << endl; + usage(); + } + break; + + case 'F': + if(!Conv.SetOutFormat("fpt")) + cout << "FingerprintFormat needs to be loaded" << endl; + else + { + Conv.AddOption("F",OBConversion::OUTOPTIONS); + Conv.Write(NULL); + } + return 0; + + case '?': + case 'H': + if(isalnum(argv[arg][2])) + { + if(strncasecmp(argv[arg]+2,"all",3)) + { + OBFormat* pFormat = Conv.FindFormat(argv[arg]+2); + if(pFormat) + { + cout << argv[arg]+2 << " " << pFormat->Description() << endl; + if(strlen(pFormat->SpecificationURL())) + cout << "Specification at: " << pFormat->SpecificationURL() << endl; + } + else + cout << "Format type: " << argv[arg]+2 << " was not recognized" <Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) + continue; + cout << str << endl; + const char* p = strchr(pFormat->Description(),'\n'); + cout << p+1; //second line of description + if(strlen(pFormat->SpecificationURL())) + cout << "Specification at: " << pFormat->SpecificationURL(); + cout << endl << endl; + } + } + } + else + help(); + exit(0); + + case '-': //long option --name text + { + //Do nothing if name is empty + //Option's text is the next arg provided it doesn't start with - + char* nam = argv[arg]+2; + if(*nam != '\0') + { + string txt; + int i; + for(i=0; iTargetClassDescription()); + pos = objectname.find('\n'); + if(count==1) --pos; + objectname.erase(pos); + pos = objectname.rfind(' '); + if(pos==std::string::npos) + pos=0; + std::clog << count << objectname.substr(pos) << " converted" << endl; if(OutputFileList.size()>1) - { - clog << OutputFileList.size() << " files output. The first is " << OutputFileList[0] <] [-o] " << endl; cout << "Try -H option for more information." << endl; @@ -340,7 +442,7 @@ void help() void help() { - cout << "Open Babel converts chemical structures from one file format to another"<< endl << endl; + cout << program_name << " converts chemical structures from one file format to another"<< endl << endl; cout << "Usage: " << program_name << " [Options]" << endl << endl; cout << "Each spec can be a file whose extension decides the format." << endl; cout << "Optionally the format can be specified by preceding the file by" << endl; @@ -358,23 +460,23 @@ void help() OBFormat* pDefault = OBConversion::GetDefaultFormat(); - if(pDefault) - cout << pDefault->TargetClassDescription();// some more options probably for OBMol + if(pDefault) + cout << pDefault->TargetClassDescription();// some more options probably for OBMol - OBFormat* pAPI= OBConversion::FindFormat("obapi"); - if(pAPI) - cout << pAPI->Description(); - - cout << "The following file formats are recognized:" << endl; + OBFormat* pAPI= OBConversion::FindFormat("obapi"); + if(pAPI) + cout << pAPI->Description(); + + cout << "The following file formats are recognized:" << endl; Formatpos pos; OBFormat* pFormat; const char* str=NULL; while(OBConversion::GetNextFormat(pos,str,pFormat)) - { - if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) - continue; - cout << " " << str << endl; - } + { + if((pFormat->Flags() & NOTWRITABLE) && (pFormat->Flags() & NOTREADABLE)) + continue; + cout << " " << str << endl; + } cout << "\nSee further specific info and options using -H, e.g. -Hpdb" << endl; }