Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dftd4/cpp-d4
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.0
Choose a base ref
...
head repository: dftd4/cpp-d4
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 3 commits
  • 6 files changed
  • 3 contributors

Commits on Jan 15, 2025

  1. Update info check syntax (#39)

    marvinfriede authored Jan 15, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    63f3b9f View commit details

Commits on Jan 17, 2025

  1. Fix spacing (#40)

    marvinfriede authored Jan 17, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3895196 View commit details

Commits on Jan 21, 2025

  1. Overload get_dispersion for atom-wise energies (#41)

    -Also added a typedef for TRVector
    
    ---------
    
    Co-authored-by: Hagen Neugebauer <[email protected]>
    haneug and Hagen Neugebauer authored Jan 21, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    8a966c0 View commit details
Showing with 67 additions and 12 deletions.
  1. +28 −0 include/dftd_dispersion.h
  2. +1 −0 include/dftd_matrix.h
  3. +1 −1 include/dftd_ncoord.h
  4. +5 −2 scripts/README.md
  5. +31 −8 src/dftd_dispersion.cpp
  6. +1 −1 test/test_grad.cpp
28 changes: 28 additions & 0 deletions include/dftd_dispersion.h
Original file line number Diff line number Diff line change
@@ -71,6 +71,34 @@ extern int get_dispersion(
double *GRAD
);

/**
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
*
* This function calculates the atom-wise 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.
* @param cutoff Real-space cutoffs for CN and dispersion.
* @param energies atom-wise dispersion energies (inout).
* @param GRAD Dispersion gradient (inout).
* @return Exit status.
*/
extern int get_dispersion(
const TMolecule &mol,
const TIVector &realIdx,
int charge,
const TD4Model &d4,
const dparam &par,
TCutoff cutoff,
TRVector &energies,
double *GRAD
);

/**
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
*
1 change: 1 addition & 0 deletions include/dftd_matrix.h
Original file line number Diff line number Diff line change
@@ -231,5 +231,6 @@ template <class T> class TMatrix {
};

typedef TVector<int> TIVector;
typedef TVector<double> TRVector;

} // namespace dftd4
2 changes: 1 addition & 1 deletion include/dftd_ncoord.h
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ extern int calc_distances(
* @param realIdx Vector to store the real indices.
* @return void
*/
void initializeRealIdx(int nat, TVector<int> &realIdx);
extern void initializeRealIdx(int nat, TVector<int> &realIdx);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
7 changes: 5 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 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.
**Important!** This is only useful for ORCA developers.

Scripts for creating the ORCA source files.
This mainly concatenates the corresponding files and adds headers and footers.
Execute within the `scripts` directory.
39 changes: 31 additions & 8 deletions src/dftd_dispersion.cpp
Original file line number Diff line number Diff line change
@@ -59,6 +59,37 @@ int get_dispersion(
double &energy,
double *GRAD
) {

int info{0};

int nat = realIdx.Max() + 1;

TRVector energies; // atom-wise energies
energies.NewVector(nat);

info = get_dispersion(mol, realIdx, charge, d4, par, cutoff, energies, GRAD);
if (info != EXIT_SUCCESS) return info;

// sum up atom-wise energies
for (int i = 0; i != nat; i++) {
energy += energies(i);
}

energies.DelVec();

return EXIT_SUCCESS;
}

int get_dispersion(
const TMolecule &mol,
const TIVector &realIdx,
const int charge,
const TD4Model &d4,
const dparam &par,
const TCutoff cutoff,
TRVector &energies,
double *GRAD
) {
// setup variables
int info{0};
bool lmbd = (par.s9 != 0.0);
@@ -137,8 +168,6 @@ int get_dispersion(

TVector<double> dEdcn;
TVector<double> dEdq;
TVector<double> energies;
energies.NewVector(nat);
if (lgrad) {
dEdcn.NewVector(nat);
dEdq.NewVector(nat);
@@ -242,12 +271,6 @@ int get_dispersion(
dEdcn.DelVec();
dEdq.DelVec();

// sum up atom-wise energies
for (int i = 0; i != nat; i++) {
energy += energies(i);
}
energies.DelVec();

// write to input gradient
if (lgrad) {
for (int i = 0, ii = 0; i != mol.NAtoms; i++) {
2 changes: 1 addition & 1 deletion test/test_grad.cpp
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ int test_numgrad(TMolecule &mol, const int charge, const dparam &par) {
d4grad[i] = 0.0;
}
info = get_dispersion(mol, realIdx, charge, d4, par, cutoff, energy, d4grad);
if (!info == EXIT_SUCCESS) return info;
if (info != EXIT_SUCCESS) return info;

// check translational invariance of analytical gradient
if (is_trans_invar(mol, d4grad) != EXIT_SUCCESS) return EXIT_FAILURE;