Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real-space cutoffs #9

Merged
merged 6 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions include/dftd_cutoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* This file is part of cpp-d4.
*
* Copyright (C) 2019 Sebastian Ehlert, Marvin Friede
*
* cpp-d4 is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cpp-d4 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with cpp-d4. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once

namespace dftd {

// Real space cutoff for CN within D4
static const double cn_default = 30.0;

// Real space cutoff for CN within EEQ
static const double cn_eeq_default = 25.0;

// Two-body interaction cutoff
static const double disp2_default = 60.0;

// Three-body interaction cutoff
static const double disp3_default = 40.0;


// Collection of real space cutoffs.
class TCutoff {
public:
double disp2;
double disp3;
double cn;
double cn_eeq;

explicit TCutoff(
double cut_disp2 = disp2_default,
double cut_disp3 = disp3_default,
double cut_cn = cn_default,
double cut_cn_eeq = cn_eeq_default
);
};

} // namespace dftd
34 changes: 24 additions & 10 deletions include/dftd_dispersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#pragma once

#include "dftd_cutoff.h"
#include "dftd_geometry.h"
#include "dftd_matrix.h"

Expand All @@ -45,13 +46,15 @@ int d4(const TMolecule& mol, int ndim, double wf, double g_a, double g_c,
const TVector<double>& cn, TVector<double>& gw, TMatrix<double>& c6ref);

extern
int edisp(const TMolecule& mol, const TMatrix<double>& dist, const dparam& par,
int ndim, TVector<double>& q,double g_a, double g_c,
TVector<double>& gw, TMatrix<double>& c6ref, bool lmbd,
double& energy);
int edisp(const TMolecule& mol, const TMatrix<double>& dist,
const double cutoff_disp2, const double cutoff_disp3,
const dparam& par, int ndim, TVector<double>& q,
double g_a, double g_c, TVector<double>& gw,
TMatrix<double>& c6ref, bool lmbd, double& energy);

extern
int dispgrad(const TMolecule& mol, const TMatrix<double>& dist,
const double cutoff_disp2, const double cutoff_disp3,
const dparam& par, int ndim, const TVector<double>& q,
TMatrix<double>& dqdr, TVector<double>& cn,
TMatrix<double>& dcndr, double wf, double g_a, double g_c,
Expand All @@ -60,17 +63,28 @@ int dispgrad(const TMolecule& mol, const TMatrix<double>& dist,

extern
int apprabc(const TMolecule& mol, const TMatrix<double>& dist,
const dparam& par, int ndim, TVector<double>& c6ab,
double& energy);
const double cutoff, const dparam& par, int ndim,
TVector<double>& c6ab, double& energy);

extern
int dabcappr(const TMolecule& mol, const TMatrix<double>& dist,
const dparam& par, int ndim, TVector<double>& gw,
TVector<double>& dgw, TMatrix<double>& c6ref,
const double cutoff, const dparam& par, int ndim,
TVector<double>& gw, TVector<double>& dgw, TMatrix<double>& c6ref,
TVector<double>& dc6dr, TVector<double>& dc6dcn, double& energy);

/**
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
*
* @param mol Molecular geometry.
* @param par DFT-D4 parameters.
* @param charge Charge of the molecule.
* @param cutoff Real-space cutoffs for CN and dispersion.
* @param energy Dispersion energy.
* @param GRAD Dispersion gradient.
* @return Exit status.
*/
extern
int DFTVDW_D4(const TMolecule &mol, const dparam &par, const int &charge,
double &energy, double *GRAD);
int get_dispersion(const TMolecule &mol, const dparam &par, const int &charge,
TCutoff cutoff, double &energy, double *GRAD);

} // namespace dftd
41 changes: 20 additions & 21 deletions include/dftd_ncoord.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,34 @@ extern int calc_distances(const TMolecule& mol, TMatrix<double>& dist);
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cn Vector of coordination numbers.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param dcndr Derivative of coordination number.
* @param lgrad Flag for gradient computation.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int get_ncoord_erf(
const TMolecule& mol,
const TMatrix<double>& dist,
const double cutoff,
TVector<double>& cn,
TMatrix<double>& dcndr,
bool lgrad = false,
double thr = 1600.0
bool lgrad = false
);

/**
* Calculate error function coordination number.
*
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
* @param dcndr Derivative of coordination number.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int ncoord_erf(
const TMolecule& mol,
const TMatrix<double>& dist,
TVector<double>& cn,
double thr = 1600.0
const double cutoff,
TVector<double>& cn
);

/**
Expand All @@ -80,17 +79,17 @@ extern int ncoord_erf(
*
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
* @param dcndr Derivative of coordination number.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int dncoord_erf(
const TMolecule& mol,
const TMatrix<double>& dist,
const double cutoff,
TVector<double>& cn,
TMatrix<double>& dcndr,
double thr = 1600.0
TMatrix<double>& dcndr
);


Expand All @@ -99,33 +98,33 @@ extern int dncoord_erf(
*
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int get_ncoord_d4(
const TMolecule& mol,
const TMatrix<double>& dist,
const double cutoff,
TVector<double>& cn,
TMatrix<double>& dcndr,
bool lgrad = false,
double thr = 1600.0
bool lgrad = false
);

/**
* Calculate covalent coordination number for DFT-D4.
*
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int ncoord_d4(
const TMolecule& mol,
const TMatrix<double>& dist,
TVector<double>& cn,
double thr = 1600.0
const double cutoff,
TVector<double>& cn
);


Expand All @@ -135,17 +134,17 @@ extern int ncoord_d4(
*
* @param mol Molecule object.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
* @param dcndr Derivative of coordination number.
* @param thr Real-space cutoff (default: 1600.0).
* @return Exit status.
*/
extern int dncoord_d4(
const TMolecule& mol,
const TMatrix<double>& dist,
const double cutoff,
TVector<double>& cn,
TMatrix<double>& dcndr,
double thr = 1600.0
TMatrix<double>& dcndr
);

/**
Expand All @@ -161,14 +160,14 @@ extern double erf_count(double k, double rr);
* Derivative of the counting function w.r.t. the distance.
*
* @param k Steepness of the counting function.
* @param rr Cutoff radius.
* @param rr TCutoff radius.
* @return Derivative of the counting function.
*/
extern double derf_count(double k, double rr);


/**
* Cutoff function for large coordination numbers
* TCutoff function for large coordination numbers
*
* @param cn_max Maximum CN (not strictly obeyed).
* @param cn On input coordination number, on output modified CN.
Expand Down
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ foreach lib: ['cblas', 'lapacke']
endforeach

srcs = files(
'src/dftd_cutoff.cpp',
'src/dftd_damping.cpp',
'src/dftd_dispersion.cpp',
'src/dftd_eeq.cpp',
'src/dftd_ncoord.cpp',
'src/dftd_damping.cpp',
)

cpp_d4_inc = include_directories('include')
Expand All @@ -53,13 +54,14 @@ cpp_d4_lib = library(
)

install_headers(
'include/dftd_cutoff.h',
'include/dftd_damping.h',
'include/dftd_dispersion.h',
'include/dftd_eeq.h',
'include/dftd_geometry.h',
'include/dftd_matrix.h',
'include/dftd_ncoord.h',
'include/dftd_parameters.h',
'include/dftd_damping.h',
'include/dftd_matrix.h',
'include/dftd_geometry.h',
)

cpp_d4_dep = declare_dependency(
Expand Down
34 changes: 34 additions & 0 deletions src/dftd_cutoff.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* This file is part of cpp-d4.
*
* Copyright (C) 2019 Sebastian Ehlert, Marvin Friede
*
* cpp-d4 is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cpp-d4 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with cpp-d4. If not, see <https://www.gnu.org/licenses/>.
*/
#include "dftd_cutoff.h"

namespace dftd {

TCutoff::TCutoff(
double cut_disp2/* = disp2_default*/,
double cut_disp3/* = disp3_default*/,
double cut_cn/* = cn_default*/,
double cut_cn_eeq/* = cn_eeq_default*/
) {
disp2 = cut_disp2;
disp3 = cut_disp3;
cn = cut_cn;
cn_eeq = cut_cn_eeq;
}

} // namespace dftd
14 changes: 6 additions & 8 deletions src/dftd_damping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
* You should have received a copy of the GNU Lesser General Public License
* along with cpp-d4. If not, see <https://www.gnu.org/licenses/>.
*/

#include "dftd_damping.h"

#include <algorithm>
#include <map>
#include <string>

#include "dftd_damping.h"
#include "dftd_dispersion.h"

namespace dftd {
Expand Down Expand Up @@ -405,8 +403,8 @@ dfunc get_dfunc(std::string name) {
return none;
};

dftd::dparam get_d4eeqbjatm_2019_parameter(dfunc num) {
dftd::dparam par;
dparam get_d4eeqbjatm_2019_parameter(dfunc num) {
dparam par;
double s6{0.0}, s8{0.0}, s10{0.0}, s9{1.0}, a1{0.0}, a2{0.0};
int alp{16};
switch (num) {
Expand Down Expand Up @@ -1116,8 +1114,8 @@ dftd::dparam get_d4eeqbjatm_2019_parameter(dfunc num) {
return par;
}

dftd::dparam get_d4eeqbjmbd_2019_parameter(dfunc num) {
dftd::dparam par;
dparam get_d4eeqbjmbd_2019_parameter(dfunc num) {
dparam par;
double s6{0.0}, s8{0.0}, s10{0.0}, s9{1.0}, a1{0.0}, a2{0.0};
int alp{16};
switch (num) {
Expand Down Expand Up @@ -1661,7 +1659,7 @@ dftd::dparam get_d4eeqbjmbd_2019_parameter(dfunc num) {
return par;
}

void d4par(const std::string func, dftd::dparam& par, const bool lmbd) {
void d4par(const std::string func, dparam& par, const bool lmbd) {
auto num = get_dfunc(func);
if (lmbd) {
par = get_d4eeqbjatm_2019_parameter(num);
Expand Down
Loading