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 _MSC_VER
00023   #include <hash_map>
00024 #endif
00025 
00026 #if __GNUC__ == 4 && __GNUC_MINOR__ >= 1
00027   #include <tr1/unordered_map>
00028 #elif defined(USE_BOOST)
00029   #include <boost/tr1/unordered_map.hpp>
00030 #endif
00031 
00032 #include <typeinfo>
00033 
00034 #include <openbabel/mol.h>
00035 #ifdef HAVE_SHARED_POINTER
00036   #include <openbabel/reaction.h>
00037 #endif
00038 #include <openbabel/babelconfig.h>
00039 #include <openbabel/obconversion.h>
00040 #include <typeinfo>
00041 #include <openbabel/descriptor.h>
00042 #include <set>
00043 
00044 namespace OpenBabel {
00045 
00046 // This macro is used in DLL builds. If it has not
00047 // been set in babelconfig.h, define it as nothing.
00048 #ifndef OBCOMMON
00049   #define OBCOMMON
00050 #endif
00051 
00066 
00067 
00068 class OBCOMMON OBMoleculeFormat : public OBFormat
00069 {
00070 public:
00071 
00072   OBMoleculeFormat()
00073   {
00074     if(!OptionsRegistered)
00075     {
00076       OptionsRegistered=true;
00077       OBConversion::RegisterOptionParam("b",         this, 0, OBConversion::INOPTIONS);
00078       OBConversion::RegisterOptionParam("s",         this, 0, OBConversion::INOPTIONS);
00079       OBConversion::RegisterOptionParam("title",     this, 1, OBConversion::GENOPTIONS);
00080       OBConversion::RegisterOptionParam("addtotitle",this, 1, OBConversion::GENOPTIONS);
00081       OBConversion::RegisterOptionParam("property",  this, 2, OBConversion::GENOPTIONS);
00082       OBConversion::RegisterOptionParam("C",         this, 0, OBConversion::GENOPTIONS);
00083       OBConversion::RegisterOptionParam("j",         this, 0, OBConversion::GENOPTIONS);
00084       OBConversion::RegisterOptionParam("join",      this, 0, OBConversion::GENOPTIONS);
00085       OBConversion::RegisterOptionParam("separate",  this, 0, OBConversion::GENOPTIONS);
00086 
00087       //The follow are OBMol options, which should not be in OBConversion.
00088       //But here isn't entirely appropriate either, since one could have
00089       //OBMol formats loaded but which don't derived from this class.
00090       //However, this possibility is remote.
00091       OBConversion::RegisterOptionParam("s", NULL, 1,OBConversion::GENOPTIONS);
00092       OBConversion::RegisterOptionParam("v", NULL, 1,OBConversion::GENOPTIONS);
00093       OBConversion::RegisterOptionParam("h", NULL, 0,OBConversion::GENOPTIONS);
00094       OBConversion::RegisterOptionParam("d", NULL, 0,OBConversion::GENOPTIONS);
00095       OBConversion::RegisterOptionParam("b", NULL, 0,OBConversion::GENOPTIONS);
00096       OBConversion::RegisterOptionParam("c", NULL, 0,OBConversion::GENOPTIONS);
00097       OBConversion::RegisterOptionParam("p", NULL, 1,OBConversion::GENOPTIONS); 
00098       OBConversion::RegisterOptionParam("t", NULL, 0,OBConversion::GENOPTIONS);
00099       OBConversion::RegisterOptionParam("k", NULL, 0,OBConversion::GENOPTIONS);
00100       OBConversion::RegisterOptionParam("filter", NULL, 1,OBConversion::GENOPTIONS);
00101       OBConversion::RegisterOptionParam("add", NULL, 1,OBConversion::GENOPTIONS);
00102       OBConversion::RegisterOptionParam("delete", NULL, 1,OBConversion::GENOPTIONS);
00103       OBConversion::RegisterOptionParam("append", NULL, 1,OBConversion::GENOPTIONS);
00104     }
00105   }
00106 
00108   static bool ReadChemObjectImpl(OBConversion* pConv, OBFormat*);
00110   static bool WriteChemObjectImpl(OBConversion* pConv, OBFormat*);
00111 
00113   virtual bool ReadChemObject(OBConversion* pConv)
00114   { return ReadChemObjectImpl(pConv, this);}
00115 
00117   virtual bool WriteChemObject(OBConversion* pConv)
00118   { return WriteChemObjectImpl(pConv, this);}
00119 
00121 
00122 
00123 
00124   static bool   DeferMolOutput(OBMol* pmol, OBConversion* pConv, OBFormat* pF);
00126   static bool   OutputDeferredMols(OBConversion* pConv);
00128   static bool   DeleteDeferredMols();
00130   static OBMol* MakeCombinedMolecule(OBMol* pFirst, OBMol* pSecond);
00132   
00134 
00135 #ifdef HAVE_SHARED_POINTER
00137   static bool OutputMolsFromReaction
00138     (OBReaction* pReact, OBConversion* pConv, OBFormat* pFormat);
00139 #endif
00140 
00141 #ifdef _MSC_VER
00142   typedef stdext::hash_map<std::string, unsigned> NameIndexType;
00143 #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && !defined(__APPLE_CC__)) || defined (USE_BOOST)
00144   typedef std::tr1::unordered_map<std::string, unsigned> NameIndexType;
00145 #else
00146   typedef std::map<std::string, unsigned> NameIndexType;
00147 #endif
00148   
00149   // documentation in obmolecformat.cpp
00150   static bool   ReadNameIndex(NameIndexType& index, const std::string& datafilename,
00151                   OBFormat* pInFormat);
00152 
00154   const std::type_info& GetType()
00155   {
00156     return typeid(OBMol*);
00157   }
00158 
00159 private:
00160 
00161   static bool OptionsRegistered;
00162   static std::map<std::string, OBMol*> IMols;
00163   static OBMol* _jmol; 
00164   static std::vector<OBMol> MolArray; 
00165   static bool StoredMolsReady; 
00166   static OBDescriptor* _pDesc;
00167 
00168 };
00169 
00170 }
00171 #endif //OB_MOLECULEFORMAT_H
00172