From 44f1b1665be40695d456acfcd3240cc400c1e45a Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Mon, 12 Jun 2006 13:23:30 +0000 Subject: [PATCH] Making reading of chemical datafiles work. I created a small OB-wrapper to hide the ugly OB-API svn path=/trunk/KDE/kdeedu/kalzium/src/openbabel2wrapper.cpp; revision=550626 --- kalzium/openbabel2wrapper.cpp | 57 +++++++++++++++++++++++++++++++++++ kalzium/openbabel2wrapper.h | 36 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 kalzium/openbabel2wrapper.cpp create mode 100644 kalzium/openbabel2wrapper.h diff --git a/kalzium/openbabel2wrapper.cpp b/kalzium/openbabel2wrapper.cpp new file mode 100644 index 0000000..b0cb071 --- /dev/null +++ b/kalzium/openbabel2wrapper.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + copyright : (C) 2006 by Carsten Niehaus + email : cniehaus@kde.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "openbabel2wrapper.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include + + +OpenBabel::OBMol* OpenBabel2Wrapper::readMolecule( const QString& filename ) +{ + OpenBabel::OBConversion Conv; + OpenBabel::OBFormat *inFormat = NULL; + + //the OB2 Molecule + OpenBabel::OBMol *mol = new OpenBabel::OBMol; + ifstream inFileStream( filename.toLatin1() ); + if ( !inFileStream ) { + QMessageBox::warning( 0, i18n( "Problem while opening the file" ), + i18n( "Cannot open the specified file." ) ); + return 0; + } + + //find out which format the file has... + inFormat = Conv.FormatFromExt( filename.toLatin1() ); + Conv.SetInAndOutFormats( inFormat,inFormat ); + Conv.Read( mol, &inFileStream ); + + kDebug() << QString::fromLatin1( mol->GetFormula().c_str() ) << " (Weight: " << mol->GetMolWt() << ", Title: "<< mol->GetTitle() << ")" << endl; + + return mol; +} diff --git a/kalzium/openbabel2wrapper.h b/kalzium/openbabel2wrapper.h new file mode 100644 index 0000000..06b108c --- /dev/null +++ b/kalzium/openbabel2wrapper.h @@ -0,0 +1,36 @@ +#ifndef OPENBABEL2WRAPPER_H +#define OPENBABEL2WRAPPER_H +/*************************************************************************** + copyright : (C) 2006 by Carsten Niehaus + email : cniehaus@kde.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +//includes for OpenBabel2 +#include +#include + +#include + +/** + * @author Carsten Niehaus + */ +class OpenBabel2Wrapper +{ + public: + /** + * This class reads the molecule in the file @p filename. It returns 0 if + * the file couldn't be read. + */ + static OpenBabel::OBMol* readMolecule( const QString& filename ); +}; + +#endif // OPENBABEL2WRAPPER_H -- 2.47.3