Skip to content

Commit

Permalink
Orca Interface for Calculations via orca. (#12)
Browse files Browse the repository at this point in the history
Start orca with an orca input file.
Get a JSON file with properties.
Read that file.
  • Loading branch information
gg27fyla authored Jan 14, 2025
1 parent 7379187 commit fd10c9e
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions src/core/orcainterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Created by gerd on 11.12.24.
//

#include "orcainterface.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>

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);
}
51 changes: 51 additions & 0 deletions src/core/orcainterface.h
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "src/core/orcainterface.h"
#include "src/core/eht.h"
#include "src/core/fileiterator.h"
#include "src/core/molecule.h"
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit fd10c9e

Please sign in to comment.