-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a generic output reader - use internal, then cclib, then OB (#1347)
* Add a generic output reader - use internal, then cclib, then OB Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
- Loading branch information
Showing
7 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/****************************************************************************** | ||
This source file is part of the Avogadro project. | ||
This source code is released under the 3-Clause BSD License, (see "LICENSE"). | ||
******************************************************************************/ | ||
|
||
#include "genericoutput.h" | ||
|
||
#include <avogadro/io/fileformat.h> | ||
#include <avogadro/io/fileformatmanager.h> | ||
|
||
#include "gamessus.h" | ||
#include "nwchemlog.h" | ||
#include "orca.h" | ||
|
||
#include <iostream> | ||
|
||
namespace Avogadro::QuantumIO { | ||
|
||
GenericOutput::GenericOutput() {} | ||
|
||
GenericOutput::~GenericOutput() {} | ||
|
||
std::vector<std::string> GenericOutput::fileExtensions() const | ||
{ | ||
std::vector<std::string> extensions; | ||
extensions.emplace_back("out"); | ||
extensions.emplace_back("output"); | ||
extensions.emplace_back("log"); | ||
return extensions; | ||
} | ||
|
||
std::vector<std::string> GenericOutput::mimeTypes() const | ||
{ | ||
return std::vector<std::string>(); | ||
} | ||
|
||
bool GenericOutput::read(std::istream& in, Core::Molecule& molecule) | ||
{ | ||
// check the stream line-by-line until we see the program name | ||
FileFormat* reader = nullptr; | ||
|
||
std::string line; | ||
while (std::getline(in, line)) { | ||
if (line.find("Northwest Computational Chemistry Package") != | ||
std::string::npos) { | ||
// NWChem | ||
reader = new NWChemLog; | ||
break; | ||
} else if (line.find("GAMESS VERSION") != std::string::npos) { | ||
// GAMESS-US .. don't know if we can read Firefly or GAMESS-UK | ||
reader = new GAMESSUSOutput; | ||
break; | ||
} else if (line.find("O R C A") != std::string::npos) { | ||
// ORCA reader | ||
reader = new ORCAOutput; | ||
break; | ||
} | ||
} | ||
|
||
// if we didn't find a program name, check for cclib or OpenBabel | ||
// prefer cclib if it's available | ||
if (reader == nullptr) { | ||
// check what output is available | ||
std::vector<const FileFormat*> readers = | ||
Io::FileFormatManager::instance().fileFormatsFromFileExtension( | ||
"out", FileFormat::File | FileFormat::Read); | ||
|
||
// loop through writers to check for "cclib" or "Open Babel" | ||
for (const FileFormat* r : readers) { | ||
if (r->name() == "cclib") { | ||
reader = r->newInstance(); | ||
break; | ||
} else if (r->identifier().compare(0, 9, "OpenBabel") == 0) { | ||
reader = r->newInstance(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// rewind the stream | ||
in.seekg(0, std::ios::beg); | ||
in.clear(); | ||
|
||
if (reader) { | ||
bool success = reader->readFile(fileName(), molecule); | ||
delete reader; | ||
return success; | ||
} else { | ||
appendError( | ||
"Could not determine the program used to generate this output file."); | ||
delete reader; | ||
return false; | ||
} | ||
} | ||
|
||
} // namespace Avogadro::QuantumIO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/****************************************************************************** | ||
This source file is part of the Avogadro project. | ||
This source code is released under the 3-Clause BSD License, (see "LICENSE"). | ||
******************************************************************************/ | ||
|
||
#ifndef AVOGADRO_QUANTUMIO_GENERICOUTPUT_H | ||
#define AVOGADRO_QUANTUMIO_GENERICOUTPUT_H | ||
|
||
#include "avogadroquantumioexport.h" | ||
#include <avogadro/io/fileformat.h> | ||
|
||
#include <map> | ||
#include <vector> | ||
|
||
namespace Avogadro { | ||
namespace QuantumIO { | ||
|
||
class AVOGADROQUANTUMIO_EXPORT GenericOutput : public Io::FileFormat | ||
{ | ||
public: | ||
GenericOutput(); | ||
~GenericOutput() override; | ||
|
||
Operations supportedOperations() const override | ||
{ | ||
return Read | File | Stream | String; | ||
} | ||
|
||
FileFormat* newInstance() const override { return new GenericOutput; } | ||
std::string identifier() const override { return "Avogadro: Generic Output"; } | ||
std::string name() const override { return "Generic Output"; } | ||
std::string description() const override { return "Generic output format."; } | ||
|
||
std::string specificationUrl() const override { return ""; } | ||
|
||
std::vector<std::string> fileExtensions() const override; | ||
std::vector<std::string> mimeTypes() const override; | ||
|
||
bool read(std::istream& in, Core::Molecule& molecule) override; | ||
bool write(std::ostream&, const Core::Molecule&) override | ||
{ | ||
// Empty, as we do not write output files. | ||
return false; | ||
} | ||
}; | ||
|
||
} // namespace QuantumIO | ||
} // namespace Avogadro | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters