obmolecformat.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 obmolecformat.h - Subclass of OBFormat for conversion of OBMol.
00003 
00004 Copyright (C) 2005 Chris Morley
00005 
00006 This file is part of the Open Babel project.
00007 For more information, see <http://openbabel.sourceforge.net/>
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation version 2 of the License.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 ***********************************************************************/
00018 
00019 #ifndef OB_MOLECULEFORMAT_H
00020 #define OB_MOLECULEFORMAT_H
00021 
00022 #ifdef _WIN32
00023   #include <hash_map>
00024 #endif
00025 
00026 #include <openbabel/mol.h>
00027 #include <openbabel/obconversion.h>
00028 
00029 namespace OpenBabel {
00030 
00031 // This macro is used in DLL builds. If it has not
00032 // been set in babelconfig.h, define it as nothing.
00033 #ifndef OBCOMMON
00034   #define OBCOMMON
00035 #endif
00036 
00050 class OBCOMMON OBMoleculeFormat : public OBFormat
00051 {
00052 private:
00053   static std::map<std::string, OBMol*> IMols;
00054   static OBMol* _jmol; 
00055   static std::vector<OBMol> MolArray; 
00056   static bool StoredMolsReady; 
00057 
00058 public:
00059 
00060   OBMoleculeFormat()
00061   {
00062     OBConversion::RegisterOptionParam("b", this, 0, OBConversion::INOPTIONS);
00063     OBConversion::RegisterOptionParam("s", this, 0, OBConversion::INOPTIONS);
00064     OBConversion::RegisterOptionParam("title", this, 1,OBConversion::GENOPTIONS);
00065     OBConversion::RegisterOptionParam("addtotitle", this, 1,OBConversion::GENOPTIONS);
00066     OBConversion::RegisterOptionParam("property", this, 2, OBConversion::GENOPTIONS);
00067     OBConversion::RegisterOptionParam("C",        this, 0,OBConversion::GENOPTIONS);
00068     OBConversion::RegisterOptionParam("j",        this, 0,OBConversion::GENOPTIONS);
00069     OBConversion::RegisterOptionParam("join",     this, 0,OBConversion::GENOPTIONS);
00070     OBConversion::RegisterOptionParam("separate", this, 0,OBConversion::GENOPTIONS);
00071 
00072     //The follow are OBMol options, which should not be in OBConversion.
00073     //But here isn't entirely appropriate either, since one could have
00074     //OBMol formats loaded but which don't derived from this class.
00075     //However, this possibility is remote.
00076     OBConversion::RegisterOptionParam("s", NULL, 1,OBConversion::GENOPTIONS);
00077     OBConversion::RegisterOptionParam("v", NULL, 1,OBConversion::GENOPTIONS);
00078     OBConversion::RegisterOptionParam("h", NULL, 0,OBConversion::GENOPTIONS);
00079     OBConversion::RegisterOptionParam("d", NULL, 0,OBConversion::GENOPTIONS);
00080     OBConversion::RegisterOptionParam("b", NULL, 0,OBConversion::GENOPTIONS);
00081     OBConversion::RegisterOptionParam("c", NULL, 0,OBConversion::GENOPTIONS);
00082     OBConversion::RegisterOptionParam("p", NULL, 0,OBConversion::GENOPTIONS); 
00083     OBConversion::RegisterOptionParam("t", NULL, 0,OBConversion::GENOPTIONS);
00084     OBConversion::RegisterOptionParam("k", NULL, 0,OBConversion::GENOPTIONS);
00085   };
00086 
00088   static bool ReadChemObjectImpl(OBConversion* pConv, OBFormat*);
00090   static bool WriteChemObjectImpl(OBConversion* pConv, OBFormat*);
00091 
00093   virtual bool ReadChemObject(OBConversion* pConv)
00094   { return ReadChemObjectImpl(pConv, this);}
00095     
00097   virtual bool WriteChemObject(OBConversion* pConv)
00098   { return WriteChemObjectImpl(pConv, this);}
00099   
00101 
00102 
00103 
00104   static bool   DeferMolOutput(OBMol* pmol, OBConversion* pConv, OBFormat* pF);
00106   static bool   OutputDeferredMols(OBConversion* pConv);
00108   static bool   DeleteDeferredMols();
00110   static OBMol* MakeCombinedMolecule(OBMol* pFirst, OBMol* pSecond);
00112 
00113 #ifdef _WIN32
00114   typedef stdext::hash_map<std::string, unsigned> NameIndexType;
00115 #else
00116   typedef std::map<std::string, unsigned> NameIndexType;
00117 #endif
00118   
00119   // documentation in obmolecformat.cpp
00120   static bool   ReadNameIndex(NameIndexType& index, const std::string& datafilename,
00121                   OBFormat* pInFormat);
00122 
00124   const std::type_info& GetType()
00125   {
00126     return typeid(OBMol*);
00127   }
00129 
00130 };
00131 
00132 }
00133 #endif //OB_MOLECULEFORMAT_H
00134