Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/moleculefile.h
00001 /**********************************************************************
00002   MoleculeFile - Class representing molecule file.
00003 
00004   Copyright (C) 2009 Marcus D. Hanwell, Tim Vandermeersch
00005 
00006   This file is part of the Avogadro molecular editor project.
00007   For more information, see <http://avogadro.openmolecules.net/>
00008 
00009   Avogadro 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; either version 2 of the License, or
00012   (at your option) any later version.
00013 
00014   Avogadro is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with this program; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00022   02110-1301, USA.
00023  **********************************************************************/
00024 
00025 #ifndef MOLECULEFILE_H
00026 #define MOLECULEFILE_H
00027 
00028 #include <avogadro/global.h>
00029 
00030 #include <QString>
00031 #include <QIODevice>
00032 
00033 #include <vector>
00034 #include <Eigen/Core>
00035 
00036 namespace OpenBabel {
00037   class OBMol;
00038 }
00039 
00040 namespace Avogadro {
00041 
00042   class Molecule;
00043 
00044   class MoleculeFilePrivate;
00045   class A_EXPORT MoleculeFile : public QObject
00046   {
00047     Q_OBJECT
00048 
00049       friend class ReadFileThread;
00050 
00051   public:
00052     virtual ~MoleculeFile();
00056     bool isReady() const;
00060     bool isConformerFile() const;
00064     unsigned int numMolecules() const;
00068     QStringList titles() const;
00069 
00071 
00072 
00081     Molecule* molecule(unsigned int i = 0);
00089     OpenBabel::OBMol* OBMol(unsigned int i = 0);
00094     const std::vector<std::vector<Eigen::Vector3d>*>& conformers() const;
00096 
00098 
00099 
00108     bool replaceMolecule(unsigned int i, Molecule *molecule, QString fileName);
00116     bool insertMolecule(unsigned int i, Molecule *molecule, QString fileName);
00123     bool appendMolecule(Molecule *molecule, QString fileName);
00125 
00127 
00128 
00131     const QString& errors() const;
00137     void clearErrors();
00139 
00141 
00142 
00145     const QString &fileName() const
00146     { return m_fileName; }
00147 
00151     const QString &fileType() const
00152     { return m_fileType; }
00153 
00157     const QString &fileOptions() const
00158     { return m_fileOptions; }
00160 
00162 
00163 
00171     static bool canOpen(const QString &fileName, QIODevice::OpenMode mode);
00172       
00183     static Molecule * readMolecule(const QString &fileName,
00184                                    const QString &fileType = QString(),
00185                                    const QString &fileOptions = QString(),
00186                                    QString *error = 0);
00187 
00198     static bool writeMolecule(const Molecule *molecule,
00199                               const QString &fileName,
00200                               const QString &fileType = QString(),
00201                               QString *error = 0)
00202     {
00203       return writeMolecule(molecule, fileName, fileType, QString(), error);
00204     }
00205 
00217     static bool writeMolecule(const Molecule *molecule,
00218                               const QString &fileName,
00219                               const QString &fileType,
00220                               const QString &fileOptions,
00221                               QString *error = 0);
00222 
00234     static bool writeConformers(const Molecule *molecule,
00235                                 const QString &fileName,
00236                                 const QString &fileType = QString(),
00237                                 QString *error = 0);
00238 
00254     static MoleculeFile* readFile(const QString &fileName,
00255                                   const QString &fileType = QString(),
00256                                   const QString &fileOptions = QString(),
00257                                   bool wait = true);
00259 
00260   Q_SIGNALS:
00264     void ready();
00265 
00269     void firstMolReady();
00270 
00271     protected Q_SLOTS:
00272     void threadFinished();
00273   protected:
00274     MoleculeFile(const QString &fileName, const QString &fileType,
00275                  const QString &fileOptions);
00276 
00277     QStringList& titlesRef();
00278     std::vector<std::streampos>& streamposRef();
00279     std::vector<std::vector<Eigen::Vector3d>*>& conformersRef();
00280     void setConformerFile(bool value);
00281     void setReady(bool value);
00282     void setFirstReady(bool value); // used by ReadFileThread
00283 
00284     MoleculeFilePrivate * const d; 
00285     QString m_fileName, m_fileType, m_fileOptions;
00286     QString m_error;
00287     std::vector<std::vector<Eigen::Vector3d>*> m_conformers;
00288   };
00289 
00290 } // End namespace Avogadro
00291 
00292 #endif // MOLECULEFILE_H