Skip to content

Commit

Permalink
add solvation to gfn methods via tblite
Browse files Browse the repository at this point in the history
Signed-off-by: Conrad Huebler <Conrad.Huebler@gmx.net>
  • Loading branch information
conradhuebler committed Nov 27, 2023
1 parent ee0da39 commit 5929000
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
2 changes: 1 addition & 1 deletion external/tblite
Submodule tblite updated 49 files
+1 −0 app/CMakeLists.txt
+184 −2 app/cli.f90
+36 −3 app/cli_help.f90
+1 −0 app/driver.f90
+284 −0 app/driver_guess.f90
+45 −12 app/driver_run.f90
+3 −1 app/main.f90
+1 −0 app/meson.build
+67 −0 include/tblite/container.h
+4 −0 python/tblite/interface.py
+23 −1 python/tblite/library.py
+34 −0 python/tblite/test_interface.py
+2 −0 src/tblite/CMakeLists.txt
+185 −0 src/tblite/api/container.f90
+1 −1 src/tblite/api/context.f90
+26 −0 src/tblite/ceh/CMakeLists.txt
+127 −0 src/tblite/ceh/calculator.f90
+900 −0 src/tblite/ceh/ceh.f90
+33 −0 src/tblite/ceh/h0.f90
+21 −0 src/tblite/ceh/meson.build
+1 −0 src/tblite/data/CMakeLists.txt
+94 −0 src/tblite/data/covrad_ceh.f90
+1 −0 src/tblite/data/meson.build
+510 −0 src/tblite/double_dictionary.f90
+1 −0 src/tblite/integral/CMakeLists.txt
+276 −0 src/tblite/integral/diat_trafo.f90
+196 −1 src/tblite/integral/dipole.f90
+1 −0 src/tblite/integral/meson.build
+225 −1 src/tblite/integral/multipole.f90
+183 −1 src/tblite/integral/overlap.f90
+2 −0 src/tblite/meson.build
+16 −1 src/tblite/ncoord.f90
+2 −0 src/tblite/ncoord/CMakeLists.txt
+216 −0 src/tblite/ncoord/ceh_en.f90
+191 −0 src/tblite/ncoord/ceh_std.f90
+2 −0 src/tblite/ncoord/meson.build
+30 −8 src/tblite/output/ascii.f90
+1 −1 src/tblite/scf/iterator.f90
+1 −1 src/tblite/wavefunction.f90
+1 −1 src/tblite/wavefunction/guess.f90
+0 −1 src/tblite/wavefunction/type.f90
+311 −1 test/api/main.c
+2 −0 test/unit/CMakeLists.txt
+4 −0 test/unit/main.f90
+2 −0 test/unit/meson.build
+351 −0 test/unit/test_ceh.f90
+484 −0 test/unit/test_double_dictionary.f90
+204 −0 test/unit/test_integral_multipole.f90
+225 −0 test/unit/test_integral_overlap.f90
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 5929000

Please sign in to comment.