diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a282c5..aff7b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,9 @@ set(curcuma_core_SRC src/tools/formats.h src/tools/geometry.h src/tools/general.h - ) + src/core/orcainterface.h + src/core/orcainterface.cpp +) add_library(curcuma_core ${curcuma_core_SRC}) set(km_SRC diff --git a/src/core/orcainterface.cpp b/src/core/orcainterface.cpp new file mode 100644 index 0000000..a1c9e1b --- /dev/null +++ b/src/core/orcainterface.cpp @@ -0,0 +1,71 @@ +// +// Created by gerd on 11.12.24. +// + +#include "orcainterface.h" +#include +#include +#include +#include + +OrcaInterface::OrcaInterface() { + inputFilePath = "orca.inp"; + outputFilePath = "orca.out"; +} + +OrcaInterface::~OrcaInterface() { + // Optionale Bereinigungsoperationen +} + +void OrcaInterface::setInputFile(const std::string& inputFile) { + inputFilePath = inputFile; +} + +bool OrcaInterface::createInputFile(const std::string& content) { + std::ofstream outFile(inputFilePath); + if (!outFile) { + std::cerr << "Fehler beim Erstellen der Eingabedatei!" << std::endl; + return false; + } + outFile << content; + outFile.close(); + return true; +} + +bool OrcaInterface::executeOrcaProcess() { + // Hier rufen wir das ORCA-Programm über einen Systemaufruf auf + std::stringstream command; + command << "orca " << inputFilePath << " > " << outputFilePath; + int result = std::system(command.str().c_str()); + + // Überprüfen, ob der ORCA-Prozess erfolgreich ausgeführt wurde + return (result == 0); +} + +bool OrcaInterface::runOrca() { + // Starten Sie den ORCA-Prozess und warten Sie auf das Ergebnis + std::cout << "Starte ORCA..." << std::endl; + if (executeOrcaProcess()) { + std::cout << "ORCA abgeschlossen!" << std::endl; + return true; + } else { + std::cerr << "Fehler beim Ausführen von ORCA!" << std::endl; + return false; + } +} + +void OrcaInterface::readOrcaJSON() { + // Liest die Ergebnisse aus der ORCA-Ausgabedatei + std::ifstream property(inputFilePath+".property.json"); + property >> OrcaJSON; +} + +bool OrcaInterface::getOrcaJSON() { + // Hier rufen wir das ORCA_2JSON-Programm über einen Systemaufruf auf + std::stringstream command; + command << "orca_2json " << inputFilePath << " -property >> " << outputFilePath; + const int result = std::system(command.str().c_str()); + + // Überprüfen, ob der ORCA-Prozess erfolgreich ausgeführt wurde + return (result == 0); +} \ No newline at end of file diff --git a/src/core/orcainterface.h b/src/core/orcainterface.h new file mode 100644 index 0000000..4ce3d55 --- /dev/null +++ b/src/core/orcainterface.h @@ -0,0 +1,51 @@ +// +// Created by gerd on 11.12.24. +// + +#pragma once +#ifndef ORCAINTERFACE_H +#define ORCAINTERFACE_H + +#include "src/core/molecule.h" + +static json ORCASettings{ + { "tb_acc", 1 }, + { "tb_max_iter", 250 }, + { "tb_damping", 0.4 }, + { "tb_temp", 9.500e-4 }, + { "tb_verbose", 0 }, + { "tb_guess", "SAD" }, + { "cpcm_solv", "none" }, + { "alpb_solv", "none" }, + { "cpcm_eps", -1 }, + { "alpb_eps", -1 } +}; + +class OrcaInterface { +public: + explicit OrcaInterface(); + ~OrcaInterface(); + + // Setzt die ORCA Eingabedaten + void setInputFile(const std::string& inputFile); + + // Führt ORCA aus und wartet auf die Beendigung + bool runOrca(); + + // Liest die Ergebnisse aus der ORCA-Ausgabedatei + void readOrcaJSON(); + + // Create Output.JSON + bool getOrcaJSON(); + +private: + std::string inputFilePath; + std::string outputFilePath; + json OrcaJSON; + + // Hilfsfunktionen + bool createInputFile(const std::string& content); + bool executeOrcaProcess(); +}; + +#endif //ORCAINTERFACE_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7ca70e8..c8b5820 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,7 @@ * along with this program. If not, see . * */ - +#include "src/core/orcainterface.h" #include "src/core/eht.h" #include "src/core/fileiterator.h" #include "src/core/molecule.h" @@ -1067,6 +1067,24 @@ int main(int argc, char **argv) { std::cout << "Dipole form partial Charges and nonlin. Scaling: " << dipole_nlin.norm() << " [eA] " << dipole_nlin.norm()*4.803 << " [D] " << std::endl; + } else if (strcmp(argv[1], "-orca") == 0) { + + if (argc < 3) { + std::cerr << "Please use curcuma as follows:\ncurcuma -orca input" << std::endl; + return -1; + } + + OrcaInterface orca; + // Eingabedatei zuweisen + orca.setInputFile(argv[2]); + + // ORCA ausführen + if (!orca.runOrca()) { + return -1; + } + // ORCA-Ausgabe lesen + orca.getOrcaJSON(); + orca.readOrcaJSON(); } else if (strcmp(argv[1], "-stride") == 0) {