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

Overload important functions for compatibility #37

Merged
merged 3 commits into from
Sep 29, 2024
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
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/software/openblas/**",
"/opt/software/lapack/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
This project is a port of the [`dftd4`](https://github.com/dftd4/dftd4) project
to C++ and provides the D4(EEQ)-ATM method.

**NOTE:** This branch contains some adaptations for compatibility with the ORCA Quantum Chemistry program. This inludes some renaming of variables and functions, and, most notably, the handling of ghost atoms.

## Building This Project

This project is build with `meson`, to setup and perform a build run:
Expand Down
13 changes: 1 addition & 12 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ int main(int argc, char **argv) {
dftd4::TCutoff cutoff;
dftd4::TD4Model d4;

// masking (nothing excluded)
dftd4::TVector<int> realIdx;
realIdx.NewVec(mol.NAtoms);
int nat = 0;
for (int i = 0; i != mol.NAtoms; i++) {
realIdx(i) = nat;
nat++;
}

// analytical gradient
double *d4grad;
if (lgrad) {
Expand All @@ -183,9 +174,7 @@ int main(int argc, char **argv) {
d4grad = nullptr;
}

info = dftd4::get_dispersion(
mol, realIdx, charge, d4, par, cutoff, energy, d4grad
);
info = dftd4::get_dispersion(mol, charge, d4, par, cutoff, energy, d4grad);
if (info != EXIT_SUCCESS) return info;

// Print results
Expand Down
38 changes: 37 additions & 1 deletion include/dftd_dispersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@

namespace dftd4 {

/**
* @brief Container for DFT-D4 damping parameters.
*
* @param s6 C6 damping parameter. Usually 1.
* @param s8 C8 damping parameter.
* @param s10 C10 damping parameter. Always 0 currently.
* @param s9 ATM (three-body) damping parameter. Usually 1.
* @param a1 Becke-Johnson damping parameter.
* @param a2 Becke-Johnson damping parameter.
* @param alp ATM (three-body) damping parameter. Usually 16.
*/
class dparam {
public:
double s6;
Expand All @@ -42,7 +53,32 @@ class dparam {
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
*
* @param mol Molecular geometry.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param charge Molecular charge.
* @param par DFT-D4 parameters.
* @param d4 Base D4 dispersion model.
* @param cutoff Real-space cutoffs for CN and dispersion.
* @param energy Dispersion energy (inout).
* @param GRAD Dispersion gradient (inout).
* @return Exit status.
*/
extern int get_dispersion(
const TMolecule &mol,
int charge,
const TD4Model &d4,
const dparam &par,
TCutoff cutoff,
double &energy,
double *GRAD
);

/**
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
*
* This function calculates the dispersion energy and gradients for the given
* molecular geometry, considering only the atoms specified in `realIdx`.
*
* @param mol Molecular geometry.
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param charge Molecular charge.
* @param par DFT-D4 parameters.
* @param d4 Base D4 dispersion model.
Expand Down
38 changes: 38 additions & 0 deletions include/dftd_eeq.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@

namespace dftd4 {

/**
* Get the EEQ charges for a given molecule.
*
* @param mol The molecule object
* @param dist The distance matrix
* @param charge The total charge of the molecule
* @param cutoff The cutoff for the EEQ coordination number
* @param q The EEQ charges
* @param dqdr The derivative of the EEQ charges
* @param lgrad Flag for the gradient
*
* @return 0 if successful, 1 otherwise
*/
extern int get_charges(
const TMolecule &mol,
const TMatrix<double> &dist,
int charge,
double cutoff,
TVector<double> &q,
TMatrix<double> &dqdr,
bool lgrad
);

/**
* Get the EEQ charges for a given molecule for the atoms specified by the
* indices in `realIdx`.
*
* @param mol The molecule object
* @param realIdx The real atom indices (for excluding dummy atoms)
* @param dist The distance matrix
* @param charge The total charge of the molecule
* @param cutoff The cutoff for the EEQ coordination number
* @param q The EEQ charges
* @param dqdr The derivative of the EEQ charges
* @param lgrad Flag for the gradient
*
* @return 0 if successful, 1 otherwise
*/
extern int get_charges(
const TMolecule &mol,
const TIVector &realIdx,
Expand Down
70 changes: 63 additions & 7 deletions include/dftd_ncoord.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace dftd4 {
* Calculate all distance pairs and store in matrix.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix (inout).
* @return Exit status.
*/
Expand All @@ -42,11 +42,23 @@ extern int calc_distances(
TMatrix<double> &dist
);

/**
* Initialize real indices to all atoms in the molecule.
*
* @param nat Number of atoms in the molecule.
* @param realIdx Vector to store the real indices.
* @return void
*/
void initializeRealIdx(int nat, TVector<int> &realIdx);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/**
* Wrapper for error function coordination number.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cn Vector of coordination numbers.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
Expand All @@ -64,11 +76,31 @@ extern int get_ncoord_erf(
bool lgrad = false
);

/**
* Wrapper for error function coordination number.
*
* @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.
* @return Exit status.
*/
extern int get_ncoord_erf(
const TMolecule &mol,
const TMatrix<double> &dist,
double cutoff,
TVector<double> &cn,
TMatrix<double> &dcndr,
bool lgrad = false
);

/**
* Calculate error function coordination number.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
Expand All @@ -87,7 +119,7 @@ extern int ncoord_erf(
* w.r.t. nuclear coordinates.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
Expand All @@ -103,11 +135,14 @@ extern int dncoord_erf(
TMatrix<double> &dcndr
);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/**
* Wrapper for error function coordination number for DFT-D4.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
Expand All @@ -123,11 +158,29 @@ extern int get_ncoord_d4(
bool lgrad = false
);

/**
* Wrapper for error function 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.
* @return Exit status.
*/
extern int get_ncoord_d4(
const TMolecule &mol,
const TMatrix<double> &dist,
double cutoff,
TVector<double> &cn,
TMatrix<double> &dcndr,
bool lgrad = false
);

/**
* Calculate covalent coordination number for DFT-D4.
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
Expand All @@ -146,7 +199,7 @@ extern int ncoord_d4(
* w.r.t. nuclear coordinates
*
* @param mol Molecule object.
* @param realIdx List for real atoms excluding ghost/non atoms
* @param realIdx List for real atoms excluding ghost/non atoms.
* @param dist Distance matrix.
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
* @param cn Vector of coordination numbers.
Expand All @@ -162,6 +215,9 @@ extern int dncoord_d4(
TMatrix<double> &dcndr
);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/**
* Error function counting function for coordination number contributions.
*
Expand Down
1 change: 1 addition & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Scripts

Scripts for creating the ORCA source files. This mainly concatenates the corresponding files and adds headers and footers. Execute within the `scripts` directory.
This is only useful for ORCA developers.
15 changes: 15 additions & 0 deletions src/dftd_dispersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@

namespace dftd4 {

int get_dispersion(
const TMolecule &mol,
const int charge,
const TD4Model &d4,
const dparam &par,
const TCutoff cutoff,
double &energy,
double *GRAD
) {
TVector<int> realIdx;
initializeRealIdx(mol.NAtoms, realIdx);

return get_dispersion(mol, realIdx, charge, d4, par, cutoff, energy, GRAD);
}

int get_dispersion(
const TMolecule &mol,
const TIVector &realIdx,
Expand Down
15 changes: 15 additions & 0 deletions src/dftd_eeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ static const double pi = 3.1415926535897932384626433832795029;
static const double sqrtpi = std::sqrt(pi);
static const double sqrt2pi = std::sqrt(2.0 / pi);

int get_charges(
const TMolecule &mol,
const TMatrix<double> &dist,
const int charge,
const double cutoff,
TVector<double> &q,
TMatrix<double> &dqdr,
bool lgrad
) {
TIVector realIdx;
initializeRealIdx(mol.NAtoms, realIdx);

return get_charges(mol, realIdx, dist, charge, cutoff, q, dqdr, lgrad);
};

int get_charges(
const TMolecule &mol,
const TIVector &realIdx,
Expand Down
Loading
Loading