Skip to content

Commit

Permalink
Merge branch 'master' of github.com:conradhuebler/curcuma
Browse files Browse the repository at this point in the history
  • Loading branch information
conradhuebler committed Dec 1, 2023
2 parents da0d418 + 5929000 commit 2244f88
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
61 changes: 59 additions & 2 deletions src/core/tbliteinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#ifndef tblite_delete
#include "tblite.h"
// #include "tblite/container.h"
#endif

#include "src/core/global.h"
Expand All @@ -36,12 +37,27 @@ TBLiteInterface::TBLiteInterface(const json& tblitesettings)
{
m_tblitesettings = MergeJson(TBLiteSettings, tblitesettings);

m_acc = m_tblitesettings["tb_ac"];
m_acc = m_tblitesettings["tb_acc"];
m_maxiter = m_tblitesettings["tb_max_iter"];
m_damping = m_tblitesettings["tb_damping"];
m_temp = m_tblitesettings["tb_temp"];
m_verbose = m_tblitesettings["tb_verbose"];
std::string guess = m_tblitesettings["tb_guess"];

m_cpcm_eps = m_tblitesettings["cpcm_eps"];
m_alpb_eps = m_tblitesettings["alpb_eps"];

std::string tmp = m_tblitesettings["cpcm_solv"];
m_cpcm = tmp.compare("none") != 0;
m_cpcm_solv = new char[tmp.length() + 1];
strcpy(m_cpcm_solv, tmp.c_str());

tmp = m_tblitesettings["alpb_solv"];
m_alpb = tmp.compare("none") != 0;

m_alpb_solv = new char[tmp.length() + 1];
strcpy(m_alpb_solv, tmp.c_str());

if (guess.compare("SAD") == 0)
m_guess = 0;
else if (guess.compare("EEQ") == 0)
Expand All @@ -63,6 +79,7 @@ TBLiteInterface::~TBLiteInterface()
delete m_tblite_res;
delete m_tblite_mol;
delete m_tblite_calc;
delete m_tb_cont;

delete[] m_coord;
delete[] m_attyp;
Expand Down Expand Up @@ -154,7 +171,47 @@ double TBLiteInterface::GFNCalculation(int parameter, double* grad)
else
tblite_set_calculator_guess(m_ctx, m_tblite_calc, TBLITE_GUESS_EEQ);

tblite_set_calculator_accuracy(m_ctx, m_tblite_calc, 0.01);
int count = m_cpcm + m_cpcm_eps != -1 + m_alpb + m_alpb_eps != -1;
if (count == 1) {
if (m_cpcm && m_cpcm_eps == -1) {
m_tb_cont = tblite_new_cpcm_solvation_solvent(m_ctx, m_tblite_mol, m_tblite_calc, m_cpcm_solv);
if (tblite_check_context(m_ctx)) {
std::cout << "Error during CPCM calculation, ... Sorry for that" << std::endl;
return 0;
}
tblite_calculator_push_back(m_ctx, m_tblite_calc, &m_tb_cont);
} else if (!m_cpcm && m_cpcm_eps != -1) {
m_tb_cont = tblite_new_cpcm_solvation_epsilon(m_ctx, m_tblite_mol, m_tblite_calc, m_cpcm_eps);
if (tblite_check_context(m_ctx)) {
std::cout << "Error during CPCM calculation, ... Sorry for that" << std::endl;
return 0;
}
tblite_calculator_push_back(m_ctx, m_tblite_calc, &m_tb_cont);
}

if (m_alpb && m_alpb_eps == -1) {
m_tb_cont = tblite_new_alpb_solvation_solvent(m_ctx, m_tblite_mol, m_tblite_calc, m_alpb_solv);
if (tblite_check_context(m_ctx)) {
std::cout << "Error during ALPB calculation, ... Sorry for that" << std::endl;
return 0;
}
tblite_calculator_push_back(m_ctx, m_tblite_calc, &m_tb_cont);
} else if (!m_alpb && m_alpb_eps != -1) {
m_tb_cont = tblite_new_alpb_solvation_epsilon(m_ctx, m_tblite_mol, m_tblite_calc, m_alpb_eps);
if (tblite_check_context(m_ctx)) {
std::cout << "Error during ALPB calculation, ... Sorry for that" << std::endl;
return 0;
}
tblite_calculator_push_back(m_ctx, m_tblite_calc, &m_tb_cont);
}
} else {
std::cout << count << std::endl
<< std::endl
<< "If three witches had three watches, which witch would watch which watch?\n Ignoring epsilon and solvent or two solvation models given simultaneously" << std::endl
<< std::endl
<< std::endl;
}
tblite_set_calculator_accuracy(m_ctx, m_tblite_calc, m_acc);
tblite_set_calculator_max_iter(m_ctx, m_tblite_calc, m_maxiter);
tblite_set_calculator_mixer_damping(m_ctx, m_tblite_calc, m_damping);
tblite_set_calculator_temperature(m_ctx, m_tblite_calc, m_temp);
Expand Down
13 changes: 10 additions & 3 deletions src/core/tbliteinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
#include "src/core/molecule.h"

static json TBLiteSettings{
{ "tb_ac", 1 },
{ "tb_acc", 1 },
{ "tb_max_iter", 250 },
{ "tb_damping", 0.4 },
{ "tb_temp", 9.500e-4 },
{ "tb_verbose", 0 },
{ "tb_guess", "SAD" }
{ "tb_guess", "SAD" },
{ "cpcm_solv", "none" },
{ "alpb_solv", "none" },
{ "cpcm_eps", -1 },
{ "alpb_eps", -1 }
};

class UFF;
Expand Down Expand Up @@ -77,12 +81,15 @@ class TBLiteInterface {
int m_guess = 0;
double m_damping = 0.5;
double m_temp = 1000;

double m_cpcm_eps = -1, m_alpb_eps = -1;
char *m_cpcm_solv = "none", *m_alpb_solv = "none";
bool m_cpcm = false, m_alpb = false;
tblite_error m_error = NULL;
tblite_structure m_tblite_mol = NULL;
tblite_result m_tblite_res = NULL;
tblite_context m_ctx = NULL;
tblite_calculator m_tblite_calc = NULL;
tblite_container m_tb_cont = NULL;

bool m_initialised = false;
json m_tblitesettings;
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/tblite_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ int main(int argc, char** argv)
double gradient[3 * 7];
auto error = tblite_new_error();
auto ctx = tblite_new_context();
auto res = tblite_new_result();

auto cont = tblite_container();
auto mol = tblite_new_structure(
error,
natoms,
Expand All @@ -36,6 +35,9 @@ int main(int argc, char** argv)
tblite_set_context_logger(ctx, NULL, NULL);
tblite_set_context_color(ctx, 5);
auto calc = tblite_new_gfn2_calculator(ctx, mol);
cont = tblite_new_cpcm_solvation_solvent(ctx, mol, calc, "ethanol");
auto res = tblite_new_result();

tblite_get_singlepoint(ctx, mol, calc, res);
tblite_get_result_gradient(error, res, gradient);
for (int i = 0; i < 3 * 7; ++i)
Expand All @@ -44,5 +46,6 @@ int main(int argc, char** argv)
delete res;
delete ctx;
delete error;
delete cont;
return 0;
}

0 comments on commit 2244f88

Please sign in to comment.